subscription entity get a endpoint object, so it can persist modified properties

Cette révision appartient à :
Daniel Seifert 2025-01-04 22:39:02 +01:00
Parent a88bb6d33f
révision fe319b2733
Signé par: DanielS
ID de la clé GPG: 6A513E13AEE66170
2 fichiers modifiés avec 44 ajouts et 18 suppressions

Voir le fichier

@ -15,11 +15,20 @@
namespace D3\KlicktippPhpClient\Entities; namespace D3\KlicktippPhpClient\Entities;
use D3\KlicktippPhpClient\Exceptions\BaseException;
use D3\KlicktippPhpClient\Resources\SubscriptionProcess; use D3\KlicktippPhpClient\Resources\SubscriptionProcess;
use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\ArrayCollection;
class Subscription extends ArrayCollection class Subscription extends ArrayCollection
{ {
private ?SubscriptionProcess $endpoint;
public function __construct(array $elements = [], ?SubscriptionProcess $endpoint = null)
{
$this->endpoint = $endpoint;
parent::__construct($elements);
}
public function getListId(): string public function getListId(): string
{ {
return $this->get(SubscriptionProcess::LISTID) ?? ''; return $this->get(SubscriptionProcess::LISTID) ?? '';
@ -30,6 +39,11 @@ class Subscription extends ArrayCollection
return $this->get(SubscriptionProcess::NAME) ?? ''; return $this->get(SubscriptionProcess::NAME) ?? '';
} }
public function setName(string $name): void
{
$this->set(SubscriptionProcess::NAME, $name);
}
public function getPendingUrl(): string public function getPendingUrl(): string
{ {
return $this->get(SubscriptionProcess::PENDINGURL) ?? ''; return $this->get(SubscriptionProcess::PENDINGURL) ?? '';
@ -59,4 +73,16 @@ class Subscription extends ArrayCollection
{ {
return $this->get(SubscriptionProcess::USE_CHANGE_EMAIL); return $this->get(SubscriptionProcess::USE_CHANGE_EMAIL);
} }
/**
* @return null|bool
* @throws BaseException
*/
public function persist(): ?bool
{
return $this->endpoint?->update(
$this->getListId(),
$this->getName()
);
}
} }

Voir le fichier

@ -73,7 +73,7 @@ class SubscriptionProcessTest extends IntegrationTestCase
* @covers \D3\KlicktippPhpClient\Resources\SubscriptionProcess::getEntity * @covers \D3\KlicktippPhpClient\Resources\SubscriptionProcess::getEntity
* @dataProvider getDataProvider * @dataProvider getDataProvider
*/ */
public function testGet(ResponseInterface $response, ?Subscription $expected, bool $expectException = false) public function testGet(ResponseInterface $response, ?array $expected, bool $expectException = false)
{ {
$sut = new SubscriptionProcess($this->getConnectionMock($response)); $sut = new SubscriptionProcess($this->getConnectionMock($response));
@ -81,14 +81,14 @@ class SubscriptionProcessTest extends IntegrationTestCase
$this->expectException(BaseException::class); $this->expectException(BaseException::class);
} }
$this->assertEquals( $return = $this->callMethod(
$expected,
$this->callMethod(
$sut, $sut,
'getEntity', 'getEntity',
['470370'] ['470370']
)
); );
$this->assertInstanceOf(Subscription::class, $return);
$this->assertSame($expected, $return->toArray());
} }
public static function getDataProvider(): Generator public static function getDataProvider(): Generator
@ -101,7 +101,7 @@ class SubscriptionProcessTest extends IntegrationTestCase
"'.SubscriptionProcess::USE_SINGLE_OPTIN.'": false, "'.SubscriptionProcess::USE_SINGLE_OPTIN.'": false,
"'.SubscriptionProcess::RESEND_CONFIRMATION_EMAIL.'": false, "'.SubscriptionProcess::RESEND_CONFIRMATION_EMAIL.'": false,
"'.SubscriptionProcess::USE_CHANGE_EMAIL.'": false "'.SubscriptionProcess::USE_CHANGE_EMAIL.'": false
}'), new Subscription([ }'), [
SubscriptionProcess::LISTID => "470370", SubscriptionProcess::LISTID => "470370",
SubscriptionProcess::NAME => "name 1", SubscriptionProcess::NAME => "name 1",
SubscriptionProcess::PENDINGURL => "", SubscriptionProcess::PENDINGURL => "",
@ -109,7 +109,7 @@ class SubscriptionProcessTest extends IntegrationTestCase
SubscriptionProcess::USE_SINGLE_OPTIN => false, SubscriptionProcess::USE_SINGLE_OPTIN => false,
SubscriptionProcess::RESEND_CONFIRMATION_EMAIL => false, SubscriptionProcess::RESEND_CONFIRMATION_EMAIL => false,
SubscriptionProcess::USE_CHANGE_EMAIL => false, SubscriptionProcess::USE_CHANGE_EMAIL => false,
])]; ]];
yield 'unknown id' => [new Response(404, [], '["Kein Opt-In-Prozess mit dieser ID."]'), null, true]; yield 'unknown id' => [new Response(404, [], '["Kein Opt-In-Prozess mit dieser ID."]'), null, true];
yield 'access denied' => [new Response(403, [], '["API Zugriff verweigert"]'), null, true]; yield 'access denied' => [new Response(403, [], '["API Zugriff verweigert"]'), null, true];
} }
@ -121,7 +121,7 @@ class SubscriptionProcessTest extends IntegrationTestCase
* @covers \D3\KlicktippPhpClient\Resources\SubscriptionProcess::create * @covers \D3\KlicktippPhpClient\Resources\SubscriptionProcess::create
* @dataProvider getDataProvider * @dataProvider getDataProvider
*/ */
public function testCreate(ResponseInterface $response, ?Subscription $expected, bool $expectException = false) public function testCreate(ResponseInterface $response, ?array $expected, bool $expectException = false)
{ {
$sut = new SubscriptionProcess($this->getConnectionMock($response)); $sut = new SubscriptionProcess($this->getConnectionMock($response));
@ -129,14 +129,14 @@ class SubscriptionProcessTest extends IntegrationTestCase
$this->expectException(BaseException::class); $this->expectException(BaseException::class);
} }
$this->assertEquals( $return = $this->callMethod(
$expected,
$this->callMethod(
$sut, $sut,
'create', 'create',
['newName'] ['newName']
)
); );
$this->assertInstanceOf(Subscription::class, $return);
$this->assertSame($expected, $return->toArray());
} }
/** /**