Skip to content

Commit

Permalink
feature symfony#1597 [make:crud] name repository variable with entity…
Browse files Browse the repository at this point in the history
… 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 <jr@rushlow.dev>
  • Loading branch information
dr-matt-smith and jrushlow authored Sep 27, 2024
1 parent d86730d commit e8d226a
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/Resources/skeleton/crud/test/Test.EntityManager.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
{
private KernelBrowser $client;
private EntityManagerInterface $manager;
private EntityRepository $repository;
private EntityRepository $<?= lcfirst($entity_var_singular); ?>Repository;
private string $path = '<?= $route_path; ?>/';

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

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

Expand Down Expand Up @@ -52,7 +52,7 @@ public function testNew(): void

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

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

public function testShow(): void
Expand Down Expand Up @@ -95,7 +95,7 @@ public function testEdit(): void

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

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

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

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

0 comments on commit e8d226a

Please sign in to comment.