Completed
Push — master ( 5507ff...622aad )
by Serhii
01:49
created

PerformancesControllerTest::getFields()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 39

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 39
rs 9.296
c 0
b 0
f 0
1
<?php
2
3
namespace App\Tests\Functional\Controller;
4
5
use App\Entity\Performance;
6
7
class PerformancesControllerTest extends AbstractController
8
{
9
    public function testGetPerformances()
10
    {
11
        $allPerformances = $this->getEm()->getRepository(Performance::class)->findAll();
12
        $repertoryPerformances = $this->getEm()->getRepository('App:Performance')->findBy(['festival' => null]);
13
14
        $this->restRequest('/api/performances?limit=100500');
15
        $response = $this->getSessionClient()->getResponse()->getContent();
16
        $response = json_decode($response);
17
18
        $this->assertEquals($response->count, count($response->performances));
19
        $this->assertEquals(count($repertoryPerformances), $response->count);
20
        // because of festival performances
21
        $this->assertNotEquals(count($allPerformances), $response->count);
22
    }
23
24
    public function testGetPerformancesSlug()
25
    {
26
        $slug = $this->getEm()->getRepository('App:Performance')->findOneBy([])->getSlug();
27
        $this->restRequest('/api/performances/'.$slug);
28
        $this->restRequest('/api/performances/nonexistent-slug', 'GET', 404);
29
    }
30
31
    public function testGetPerformancesSlugRoles()
32
    {
33
        $slug = $this->getEm()->getRepository('App:Performance')->findOneBy([])->getSlug();
34
        $this->restRequest('/api/performances/'.$slug.'/roles');
35
        $this->restRequest('/api/performances/nonexistent-slug/roles', 'GET', 404);
36
    }
37
38
    public function testGetPerformancesSlugPerformanceEvents()
39
    {
40
        $slug = $this->getEm()->getRepository('App:Performance')->findOneBy([])->getSlug();
41
        $this->restRequest('/api/performances/'.$slug.'/performanceevents');
42
        $this->restRequest('/api/performances/nonexistent-slug/performanceevents', 'GET', 404);
43
    }
44
45 View Code Duplication
    public function testPerformancesResponseFields()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
46
    {
47
        $this->restRequest('/api/performances');
48
        $content = $this->getSessionClient()->getResponse()->getContent();
49
        foreach ($this->getFields() as $field) {
50
            $this->assertContains($field, $content);
51
        }
52
    }
53
54
    public function getFields()
55
    {
56
        return [
57
            'performances',
58
            'title',
59
            'type',
60
            'description',
61
            'premiere',
62
            'mainPicture',
63
            'sliderImage',
64
            'performance_small',
65
            'performance_big',
66
            'slider_small',
67
            'slider_slider',
68
            'reference',
69
            'url',
70
            'properties',
71
            'alt',
72
            'title',
73
            'src',
74
            'width',
75
            'height',
76
            'slug',
77
            'created_at',
78
            'updated_at',
79
            'links',
80
            'rel',
81
            'page',
82
            'count',
83
            'total_count',
84
            '_links',
85
            'self',
86
            'first',
87
            'prev',
88
            'next',
89
            'last',
90
            'href',
91
        ];
92
    }
93
}
94