bankiru /
doctrine-api-client
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 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 | View Code Duplication | public function testSimpleCommit() |
|
|
0 ignored issues
–
show
|
|||
| 12 | { |
||
| 13 | $entity = new TestReference(); |
||
| 14 | |||
| 15 | $this->getClient('test-reference-client')->push( |
||
| 16 | $this->getResponseMock(true, 241), |
||
| 17 | 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 | View Code Duplication | public function testExtendedIdIsSameAsSimpleCommit() |
|
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
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. Loading history...
|
|||
| 39 | { |
||
| 40 | $entity = new TestReference(); |
||
| 41 | |||
| 42 | $this->getClient('test-reference-client')->push( |
||
| 43 | $this->getResponseMock(true, ['id' => 241]), |
||
| 44 | function (RpcRequestInterface $request) { |
||
| 45 | self::assertEquals('test-reference/create', $request->getMethod()); |
||
| 46 | self::assertEquals( |
||
| 47 | [ |
||
| 48 | 'reference-payload' => '', |
||
| 49 | 'owner' => null, |
||
| 50 | ], |
||
| 51 | $request->getParameters() |
||
| 52 | ); |
||
| 53 | |||
| 54 | return true; |
||
| 55 | } |
||
| 56 | ); |
||
| 57 | |||
| 58 | $this->getManager()->persist($entity); |
||
| 59 | $this->getManager()->flush(); |
||
| 60 | |||
| 61 | self::assertNotNull($entity->getId()); |
||
| 62 | self::assertEquals(241, $entity->getId()); |
||
| 63 | } |
||
| 64 | |||
| 65 | public function testChainCommitWithRelation() |
||
| 66 | { |
||
| 67 | $entity = new TestReference(); |
||
| 68 | $parent = new TestEntity(); |
||
| 69 | $entity->setOwner($parent); |
||
| 70 | |||
| 71 | $this->getClient()->push( |
||
| 72 | $this->getResponseMock(true, ['id' => 42]), |
||
| 73 | function (RpcRequestInterface $request) { |
||
| 74 | self::assertEquals('test-entity/create', $request->getMethod()); |
||
| 75 | self::assertEquals( |
||
| 76 | [ |
||
| 77 | 'payload' => '', |
||
| 78 | 'parent' => null, |
||
| 79 | ], |
||
| 80 | $request->getParameters() |
||
| 81 | ); |
||
| 82 | |||
| 83 | return true; |
||
| 84 | } |
||
| 85 | ); |
||
| 86 | |||
| 87 | $this->getClient('test-reference-client')->push( |
||
| 88 | $this->getResponseMock(true, ['id' => 241]), |
||
| 89 | function (RpcRequestInterface $request) { |
||
| 90 | self::assertEquals('test-reference/create', $request->getMethod()); |
||
| 91 | self::assertEquals( |
||
| 92 | [ |
||
| 93 | 'reference-payload' => '', |
||
| 94 | 'owner' => 42, |
||
| 95 | ], |
||
| 96 | $request->getParameters() |
||
| 97 | ); |
||
| 98 | |||
| 99 | return true; |
||
| 100 | } |
||
| 101 | ); |
||
| 102 | |||
| 103 | $this->getManager()->persist($entity); |
||
| 104 | $this->getManager()->persist($parent); |
||
| 105 | $this->getManager()->flush(); |
||
| 106 | |||
| 107 | self::assertNotNull($parent->getId()); |
||
| 108 | self::assertEquals(42, $parent->getId()); |
||
| 109 | |||
| 110 | self::assertNotNull($entity->getId()); |
||
| 111 | self::assertEquals(241, $entity->getId()); |
||
| 112 | |||
| 113 | self::assertEquals($entity->getOwner(), $parent); |
||
| 114 | |||
| 115 | return $entity; |
||
| 116 | } |
||
| 117 | |||
| 118 | public function testChainUpdateWithRelation() |
||
| 119 | { |
||
| 120 | $entity = $this->testChainCommitWithRelation(); |
||
| 121 | |||
| 122 | $oldParent = $entity->getOwner(); |
||
| 123 | $newParent = new TestEntity(); |
||
| 124 | $this->getClient()->push( |
||
| 125 | $this->getResponseMock(true, ['id' => 17]), |
||
| 126 | function (RpcRequestInterface $request) { |
||
| 127 | self::assertEquals('test-entity/create', $request->getMethod()); |
||
| 128 | self::assertEquals( |
||
| 129 | [ |
||
| 130 | 'payload' => '', |
||
| 131 | 'parent' => null, |
||
| 132 | ], |
||
| 133 | $request->getParameters() |
||
| 134 | ); |
||
| 135 | |||
| 136 | return true; |
||
| 137 | } |
||
| 138 | ); |
||
| 139 | $this->getClient('test-reference-client')->push( |
||
| 140 | $this->getResponseMock(true, null), |
||
| 141 | function (RpcRequestInterface $request) { |
||
| 142 | self::assertEquals('test-reference/patch', $request->getMethod()); |
||
| 143 | self::assertEquals( |
||
| 144 | [ |
||
| 145 | 'identifier' => ['id' => 241], |
||
| 146 | 'patch' => ['owner' => 17], |
||
| 147 | ], |
||
| 148 | $request->getParameters() |
||
| 149 | ); |
||
| 150 | |||
| 151 | return true; |
||
| 152 | } |
||
| 153 | ); |
||
| 154 | |||
| 155 | $entity->setOwner($newParent); |
||
| 156 | |||
| 157 | $this->getManager()->persist($newParent); |
||
| 158 | $this->getManager()->flush(); |
||
| 159 | |||
| 160 | self::assertNotNull($newParent->getId()); |
||
| 161 | self::assertEquals(17, $newParent->getId()); |
||
| 162 | |||
| 163 | self::assertNotNull($entity->getId()); |
||
| 164 | self::assertEquals(241, $entity->getId()); |
||
| 165 | |||
| 166 | self::assertEquals($entity->getOwner(), $newParent); |
||
| 167 | |||
| 168 | self::assertNotSame($newParent, $oldParent); |
||
| 169 | self::assertFalse($oldParent->getReferences()->contains($entity)); |
||
| 170 | } |
||
| 171 | |||
| 172 | public function testRemove() |
||
| 173 | { |
||
| 174 | $entity = new TestReference(); |
||
| 175 | |||
| 176 | $this->getClient('test-reference-client')->push($this->getResponseMock(true, 241)); |
||
| 177 | |||
| 178 | $this->getManager()->persist($entity); |
||
| 179 | $this->getManager()->flush(); |
||
| 180 | |||
| 181 | self::assertNotNull($entity->getId()); |
||
| 182 | self::assertEquals(241, $entity->getId()); |
||
| 183 | |||
| 184 | $this->getClient('test-reference-client')->push($this->getResponseMock(true, null)); |
||
| 185 | |||
| 186 | $this->getManager()->remove($entity); |
||
| 187 | $this->getManager()->flush(); |
||
| 188 | } |
||
| 189 | |||
| 190 | protected function getClientNames() |
||
| 191 | { |
||
| 192 | return array_merge(parent::getClientNames(), ['test-reference-client']); |
||
| 193 | } |
||
| 194 | } |
||
| 195 |
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.