can get endpoints raw element, get entity by a separate call

This commit is contained in:
Daniel Seifert 2025-01-04 22:37:16 +01:00
bovenliggende 55bad44a22
commit a88bb6d33f
Getekend door: DanielS
GPG sleutel-ID: 6A513E13AEE66170
12 gewijzigde bestanden met toevoegingen van 64 en 29 verwijderingen

Bestand weergeven

@ -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)) {

Bestand weergeven

@ -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);
}
/**

Bestand weergeven

@ -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);
}
/**

Bestand weergeven

@ -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)
);
}

Bestand weergeven

@ -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);
}
/**

Bestand weergeven

@ -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);
}
/**

Bestand weergeven

@ -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);

Bestand weergeven

@ -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']
);

Bestand weergeven

@ -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());

Bestand weergeven

@ -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']
)
);

Bestand weergeven

@ -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']
);

Bestand weergeven

@ -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);