CounterControllerTest.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <?php
  2. namespace App\Test\Controller;
  3. use App\Entity\Counter;
  4. use Doctrine\ORM\EntityManagerInterface;
  5. use Doctrine\ORM\EntityRepository;
  6. use Symfony\Bundle\FrameworkBundle\KernelBrowser;
  7. use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
  8. class CounterControllerTest extends WebTestCase
  9. {
  10. private KernelBrowser $client;
  11. private EntityManagerInterface $manager;
  12. private EntityRepository $repository;
  13. private string $path = '/admin/';
  14. protected function setUp(): void
  15. {
  16. $this->client = static::createClient();
  17. $this->manager = static::getContainer()->get('doctrine')->getManager();
  18. $this->repository = $this->manager->getRepository(Counter::class);
  19. foreach ($this->repository->findAll() as $object) {
  20. $this->manager->remove($object);
  21. }
  22. $this->manager->flush();
  23. }
  24. public function testIndex(): void
  25. {
  26. $crawler = $this->client->request('GET', $this->path);
  27. self::assertResponseStatusCodeSame(200);
  28. self::assertPageTitleContains('Counter index');
  29. // Use the $crawler to perform additional assertions e.g.
  30. // self::assertSame('Some text on the page', $crawler->filter('.p')->first());
  31. }
  32. public function testNew(): void
  33. {
  34. $this->markTestIncomplete();
  35. $this->client->request('GET', sprintf('%snew', $this->path));
  36. self::assertResponseStatusCodeSame(200);
  37. $this->client->submitForm('Save', [
  38. 'counter[startTime]' => 'Testing',
  39. 'counter[endTime]' => 'Testing',
  40. 'counter[name]' => 'Testing',
  41. 'counter[state]' => 'Testing',
  42. 'counter[timeToLive]' => 'Testing',
  43. ]);
  44. self::assertResponseRedirects($this->path);
  45. self::assertSame(1, $this->repository->count([]));
  46. }
  47. public function testShow(): void
  48. {
  49. $this->markTestIncomplete();
  50. $fixture = new Counter();
  51. $fixture->setStartTime('My Title');
  52. $fixture->setEndTime('My Title');
  53. $fixture->setName('My Title');
  54. $fixture->setState('My Title');
  55. $fixture->setTimeToLive('My Title');
  56. $this->manager->persist($fixture);
  57. $this->manager->flush();
  58. $this->client->request('GET', sprintf('%s%s', $this->path, $fixture->getId()));
  59. self::assertResponseStatusCodeSame(200);
  60. self::assertPageTitleContains('Counter');
  61. // Use assertions to check that the properties are properly displayed.
  62. }
  63. public function testEdit(): void
  64. {
  65. $this->markTestIncomplete();
  66. $fixture = new Counter();
  67. $fixture->setStartTime('Value');
  68. $fixture->setEndTime('Value');
  69. $fixture->setName('Value');
  70. $fixture->setState('Value');
  71. $fixture->setTimeToLive('Value');
  72. $this->manager->persist($fixture);
  73. $this->manager->flush();
  74. $this->client->request('GET', sprintf('%s%s/edit', $this->path, $fixture->getId()));
  75. $this->client->submitForm('Update', [
  76. 'counter[startTime]' => 'Something New',
  77. 'counter[endTime]' => 'Something New',
  78. 'counter[name]' => 'Something New',
  79. 'counter[state]' => 'Something New',
  80. 'counter[timeToLive]' => 'Something New',
  81. ]);
  82. self::assertResponseRedirects('/admin/');
  83. $fixture = $this->repository->findAll();
  84. self::assertSame('Something New', $fixture[0]->getStartTime());
  85. self::assertSame('Something New', $fixture[0]->getEndTime());
  86. self::assertSame('Something New', $fixture[0]->getName());
  87. self::assertSame('Something New', $fixture[0]->getState());
  88. self::assertSame('Something New', $fixture[0]->getTimeToLive());
  89. }
  90. public function testRemove(): void
  91. {
  92. $this->markTestIncomplete();
  93. $fixture = new Counter();
  94. $fixture->setStartTime('Value');
  95. $fixture->setEndTime('Value');
  96. $fixture->setName('Value');
  97. $fixture->setState('Value');
  98. $fixture->setTimeToLive('Value');
  99. $this->manager->persist($fixture);
  100. $this->manager->flush();
  101. $this->client->request('GET', sprintf('%s%s', $this->path, $fixture->getId()));
  102. $this->client->submitForm('Delete');
  103. self::assertResponseRedirects('/admin/');
  104. self::assertSame(0, $this->repository->count([]));
  105. }
  106. }