Skip to content

Commit ea787b1

Browse files
committed
refactor index test
1 parent d330589 commit ea787b1

File tree

2 files changed

+11
-31
lines changed

2 files changed

+11
-31
lines changed

src/Resources/skeleton/crud/test/Test.tpl.php

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,43 +5,26 @@
55

66
use <?= $entity_full_class_name ?>;
77
use Doctrine\ORM\EntityManager;
8-
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
98
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
109

1110
class <?= $class_name ?> extends WebTestCase<?= "\n" ?>
1211
{
13-
private static ?KernelBrowser $client = null;
14-
15-
private ?EntityManager $entityManager;
16-
17-
protected function setUp(): void
12+
public function testIndex(): void
1813
{
19-
if (null === self::$client) {
20-
self::$client = static::createClient();
21-
}
14+
$client = static::createClient();
2215

23-
$kernel = self::bootKernel();
24-
25-
$this->entityManager = $kernel->getContainer()
26-
->get('doctrine')
27-
->getManager();
28-
}
29-
30-
public function testIndex()
31-
{
32-
$client = self::$client;
3316
$crawler = $client->request('GET', '<?= $route_path ?>/');
3417

35-
$this->assertSame(200, $client->getResponse()->getStatusCode());
36-
$this->assertContains('<!DOCTYPE html>', $client->getResponse()->getContent());
37-
$this->assertContains('<?= $entity_class_name ?> index', $crawler->filter('h1')->text());
18+
self::assertResponseStatusCodeSame(200);
19+
self::assertPageTitleContains('SweetFood index');
3820
}
3921

4022
/**
4123
* @TODO implement new test
4224
*/
4325
public function testNew()
4426
{
27+
$this->markTestIncomplete();
4528
$client = self::$client;
4629
$crawler = $client->request('GET', '<?= $route_path ?>/');
4730
$newLink = $crawler->filter('a:contains("Create new")')->eq(0)->link();
@@ -184,12 +167,4 @@ public function testNew()
184167
// $this->assertNotContains('Delete ipsum', $client->getResponse()->getContent());
185168
<?php endif; ?>
186169
// }
187-
188-
protected function tearDown(): void
189-
{
190-
parent::tearDown();
191-
192-
$this->entityManager->close();
193-
$this->entityManager = null;
194-
}
195170
}

tests/Maker/MakeCrudTest.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,14 @@ public function getTestDetails(): \Generator
6565
}),
6666
];
6767

68-
yield 'crud_basic_tests' => [$this->createMakerTest()
68+
yield 'it_generates_crud_with_tests' => [$this->createMakerTest()
6969
->addExtraDependencies('symfony/css-selector', 'symfony/browser-kit')
7070
->run(function (MakerTestRunner $runner) {
71+
$runner->copy(
72+
'make-crud/SweetFood.php',
73+
'src/Entity/SweetFood.php'
74+
);
75+
7176
$output = $runner->runMaker([
7277
'SweetFood', // Entity Class Name
7378
'', // Default Controller

0 commit comments

Comments
 (0)