|
| 1 | +<?= "<?php\n" ?> |
| 2 | +<?php use Symfony\Bundle\MakerBundle\Str; ?> |
| 3 | + |
| 4 | +namespace <?= $namespace ?>; |
| 5 | + |
| 6 | +<?= $use_statements; ?> |
| 7 | + |
| 8 | +class <?= $class_name ?> extends WebTestCase<?= "\n" ?> |
| 9 | +{ |
| 10 | +<?= $use_typed_properties ? null : " /** @var KernelBrowser */\n" ?> |
| 11 | + private <?= $use_typed_properties ? 'KernelBrowser ' : null ?>$client; |
| 12 | +<?= $use_typed_properties ? null : " /** @var EntityManagerInterface */\n" ?> |
| 13 | + private <?= $use_typed_properties ? 'EntityManagerInterface ' : null ?>$manager; |
| 14 | +<?= $use_typed_properties ? null : " /** @var EntityRepository */\n" ?> |
| 15 | + private <?= $use_typed_properties ? 'EntityRepository ' : null ?>$repository; |
| 16 | + private <?= $use_typed_properties ? 'string ' : null ?>$path = '<?= $route_path; ?>/'; |
| 17 | + |
| 18 | + protected function setUp(): void |
| 19 | + { |
| 20 | + $this->client = static::createClient(); |
| 21 | + $this->manager = (static::getContainer()->get('doctrine'))->getManager(); |
| 22 | + $this->repository = $this->manager->getRepository(<?= $entity_class_name; ?>::class); |
| 23 | + |
| 24 | + foreach ($this->repository->findAll() as $object) { |
| 25 | + $this->manager->remove($object); |
| 26 | + } |
| 27 | + |
| 28 | + $this->manager->flush(); |
| 29 | + } |
| 30 | + |
| 31 | + public function testIndex(): void |
| 32 | + { |
| 33 | + $crawler = $this->client->request('GET', $this->path); |
| 34 | + |
| 35 | + self::assertResponseStatusCodeSame(200); |
| 36 | + self::assertPageTitleContains('<?= ucfirst($entity_var_singular); ?> index'); |
| 37 | + |
| 38 | + // Use the $crawler to perform additional assertions e.g. |
| 39 | + // self::assertSame('Some text on the page', $crawler->filter('.p')->first()); |
| 40 | + } |
| 41 | + |
| 42 | + public function testNew(): void |
| 43 | + { |
| 44 | + $this->markTestIncomplete(); |
| 45 | + $this->client->request('GET', sprintf('%snew', $this->path)); |
| 46 | + |
| 47 | + self::assertResponseStatusCodeSame(200); |
| 48 | + |
| 49 | + $this->client->submitForm('Save', [ |
| 50 | +<?php foreach ($form_fields as $form_field => $typeOptions): ?> |
| 51 | + '<?= $form_field_prefix; ?>[<?= $form_field; ?>]' => 'Testing', |
| 52 | +<?php endforeach; ?> |
| 53 | + ]); |
| 54 | + |
| 55 | + self::assertResponseRedirects('/sweet/food/'); |
| 56 | + |
| 57 | + self::assertSame(1, $this->getRepository()->count([])); |
| 58 | + } |
| 59 | + |
| 60 | + public function testShow(): void |
| 61 | + { |
| 62 | + $this->markTestIncomplete(); |
| 63 | + $fixture = new <?= $entity_class_name; ?>(); |
| 64 | +<?php foreach ($form_fields as $form_field => $typeOptions): ?> |
| 65 | + $fixture->set<?= ucfirst($form_field); ?>('My Title'); |
| 66 | +<?php endforeach; ?> |
| 67 | + |
| 68 | + $this->repository->add($fixture, true); |
| 69 | + |
| 70 | + $this->client->request('GET', sprintf('%s%s', $this->path, $fixture->getId())); |
| 71 | + |
| 72 | + self::assertResponseStatusCodeSame(200); |
| 73 | + self::assertPageTitleContains('<?= ucfirst($entity_var_singular); ?>'); |
| 74 | + |
| 75 | + // Use assertions to check that the properties are properly displayed. |
| 76 | + } |
| 77 | + |
| 78 | + public function testEdit(): void |
| 79 | + { |
| 80 | + $this->markTestIncomplete(); |
| 81 | + $fixture = new <?= $entity_class_name; ?>(); |
| 82 | +<?php foreach ($form_fields as $form_field => $typeOptions): ?> |
| 83 | + $fixture->set<?= ucfirst($form_field); ?>('Value'); |
| 84 | +<?php endforeach; ?> |
| 85 | + |
| 86 | + $this->manager->persist($fixture); |
| 87 | + $this->manager->flush(); |
| 88 | + |
| 89 | + $this->client->request('GET', sprintf('%s%s/edit', $this->path, $fixture->getId())); |
| 90 | + |
| 91 | + $this->client->submitForm('Update', [ |
| 92 | +<?php foreach ($form_fields as $form_field => $typeOptions): ?> |
| 93 | + '<?= $form_field_prefix; ?>[<?= $form_field; ?>]' => 'Something New', |
| 94 | +<?php endforeach; ?> |
| 95 | + ]); |
| 96 | + |
| 97 | + self::assertResponseRedirects('<?= $route_path; ?>/'); |
| 98 | + |
| 99 | + $fixture = $this->repository->findAll(); |
| 100 | + |
| 101 | +<?php foreach ($form_fields as $form_field => $typeOptions): ?> |
| 102 | + self::assertSame('Something New', $fixture[0]->get<?= ucfirst($form_field); ?>()); |
| 103 | +<?php endforeach; ?> |
| 104 | + } |
| 105 | + |
| 106 | + public function testRemove(): void |
| 107 | + { |
| 108 | + $this->markTestIncomplete(); |
| 109 | + $fixture = new <?= $entity_class_name; ?>(); |
| 110 | +<?php foreach ($form_fields as $form_field => $typeOptions): ?> |
| 111 | + $fixture->set<?= ucfirst($form_field); ?>('Value'); |
| 112 | +<?php endforeach; ?> |
| 113 | + |
| 114 | + $$this->manager->remove($fixture); |
| 115 | + $this->manager->flush(); |
| 116 | + |
| 117 | + $this->client->request('GET', sprintf('%s%s', $this->path, $fixture->getId())); |
| 118 | + $this->client->submitForm('Delete'); |
| 119 | + |
| 120 | + self::assertResponseRedirects('<?= $route_path; ?>/'); |
| 121 | + self::assertSame(0, $this->repository->count([])); |
| 122 | + } |
| 123 | +} |
0 commit comments