diff --git a/src/Connection.php b/src/Connection.php index 8c9e224..6ec82d8 100644 --- a/src/Connection.php +++ b/src/Connection.php @@ -19,8 +19,9 @@ namespace D3\KlicktippPhpClient; use Assert\Assert; use Composer\InstalledVersions; -use D3\KlicktippPhpClient\Exceptions\BaseException; +use D3\KlicktippPhpClient\Exceptions\CommunicationException; use D3\KlicktippPhpClient\Exceptions\NoCredentialsException; +use D3\KlicktippPhpClient\Exceptions\ResponseContentException; use GuzzleHttp\Client; use GuzzleHttp\ClientInterface; use GuzzleHttp\Cookie\CookieJar; @@ -28,7 +29,6 @@ use GuzzleHttp\Exception\GuzzleException; use GuzzleHttp\Exception\RequestException; use GuzzleHttp\RequestOptions; use Psr\Http\Message\ResponseInterface; -use RuntimeException; class Connection { @@ -102,8 +102,10 @@ class Connection * @param string $method * @param string $uri * @param array $options + * * @return ResponseInterface - * @throws BaseException + * @throws CommunicationException + * @throws ResponseContentException */ public function request(string $method, string $uri, array $options = []): ResponseInterface { @@ -121,22 +123,24 @@ class Connection $this->parseResponse($e->getResponse()); } - throw new BaseException( + throw new CommunicationException( $e->getResponse()->getBody(), $e->getResponse()->getStatusCode(), $e ); } catch (GuzzleException $e) { - throw new BaseException($e->getMessage(), $e->getCode(), $e); + throw new CommunicationException($e->getMessage(), $e->getCode(), $e); } } /** * @param string $method * @param string $uri - * @param array $options + * @param array $options + * * @return array - * @throws BaseException + * @throws ResponseContentException + * @throws CommunicationException */ public function requestAndParse(string $method, string $uri, array $options = []): array { @@ -145,38 +149,30 @@ class Connection /** * @param ResponseInterface $response + * * @return array Parsed JSON result - * @throws BaseException + * @throws ResponseContentException */ public function parseResponse(ResponseInterface $response): array { - try { - // Rewind the response (middlewares might have read it already) - $response->getBody()->rewind(); + // Rewind the response (middlewares might have read it already) + $response->getBody()->rewind(); - $response_body = $response->getBody()->getContents(); + $response_body = $response->getBody()->getContents(); - $result_array = json_decode($response_body, true); + $result_array = json_decode($response_body, true); - if ($response->getStatusCode() === 204) { - return []; - } - - if (! is_array($result_array)) { - throw new BaseException( - sprintf('%s: %s', $response->getStatusCode(), $response_body), - $response->getStatusCode() - ); - } - - return $result_array; - } catch (RuntimeException $e) { - throw new BaseException( - $e->getMessage(), - 0, - $e - ); + if ($response->getStatusCode() === 204) { + return []; } + + Assert::lazy() + ->setExceptionClass(ResponseContentException::class) + ->that($result_array) + ->isArray(sprintf('%s: %s', $response->getStatusCode(), $response_body)) + ->verifyNow(); + + return $result_array; } public function getCookiesJar(): CookieJar diff --git a/src/Entities/Account.php b/src/Entities/Account.php index bd8771d..56ce327 100644 --- a/src/Entities/Account.php +++ b/src/Entities/Account.php @@ -17,7 +17,7 @@ declare(strict_types=1); namespace D3\KlicktippPhpClient\Entities; -use D3\KlicktippPhpClient\Exceptions\BaseException; +use D3\KlicktippPhpClient\Exceptions\CommunicationException; use D3\KlicktippPhpClient\Exceptions\InvalidCredentialTypeException; use D3\KlicktippPhpClient\Resources\Account as AccountEndpoint; use Doctrine\Common\Collections\ArrayCollection; @@ -192,7 +192,7 @@ class Account extends Entity /** * @return null|bool - * @throws BaseException + * @throws CommunicationException */ public function persist(): ?bool { diff --git a/src/Entities/Field.php b/src/Entities/Field.php index f96bb99..60c737f 100644 --- a/src/Entities/Field.php +++ b/src/Entities/Field.php @@ -17,7 +17,7 @@ declare(strict_types=1); namespace D3\KlicktippPhpClient\Entities; -use D3\KlicktippPhpClient\Exceptions\BaseException; +use D3\KlicktippPhpClient\Exceptions\CommunicationException; use D3\KlicktippPhpClient\Resources\Field as FieldEndpoint; class Field extends Entity @@ -49,7 +49,7 @@ class Field extends Entity /** * @return null|bool - * @throws BaseException + * @throws CommunicationException */ public function persist(): ?bool { diff --git a/src/Entities/Subscriber.php b/src/Entities/Subscriber.php index 94fd7f9..2283453 100644 --- a/src/Entities/Subscriber.php +++ b/src/Entities/Subscriber.php @@ -17,7 +17,7 @@ declare(strict_types=1); namespace D3\KlicktippPhpClient\Entities; -use D3\KlicktippPhpClient\Exceptions\BaseException; +use D3\KlicktippPhpClient\Exceptions\CommunicationException; use D3\KlicktippPhpClient\Resources\Subscriber as SubscriberEndpoint; use DateTime; use Doctrine\Common\Collections\ArrayCollection; @@ -313,7 +313,7 @@ class Subscriber extends Entity /** * @return null|bool - * @throws BaseException + * @throws CommunicationException */ public function persist(): ?bool { @@ -330,7 +330,7 @@ class Subscriber extends Entity } /** - * @throws BaseException + * @throws CommunicationException */ protected function persistTags(): void { diff --git a/src/Entities/Subscription.php b/src/Entities/Subscription.php index c44f895..fc8577c 100644 --- a/src/Entities/Subscription.php +++ b/src/Entities/Subscription.php @@ -17,9 +17,8 @@ declare(strict_types=1); namespace D3\KlicktippPhpClient\Entities; -use D3\KlicktippPhpClient\Exceptions\BaseException; +use D3\KlicktippPhpClient\Exceptions\CommunicationException; use D3\KlicktippPhpClient\Resources\SubscriptionProcess; -use Doctrine\Common\Collections\ArrayCollection; class Subscription extends Entity { @@ -78,7 +77,7 @@ class Subscription extends Entity /** * @return null|bool - * @throws BaseException + * @throws CommunicationException */ public function persist(): ?bool { diff --git a/src/Entities/Tag.php b/src/Entities/Tag.php index c99abf4..9b3a252 100644 --- a/src/Entities/Tag.php +++ b/src/Entities/Tag.php @@ -17,7 +17,7 @@ declare(strict_types=1); namespace D3\KlicktippPhpClient\Entities; -use D3\KlicktippPhpClient\Exceptions\BaseException; +use D3\KlicktippPhpClient\Exceptions\CommunicationException; use D3\KlicktippPhpClient\Resources\Tag as TagEndpoint; class Tag extends Entity @@ -61,7 +61,7 @@ class Tag extends Entity /** * @return null|bool - * @throws BaseException + * @throws CommunicationException */ public function persist(): ?bool { diff --git a/src/Exceptions/BaseException.php b/src/Exceptions/CommunicationException.php similarity index 89% rename from src/Exceptions/BaseException.php rename to src/Exceptions/CommunicationException.php index 908200d..4d654ab 100644 --- a/src/Exceptions/BaseException.php +++ b/src/Exceptions/CommunicationException.php @@ -19,7 +19,7 @@ namespace D3\KlicktippPhpClient\Exceptions; use Exception; -class BaseException extends Exception implements KlicktippExceptionInterface +class CommunicationException extends Exception implements KlicktippExceptionInterface { public function __construct($message = "", $code = 0, Exception $previous = null) { diff --git a/src/Exceptions/ResponseContentException.php b/src/Exceptions/ResponseContentException.php new file mode 100644 index 0000000..afc0c94 --- /dev/null +++ b/src/Exceptions/ResponseContentException.php @@ -0,0 +1,24 @@ + + * @link https://www.oxidmodule.com + */ + +declare(strict_types=1); + +namespace D3\KlicktippPhpClient\Exceptions; + +use Assert\LazyAssertionException; + +class ResponseContentException extends LazyAssertionException implements KlicktippExceptionInterface +{ +} diff --git a/src/Klicktipp.php b/src/Klicktipp.php index 583b12c..d2041a1 100644 --- a/src/Klicktipp.php +++ b/src/Klicktipp.php @@ -17,7 +17,7 @@ declare(strict_types=1); namespace D3\KlicktippPhpClient; -use D3\KlicktippPhpClient\Exceptions\BaseException; +use D3\KlicktippPhpClient\Exceptions\CommunicationException; use D3\KlicktippPhpClient\Resources\Account; use D3\KlicktippPhpClient\Resources\Field; use D3\KlicktippPhpClient\Resources\Subscriber; @@ -30,7 +30,7 @@ class Klicktipp protected ?Connection $connection = null; /** - * @throws BaseException + * @throws CommunicationException */ public function __construct( protected string $client_key, diff --git a/src/Resources/Account.php b/src/Resources/Account.php index fa3524e..d415332 100644 --- a/src/Resources/Account.php +++ b/src/Resources/Account.php @@ -18,7 +18,8 @@ declare(strict_types=1); namespace D3\KlicktippPhpClient\Resources; use D3\KlicktippPhpClient\Entities\Account as AccountEntity; -use D3\KlicktippPhpClient\Exceptions\BaseException; +use D3\KlicktippPhpClient\Exceptions\CommunicationException; +use D3\KlicktippPhpClient\Exceptions\ResponseContentException; use GuzzleHttp\RequestOptions; class Account extends Model @@ -58,7 +59,8 @@ class Account extends Model public const PASSWORD = 'password'; /** - * @throws BaseException + * @throws CommunicationException + * @throws ResponseContentException */ public function login(): array { @@ -75,7 +77,8 @@ class Account extends Model } /** - * @throws BaseException + * @throws CommunicationException + * @throws ResponseContentException */ public function logout(): bool { @@ -88,7 +91,8 @@ class Account extends Model } /** - * @throws BaseException + * @throws CommunicationException + * @throws ResponseContentException */ public function get(): array { @@ -99,7 +103,7 @@ class Account extends Model } /** - * @throws BaseException + * @throws CommunicationException */ public function getEntity(): AccountEntity { @@ -107,7 +111,8 @@ class Account extends Model } /** - * @throws BaseException + * @throws CommunicationException + * @throws ResponseContentException */ public function update(): bool { diff --git a/src/Resources/Field.php b/src/Resources/Field.php index 86a4dfa..d752cb6 100644 --- a/src/Resources/Field.php +++ b/src/Resources/Field.php @@ -19,7 +19,8 @@ namespace D3\KlicktippPhpClient\Resources; use D3\KlicktippPhpClient\Entities\Field as FieldEntity; use D3\KlicktippPhpClient\Entities\FieldList; -use D3\KlicktippPhpClient\Exceptions\BaseException; +use D3\KlicktippPhpClient\Exceptions\CommunicationException; +use D3\KlicktippPhpClient\Exceptions\ResponseContentException; use GuzzleHttp\RequestOptions; class Field extends Model @@ -28,7 +29,8 @@ class Field extends Model public const NAME = 'name'; /** - * @throws BaseException + * @throws CommunicationException + * @throws ResponseContentException */ public function index(): FieldList { @@ -41,7 +43,8 @@ class Field extends Model } /** - * @throws BaseException + * @throws CommunicationException + * @throws ResponseContentException */ public function get(string $fieldId): array { @@ -52,7 +55,7 @@ class Field extends Model } /** - * @throws BaseException + * @throws CommunicationException */ public function getEntity(string $fieldId): FieldEntity { @@ -61,7 +64,8 @@ class Field extends Model /** * @return string - new field id - * @throws BaseException + * @throws CommunicationException + * @throws ResponseContentException */ public function create(string $name): string { @@ -79,7 +83,8 @@ class Field extends Model } /** - * @throws BaseException + * @throws CommunicationException + * @throws ResponseContentException */ public function update(string $fieldId, ?string $name = null): bool { @@ -97,7 +102,8 @@ class Field extends Model } /** - * @throws BaseException + * @throws CommunicationException + * @throws ResponseContentException */ public function delete(string $fieldId): bool { diff --git a/src/Resources/Subscriber.php b/src/Resources/Subscriber.php index 41237f4..2f3436b 100644 --- a/src/Resources/Subscriber.php +++ b/src/Resources/Subscriber.php @@ -19,7 +19,8 @@ namespace D3\KlicktippPhpClient\Resources; use D3\KlicktippPhpClient\Entities\Subscriber as SubscriberEntity; use D3\KlicktippPhpClient\Entities\SubscriberList; -use D3\KlicktippPhpClient\Exceptions\BaseException; +use D3\KlicktippPhpClient\Exceptions\CommunicationException; +use D3\KlicktippPhpClient\Exceptions\ResponseContentException; use GuzzleHttp\RequestOptions; class Subscriber extends Model @@ -77,7 +78,8 @@ class Subscriber extends Model public const PARAM_APIKEY = 'apikey'; /** - * @throws BaseException + * @throws CommunicationException + * @throws ResponseContentException */ public function index(): SubscriberList { @@ -90,7 +92,8 @@ class Subscriber extends Model } /** - * @throws BaseException + * @throws CommunicationException + * @throws ResponseContentException */ public function get(string $subscriberId): array { @@ -101,7 +104,7 @@ class Subscriber extends Model } /** - * @throws BaseException + * @throws CommunicationException */ public function getEntity(string $subscriberId): SubscriberEntity { @@ -109,7 +112,8 @@ class Subscriber extends Model } /** - * @throws BaseException + * @throws CommunicationException + * @throws ResponseContentException */ public function search(string $mailAddress): string { @@ -127,7 +131,8 @@ class Subscriber extends Model } /** - * @throws BaseException + * @throws CommunicationException + * @throws ResponseContentException */ public function subscribe( string $mailAddress, @@ -158,7 +163,8 @@ class Subscriber extends Model } /** - * @throws BaseException + * @throws CommunicationException + * @throws ResponseContentException */ public function unsubscribe(string $mailAddress): bool { @@ -177,7 +183,9 @@ class Subscriber extends Model /** * add tag - * @throws BaseException + * + * @throws CommunicationException + * @throws ResponseContentException */ public function tag(string $mailAddress, array $tagIds): bool { @@ -201,7 +209,9 @@ class Subscriber extends Model /** * remove tag - * @throws BaseException + * + * @throws CommunicationException + * @throws ResponseContentException */ public function untag(string $mailAddress, string $tagId): bool { @@ -220,7 +230,8 @@ class Subscriber extends Model } /** - * @throws BaseException + * @throws CommunicationException + * @throws ResponseContentException */ public function tagged(string $tagId): SubscriberList { @@ -238,7 +249,8 @@ class Subscriber extends Model } /** - * @throws BaseException + * @throws CommunicationException + * @throws ResponseContentException */ public function update( string $subscriberId, @@ -266,8 +278,9 @@ class Subscriber extends Model } /** - * @throws BaseException * @return true + * @throws CommunicationException + * @throws ResponseContentException */ public function delete(string $subscriberId): bool { @@ -280,7 +293,8 @@ class Subscriber extends Model } /** - * @throws BaseException + * @throws CommunicationException + * @throws ResponseContentException */ public function signin( string $apikey, @@ -309,7 +323,8 @@ class Subscriber extends Model } /** - * @throws BaseException + * @throws CommunicationException + * @throws ResponseContentException */ public function signout(string $apikey, string $emailAddress): string { @@ -328,7 +343,8 @@ class Subscriber extends Model } /** - * @throws BaseException + * @throws CommunicationException + * @throws ResponseContentException */ public function signoff(string $apikey, string $emailAddress): bool { @@ -347,7 +363,7 @@ class Subscriber extends Model } /** - * @throws BaseException + * @throws CommunicationException */ public function setSubscriber( string $mailAddress, @@ -358,7 +374,7 @@ class Subscriber extends Model try { $id = $this->search($mailAddress); $this->update($id, $fields, $newMailAddress ?? $mailAddress, $smsNumber); - } catch (BaseException) { + } catch (CommunicationException) { $id = $this->subscribe($newMailAddress ?? $mailAddress, null, null, $fields, $smsNumber); } @@ -366,7 +382,7 @@ class Subscriber extends Model } /** - * @throws BaseException + * @throws CommunicationException */ public function getSubscriberByMailAddress(string $mailAddress): SubscriberEntity { diff --git a/src/Resources/SubscriptionProcess.php b/src/Resources/SubscriptionProcess.php index d31e223..74947ad 100644 --- a/src/Resources/SubscriptionProcess.php +++ b/src/Resources/SubscriptionProcess.php @@ -19,7 +19,8 @@ namespace D3\KlicktippPhpClient\Resources; use D3\KlicktippPhpClient\Entities\Subscription as SubscriptionEntity; use D3\KlicktippPhpClient\Entities\SubscriptionList; -use D3\KlicktippPhpClient\Exceptions\BaseException; +use D3\KlicktippPhpClient\Exceptions\CommunicationException; +use D3\KlicktippPhpClient\Exceptions\ResponseContentException; use GuzzleHttp\RequestOptions; class SubscriptionProcess extends Model @@ -34,7 +35,8 @@ class SubscriptionProcess extends Model public const PARAM_EMAIL = 'email'; /** - * @throws BaseException + * @throws CommunicationException + * @throws ResponseContentException */ public function index(): SubscriptionList { @@ -47,7 +49,8 @@ class SubscriptionProcess extends Model } /** - * @throws BaseException + * @throws CommunicationException + * @throws ResponseContentException */ public function get(string $listId): array { @@ -58,7 +61,7 @@ class SubscriptionProcess extends Model } /** - * @throws BaseException + * @throws CommunicationException */ public function getEntity(string $listId): SubscriptionEntity { @@ -66,7 +69,8 @@ class SubscriptionProcess extends Model } /** - * @throws BaseException + * @throws CommunicationException + * @throws ResponseContentException */ public function create(?string $name): SubscriptionEntity { @@ -84,7 +88,8 @@ class SubscriptionProcess extends Model } /** - * @throws BaseException + * @throws CommunicationException + * @throws ResponseContentException */ public function update(string $listId, ?string $name): bool { @@ -102,7 +107,8 @@ class SubscriptionProcess extends Model } /** - * @throws BaseException + * @throws CommunicationException + * @throws ResponseContentException */ public function redirect(string $listId, string $email): string { @@ -121,7 +127,8 @@ class SubscriptionProcess extends Model } /** - * @throws BaseException + * @throws CommunicationException + * @throws ResponseContentException */ public function delete(string $listId): bool { diff --git a/src/Resources/Tag.php b/src/Resources/Tag.php index 7ae2c89..334bef2 100644 --- a/src/Resources/Tag.php +++ b/src/Resources/Tag.php @@ -19,7 +19,8 @@ namespace D3\KlicktippPhpClient\Resources; use D3\KlicktippPhpClient\Entities\Tag as TagEntity; use D3\KlicktippPhpClient\Entities\TagList; -use D3\KlicktippPhpClient\Exceptions\BaseException; +use D3\KlicktippPhpClient\Exceptions\CommunicationException; +use D3\KlicktippPhpClient\Exceptions\ResponseContentException; use GuzzleHttp\RequestOptions; class Tag extends Model @@ -29,7 +30,8 @@ class Tag extends Model public const TEXT = 'text'; /** - * @throws BaseException + * @throws CommunicationException + * @throws ResponseContentException */ public function index(): TagList { @@ -42,7 +44,8 @@ class Tag extends Model } /** - * @throws BaseException + * @throws CommunicationException + * @throws ResponseContentException */ public function get(string $tagId): array { @@ -53,7 +56,8 @@ class Tag extends Model } /** - * @throws BaseException + * @throws CommunicationException + * @throws ResponseContentException */ public function getEntity(string $tagId): TagEntity { @@ -62,7 +66,8 @@ class Tag extends Model /** * @return string - new tag id - * @throws BaseException + * @throws CommunicationException + * @throws ResponseContentException */ public function create(string $name): string { @@ -80,7 +85,8 @@ class Tag extends Model } /** - * @throws BaseException + * @throws CommunicationException + * @throws ResponseContentException */ public function update(string $tagId, ?string $name = null, ?string $text = null): bool { @@ -99,7 +105,8 @@ class Tag extends Model } /** - * @throws BaseException + * @throws CommunicationException + * @throws ResponseContentException */ public function delete(string $tagId): bool { diff --git a/tests/integration/Resources/AccountTest.php b/tests/integration/Resources/AccountTest.php index 15f91e9..e856d1b 100644 --- a/tests/integration/Resources/AccountTest.php +++ b/tests/integration/Resources/AccountTest.php @@ -18,7 +18,7 @@ declare(strict_types=1); namespace D3\KlicktippPhpClient\tests\integration\Resources; use D3\KlicktippPhpClient\Entities\Account as AccountEntity; -use D3\KlicktippPhpClient\Exceptions\BaseException; +use D3\KlicktippPhpClient\Exceptions\CommunicationException; use D3\KlicktippPhpClient\Resources\Account; use D3\KlicktippPhpClient\tests\integration\IntegrationTestCase; use Generator; @@ -42,7 +42,7 @@ class AccountTest extends IntegrationTestCase $sut = new Account($this->getConnectionMock($response)); if ($expectException) { - $this->expectException(BaseException::class); + $this->expectException(CommunicationException::class); } $this->assertEquals( @@ -116,7 +116,7 @@ class AccountTest extends IntegrationTestCase $sut = new Account($this->getConnectionMock($response)); if ($expectException) { - $this->expectException(BaseException::class); + $this->expectException(CommunicationException::class); } $this->assertEquals( @@ -146,7 +146,7 @@ class AccountTest extends IntegrationTestCase $sut = new Account($this->getConnectionMock($response)); if ($expectException) { - $this->expectException(BaseException::class); + $this->expectException(CommunicationException::class); } $return = $this->callMethod( @@ -187,7 +187,7 @@ class AccountTest extends IntegrationTestCase $sut = new Account($this->getConnectionMock($response)); if ($expectException) { - $this->expectException(BaseException::class); + $this->expectException(CommunicationException::class); } $this->assertEquals( diff --git a/tests/integration/Resources/FieldTest.php b/tests/integration/Resources/FieldTest.php index dd8d7f2..9878664 100644 --- a/tests/integration/Resources/FieldTest.php +++ b/tests/integration/Resources/FieldTest.php @@ -19,7 +19,7 @@ namespace D3\KlicktippPhpClient\tests\integration\Resources; use D3\KlicktippPhpClient\Entities\Field as FieldEntity; use D3\KlicktippPhpClient\Entities\FieldList; -use D3\KlicktippPhpClient\Exceptions\BaseException; +use D3\KlicktippPhpClient\Exceptions\CommunicationException; use D3\KlicktippPhpClient\Resources\Field; use D3\KlicktippPhpClient\Resources\Subscriber; use D3\KlicktippPhpClient\tests\integration\IntegrationTestCase; @@ -44,7 +44,7 @@ class FieldTest extends IntegrationTestCase $sut = new Field($this->getConnectionMock($response)); if ($expectException) { - $this->expectException(BaseException::class); + $this->expectException(CommunicationException::class); } $this->assertEquals( @@ -109,7 +109,7 @@ class FieldTest extends IntegrationTestCase $sut = new Field($this->getConnectionMock($response)); if ($expectException) { - $this->expectException(BaseException::class); + $this->expectException(CommunicationException::class); } $return = $this->callMethod( @@ -146,7 +146,7 @@ class FieldTest extends IntegrationTestCase $sut = new Field($this->getConnectionMock($response)); if ($expectException) { - $this->expectException(BaseException::class); + $this->expectException(CommunicationException::class); } $this->assertEquals( @@ -177,7 +177,7 @@ class FieldTest extends IntegrationTestCase $sut = new Field($this->getConnectionMock($response)); if ($expectException) { - $this->expectException(BaseException::class); + $this->expectException(CommunicationException::class); } $this->assertEquals( @@ -208,7 +208,7 @@ class FieldTest extends IntegrationTestCase $sut = new Field($this->getConnectionMock($response)); if ($expectException) { - $this->expectException(BaseException::class); + $this->expectException(CommunicationException::class); } $this->assertEquals( diff --git a/tests/integration/Resources/SubscriberTest.php b/tests/integration/Resources/SubscriberTest.php index 4a80e27..311a014 100644 --- a/tests/integration/Resources/SubscriberTest.php +++ b/tests/integration/Resources/SubscriberTest.php @@ -19,7 +19,8 @@ namespace D3\KlicktippPhpClient\tests\integration\Resources; use D3\KlicktippPhpClient\Entities\Subscriber as SubscriberEntity; use D3\KlicktippPhpClient\Entities\SubscriberList; -use D3\KlicktippPhpClient\Exceptions\BaseException; +use D3\KlicktippPhpClient\Exceptions\CommunicationException; +use D3\KlicktippPhpClient\Exceptions\KlicktippExceptionInterface; use D3\KlicktippPhpClient\Resources\Subscriber; use D3\KlicktippPhpClient\tests\integration\IntegrationTestCase; use Generator; @@ -61,7 +62,7 @@ class SubscriberTest extends IntegrationTestCase $sut = new Subscriber($this->getConnectionMock($response)); if ($expectException) { - $this->expectException(BaseException::class); + $this->expectException(CommunicationException::class); } $this->assertEquals( @@ -103,7 +104,7 @@ class SubscriberTest extends IntegrationTestCase $sut = new Subscriber($this->getConnectionMock($response)); if ($expectException) { - $this->expectException(BaseException::class); + $this->expectException(KlicktippExceptionInterface::class); } $return = $this->callMethod( @@ -204,7 +205,7 @@ class SubscriberTest extends IntegrationTestCase $sut = new Subscriber($this->getConnectionMock($response)); if ($expectException) { - $this->expectException(BaseException::class); + $this->expectException(KlicktippExceptionInterface::class); } $this->assertEquals( @@ -235,7 +236,7 @@ class SubscriberTest extends IntegrationTestCase $sut = new Subscriber($this->getConnectionMock($response)); if ($expectException) { - $this->expectException(BaseException::class); + $this->expectException(CommunicationException::class); } $this->assertEquals( @@ -308,7 +309,7 @@ class SubscriberTest extends IntegrationTestCase $sut = new Subscriber($this->getConnectionMock($response)); if ($expectException) { - $this->expectException(BaseException::class); + $this->expectException(KlicktippExceptionInterface::class); } $this->assertEquals( @@ -341,7 +342,7 @@ class SubscriberTest extends IntegrationTestCase $sut = new Subscriber($this->getConnectionMock($response)); if ($expectException) { - $this->expectException(BaseException::class); + $this->expectException(KlicktippExceptionInterface::class); } $this->assertEquals( @@ -380,7 +381,7 @@ class SubscriberTest extends IntegrationTestCase $sut = new Subscriber($this->getConnectionMock($response)); if ($expectException) { - $this->expectException(BaseException::class); + $this->expectException(KlicktippExceptionInterface::class); } $this->assertEquals( @@ -412,7 +413,7 @@ class SubscriberTest extends IntegrationTestCase $sut = new Subscriber($this->getConnectionMock($response)); if ($expectException) { - $this->expectException(BaseException::class); + $this->expectException(KlicktippExceptionInterface::class); } $return = $this->callMethod( @@ -449,7 +450,7 @@ class SubscriberTest extends IntegrationTestCase $sut = new Subscriber($this->getConnectionMock($response)); if ($expectException) { - $this->expectException(BaseException::class); + $this->expectException(CommunicationException::class); } $this->assertEquals( @@ -487,7 +488,7 @@ class SubscriberTest extends IntegrationTestCase $sut = new Subscriber($this->getConnectionMock($response)); if ($expectException) { - $this->expectException(BaseException::class); + $this->expectException(CommunicationException::class); } $this->assertEquals( @@ -517,7 +518,7 @@ class SubscriberTest extends IntegrationTestCase $sut = new Subscriber($this->getConnectionMock($response)); if ($expectException) { - $this->expectException(BaseException::class); + $this->expectException(KlicktippExceptionInterface::class); } $this->assertEquals( @@ -556,7 +557,7 @@ class SubscriberTest extends IntegrationTestCase $sut = new Subscriber($this->getConnectionMock($response)); if ($expectException) { - $this->expectException(BaseException::class); + $this->expectException(CommunicationException::class); } $this->assertEquals( @@ -588,7 +589,7 @@ class SubscriberTest extends IntegrationTestCase $sut = new Subscriber($this->getConnectionMock($response)); if ($expectException) { - $this->expectException(BaseException::class); + $this->expectException(CommunicationException::class); } $this->assertEquals( @@ -628,7 +629,7 @@ class SubscriberTest extends IntegrationTestCase ->onlyMethods(['search', 'update', 'subscribe', 'getEntity']) ->getMock(); $sut->expects($this->once())->method('search')->will( - $foundId ? $this->returnValue($foundId) : $this->throwException(new BaseException()) + $foundId ? $this->returnValue($foundId) : $this->throwException(new CommunicationException()) ); $sut->expects($updateInvocations)->method('update')->willReturn(true); $sut->expects($subscribeInvocations)->method('subscribe')->willReturn('myId'); diff --git a/tests/integration/Resources/SubscriptionProcessTest.php b/tests/integration/Resources/SubscriptionProcessTest.php index 003a98e..6c9e64f 100644 --- a/tests/integration/Resources/SubscriptionProcessTest.php +++ b/tests/integration/Resources/SubscriptionProcessTest.php @@ -19,7 +19,7 @@ namespace D3\KlicktippPhpClient\tests\integration\Resources; use D3\KlicktippPhpClient\Entities\Subscription; use D3\KlicktippPhpClient\Entities\SubscriptionList; -use D3\KlicktippPhpClient\Exceptions\BaseException; +use D3\KlicktippPhpClient\Exceptions\CommunicationException; use D3\KlicktippPhpClient\Resources\SubscriptionProcess; use D3\KlicktippPhpClient\tests\integration\IntegrationTestCase; use Generator; @@ -43,7 +43,7 @@ class SubscriptionProcessTest extends IntegrationTestCase $sut = new SubscriptionProcess($this->getConnectionMock($response)); if ($expectException) { - $this->expectException(BaseException::class); + $this->expectException(CommunicationException::class); } $this->assertEquals( @@ -80,7 +80,7 @@ class SubscriptionProcessTest extends IntegrationTestCase $sut = new SubscriptionProcess($this->getConnectionMock($response)); if ($expectException) { - $this->expectException(BaseException::class); + $this->expectException(CommunicationException::class); } $return = $this->callMethod( @@ -128,7 +128,7 @@ class SubscriptionProcessTest extends IntegrationTestCase $sut = new SubscriptionProcess($this->getConnectionMock($response)); if ($expectException) { - $this->expectException(BaseException::class); + $this->expectException(CommunicationException::class); } $return = $this->callMethod( @@ -152,7 +152,7 @@ class SubscriptionProcessTest extends IntegrationTestCase $sut = new SubscriptionProcess($this->getConnectionMock($response)); if ($expectException) { - $this->expectException(BaseException::class); + $this->expectException(CommunicationException::class); } $this->assertEquals( @@ -183,7 +183,7 @@ class SubscriptionProcessTest extends IntegrationTestCase $sut = new SubscriptionProcess($this->getConnectionMock($response)); if ($expectException) { - $this->expectException(BaseException::class); + $this->expectException(CommunicationException::class); } $this->assertEquals( @@ -214,7 +214,7 @@ class SubscriptionProcessTest extends IntegrationTestCase $sut = new SubscriptionProcess($this->getConnectionMock($response)); if ($expectException) { - $this->expectException(BaseException::class); + $this->expectException(CommunicationException::class); } $this->assertEquals( diff --git a/tests/integration/Resources/TagTest.php b/tests/integration/Resources/TagTest.php index 7c6d82a..fec199a 100644 --- a/tests/integration/Resources/TagTest.php +++ b/tests/integration/Resources/TagTest.php @@ -19,7 +19,9 @@ namespace D3\KlicktippPhpClient\tests\integration\Resources; use D3\KlicktippPhpClient\Entities\Tag as TagEntity; use D3\KlicktippPhpClient\Entities\TagList; -use D3\KlicktippPhpClient\Exceptions\BaseException; +use D3\KlicktippPhpClient\Exceptions\CommunicationException; +use D3\KlicktippPhpClient\Exceptions\KlicktippExceptionInterface; +use D3\KlicktippPhpClient\Exceptions\ResponseContentException; use D3\KlicktippPhpClient\Resources\Tag; use D3\KlicktippPhpClient\tests\integration\IntegrationTestCase; use Generator; @@ -43,7 +45,7 @@ class TagTest extends IntegrationTestCase $sut = new Tag($this->getConnectionMock($response)); if ($expectException) { - $this->expectException(BaseException::class); + $this->expectException(KlicktippExceptionInterface::class); } $this->assertEquals( @@ -80,7 +82,7 @@ class TagTest extends IntegrationTestCase $sut = new Tag($this->getConnectionMock($response)); if ($expectException) { - $this->expectException(BaseException::class); + $this->expectException(CommunicationException::class); } $return = $this->callMethod( @@ -119,7 +121,7 @@ class TagTest extends IntegrationTestCase $sut = new Tag($this->getConnectionMock($response)); if ($expectException) { - $this->expectException(BaseException::class); + $this->expectException(CommunicationException::class); } $this->assertEquals( @@ -150,7 +152,7 @@ class TagTest extends IntegrationTestCase $sut = new Tag($this->getConnectionMock($response)); if ($expectException) { - $this->expectException(BaseException::class); + $this->expectException(CommunicationException::class); } $this->assertEquals( @@ -181,7 +183,7 @@ class TagTest extends IntegrationTestCase $sut = new Tag($this->getConnectionMock($response)); if ($expectException) { - $this->expectException(BaseException::class); + $this->expectException(CommunicationException::class); } $this->assertEquals(