Skip to content

Commit e8d226a

Browse files
feature #1597 [make:crud] name repository variable with entity prefix when generating tests
* name repository variable with entity prefix Use lower case first version of entity name to name repository variable in the test class e.g. if entity named “Product” then repository variable will be “productRepository” rather than just “repository” this makes copy-paste of setup code from other test classes simpler, when a related entity needs to be created for test cases * fix typo - missing '-' --------- Co-authored-by: Jesse Rushlow <[email protected]>
1 parent d86730d commit e8d226a

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@
99
{
1010
private KernelBrowser $client;
1111
private EntityManagerInterface $manager;
12-
private EntityRepository $repository;
12+
private EntityRepository $<?= lcfirst($entity_var_singular); ?>Repository;
1313
private string $path = '<?= $route_path; ?>/';
1414

1515
protected function setUp(): void
1616
{
1717
$this->client = static::createClient();
1818
$this->manager = static::getContainer()->get('doctrine')->getManager();
19-
$this->repository = $this->manager->getRepository(<?= $entity_class_name; ?>::class);
19+
$this-><?= lcfirst($entity_var_singular); ?>Repository = $this->manager->getRepository(<?= $entity_class_name; ?>::class);
2020

21-
foreach ($this->repository->findAll() as $object) {
21+
foreach ($this-><?= lcfirst($entity_var_singular); ?>Repository->findAll() as $object) {
2222
$this->manager->remove($object);
2323
}
2424

@@ -52,7 +52,7 @@ public function testNew(): void
5252

5353
self::assertResponseRedirects($this->path);
5454

55-
self::assertSame(1, $this->repository->count([]));
55+
self::assertSame(1, $this-><?= lcfirst($entity_var_singular); ?>Repository->count([]));
5656
}
5757

5858
public function testShow(): void
@@ -95,7 +95,7 @@ public function testEdit(): void
9595

9696
self::assertResponseRedirects('<?= $route_path; ?>/');
9797

98-
$fixture = $this->repository->findAll();
98+
$fixture = $this-><?= lcfirst($entity_var_singular); ?>Repository->findAll();
9999

100100
<?php foreach ($form_fields as $form_field => $typeOptions): ?>
101101
self::assertSame('Something New', $fixture[0]->get<?= ucfirst($form_field); ?>());
@@ -117,6 +117,6 @@ public function testRemove(): void
117117
$this->client->submitForm('Delete');
118118

119119
self::assertResponseRedirects('<?= $route_path; ?>/');
120-
self::assertSame(0, $this->repository->count([]));
120+
self::assertSame(0, $this-><?= lcfirst($entity_var_singular); ?>Repository->count([]));
121121
}
122122
}

0 commit comments

Comments
 (0)