File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -87,6 +87,28 @@ public function getTestDetails(): \Generator
8787 }),
8888 ];
8989
90+ yield 'it_generates_correct_class_methods ' => [$ this ->createMakerTest ()
91+ ->addExtraDependencies ('symfony/test-pack ' )
92+ ->run (function (MakerTestRunner $ runner ) {
93+ $ runner ->copy (
94+ 'make-crud/Foo.php ' ,
95+ 'src/Entity/Foo.php '
96+ );
97+
98+ $ output = $ runner ->runMaker ([
99+ 'Foo ' , // Entity Class Name
100+ '' , // Default Controller,
101+ 'y ' , // Generate Tests
102+ ]);
103+
104+ $ this ->assertStringContainsString ('src/Controller/FooController.php ' , $ output );
105+ $ this ->assertStringContainsString ('src/Form/FooType.php ' , $ output );
106+ $ this ->assertStringContainsString ('tests/Controller/FooControllerTest.php ' , $ output );
107+
108+ $ this ->runCrudTest ($ runner , 'it_generates_correct_class_methods.php ' );
109+ }),
110+ ];
111+
90112 yield 'it_generates_crud_custom_repository_with_test ' => [$ this ->createMakerTest ()
91113 ->addExtraDependencies ('symfony/test-pack ' )
92114 ->run (function (MakerTestRunner $ runner ) {
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace App \Entity ;
4+
5+ use Doctrine \ORM \Mapping as ORM ;
6+
7+ #[ORM \Entity()]
8+ class Foo
9+ {
10+ #[ORM \Id]
11+ #[ORM \GeneratedValue]
12+ #[ORM \Column()]
13+ private ?int $ id = null ;
14+
15+ #[ORM \Column(length: 255 )]
16+ private ?string $ foo = null ;
17+
18+ #[ORM \Column(length: 255 )]
19+ private ?string $ foo_bar = null ;
20+
21+ public function getId ()
22+ {
23+ return $ this ->id ;
24+ }
25+
26+ public function getFoo (): string
27+ {
28+ return $ this ->foo ;
29+ }
30+
31+ public function setFoo (string $ foo ): self
32+ {
33+ $ this ->foo = $ foo ;
34+
35+ return $ this ;
36+ }
37+
38+ public function getFooBar (): string
39+ {
40+ return $ this ->foo_bar ;
41+ }
42+
43+ public function setFooBar (string $ foo_bar ): self
44+ {
45+ $ this ->foo_bar = $ foo_bar ;
46+
47+ return $ this ;
48+ }
49+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+
4+ namespace App \Tests ;
5+
6+ use Symfony \Bundle \FrameworkBundle \Test \WebTestCase ;
7+
8+ class GeneratedCrudControllerTest extends WebTestCase
9+ {
10+ /**
11+ * Refers to the source folder where all generated files will be placed.
12+ * Facilitates access to src/, templates/ and tests/ folders.
13+ * @var string
14+ */
15+ private string $ rootFolder = __DIR__ . "/.. " ;
16+
17+ public function testGeneratedTestsHasCorrectGettersAndSetters ()
18+ {
19+ $ testFileContent = file_get_contents ($ this ->rootFolder . '/tests/Controller/FooControllerTest.php ' );
20+
21+ $ this ->assertStringContainsString ("getFooBar() " , $ testFileContent );
22+ $ this ->assertMatchesRegularExpression ("/setFooBar(.*)/ " , $ testFileContent );
23+ $ this ->assertStringNotContainsString ("getFoo_bar() " , $ testFileContent );
24+ }
25+ }
You can’t perform that action at this time.
0 commit comments