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() |
|
|
|
|
46
|
|
|
{ |
47
|
|
|
$this->restRequest('/api/performances'); |
48
|
|
|
$response = json_decode($this->getSessionClient()->getResponse()->getContent(), true); |
49
|
|
|
|
50
|
|
|
$this->assertEquals( |
51
|
|
|
count($this->getListFields()), |
52
|
|
|
count(array_keys($response)) |
53
|
|
|
); |
54
|
|
|
|
55
|
|
|
foreach ($this->getListFields() as $field) { |
56
|
|
|
$this->assertArrayHasKey($field, $response); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
$firstEntity = array_shift($response['performances']); |
60
|
|
|
|
61
|
|
|
$this->assertEquals( |
62
|
|
|
count($this->getEntityFields()), |
63
|
|
|
count(array_keys($firstEntity)) |
64
|
|
|
); |
65
|
|
|
|
66
|
|
|
foreach ($this->getEntityFields() as $field) { |
67
|
|
|
$this->assertArrayHasKey($field, $firstEntity); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
private function getListFields() |
72
|
|
|
{ |
73
|
|
|
return array ( |
74
|
|
|
'_links', |
75
|
|
|
'page', |
76
|
|
|
'total_count', |
77
|
|
|
'performances', |
78
|
|
|
'count', |
79
|
|
|
); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
private function getEntityFields() |
83
|
|
|
{ |
84
|
|
|
return array ( |
85
|
|
|
'locale', |
86
|
|
|
'title', |
87
|
|
|
'type', |
88
|
|
|
'description', |
89
|
|
|
'premiere', |
90
|
|
|
'mainPicture', |
91
|
|
|
'sliderImage', |
92
|
|
|
'slug', |
93
|
|
|
'created_at', |
94
|
|
|
'updated_at', |
95
|
|
|
'links', |
96
|
|
|
); |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|
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.