|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* EmbeddingDocumentsTest class file |
|
4
|
|
|
*/ |
|
5
|
|
|
|
|
6
|
|
|
namespace Graviton\CoreBundle\Tests\Controller; |
|
7
|
|
|
|
|
8
|
|
|
use GravitonDyn\VersioningEntityBundle\DataFixtures\MongoDB\LoadVersioningEntityData; |
|
9
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
10
|
|
|
use Graviton\TestBundle\Test\RestTestCase; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* @author List of contributors <https://github.com/libgraviton/graviton/graphs/contributors> |
|
14
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GNU Public License |
|
15
|
|
|
* @link http://swisscom.ch |
|
16
|
|
|
*/ |
|
17
|
|
|
class VersioningDocumentsTest extends RestTestCase |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* load fixtures |
|
21
|
|
|
* |
|
22
|
|
|
* @return void |
|
23
|
|
|
*/ |
|
24
|
|
View Code Duplication |
public function setUp() |
|
|
|
|
|
|
25
|
|
|
{ |
|
26
|
|
|
|
|
27
|
|
|
if (!class_exists(LoadVersioningEntityData::class)) { |
|
28
|
|
|
$this->markTestSkipped('Test definitions are not loaded'); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
$this->loadFixtures( |
|
32
|
|
|
[ |
|
33
|
|
|
LoadVersioningEntityData::class |
|
34
|
|
|
], |
|
35
|
|
|
null, |
|
36
|
|
|
'doctrine_mongodb' |
|
37
|
|
|
); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Test Document as embedded |
|
42
|
|
|
* |
|
43
|
|
|
* @return void |
|
44
|
|
|
*/ |
|
45
|
|
View Code Duplication |
public function testPut() |
|
|
|
|
|
|
46
|
|
|
{ |
|
47
|
|
|
// check document |
|
48
|
|
|
$client = static::createRestClient(); |
|
49
|
|
|
$client->request('GET', '/testcase/versioning-entity/one'); |
|
50
|
|
|
$this->assertEquals(Response::HTTP_OK, $client->getResponse()->getStatusCode()); |
|
51
|
|
|
$original = $client->getResults(); |
|
52
|
|
|
/* not working yet ... |
|
53
|
|
|
// Let's change something |
|
54
|
|
|
$original->data = "one-one"; |
|
55
|
|
|
|
|
56
|
|
|
$client = static::createRestClient(); |
|
57
|
|
|
$client->put('/testcase/versioning-entity/one', $original); |
|
58
|
|
|
$this->assertEquals(Response::HTTP_NO_CONTENT, $client->getResponse()->getStatusCode()); |
|
59
|
|
|
|
|
60
|
|
|
$client->request('GET', '/testcase/versioning-entity/one'); |
|
61
|
|
|
$this->assertEquals(Response::HTTP_OK, $client->getResponse()->getStatusCode()); |
|
62
|
|
|
|
|
63
|
|
|
$original2 = $client->getResults(); |
|
64
|
|
|
$this->assertEquals("one-one", $original2->data, json_encode($original2)); |
|
65
|
|
|
$this->assertEquals(2, $original2->version, json_encode($original2)); |
|
66
|
|
|
|
|
67
|
|
|
// Let's change something, version should be possible |
|
68
|
|
|
$original->data = "one"; |
|
69
|
|
|
$original->version = 1; |
|
70
|
|
|
|
|
71
|
|
|
$client = static::createRestClient(); |
|
72
|
|
|
$client->put('/testcase/versioning-entity/one', $original); |
|
73
|
|
|
$this->assertEquals(Response::HTTP_NO_CONTENT, $client->getResponse()->getStatusCode()); |
|
74
|
|
|
$original3 = $client->getResults(); |
|
75
|
|
|
// Version should be updated, not be 1. |
|
76
|
|
|
$this->assertEquals(3, $original3->version, json_encode($original3)); |
|
77
|
|
|
|
|
78
|
|
|
*/ |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|
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.