| @@ 11-33 (lines=23) @@ | ||
| 8 | ||
| 9 | class EntityFactoryTest extends AbstractEntityManagerTest |
|
| 10 | { |
|
| 11 | public function testEntityLoading() |
|
| 12 | { |
|
| 13 | $repository = $this->getManager()->getRepository(TestEntity::class); |
|
| 14 | ||
| 15 | $this->getClient()->push( |
|
| 16 | $this->getResponseMock( |
|
| 17 | true, |
|
| 18 | (object)[ |
|
| 19 | 'id' => '1', |
|
| 20 | 'payload' => 'test-payload', |
|
| 21 | ] |
|
| 22 | ||
| 23 | ) |
|
| 24 | ); |
|
| 25 | ||
| 26 | /** @var TestEntity $entity */ |
|
| 27 | $entity = $repository->find(1); |
|
| 28 | ||
| 29 | self::assertInstanceOf(TestEntity::class, $entity); |
|
| 30 | self::assertEquals(1, $entity->getId()); |
|
| 31 | self::assertInternalType('int', $entity->getId()); |
|
| 32 | self::assertEquals('test-payload', $entity->getPayload()); |
|
| 33 | } |
|
| 34 | ||
| 35 | public function testInheritanceLoading() |
|
| 36 | { |
|
| @@ 35-56 (lines=22) @@ | ||
| 32 | self::assertEquals('test-payload', $entity->getPayload()); |
|
| 33 | } |
|
| 34 | ||
| 35 | public function testInheritanceLoading() |
|
| 36 | { |
|
| 37 | $repository = $this->getManager()->getRepository(SubEntity::class); |
|
| 38 | $this->getClient()->push( |
|
| 39 | $this->getResponseMock( |
|
| 40 | true, |
|
| 41 | (object)[ |
|
| 42 | 'id' => 2, |
|
| 43 | 'payload' => 'test-payload', |
|
| 44 | 'sub-payload' => 'sub-payload', |
|
| 45 | ] |
|
| 46 | ) |
|
| 47 | ); |
|
| 48 | ||
| 49 | /** @var SubEntity $entity */ |
|
| 50 | $entity = $repository->find(2); |
|
| 51 | ||
| 52 | self::assertInstanceOf(SubEntity::class, $entity); |
|
| 53 | self::assertEquals(2, $entity->getId()); |
|
| 54 | self::assertEquals('test-payload', $entity->getPayload()); |
|
| 55 | self::assertEquals('sub-payload', $entity->getSubPayload()); |
|
| 56 | } |
|
| 57 | ||
| 58 | public function testCompositeKeyLoading() |
|
| 59 | { |
|
| @@ 9-28 (lines=20) @@ | ||
| 6 | ||
| 7 | class IndirectFieldsTestAbstract extends AbstractEntityManagerTest |
|
| 8 | { |
|
| 9 | public function testIndirectId() |
|
| 10 | { |
|
| 11 | $repository = $this->getManager()->getRepository(IndirectIdEntity::class); |
|
| 12 | $this->getClient()->push( |
|
| 13 | $this->getResponseMock( |
|
| 14 | true, |
|
| 15 | (object)[ |
|
| 16 | 'some-long-api-field-name' => 241, |
|
| 17 | 'payload' => 'test', |
|
| 18 | ] |
|
| 19 | ) |
|
| 20 | ); |
|
| 21 | ||
| 22 | /** @var IndirectIdEntity $entity */ |
|
| 23 | $entity = $repository->find(241); |
|
| 24 | ||
| 25 | self::assertInstanceOf(IndirectIdEntity::class, $entity); |
|
| 26 | self::assertEquals(241, $entity->getId()); |
|
| 27 | self::assertEquals('test', $entity->getPayload()); |
|
| 28 | } |
|
| 29 | } |
|
| 30 | ||
| @@ 50-73 (lines=24) @@ | ||
| 47 | self::assertEquals(0, $this->getClient()->count()); |
|
| 48 | } |
|
| 49 | ||
| 50 | public function testSimpleProxy() |
|
| 51 | { |
|
| 52 | $repository = $this->getManager()->getRepository(SubEntity::class); |
|
| 53 | ||
| 54 | $this->getClient()->push( |
|
| 55 | $this->getResponseMock( |
|
| 56 | true, |
|
| 57 | (object)[ |
|
| 58 | 'id' => 2, |
|
| 59 | 'payload' => 'test-payload', |
|
| 60 | 'sub-payload' => 'sub-payload', |
|
| 61 | ] |
|
| 62 | ) |
|
| 63 | ); |
|
| 64 | ||
| 65 | /** @var SubEntity|Proxy $entity */ |
|
| 66 | $entity = $repository->find(2); |
|
| 67 | ||
| 68 | //Test that we can obtain data and request was sent |
|
| 69 | self::assertInstanceOf(SubEntity::class, $entity); |
|
| 70 | self::assertEquals(2, $entity->getId()); |
|
| 71 | self::assertEquals('test-payload', $entity->getPayload()); |
|
| 72 | self::assertEquals('sub-payload', $entity->getSubPayload()); |
|
| 73 | } |
|
| 74 | ||
| 75 | protected function getClientNames() |
|
| 76 | { |
|