1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Tests\Functional\Repository; |
4
|
|
|
|
5
|
|
|
use App\Entity\Performance; |
6
|
|
|
use App\Entity\RepertoireSeason; |
7
|
|
|
use App\Repository\PerformanceRepository; |
8
|
|
|
use App\Repository\RepertoireSeasonRepository; |
9
|
|
|
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; |
10
|
|
|
|
11
|
|
|
class PerformanceRepositoryTest extends WebTestCase |
12
|
|
|
{ |
13
|
|
|
public function testFindAllWithinSeasonsExcept() |
14
|
|
|
{ |
15
|
|
|
self::bootKernel(); |
16
|
|
|
$seasons = self::$container |
17
|
|
|
->get(RepertoireSeasonRepository::class) |
18
|
|
|
->findAll(); |
19
|
|
|
self::assertNotEmpty($seasons); |
20
|
|
|
|
21
|
|
|
/** @var PerformanceRepository $performanceRepository */ |
22
|
|
|
$performanceRepository = self::$container->get(PerformanceRepository::class); |
23
|
|
|
|
24
|
|
|
foreach ($seasons as $season) { |
25
|
|
|
$performances = $performanceRepository->findAllWithinSeasonsExcept($season); |
26
|
|
|
static::assertNotEmpty($performances); |
27
|
|
|
|
28
|
|
|
foreach ($performances as $performance) { |
29
|
|
|
$seasonIds = array_map( |
30
|
|
|
fn (RepertoireSeason $season) => $season->getId(), |
|
|
|
|
31
|
|
|
$performance->getSeasons()->toArray() |
32
|
|
|
); |
33
|
|
|
self::assertNotContains( |
34
|
|
|
$season->getId(), |
35
|
|
|
$seasonIds, |
36
|
|
|
sprintf('Expect that performance %s doesn\'t contain %s season', $performance->getId(), $season->getId()) |
37
|
|
|
); |
38
|
|
|
} |
39
|
|
|
} |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function testFindAllWithinSeasons() |
43
|
|
|
{ |
44
|
|
|
self::bootKernel(); |
45
|
|
|
$performances = self::$container |
46
|
|
|
->get(PerformanceRepository::class) |
47
|
|
|
->findAllWithinSeasons(); |
48
|
|
|
|
49
|
|
|
$this->assertNotEmpty($performances); |
50
|
|
|
$this->allPerformancesHasAtLeastOneSeason($performances); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
private function allPerformancesHasAtLeastOneSeason(array $performances) |
54
|
|
|
{ |
55
|
|
|
$this->assertNotEmpty(array_filter($performances, function (Performance $performance) { |
56
|
|
|
return !$performance->getSeasons()->isEmpty(); |
57
|
|
|
})); |
58
|
|
|
$this->assertEmpty(array_filter($performances, function (Performance $performance) { |
59
|
|
|
return $performance->getSeasons()->isEmpty(); |
60
|
|
|
})); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|