1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* XDynamicKeyControllerTest class file |
4
|
|
|
*/ |
5
|
|
|
|
6
|
|
|
namespace Graviton\CoreBundle\Tests\Controller; |
7
|
|
|
|
8
|
|
|
use Graviton\TestBundle\Test\RestTestCase; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @author List of contributors <https://github.com/libgraviton/graviton/graphs/contributors> |
12
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GNU Public License |
13
|
|
|
* @link http://swisscom.ch |
14
|
|
|
*/ |
15
|
|
|
class XDynamicKeyControllerTest extends RestTestCase |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* load fixtures |
19
|
|
|
* |
20
|
|
|
* @return void |
21
|
|
|
*/ |
22
|
|
View Code Duplication |
public function setUp() |
|
|
|
|
23
|
|
|
{ |
24
|
|
|
if (!class_exists('GravitonDyn\TestCaseXDynamicKeyBundle\DataFixtures\MongoDB\LoadTestCaseXDynamicKeyData')) { |
25
|
|
|
$this->markTestSkipped('LoadTestCaseXDynamicKeyData definition is not loaded'); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
$this->loadFixtures( |
29
|
|
|
[ |
30
|
|
|
'GravitonDyn\TestCaseXDynamicKeyAppBundle\DataFixtures\MongoDB\LoadTestCaseXDynamicKeyAppData', |
31
|
|
|
'GravitonDyn\TestCaseXDynamicKeyBundle\DataFixtures\MongoDB\LoadTestCaseXDynamicKeyData' |
32
|
|
|
], |
33
|
|
|
null, |
34
|
|
|
'doctrine_mongodb' |
35
|
|
|
); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* test that XDynamicKey functionality transforms the output as expected |
40
|
|
|
* |
41
|
|
|
* @return void |
42
|
|
|
*/ |
43
|
|
|
public function testExpectedStructure() |
44
|
|
|
{ |
45
|
|
|
$client = static::createRestClient(); |
46
|
|
|
$client->request('GET', '/testcase/xdynamickey/?sort(+id)'); |
47
|
|
|
$this->assertEquals(200, $client->getResponse()->getStatusCode()); |
48
|
|
|
|
49
|
|
|
$result = $client->getResults(); |
50
|
|
|
// two records |
51
|
|
|
$this->assertEquals(2, count($result)); |
52
|
|
|
// check for the 'apps' keys - those are generated by x-dynamic-key! |
53
|
|
|
$this->assertObjectHasAttribute('someApp', $result[0]->apps); |
54
|
|
|
$this->assertObjectHasAttribute('someOtherApp', $result[0]->apps); |
55
|
|
|
$this->assertObjectHasAttribute('oneMoreApp', $result[0]->apps); |
56
|
|
|
|
57
|
|
|
$this->assertObjectHasAttribute('someOtherApp', $result[1]->apps); |
58
|
|
|
$this->assertObjectHasAttribute('oneMoreApp', $result[1]->apps); |
59
|
|
|
$this->assertObjectNotHasAttribute('someApp', $result[1]->apps); |
60
|
|
|
|
61
|
|
|
$this->assertEquals( |
62
|
|
|
'http://localhost/testcase/xdynamickey-app/someApp', |
63
|
|
|
$result[0]->apps->someApp->app->{'$ref'} |
64
|
|
|
); |
65
|
|
|
$this->assertEquals( |
66
|
|
|
'http://localhost/testcase/xdynamickey-app/someOtherApp', |
67
|
|
|
$result[0]->apps->someOtherApp->app->{'$ref'} |
68
|
|
|
); |
69
|
|
|
$this->assertEquals( |
70
|
|
|
'http://localhost/testcase/xdynamickey-app/oneMoreApp', |
71
|
|
|
$result[0]->apps->oneMoreApp->app->{'$ref'} |
72
|
|
|
); |
73
|
|
|
|
74
|
|
|
$this->assertEquals( |
75
|
|
|
'http://localhost/testcase/xdynamickey-app/someOtherApp', |
76
|
|
|
$result[1]->apps->someOtherApp->app->{'$ref'} |
77
|
|
|
); |
78
|
|
|
$this->assertEquals( |
79
|
|
|
'http://localhost/testcase/xdynamickey-app/oneMoreApp', |
80
|
|
|
$result[1]->apps->oneMoreApp->app->{'$ref'} |
81
|
|
|
); |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|
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.