Skip to content

Commit 1ee3b38

Browse files
committed
add generated file assertions
1 parent 7149e86 commit 1ee3b38

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
@@ -32,8 +32,13 @@ public function getTestDetails(): \Generator
3232
]);
3333

3434
$this->assertContainsCount('created: ', $output, 1);
35-
3635
$this->runControllerTest($runner, 'it_generates_a_controller.php');
36+
37+
// Ensure the generated controller matches what we expect
38+
self::assertSame(
39+
expected: file_get_contents(\dirname(__DIR__).'/fixtures/make-controller/expected/FinalController.php'),
40+
actual: file_get_contents($runner->getPath('src/Controller/FooBarController.php'))
41+
);
3742
}),
3843
];
3944

@@ -49,6 +54,12 @@ public function getTestDetails(): \Generator
4954
self::assertFileExists($controllerPath);
5055

5156
$this->runControllerTest($runner, 'it_generates_a_controller_with_twig.php');
57+
58+
// Ensure the generated controller matches what we expect
59+
self::assertSame(
60+
expected: file_get_contents(\dirname(__DIR__).'/fixtures/make-controller/expected/FinalControllerWithTemplate.php'),
61+
actual: file_get_contents($runner->getPath('src/Controller/FooTwigController.php'))
62+
);
5263
}),
5364
];
5465

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)