Completed
Pull Request — master (#191)
by Serhii
02:32
created

PerformanceRepositoryTest::testFindAllWithinSeasons()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 1
nc 1
nop 0
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(),
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_VARIABLE, expecting ',' or ')'
Loading history...
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