diff --git a/src/Entities/Subscriber.php b/src/Entities/Subscriber.php index 0d38de2..787eee4 100644 --- a/src/Entities/Subscriber.php +++ b/src/Entities/Subscriber.php @@ -339,7 +339,7 @@ class Subscriber extends ArrayCollection return; } - $currentTags = $this->endpoint->get($this->getId())->getTags(); + $currentTags = $this->endpoint->getEntity($this->getId())->getTags(); $removeTags = array_diff($currentTags->toArray(), $this->getTags()->toArray()); if (count($removeTags)) { diff --git a/src/Resources/Account.php b/src/Resources/Account.php index 45b6375..0e48d6c 100644 --- a/src/Resources/Account.php +++ b/src/Resources/Account.php @@ -88,14 +88,20 @@ class Account extends Model /** * @throws BaseException */ - public function get(): AccountEntity + public function get(): array { - $data = $this->connection->requestAndParse( + return $this->connection->requestAndParse( 'GET', 'account.json' ); + } - return new AccountEntity($data, $this); + /** + * @throws BaseException + */ + public function getEntity(): AccountEntity + { + return new AccountEntity($this->get(), $this); } /** diff --git a/src/Resources/Field.php b/src/Resources/Field.php index b6b18e6..5e3ee81 100644 --- a/src/Resources/Field.php +++ b/src/Resources/Field.php @@ -41,14 +41,20 @@ class Field extends Model /** * @throws BaseException */ - public function get(string $fieldId): FieldEntity + public function get(string $fieldId): array { - $data = $this->connection->requestAndParse( + return $this->connection->requestAndParse( 'GET', 'field/'.urlencode(trim($fieldId)).'.json' ); + } - return new FieldEntity($data, $this); + /** + * @throws BaseException + */ + public function getEntity(string $fieldId): FieldEntity + { + return new FieldEntity($this->get($fieldId), $this); } /** diff --git a/src/Resources/Subscriber.php b/src/Resources/Subscriber.php index aea25a1..d69050d 100644 --- a/src/Resources/Subscriber.php +++ b/src/Resources/Subscriber.php @@ -90,14 +90,20 @@ class Subscriber extends Model /** * @throws BaseException */ - public function get(string $subscriberId): SubscriberEntity + public function get(string $subscriberId): array { - $data = $this->connection->requestAndParse( + return $this->connection->requestAndParse( 'GET', 'subscriber/'.urlencode(trim($subscriberId)).'.json' ); + } - return new SubscriberEntity($data, $this); + /** + * @throws BaseException + */ + public function getEntity(string $subscriberId): SubscriberEntity + { + return new SubscriberEntity($this->get($subscriberId), $this); } /** @@ -352,7 +358,7 @@ class Subscriber extends Model $id = $this->subscribe($newMailAddress ?? $mailAddress, null, null, $fields, $smsNumber); } - return $this->get($id); + return $this->getEntity($id); } /** @@ -360,7 +366,7 @@ class Subscriber extends Model */ public function getSubscriberByMailAddress(string $mailAddress): SubscriberEntity { - return $this->get( + return $this->getEntity( $this->search($mailAddress) ); } diff --git a/src/Resources/SubscriptionProcess.php b/src/Resources/SubscriptionProcess.php index 29f7747..2baa5dc 100644 --- a/src/Resources/SubscriptionProcess.php +++ b/src/Resources/SubscriptionProcess.php @@ -47,14 +47,20 @@ class SubscriptionProcess extends Model /** * @throws BaseException */ - public function get(string $listId): SubscriptionEntity + public function get(string $listId): array { - $data = $this->connection->requestAndParse( + return $this->connection->requestAndParse( 'GET', 'list/'.urlencode(trim($listId)).'.json' ); + } - return new SubscriptionEntity($data); + /** + * @throws BaseException + */ + public function getEntity(string $listId): SubscriptionEntity + { + return new SubscriptionEntity($this->get($listId), $this); } /** diff --git a/src/Resources/Tag.php b/src/Resources/Tag.php index 49d1dc8..fcae57c 100644 --- a/src/Resources/Tag.php +++ b/src/Resources/Tag.php @@ -42,14 +42,20 @@ class Tag extends Model /** * @throws BaseException */ - public function get(string $tagId): TagEntity + public function get(string $tagId): array { - $data = $this->connection->requestAndParse( + return $this->connection->requestAndParse( 'GET', 'tag/'.urlencode(trim($tagId)).'.json' ); + } - return new TagEntity($data, $this); + /** + * @throws BaseException + */ + public function getEntity(string $tagId): TagEntity + { + return new TagEntity($this->get($tagId), $this); } /** diff --git a/tests/integration/Resources/AccountTest.php b/tests/integration/Resources/AccountTest.php index f3dc618..582b139 100644 --- a/tests/integration/Resources/AccountTest.php +++ b/tests/integration/Resources/AccountTest.php @@ -136,6 +136,7 @@ class AccountTest extends IntegrationTestCase * @test * @throws ReflectionException * @covers \D3\KlicktippPhpClient\Resources\Account::get + * @covers \D3\KlicktippPhpClient\Resources\Account::getEntity * @dataProvider getDataProvider */ public function testGet(ResponseInterface $response, ?array $expected, bool $expectException = false) @@ -148,7 +149,7 @@ class AccountTest extends IntegrationTestCase $return = $this->callMethod( $sut, - 'get' + 'getEntity' ); $this->assertInstanceOf(AccountEntity::class, $return); diff --git a/tests/integration/Resources/FieldTest.php b/tests/integration/Resources/FieldTest.php index 39dd5b1..12bee6d 100644 --- a/tests/integration/Resources/FieldTest.php +++ b/tests/integration/Resources/FieldTest.php @@ -99,6 +99,7 @@ class FieldTest extends IntegrationTestCase * @test * @throws ReflectionException * @covers \D3\KlicktippPhpClient\Resources\Field::get + * @covers \D3\KlicktippPhpClient\Resources\Field::getEntity * @dataProvider getDataProvider */ public function testGet(ResponseInterface $response, ?array $expected, bool $expectException = false) @@ -111,7 +112,7 @@ class FieldTest extends IntegrationTestCase $return = $this->callMethod( $sut, - 'get', + 'getEntity', ['12514414'] ); diff --git a/tests/integration/Resources/SubscriberTest.php b/tests/integration/Resources/SubscriberTest.php index 561e739..13f598d 100644 --- a/tests/integration/Resources/SubscriberTest.php +++ b/tests/integration/Resources/SubscriberTest.php @@ -93,6 +93,7 @@ class SubscriberTest extends IntegrationTestCase * @test * @throws ReflectionException * @covers \D3\KlicktippPhpClient\Resources\Subscriber::get + * @covers \D3\KlicktippPhpClient\Resources\Subscriber::getEntity * @dataProvider getDataProvider */ public function testGet(ResponseInterface $response, ?array $expected, bool $expectException = false) @@ -105,7 +106,7 @@ class SubscriberTest extends IntegrationTestCase $return = $this->callMethod( $sut, - 'get', + 'getEntity', ['155988456'] ); @@ -622,14 +623,14 @@ class SubscriberTest extends IntegrationTestCase $sut = $this->getMockBuilder(Subscriber::class) ->setConstructorArgs([$this->getConnectionMock($responses)]) - ->onlyMethods(['search', 'update', 'subscribe', 'get']) + ->onlyMethods(['search', 'update', 'subscribe', 'getEntity']) ->getMock(); $sut->expects($this->once())->method('search')->will( $foundId ? $this->returnValue($foundId) : $this->throwException(new BaseException()) ); $sut->expects($updateInvocations)->method('update')->willReturn(true); $sut->expects($subscribeInvocations)->method('subscribe')->willReturn('myId'); - $sut->expects($this->once())->method('get')->with( + $sut->expects($this->once())->method('getEntity')->with( $this->identicalTo('myId') )->willReturn($entityMock); @@ -678,10 +679,10 @@ class SubscriberTest extends IntegrationTestCase $sut = $this->getMockBuilder(Subscriber::class) ->setConstructorArgs([$this->getConnectionMock($responses)]) - ->onlyMethods(['search', 'get']) + ->onlyMethods(['search', 'getEntity']) ->getMock(); $sut->expects($this->once())->method('search')->willReturn('myId'); - $sut->expects($this->once())->method('get')->with( + $sut->expects($this->once())->method('getEntity')->with( $this->identicalTo('myId') )->willReturn(new SubscriberEntity()); diff --git a/tests/integration/Resources/SubscriptionProcessTest.php b/tests/integration/Resources/SubscriptionProcessTest.php index a2c1e35..8d84019 100644 --- a/tests/integration/Resources/SubscriptionProcessTest.php +++ b/tests/integration/Resources/SubscriptionProcessTest.php @@ -70,6 +70,7 @@ class SubscriptionProcessTest extends IntegrationTestCase * @test * @throws ReflectionException * @covers \D3\KlicktippPhpClient\Resources\SubscriptionProcess::get + * @covers \D3\KlicktippPhpClient\Resources\SubscriptionProcess::getEntity * @dataProvider getDataProvider */ public function testGet(ResponseInterface $response, ?Subscription $expected, bool $expectException = false) @@ -84,7 +85,7 @@ class SubscriptionProcessTest extends IntegrationTestCase $expected, $this->callMethod( $sut, - 'get', + 'getEntity', ['470370'] ) ); diff --git a/tests/integration/Resources/TagTest.php b/tests/integration/Resources/TagTest.php index 5d459b7..505e1e9 100644 --- a/tests/integration/Resources/TagTest.php +++ b/tests/integration/Resources/TagTest.php @@ -70,6 +70,7 @@ class TagTest extends IntegrationTestCase * @test * @throws ReflectionException * @covers \D3\KlicktippPhpClient\Resources\Tag::get + * @covers \D3\KlicktippPhpClient\Resources\Tag::getEntity * @dataProvider getDataProvider */ public function testGet(ResponseInterface $response, ?array $expected, bool $expectException = false) @@ -82,7 +83,7 @@ class TagTest extends IntegrationTestCase $return = $this->callMethod( $sut, - 'get', + 'getEntity', ['12514414'] ); diff --git a/tests/unit/Entities/SubscriberTest.php b/tests/unit/Entities/SubscriberTest.php index 7adbe57..93bce20 100644 --- a/tests/unit/Entities/SubscriberTest.php +++ b/tests/unit/Entities/SubscriberTest.php @@ -640,9 +640,9 @@ class SubscriberTest extends TestCase $endpointMock = $this->getMockBuilder(SubscriberEndpoint::class) ->disableOriginalConstructor() - ->onlyMethods(['get', 'tag', 'untag']) + ->onlyMethods(['getEntity', 'tag', 'untag']) ->getMock(); - $endpointMock->expects($endpointInvocation)->method('get')->willReturn($entityMock); + $endpointMock->expects($endpointInvocation)->method('getEntity')->willReturn($entityMock); $endpointMock->expects($setTagInvocation)->method('tag')->willReturn(true); $endpointMock->expects($removeTagInvocation)->method('untag')->willReturn(true);