1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Tests\Functional\EventListener; |
4
|
|
|
|
5
|
|
|
use App\Entity\Performance; |
6
|
|
|
use App\Entity\PerformanceEvent; |
7
|
|
|
use App\Entity\RepertoireSeason; |
8
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
9
|
|
|
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; |
10
|
|
|
|
11
|
|
|
class AddSeasonSubscriberTest extends WebTestCase |
12
|
|
|
{ |
13
|
|
|
public function testOnFlush() |
14
|
|
|
{ |
15
|
|
|
static::bootKernel(); |
16
|
|
|
$container = self::$container; |
17
|
|
|
$em = $container->get(EntityManagerInterface::class); |
18
|
|
|
$em->getConnection()->beginTransaction(); |
19
|
|
|
|
20
|
|
|
$season = (new RepertoireSeason()) |
21
|
|
|
->setNumber(100500) |
22
|
|
|
->setStartDate(new \DateTime('2199-01-01 00:00:00')) |
23
|
|
|
->setEndDate(new \DateTime('2199-12-31 00:00:00')); |
24
|
|
|
$em->persist($season); |
25
|
|
|
$em->flush(); |
26
|
|
|
|
27
|
|
|
/** @var Performance $performance */ |
28
|
|
|
$performance = $em->getRepository(Performance::class) |
29
|
|
|
->findOneBy([]); |
30
|
|
|
|
31
|
|
|
$this->assertInstanceOf(Performance::class, $performance); |
32
|
|
|
$this->assertNotContains(100500, array_map(function(RepertoireSeason $season) { |
33
|
|
|
return $season->getNumber(); |
34
|
|
|
}, $performance->getSeasons()->toArray())); |
35
|
|
|
|
36
|
|
|
$performanceId = $performance->getId(); |
37
|
|
|
$performanceEvent = (new PerformanceEvent()) |
38
|
|
|
->setPerformance($performance) |
39
|
|
|
->setDateTime(new \DateTime('2199-06-01 00:00:00')) |
40
|
|
|
->setVenue('moon'); |
41
|
|
|
$em->persist($performanceEvent); |
42
|
|
|
$em->flush(); |
43
|
|
|
|
44
|
|
|
$performance = $em->getRepository(Performance::class) |
45
|
|
|
->find($performanceId); |
46
|
|
|
$this->assertContains(100500, array_map(function(RepertoireSeason $season) { |
47
|
|
|
return $season->getNumber(); |
48
|
|
|
}, $performance->getSeasons()->toArray())); |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
|