1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Bankiru\Api\Doctrine\Tests; |
4
|
|
|
|
5
|
|
|
use Bankiru\Api\Doctrine\Test\Entity\TestEntity; |
6
|
|
|
use Bankiru\Api\Doctrine\Test\Entity\TestReference; |
7
|
|
|
use ScayTrase\Api\Rpc\RpcRequestInterface; |
8
|
|
|
|
9
|
|
|
class CommitTest extends AbstractEntityManagerTest |
10
|
|
|
{ |
11
|
|
|
public function testSimpleCommit() |
12
|
|
|
{ |
13
|
|
|
$entity = new TestReference(); |
14
|
|
|
|
15
|
|
|
$this->getClient('test-reference-client')->push( |
16
|
|
|
$this->getResponseMock(true, 241), |
17
|
|
View Code Duplication |
function (RpcRequestInterface $request) { |
|
|
|
|
18
|
|
|
self::assertEquals('test-reference/create', $request->getMethod()); |
19
|
|
|
self::assertEquals( |
20
|
|
|
[ |
21
|
|
|
'reference-payload' => '', |
22
|
|
|
'owner' => null, |
23
|
|
|
], |
24
|
|
|
$request->getParameters() |
25
|
|
|
); |
26
|
|
|
|
27
|
|
|
return true; |
28
|
|
|
} |
29
|
|
|
); |
30
|
|
|
|
31
|
|
|
$this->getManager()->persist($entity); |
32
|
|
|
$this->getManager()->flush(); |
33
|
|
|
|
34
|
|
|
self::assertNotNull($entity->getId()); |
35
|
|
|
self::assertEquals(241, $entity->getId()); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function testChainCommitWithRelation() |
39
|
|
|
{ |
40
|
|
|
$entity = new TestReference(); |
41
|
|
|
$parent = new TestEntity(); |
42
|
|
|
$entity->setOwner($parent); |
43
|
|
|
|
44
|
|
|
$this->getClient()->push($this->getResponseMock(true, 42)); |
45
|
|
|
|
46
|
|
|
$this->getClient('test-reference-client')->push($this->getResponseMock(true, 241)); |
47
|
|
|
|
48
|
|
|
$this->getManager()->persist($entity); |
49
|
|
|
$this->getManager()->persist($parent); |
50
|
|
|
$this->getManager()->flush(); |
51
|
|
|
|
52
|
|
|
self::assertNotNull($parent->getId()); |
53
|
|
|
self::assertEquals(42, $parent->getId()); |
54
|
|
|
|
55
|
|
|
self::assertNotNull($entity->getId()); |
56
|
|
|
self::assertEquals(241, $entity->getId()); |
57
|
|
|
|
58
|
|
|
self::assertEquals($entity->getOwner(), $parent); |
59
|
|
|
|
60
|
|
|
return $entity; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function testChainUpdateWithRelation() |
64
|
|
|
{ |
65
|
|
|
$entity = $this->testChainCommitWithRelation(); |
66
|
|
|
|
67
|
|
|
$oldParent = $entity->getOwner(); |
68
|
|
|
$newParent = new TestEntity(); |
69
|
|
|
$this->getClient()->push($this->getResponseMock(true, 17)); |
70
|
|
|
$this->getClient('test-reference-client')->push($this->getResponseMock(true, null)); |
71
|
|
|
|
72
|
|
|
$entity->setOwner($newParent); |
73
|
|
|
|
74
|
|
|
$this->getManager()->persist($newParent); |
75
|
|
|
$this->getManager()->flush(); |
76
|
|
|
|
77
|
|
|
self::assertNotNull($newParent->getId()); |
78
|
|
|
self::assertEquals(17, $newParent->getId()); |
79
|
|
|
|
80
|
|
|
self::assertNotNull($entity->getId()); |
81
|
|
|
self::assertEquals(241, $entity->getId()); |
82
|
|
|
|
83
|
|
|
self::assertEquals($entity->getOwner(), $newParent); |
84
|
|
|
|
85
|
|
|
self::assertNotSame($newParent, $oldParent); |
86
|
|
|
self::assertFalse($oldParent->getReferences()->contains($entity)); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
public function testRemove() |
90
|
|
|
{ |
91
|
|
|
$entity = new TestReference(); |
92
|
|
|
|
93
|
|
|
$this->getClient('test-reference-client')->push($this->getResponseMock(true, 241)); |
94
|
|
|
|
95
|
|
|
$this->getManager()->persist($entity); |
96
|
|
|
$this->getManager()->flush(); |
97
|
|
|
|
98
|
|
|
self::assertNotNull($entity->getId()); |
99
|
|
|
self::assertEquals(241, $entity->getId()); |
100
|
|
|
|
101
|
|
|
$this->getClient('test-reference-client')->push($this->getResponseMock(true, null)); |
102
|
|
|
|
103
|
|
|
$this->getManager()->remove($entity); |
104
|
|
|
$this->getManager()->flush(); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
protected function getClientNames() |
108
|
|
|
{ |
109
|
|
|
return array_merge(parent::getClientNames(), ['test-reference-client']); |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
|
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.