From abcfea9480842df004678d379c2073bda27f3768 Mon Sep 17 00:00:00 2001 From: Daniel Seifert Date: Fri, 3 Jan 2025 09:19:29 +0100 Subject: [PATCH] add subscription process create endpoint --- src/Resources/SubscriptionProcess.php | 18 +++++++++++++ .../Resources/SubscriptionProcessTest.php | 25 +++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/src/Resources/SubscriptionProcess.php b/src/Resources/SubscriptionProcess.php index 89169a5..fd23e8a 100644 --- a/src/Resources/SubscriptionProcess.php +++ b/src/Resources/SubscriptionProcess.php @@ -48,6 +48,24 @@ class SubscriptionProcess extends Model return new SubscriptionEntity($data); } + /** + * @throws BaseException + */ + public function create(?string $name): SubscriptionEntity + { + $data = $this->connection->requestAndParse( + 'POST', + 'list.json', + [ + RequestOptions::FORM_PARAMS => array_filter([ + 'name' => trim($name ?? ''), + ]), + ] + ); + + return new SubscriptionEntity($data); + } + /** * @throws BaseException */ diff --git a/tests/integration/Resources/SubscriptionProcessTest.php b/tests/integration/Resources/SubscriptionProcessTest.php index 7a7e3d8..218da26 100644 --- a/tests/integration/Resources/SubscriptionProcessTest.php +++ b/tests/integration/Resources/SubscriptionProcessTest.php @@ -113,6 +113,31 @@ class SubscriptionProcessTest extends IntegrationTestCase yield 'access denied' => [new Response(403, [], '["API Zugriff verweigert"]'), null, true]; } + /** + * @test + * @return void + * @throws ReflectionException + * @covers \D3\KlicktippPhpClient\Resources\SubscriptionProcess::create + * @dataProvider getDataProvider + */ + public function testCreate(ResponseInterface $response, ?Subscription $expected, bool $expectException = false) + { + $sut = new SubscriptionProcess($this->getConnectionMock($response)); + + if ($expectException) { + $this->expectException(BaseException::class); + } + + $this->assertEquals( + $expected, + $this->callMethod( + $sut, + 'create', + ['newName'] + ) + ); + } + /** * @test * @throws ReflectionException