Skip to content

Commit deb71d3

Browse files
committed
add generated file assertions
1 parent ca3e8c1 commit deb71d3

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed

tests/Maker/MakeControllerTest.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,13 @@ public function getTestDetails(): \Generator
3737
]);
3838

3939
$this->assertContainsCount('created: ', $output, 1);
40-
4140
$this->runControllerTest($runner, 'it_generates_a_controller.php');
41+
42+
// Ensure the generated controller matches what we expect
43+
self::assertSame(
44+
expected: file_get_contents(\dirname(__DIR__).'/fixtures/make-controller/expected/FinalController.php'),
45+
actual: file_get_contents($runner->getPath('src/Controller/FooBarController.php'))
46+
);
4247
}),
4348
];
4449

@@ -66,6 +71,12 @@ public function getTestDetails(): \Generator
6671
self::assertFileExists($controllerPath);
6772

6873
$this->runControllerTest($runner, 'it_generates_a_controller_with_twig.php');
74+
75+
// Ensure the generated controller matches what we expect
76+
self::assertSame(
77+
expected: file_get_contents(\dirname(__DIR__).'/fixtures/make-controller/expected/FinalControllerWithTemplate.php'),
78+
actual: file_get_contents($runner->getPath('src/Controller/FooTwigController.php'))
79+
);
6980
}),
7081
];
7182

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace App\Controller;
4+
5+
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
6+
use Symfony\Component\HttpFoundation\JsonResponse;
7+
use Symfony\Component\Routing\Attribute\Route;
8+
9+
final class FooBarController extends AbstractController
10+
{
11+
#[Route('/foo/bar', name: 'app_foo_bar')]
12+
public function index(): JsonResponse
13+
{
14+
return $this->json([
15+
'message' => 'Welcome to your new controller!',
16+
'path' => 'src/Controller/FooBarController.php',
17+
]);
18+
}
19+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace App\Controller;
4+
5+
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
6+
use Symfony\Component\HttpFoundation\Response;
7+
use Symfony\Component\Routing\Attribute\Route;
8+
9+
final class FooTwigController extends AbstractController
10+
{
11+
#[Route('/foo/twig', name: 'app_foo_twig')]
12+
public function index(): Response
13+
{
14+
return $this->render('foo_twig/index.html.twig', [
15+
'controller_name' => 'FooTwigController',
16+
]);
17+
}
18+
}

0 commit comments

Comments
 (0)