1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* SerializerSelectExclusionStrategyTest class file |
4
|
|
|
*/ |
5
|
|
|
|
6
|
|
|
namespace Graviton\CoreBundle\Tests\Controller; |
7
|
|
|
|
8
|
|
|
use Graviton\TestBundle\Test\RestTestCase; |
9
|
|
|
use Symfony\Component\HttpFoundation\Response; |
10
|
|
|
use GravitonDyn\TestCasePrimitiveArrayBundle\DataFixtures\MongoDB\LoadTestCasePrimitiveArrayData; |
11
|
|
|
use GravitonDyn\TestCaseNullExtrefBundle\DataFixtures\MongoDB\LoadTestCaseNullExtrefData; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @author List of contributors <https://github.com/libgraviton/graviton/graphs/contributors> |
15
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GNU Public License |
16
|
|
|
* @link http://swisscom.ch |
17
|
|
|
*/ |
18
|
|
|
class SerializerSelectExclusionStrategyTest extends RestTestCase |
19
|
|
|
{ |
20
|
|
|
const DATE_FORMAT = 'Y-m-d\\TH:i:sO'; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* load fixtures (in this case we can reuse fixtures from other tests) |
24
|
|
|
* |
25
|
|
|
* @return void |
26
|
|
|
*/ |
27
|
|
|
public function setUp() |
28
|
|
|
{ |
29
|
|
|
if (!class_exists(LoadTestCasePrimitiveArrayData::class)) { |
30
|
|
|
$this->markTestSkipped('TestCasePrimitiveArray definition is not loaded'); |
31
|
|
|
} |
32
|
|
|
if (!class_exists(LoadTestCaseNullExtrefData::class)) { |
33
|
|
|
$this->markTestSkipped('TestCaseNullExtref definition is not loaded'); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
$this->loadFixtures( |
37
|
|
|
[LoadTestCasePrimitiveArrayData::class, LoadTestCaseNullExtrefData::class], |
38
|
|
|
null, |
39
|
|
|
'doctrine_mongodb' |
40
|
|
|
); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Test testRqlSelectionOnArrays testing the correct serialization of nested arrays |
45
|
|
|
* |
46
|
|
|
* @return void |
47
|
|
|
*/ |
48
|
|
View Code Duplication |
public function testRqlSelectionOnArrays() |
|
|
|
|
49
|
|
|
{ |
50
|
|
|
$expectedResult = json_decode( |
51
|
|
|
file_get_contents(dirname(__FILE__).'/../resources/serializer-exclusion-array.json'), |
52
|
|
|
false |
53
|
|
|
); |
54
|
|
|
|
55
|
|
|
$client = static::createRestClient(); |
56
|
|
|
$client->request( |
57
|
|
|
'GET', |
58
|
|
|
'/testcase/primitivearray/testdata?select(hash.strarray,arrayhash.intarray,arrayhash.hasharray)' |
59
|
|
|
); |
60
|
|
|
$this->assertEquals(Response::HTTP_OK, $client->getResponse()->getStatusCode()); |
61
|
|
|
$this->assertEquals($expectedResult, $client->getResults()); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Test testRqlSelectionOnNested testing the correct serialization of deeply nested values |
66
|
|
|
* |
67
|
|
|
* @return void |
68
|
|
|
*/ |
69
|
|
View Code Duplication |
public function testRqlSelectionOnNested() |
|
|
|
|
70
|
|
|
{ |
71
|
|
|
$expectedResult = json_decode( |
72
|
|
|
file_get_contents(dirname(__FILE__).'/../resources/serializer-exclusion-nested.json'), |
73
|
|
|
false |
74
|
|
|
); |
75
|
|
|
|
76
|
|
|
$client = static::createRestClient(); |
77
|
|
|
$client->request( |
78
|
|
|
'GET', |
79
|
|
|
'/testcase/nullextref/testdata?select(requiredExtref,requiredExtrefDeep.deep.deep,optionalExtrefDeep)' |
80
|
|
|
); |
81
|
|
|
$this->assertEquals(Response::HTTP_OK, $client->getResponse()->getStatusCode()); |
82
|
|
|
$this->assertEquals($expectedResult, $client->getResults()); |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|
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.