From f58b407f9a348340c4f9a61a531674de4f5e39ef Mon Sep 17 00:00:00 2001 From: Artem Henvald Date: Wed, 4 Sep 2019 10:35:46 +0300 Subject: [PATCH 1/7] Refactoring --- .travis.yml | 6 +- Controller/SinchController.php | 4 +- DependencyInjection/Configuration.php | 14 +- ...{SmsEvent.php => AbstractBaseSmsEvent.php} | 6 +- Event/PostSmsSendEvent.php | 22 +++ Event/PreSmsSendEvent.php | 22 +++ Event/SinchEvents.php | 42 ------ Event/SmsMessageCallbackEvent.php | 3 +- Resources/config/services.yml | 3 + Resources/images/sinch-logo.png | Bin 77140 -> 3129 bytes Service/HTTPClientInterface.php | 39 ----- Service/HTTPClientService.php | 37 ----- Service/Sinch.php | 100 ++++++------- Service/SinchExceptionResolver.php | 14 -- Tests/Controller/SinchControllerTest.php | 141 ++++++++++-------- .../DependencyInjection/ConfigurationTest.php | 22 +-- .../FreshSinchExtensionTest.php | 28 ++-- Tests/Event/PostSmsSendEventTest.php | 75 ++++++++++ Tests/Event/PreSmsSendEventTest.php | 73 +++++++++ Tests/Event/SmsEventTest.php | 73 --------- Tests/Event/SmsMessageCallbackEventTest.php | 15 +- ...eTestCase.php => AbstractTypeTestCase.php} | 8 +- Tests/Form/Type/CallbackRequestTypeTest.php | 50 +++---- Tests/Form/Type/IdentityTypeTest.php | 40 ++--- Tests/Helper/SinchSupportedCountriesTest.php | 8 +- Tests/Model/CallbackRequestTest.php | 38 ++--- Tests/Model/IdentityTest.php | 14 +- Tests/Service/SinchExceptionResolverTest.php | 86 ++++++----- Tests/Service/SinchTest.php | 2 +- composer.json | 22 +-- phpstan.neon | 11 ++ phpunit.xml.dist | 11 +- 32 files changed, 521 insertions(+), 508 deletions(-) rename Event/{SmsEvent.php => AbstractBaseSmsEvent.php} (95%) create mode 100644 Event/PostSmsSendEvent.php create mode 100644 Event/PreSmsSendEvent.php delete mode 100644 Event/SinchEvents.php delete mode 100644 Service/HTTPClientInterface.php delete mode 100644 Service/HTTPClientService.php create mode 100644 Tests/Event/PostSmsSendEventTest.php create mode 100644 Tests/Event/PreSmsSendEventTest.php delete mode 100644 Tests/Event/SmsEventTest.php rename Tests/Form/Type/{TypeTestCase.php => AbstractTypeTestCase.php} (86%) create mode 100644 phpstan.neon diff --git a/.travis.yml b/.travis.yml index 6b03519..914ec86 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,14 +3,9 @@ language: php sudo: false php: - - 7.1 - - 7.2 - 7.3 env: - - SYMFONY_VERSION=4.0.* - - SYMFONY_VERSION=4.1.* - - SYMFONY_VERSION=4.2.* - SYMFONY_VERSION=4.3.* before_install: @@ -23,6 +18,7 @@ install: script: - ./vendor/bin/phpcs ./ -p --encoding=utf-8 --extensions=php --ignore="vendor|Tests" --standard=./vendor/escapestudios/symfony2-coding-standard/Symfony - ./vendor/bin/phpunit -c phpunit.xml.dist --coverage-clover=coverage.xml + - ./vendor/bin/phpstan analyse -l 7 --no-progress -c phpstan.neon ./ after_success: - bash <(curl -s https://codecov.io/bash) diff --git a/Controller/SinchController.php b/Controller/SinchController.php index c450f55..81bbaec 100644 --- a/Controller/SinchController.php +++ b/Controller/SinchController.php @@ -12,7 +12,6 @@ namespace Fresh\SinchBundle\Controller; -use Fresh\SinchBundle\Event\SinchEvents; use Fresh\SinchBundle\Event\SmsMessageCallbackEvent; use Fresh\SinchBundle\Form\Type\CallbackRequestType; use Fresh\SinchBundle\Model\CallbackRequest; @@ -57,8 +56,7 @@ public function callbackAction(Request $request): Response $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { - $event = new SmsMessageCallbackEvent($callbackRequest); - $this->eventDispatcher->dispatch(SinchEvents::CALLBACK_RECEIVED, $event); + $this->eventDispatcher->dispatch(new SmsMessageCallbackEvent($callbackRequest)); } else { return new Response('Bad Request', Response::HTTP_BAD_REQUEST); } diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 3c1ef6c..a557021 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -12,13 +12,14 @@ namespace Fresh\SinchBundle\DependencyInjection; +use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; use Symfony\Component\Config\Definition\Builder\TreeBuilder; use Symfony\Component\Config\Definition\ConfigurationInterface; /** * Configuration. * - * @author Artem Henvald + * @author Artem Henvald */ class Configuration implements ConfigurationInterface { @@ -27,16 +28,19 @@ class Configuration implements ConfigurationInterface */ public function getConfigTreeBuilder(): TreeBuilder { - $treeBuilder = new TreeBuilder(); - $rootNode = $treeBuilder->root('fresh_sinch'); + $treeBuilder = new TreeBuilder('fresh_sinch'); - $rootNode + /** @var ArrayNodeDefinition $root */ + $root = $treeBuilder->getRootNode(); + + $root ->children() ->scalarNode('host')->defaultValue('https://messagingapi.sinch.com')->end() ->scalarNode('key')->end() ->scalarNode('secret')->end() ->scalarNode('from')->defaultNull()->end() - ->end(); + ->end() + ; return $treeBuilder; } diff --git a/Event/SmsEvent.php b/Event/AbstractBaseSmsEvent.php similarity index 95% rename from Event/SmsEvent.php rename to Event/AbstractBaseSmsEvent.php index 8a5cb5d..60052fb 100644 --- a/Event/SmsEvent.php +++ b/Event/AbstractBaseSmsEvent.php @@ -12,14 +12,12 @@ namespace Fresh\SinchBundle\Event; -use Symfony\Component\EventDispatcher\Event; - /** - * SmsEvent. + * AbstractBaseSmsEvent. * * @author Artem Henvald */ -class SmsEvent extends Event +abstract class AbstractBaseSmsEvent { /** @var string */ private $number; diff --git a/Event/PostSmsSendEvent.php b/Event/PostSmsSendEvent.php new file mode 100644 index 0000000..11e8660 --- /dev/null +++ b/Event/PostSmsSendEvent.php @@ -0,0 +1,22 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); + +namespace Fresh\SinchBundle\Event; + +/** + * PostSmsSendEvent. + * + * @author Artem Henvald + */ +class PostSmsSendEvent extends AbstractBaseSmsEvent +{ +} diff --git a/Event/PreSmsSendEvent.php b/Event/PreSmsSendEvent.php new file mode 100644 index 0000000..72a062a --- /dev/null +++ b/Event/PreSmsSendEvent.php @@ -0,0 +1,22 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); + +namespace Fresh\SinchBundle\Event; + +/** + * PreSmsSendEvent. + * + * @author Artem Henvald + */ +class PreSmsSendEvent extends AbstractBaseSmsEvent +{ +} diff --git a/Event/SinchEvents.php b/Event/SinchEvents.php deleted file mode 100644 index ed874ab..0000000 --- a/Event/SinchEvents.php +++ /dev/null @@ -1,42 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -declare(strict_types=1); - -namespace Fresh\SinchBundle\Event; - -/** - * SinchEvents. - * - * @author Artem Henvald - */ -final class SinchEvents -{ - /** - * This event is triggered before the SMS is going to be sent. - * - * @see \Fresh\SinchBundle\Event\SmsEvent Listeners receive an instance of this class - */ - public const PRE_SMS_SEND = 'sinch.sms.pre_send'; - - /** - * This event is triggered after the SMS is successfully sent. - * - * @see \Fresh\SinchBundle\Event\SmsEvent Listeners receive an instance of this class - */ - public const POST_SMS_SEND = 'sinch.sms.post_send'; - - /** - * This event is triggered callback from Sinch is received. - * - * @see \Fresh\SinchBundle\Event\SmsMessageCallbackEvent Listeners receive an instance of this class - */ - public const CALLBACK_RECEIVED = 'sinch.callback.received'; -} diff --git a/Event/SmsMessageCallbackEvent.php b/Event/SmsMessageCallbackEvent.php index e37a120..3663b9d 100644 --- a/Event/SmsMessageCallbackEvent.php +++ b/Event/SmsMessageCallbackEvent.php @@ -14,14 +14,13 @@ use Fresh\SinchBundle\Model\CallbackRequest; use Fresh\SinchBundle\Model\Identity; -use Symfony\Component\EventDispatcher\Event; /** * SmsMessageCallbackEvent. * * @author Artem Henvald */ -class SmsMessageCallbackEvent extends Event +class SmsMessageCallbackEvent { /** @var CallbackRequest */ private $callbackRequest; diff --git a/Resources/config/services.yml b/Resources/config/services.yml index db7c5ae..54f2746 100644 --- a/Resources/config/services.yml +++ b/Resources/config/services.yml @@ -16,3 +16,6 @@ services: Fresh\SinchBundle\Service\Sinch: class: Fresh\SinchBundle\Service\Sinch + + Symfony\Contracts\HttpClient\HttpClientInterface: + factory: ['Symfony\Component\HttpClient\HttpClient', 'create'] diff --git a/Resources/images/sinch-logo.png b/Resources/images/sinch-logo.png index 1a597c7cc5963e5cb3161618323aaa6c05e4c517..85a3db2f99f145e205d1e9e21a34385f33e23d14 100644 GIT binary patch literal 3129 zcmZ9Pc{o(<8^;GVwq(f?UiwC0*~S_oiEJf1WiLy%7ZIsYC|gk^qe4+a zk*yM0l6@>8OL@|>AEwHa$v~{7MMWTt)d+;cIGhs7L{pQD zz~iAfoGRMzuoh86Umt-phGEER+5{C%eI$;8zz|_51BjN98jg&_5)f!SOq&A5k<_pR zBpQ#9#WQdm0fD8!F(eq82-P-#V99_E98CbEpgJT7hKN8D z;3zUohXlnEpcn%LngrJ&!mtE@g`!Ci9U`0&GjSaP1Zx0D!O?&d0u)PvGNl-5%ovIx zzyTaff&o@B1OSI)cX0v?4d?^*2)j-gW*F_5Qh#uUvEMj@W$Ns*Kn%w)bYM&!1`A{X zCrq7PCx8uRYa$fTWUxR1;Pa0TgJtUcYXbu;cc<7LnSn#myPkjJ%tlP9UpSCr*kBYh zEHNvA;9r)RWqM=IyPE~{nT>#bCI}S&_5j3yAmdaS0n<5fKFm$#&hCtVbapoxbld|G9xN|GWJE_}|ul>i=87bn-j(>tO#Q{=0Z*X9q578v}gt8~)}d79bW@ zwmo~n>>Qk2-1~U;^YZZv91s)|7C9&?CjOU%q?ELbtem`pqSF7A52>iCL7*@=LLI50 zc|=Pag~niYaJqW>cmo2FM5Y)T8Jiq6H8Z!cq*__q*xK12b8vJz?(A~H^`zS=cMnf5 zZy(wwT-#0e5wtxJ@_#OKK90H4r zArZgX=MAQSKau}()j7oI@r9gX0!y;d?t5O?Kj-GxHMObTIq4Q!QWBOD@X2;~A*^6$ z&MF{aRTF`senJXT2WCF(6x(W#{vB5n7c&0AHQG==P5m**)#fUaeksyt%i;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YzoI^@T z>1(Y4bL>P{KyN=7=RB|n&?qBBk={eq>uWN$^D&IM%8)L|rG=E%1`XsL_0CG25$d(R)_k%9c`2nD_{wOYWdw0QdSz?I zC@=*7i9nyv&`TvUig$s|Uq0TMUxB%vvsC!a@!Hfdq=}T)HVv$|)589Jho7#Op`4*Z M4jg>X-Xq5UAI;wyPyhe` diff --git a/Service/HTTPClientInterface.php b/Service/HTTPClientInterface.php deleted file mode 100644 index 39a3ab4..0000000 --- a/Service/HTTPClientInterface.php +++ /dev/null @@ -1,39 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -declare(strict_types=1); - -namespace Fresh\SinchBundle\Service; - -/** - * HTTPClientInterface. - * - * @author Artem Henvald - */ -interface HTTPClientInterface -{ - /** - * @param string $uri - * @param array $body - * @param array $headers - * - * @return mixed - */ - public function post(string $uri, array $body = [], array $headers = []); - - /** - * @param string $uri - * @param array $queryParameters - * @param array $headers - * - * @return mixed - */ - public function get(string $uri, array $queryParameters = [], array $headers = []); -} diff --git a/Service/HTTPClientService.php b/Service/HTTPClientService.php deleted file mode 100644 index 32efa60..0000000 --- a/Service/HTTPClientService.php +++ /dev/null @@ -1,37 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -declare(strict_types=1); - -namespace Fresh\SinchBundle\Service; - -/** - * HTTPClientInterface. - * - * @author Artem Henvald - */ -class HTTPClientService implements HTTPClientInterface -{ - /** - * {@inheritdoc} - */ - public function post(string $uri, array $body = [], array $headers = []) - { - // @todo - } - - /** - * {@inheritdoc} - */ - public function get(string $uri, array $queryParameters = [], array $headers = []) - { - // @todo - } -} diff --git a/Service/Sinch.php b/Service/Sinch.php index f565e23..69f8af6 100644 --- a/Service/Sinch.php +++ b/Service/Sinch.php @@ -12,17 +12,18 @@ namespace Fresh\SinchBundle\Service; -use Fresh\SinchBundle\Event\SinchEvents; -use Fresh\SinchBundle\Event\SmsEvent; +use Fresh\SinchBundle\Event\PostSmsSendEvent; +use Fresh\SinchBundle\Event\PreSmsSendEvent; use Fresh\SinchBundle\Exception\SinchException; use Fresh\SinchBundle\Helper\SinchSmsStatus; -use GuzzleHttp\Client; -use GuzzleHttp\Exception\ClientException; use Symfony\Component\EventDispatcher\EventDispatcherInterface; +use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; +use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface; +use Symfony\Contracts\HttpClient\HttpClientInterface; /** - * Sinch Service. + * Sinch. * * @author Artem Henvald */ @@ -32,12 +33,12 @@ class Sinch public const URL_FOR_CHECKING_SMS_STATUS = '/v1/message/status/'; - /** @var Client */ - private $guzzleHTTPClient; - /** @var EventDispatcherInterface */ private $dispatcher; + /** @var HttpClientInterface */ + private $httpClient; + /** @var string */ private $host; @@ -52,22 +53,20 @@ class Sinch /** * @param EventDispatcherInterface $dispatcher + * @param HttpClientInterface $httpClient * @param string $host * @param string $key * @param string $secret * @param string|null $from */ - public function __construct(EventDispatcherInterface $dispatcher, $host, $key, $secret, $from = null) + public function __construct(EventDispatcherInterface $dispatcher, HttpClientInterface $httpClient, $host, $key, $secret, $from = null) { $this->dispatcher = $dispatcher; + $this->httpClient = $httpClient; $this->host = $host; $this->key = $key; $this->secret = $secret; $this->from = $from; - - $this->guzzleHTTPClient = new Client([ - 'base_uri' => \rtrim($this->host, '/'), - ]); } /** @@ -84,37 +83,38 @@ public function sendSMS(string $phoneNumber, string $messageText, ?string $from // @todo validate phone number $body = [ - 'auth' => [$this->key, $this->secret], - 'headers' => ['X-Timestamp' => (new \DateTime('now'))->format('c')], // ISO 8601 date format - 'json' => ['message' => $messageText], + 'message' => $messageText, ]; if (null !== $from) { - $body['json']['from'] = $from; + $body['from'] = $from; } elseif (null !== $this->from) { $from = $this->from; - $body['json']['from'] = $from; + $body['from'] = $from; } - try { - $smsEvent = new SmsEvent($phoneNumber, $messageText, $from); + $this->dispatcher->dispatch(new PreSmsSendEvent($phoneNumber, $messageText, $from)); - $this->dispatcher->dispatch(SinchEvents::PRE_SMS_SEND, $smsEvent); - $response = $this->guzzleHTTPClient->post(self::URL_FOR_SENDING_SMS.$phoneNumber, $body); - $this->dispatcher->dispatch(SinchEvents::POST_SMS_SEND, $smsEvent); - } catch (ClientException $e) { - throw SinchExceptionResolver::createAppropriateSinchException($e); - } + $response = $this->httpClient->request( + Request::METHOD_POST, + self::URL_FOR_SENDING_SMS.$phoneNumber, + [ + 'auth_basic' => [$this->key, $this->secret], + 'headers' => ['X-Timestamp' => (new \DateTime('now'))->format('c')], + 'json' => $body, + ] + ); + + $this->dispatcher->dispatch(new PostSmsSendEvent($phoneNumber, $messageText, $from)); $messageId = null; - if (Response::HTTP_OK === $response->getStatusCode() && $response->hasHeader('Content-Type') - && 'application/json; charset=utf-8' === $response->getHeaderLine('Content-Type') + $headers = $response->getHeaders(); + if (Response::HTTP_OK === $response->getStatusCode() && isset($headers['Content-Type']) + && 'application/json; charset=utf-8' === $headers['Content-Type'] ) { - $content = $response->getBody()->getContents(); - $content = \json_decode($content, true); - - if (isset($content['messageId']) && \array_key_exists('messageId', $content)) { + $content = \json_decode($response->getContent(), true); + if (\array_key_exists('messageId', $content)) { $messageId = $content['messageId']; } } @@ -132,7 +132,7 @@ public function getStatusOfSMS(int $messageId): string $response = $this->sendRequestToCheckStatusOfSMS($messageId); $result = ''; - if (isset($response['status']) && \array_key_exists('status', $response)) { + if (\array_key_exists('status', $response)) { $result = $response['status']; } @@ -149,7 +149,7 @@ public function smsIsSentSuccessfully(int $messageId): bool $response = $this->sendRequestToCheckStatusOfSMS($messageId); $result = false; - if (isset($response['status']) && SinchSmsStatus::SUCCESSFUL === $response['status']) { + if (\array_key_exists('status', $response) && SinchSmsStatus::SUCCESSFUL === $response['status']) { $result = true; } @@ -166,7 +166,7 @@ public function smsIsPending(int $messageId): bool $response = $this->sendRequestToCheckStatusOfSMS($messageId); $result = false; - if (isset($response['status']) && SinchSmsStatus::PENDING === $response['status']) { + if (\array_key_exists('status', $response) && SinchSmsStatus::PENDING === $response['status']) { $result = true; } @@ -183,7 +183,7 @@ public function smsIsFaulted(int $messageId): bool $response = $this->sendRequestToCheckStatusOfSMS($messageId); $result = false; - if (isset($response['status']) && SinchSmsStatus::FAULTED === $response['status']) { + if (\array_key_exists('status', $response) && SinchSmsStatus::FAULTED === $response['status']) { $result = true; } @@ -200,7 +200,7 @@ public function smsInUnknownStatus(int $messageId): bool $response = $this->sendRequestToCheckStatusOfSMS($messageId); $result = false; - if (isset($response['status']) && SinchSmsStatus::UNKNOWN === $response['status']) { + if (\array_key_exists('status', $response) && SinchSmsStatus::UNKNOWN === $response['status']) { $result = true; } @@ -214,24 +214,22 @@ public function smsInUnknownStatus(int $messageId): bool */ private function sendRequestToCheckStatusOfSMS(int $messageId): ?array { - $body = [ - 'auth' => [$this->key, $this->secret], - 'headers' => ['X-Timestamp' => (new \DateTime('now'))->format('c')], - ]; - - try { - $response = $this->guzzleHTTPClient->get(self::URL_FOR_CHECKING_SMS_STATUS.$messageId, $body); - } catch (ClientException $e) { - throw SinchExceptionResolver::createAppropriateSinchException($e); - } + $response = $this->httpClient->request( + Request::METHOD_GET, + self::URL_FOR_CHECKING_SMS_STATUS.$messageId, + [ + 'auth_basic' => [$this->key, $this->secret], + 'headers' => ['X-Timestamp' => (new \DateTime('now'))->format('c')], + ] + ); $result = null; - if (Response::HTTP_OK === $response->getStatusCode() && $response->hasHeader('Content-Type') - && 'application/json; charset=utf-8' === $response->getHeaderLine('Content-Type') + $headers = $response->getHeaders(); + if (Response::HTTP_OK === $response->getStatusCode() && isset($headers['Content-Type']) + && 'application/json; charset=utf-8' === $headers['Content-Type'] ) { - $content = $response->getBody()->getContents(); - $result = \json_decode($content, true); + $result = \json_decode($response->getContent(), true); } return $result; diff --git a/Service/SinchExceptionResolver.php b/Service/SinchExceptionResolver.php index 5403af7..97b80f0 100644 --- a/Service/SinchExceptionResolver.php +++ b/Service/SinchExceptionResolver.php @@ -23,7 +23,6 @@ use Fresh\SinchBundle\Exception\SinchException; use Fresh\SinchBundle\Exception\Unauthorized\SinchIllegalAuthorizationHeaderException; use Fresh\SinchBundle\Helper\SinchErrorCode; -use GuzzleHttp\Exception\ClientException; use Symfony\Component\HttpFoundation\Response; /** @@ -51,23 +50,18 @@ public static function createAppropriateSinchException(ClientException $e): \Exc switch ($responseStatusCode) { case Response::HTTP_BAD_REQUEST: $exception = self::getSinchExceptionForBadRequest($errorCode, $errorMessage); - break; case Response::HTTP_UNAUTHORIZED: $exception = self::getSinchExceptionForUnauthorized($errorCode, $errorMessage); - break; case Response::HTTP_PAYMENT_REQUIRED: $exception = self::getSinchExceptionForPaymentRequired($errorCode, $errorMessage); - break; case Response::HTTP_FORBIDDEN: $exception = self::getSinchExceptionForForbidden($errorCode, $errorMessage); - break; case Response::HTTP_INTERNAL_SERVER_ERROR: $exception = self::getSinchExceptionForInternalServerError($errorCode, $errorMessage); - break; } @@ -91,15 +85,12 @@ private static function getSinchExceptionForBadRequest(int $errorCode, string $e switch ($errorCode) { case SinchErrorCode::PARAMETER_VALIDATION: $exception = new SinchParameterValidationException($errorMessage); - break; case SinchErrorCode::MISSING_PARAMETER: $exception = new SinchMissingParameterException($errorMessage); - break; case SinchErrorCode::INVALID_REQUEST: $exception = new SinchInvalidRequestException($errorMessage); - break; } @@ -155,16 +146,13 @@ private static function getSinchExceptionForForbidden(int $errorCode, string $er switch ($errorCode) { case SinchErrorCode::FORBIDDEN_REQUEST: $exception = new SinchForbiddenRequestException($errorMessage); - break; case SinchErrorCode::INVALID_AUTHORIZATION_SCHEME_FOR_CALLING_THE_METHOD: $exception = new SinchInvalidAuthorizationSchemeException($errorMessage); - break; case SinchErrorCode::NO_VERIFIED_PHONE_NUMBER_ON_YOUR_SINCH_ACCOUNT: case SinchErrorCode::SANDBOX_SMS_ONLY_ALLOWED_TO_BE_SENT_TO_VERIFIED_NUMBERS: $exception = new SinchNoVerifiedPhoneNumberException($errorMessage); - break; } @@ -187,6 +175,4 @@ private static function getSinchExceptionForInternalServerError(int $errorCode, return $exception; } - - // endregion } diff --git a/Tests/Controller/SinchControllerTest.php b/Tests/Controller/SinchControllerTest.php index a6747fa..fc13ca4 100644 --- a/Tests/Controller/SinchControllerTest.php +++ b/Tests/Controller/SinchControllerTest.php @@ -10,6 +10,7 @@ namespace Fresh\SinchBundle\Tests\Controller; +use PHPUnit\Framework\MockObject\MockObject; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; use Symfony\Component\EventDispatcher\Debug\TraceableEventDispatcher; use Symfony\Component\Form\Form; @@ -27,109 +28,119 @@ class SinchControllerTest extends WebTestCase { public const DEFAULT_SINCH_CALLBACK_URL = '/sinch/callback'; - /** @var \PHPUnit_Framework_MockObject_MockObject|TraceableEventDispatcher */ + /** @var TraceableEventDispatcher|MockObject */ private $eventDispatcher; - /** @var \PHPUnit_Framework_MockObject_MockObject|FormFactory */ + /** @var FormFactory|MockObject */ private $formFactory; - /** @var \PHPUnit_Framework_MockObject_MockObject|Form */ + /** @var Form|MockObject */ private $form; /** @var SinchController */ private $controller; - protected function setUp() + protected function setUp(): void { - $this->eventDispatcher = $this->getMockBuilder(TraceableEventDispatcher::class) - ->disableOriginalConstructor() - ->setMethods(['dispatch']) - ->getMock(); - - $this->formFactory = $this->getMockBuilder(FormFactory::class) - ->disableOriginalConstructor() - ->setMethods(['create']) - ->getMock(); - - $this->form = $this->getMockBuilder(Form::class) - ->disableOriginalConstructor() - ->setMethods(['isValid', 'isSubmitted', 'handleRequest']) - ->getMock(); - - $this->formFactory->expects($this->once()) - ->method('create') - ->willReturn($this->form); + $this->eventDispatcher = $this->createMock(TraceableEventDispatcher::class); + $this->form = $this->createMock(Form::class); + $this->formFactory = $this->createMock(FormFactory::class); + $this->formFactory + ->expects(self::once()) + ->method('create') + ->willReturn($this->form) + ; $this->controller = new SinchController($this->formFactory, $this->eventDispatcher); } - protected function tearDown() + protected function tearDown(): void { - unset($this->formFactory); - unset($this->eventDispatcher); - unset($this->controller); - unset($this->form); + unset( + $this->eventDispatcher, + $this->form, + $this->formFactory, + $this->controller, + ); } - public function testValidCallback() + public function testValidCallback(): void { - $this->form->expects($this->once()) - ->method('isSubmitted') - ->willReturn(true); - - $this->form->expects($this->once()) - ->method('isValid') - ->willReturn(true); + $this->form + ->expects(self::once()) + ->method('isSubmitted') + ->willReturn(true) + ; + + $this->form + ->expects(self::once()) + ->method('isValid') + ->willReturn(true) + ; $request = Request::create(self::DEFAULT_SINCH_CALLBACK_URL, 'POST'); $response = $this->controller->callbackAction($request); - $this->assertEquals(Response::HTTP_OK, $response->getStatusCode()); + self::assertEquals(Response::HTTP_OK, $response->getStatusCode()); } - public function testNotSubmittedData() + public function testNotSubmittedData(): void { - $this->form->expects($this->once()) - ->method('isSubmitted') - ->willReturn(false); - $this->form->expects($this->never()) - ->method('isValid'); + $this->form + ->expects(self::once()) + ->method('isSubmitted') + ->willReturn(false) + ; + $this->form + ->expects($this->never()) + ->method('isValid') + ; $request = Request::create(self::DEFAULT_SINCH_CALLBACK_URL, 'POST'); $response = $this->controller->callbackAction($request); - $this->assertEquals(Response::HTTP_BAD_REQUEST, $response->getStatusCode()); + self::assertEquals(Response::HTTP_BAD_REQUEST, $response->getStatusCode()); } - public function testNotValidData() + public function testNotValidData(): void { - $this->form->expects($this->once()) - ->method('isSubmitted') - ->willReturn(true); - - $this->form->expects($this->once()) - ->method('isValid') - ->willReturn(false); + $this->form + ->expects(self::once()) + ->method('isSubmitted') + ->willReturn(true) + ; + + $this->form + ->expects(self::once()) + ->method('isValid') + ->willReturn(false) + ; $request = Request::create(self::DEFAULT_SINCH_CALLBACK_URL, 'POST'); $response = $this->controller->callbackAction($request); - $this->assertEquals(Response::HTTP_BAD_REQUEST, $response->getStatusCode()); + self::assertEquals(Response::HTTP_BAD_REQUEST, $response->getStatusCode()); } - public function testInternalError() + public function testInternalError(): void { - $this->eventDispatcher->expects($this->once()) - ->method('dispatch') - ->willThrowException(new \Exception()); - - $this->form->expects($this->once()) - ->method('isSubmitted') - ->willReturn(true); - - $this->form->expects($this->once()) - ->method('isValid') - ->willReturn(true); + $this->eventDispatcher + ->expects(self::once()) + ->method('dispatch') + ->willThrowException(new \Exception()) + ; + + $this->form + ->expects(self::once()) + ->method('isSubmitted') + ->willReturn(true) + ; + + $this->form + ->expects(self::once()) + ->method('isValid') + ->willReturn(true) + ; $request = Request::create(self::DEFAULT_SINCH_CALLBACK_URL, 'POST'); $response = $this->controller->callbackAction($request); - $this->assertEquals(Response::HTTP_INTERNAL_SERVER_ERROR, $response->getStatusCode()); + self::assertEquals(Response::HTTP_INTERNAL_SERVER_ERROR, $response->getStatusCode()); } } diff --git a/Tests/DependencyInjection/ConfigurationTest.php b/Tests/DependencyInjection/ConfigurationTest.php index efe5b41..060016c 100644 --- a/Tests/DependencyInjection/ConfigurationTest.php +++ b/Tests/DependencyInjection/ConfigurationTest.php @@ -23,9 +23,9 @@ class ConfigurationTest extends TestCase { use ConfigurationTestCaseTrait; - public function testInvalidConfiguration() + public function testInvalidConfiguration(): void { - $this->assertConfigurationIsInvalid( + self::assertConfigurationIsInvalid( [ [ 'invalid_parameter' => 123, @@ -35,9 +35,9 @@ public function testInvalidConfiguration() ); } - public function testValidDefaultConfiguration() + public function testValidDefaultConfiguration(): void { - $this->assertProcessedConfigurationEquals( + self::assertProcessedConfigurationEquals( [], [ 'host' => 'https://messagingapi.sinch.com', @@ -46,9 +46,9 @@ public function testValidDefaultConfiguration() ); } - public function testValidConfigurationWithHost() + public function testValidConfigurationWithHost(): void { - $this->assertProcessedConfigurationEquals( + self::assertProcessedConfigurationEquals( [ [ 'host' => 'https://test.com', @@ -65,9 +65,9 @@ public function testValidConfigurationWithHost() ); } - public function testValidConfigurationWithoutFrom() + public function testValidConfigurationWithoutFrom(): void { - $this->assertProcessedConfigurationEquals( + self::assertProcessedConfigurationEquals( [ [ 'key' => '1234567890', @@ -83,9 +83,9 @@ public function testValidConfigurationWithoutFrom() ); } - public function testValidConfigurationWithFrom() + public function testValidConfigurationWithFrom(): void { - $this->assertProcessedConfigurationEquals( + self::assertProcessedConfigurationEquals( [ [ 'key' => '1234567890', @@ -102,7 +102,7 @@ public function testValidConfigurationWithFrom() ); } - protected function getConfiguration() + protected function getConfiguration(): Configuration { return new Configuration(); } diff --git a/Tests/DependencyInjection/FreshSinchExtensionTest.php b/Tests/DependencyInjection/FreshSinchExtensionTest.php index ccc500a..47d612a 100644 --- a/Tests/DependencyInjection/FreshSinchExtensionTest.php +++ b/Tests/DependencyInjection/FreshSinchExtensionTest.php @@ -31,20 +31,20 @@ class FreshSinchExtensionTest extends TestCase /** @var ContainerBuilder */ private $container; - protected function setUp() + protected function setUp(): void { $this->extension = new FreshSinchExtension(); $this->container = new ContainerBuilder(); $this->container->registerExtension($this->extension); } - public function testLoadExtension() + public function testLoadExtension(): void { $yaml = <<<'CONFIG' -fresh_sinch: - key: some_dummy_key - secret: some_dummy_secret -CONFIG; + fresh_sinch: + key: some_dummy_key + secret: some_dummy_secret + CONFIG; $parser = new Parser(); $config = $parser->parse($yaml); @@ -54,19 +54,19 @@ public function testLoadExtension() $this->container->set('form.factory', new \stdClass()); $this->container->compile(); - $this->assertArrayHasKey(Sinch::class, $this->container->getRemovedIds()); - $this->assertArrayHasKey(SinchController::class, $this->container->getRemovedIds()); + self::assertArrayHasKey(Sinch::class, $this->container->getRemovedIds()); + self::assertArrayHasKey(SinchController::class, $this->container->getRemovedIds()); - $this->assertArrayNotHasKey(Sinch::class, $this->container->getDefinitions()); - $this->assertArrayNotHasKey(SinchController::class, $this->container->getDefinitions()); + self::assertArrayNotHasKey(Sinch::class, $this->container->getDefinitions()); + self::assertArrayNotHasKey(SinchController::class, $this->container->getDefinitions()); $this->expectException(ServiceNotFoundException::class); $this->container->get(Sinch::class); $this->container->get(SinchController::class); - $this->assertTrue($this->container->hasParameter('sinch.host')); - $this->assertTrue($this->container->hasParameter('sinch.key')); - $this->assertTrue($this->container->hasParameter('sinch.secret')); - $this->assertTrue($this->container->hasParameter('sinch.from')); + self::assertTrue($this->container->hasParameter('sinch.host')); + self::assertTrue($this->container->hasParameter('sinch.key')); + self::assertTrue($this->container->hasParameter('sinch.secret')); + self::assertTrue($this->container->hasParameter('sinch.from')); } } diff --git a/Tests/Event/PostSmsSendEventTest.php b/Tests/Event/PostSmsSendEventTest.php new file mode 100644 index 0000000..3e3dd63 --- /dev/null +++ b/Tests/Event/PostSmsSendEventTest.php @@ -0,0 +1,75 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Fresh\SinchBundle\Tests\Event; + +use Fresh\SinchBundle\Event\AbstractBaseSmsEvent; +use Fresh\SinchBundle\Event\PostSmsSendEvent; +use PHPUnit\Framework\TestCase; + +/** + * PostSmsSendEventTest. + * + * @author Artem Henvald + */ +class PostSmsSendEventTest extends TestCase +{ + public function testConstructorWithoutFrom(): void + { + $number = '+46700000000'; + $message = 'Hello world'; + + $postSmsSendEvent = new PostSmsSendEvent($number, $message); + + self::assertEquals($number, $postSmsSendEvent->getNumber()); + self::assertEquals($message, $postSmsSendEvent->getMessage()); + self::assertInstanceOf(AbstractBaseSmsEvent::class, $postSmsSendEvent); + } + + public function testConstructorWithFrom(): void + { + $number = '+46700000000'; + $message = 'Hello world'; + $from = 'Santa Claus'; + + $postSmsSendEvent = new PostSmsSendEvent($number, $message, $from); + + self::assertEquals($number, $postSmsSendEvent->getNumber()); + self::assertEquals($message, $postSmsSendEvent->getMessage()); + self::assertEquals($from, $postSmsSendEvent->getFrom()); + } + + public function testSetGetNumber(): void + { + $postSmsSendEvent = new PostSmsSendEvent('', ''); + + $number = '+46700000000'; + $postSmsSendEvent->setNumber($number); + self::assertEquals($number, $postSmsSendEvent->getNumber()); + } + + public function testSetGetMessage(): void + { + $postSmsSendEvent = new PostSmsSendEvent('', ''); + + $message = 'Hello world'; + $postSmsSendEvent->setMessage($message); + self::assertEquals($message, $postSmsSendEvent->getMessage()); + } + + public function testSetGetFrom(): void + { + $postSmsSendEvent = new PostSmsSendEvent('', ''); + + $from = 'Santa Claus'; + $postSmsSendEvent->setFrom($from); + self::assertEquals($from, $postSmsSendEvent->getFrom()); + } +} diff --git a/Tests/Event/PreSmsSendEventTest.php b/Tests/Event/PreSmsSendEventTest.php new file mode 100644 index 0000000..099f90c --- /dev/null +++ b/Tests/Event/PreSmsSendEventTest.php @@ -0,0 +1,73 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Fresh\SinchBundle\Tests\Event; + +use Fresh\SinchBundle\Event\PreSmsSendEvent; +use PHPUnit\Framework\TestCase; + +/** + * PreSmsSendEventTest. + * + * @author Artem Henvald + */ +class PreSmsSendEventTest extends TestCase +{ + public function testConstructorWithoutFrom(): void + { + $number = '+46700000000'; + $message = 'Hello world'; + + $preSmsSendEvent = new PreSmsSendEvent($number, $message); + + self::assertEquals($number, $preSmsSendEvent->getNumber()); + self::assertEquals($message, $preSmsSendEvent->getMessage()); + } + + public function testConstructorWithFrom(): void + { + $number = '+46700000000'; + $message = 'Hello world'; + $from = 'Santa Claus'; + + $preSmsSendEvent = new PreSmsSendEvent($number, $message, $from); + + self::assertEquals($number, $preSmsSendEvent->getNumber()); + self::assertEquals($message, $preSmsSendEvent->getMessage()); + self::assertEquals($from, $preSmsSendEvent->getFrom()); + } + + public function testSetGetNumber(): void + { + $preSmsSendEvent = new PreSmsSendEvent('', ''); + + $number = '+46700000000'; + $preSmsSendEvent->setNumber($number); + self::assertEquals($number, $preSmsSendEvent->getNumber()); + } + + public function testSetGetMessage(): void + { + $preSmsSendEvent = new PreSmsSendEvent('', ''); + + $message = 'Hello world'; + $preSmsSendEvent->setMessage($message); + self::assertEquals($message, $preSmsSendEvent->getMessage()); + } + + public function testSetGetFrom(): void + { + $preSmsSendEvent = new PreSmsSendEvent('', ''); + + $from = 'Santa Claus'; + $preSmsSendEvent->setFrom($from); + self::assertEquals($from, $preSmsSendEvent->getFrom()); + } +} diff --git a/Tests/Event/SmsEventTest.php b/Tests/Event/SmsEventTest.php deleted file mode 100644 index 2c109b4..0000000 --- a/Tests/Event/SmsEventTest.php +++ /dev/null @@ -1,73 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Fresh\SinchBundle\Tests\Event; - -use Fresh\SinchBundle\Event\SmsEvent; -use PHPUnit\Framework\TestCase; - -/** - * SmsEventTest. - * - * @author Artem Henvald - */ -class SmsEventTest extends TestCase -{ - public function testConstructorWithoutFrom() - { - $number = '+46700000000'; - $message = 'Hello world'; - - $smsEvent = new SmsEvent($number, $message); - - $this->assertEquals($number, $smsEvent->getNumber()); - $this->assertEquals($message, $smsEvent->getMessage()); - } - - public function testConstructorWithFrom() - { - $number = '+46700000000'; - $message = 'Hello world'; - $from = 'Santa Claus'; - - $smsEvent = new SmsEvent($number, $message, $from); - - $this->assertEquals($number, $smsEvent->getNumber()); - $this->assertEquals($message, $smsEvent->getMessage()); - $this->assertEquals($from, $smsEvent->getFrom()); - } - - public function testSetGetNumber() - { - $smsEvent = new SmsEvent('', ''); - - $number = '+46700000000'; - $smsEvent->setNumber($number); - $this->assertEquals($number, $smsEvent->getNumber()); - } - - public function testSetGetMessage() - { - $smsEvent = new SmsEvent('', ''); - - $message = 'Hello world'; - $smsEvent->setMessage($message); - $this->assertEquals($message, $smsEvent->getMessage()); - } - - public function testSetGetFrom() - { - $smsEvent = new SmsEvent('', ''); - - $from = 'Santa Claus'; - $smsEvent->setFrom($from); - $this->assertEquals($from, $smsEvent->getFrom()); - } -} diff --git a/Tests/Event/SmsMessageCallbackEventTest.php b/Tests/Event/SmsMessageCallbackEventTest.php index 5e8b430..6923b10 100644 --- a/Tests/Event/SmsMessageCallbackEventTest.php +++ b/Tests/Event/SmsMessageCallbackEventTest.php @@ -22,7 +22,7 @@ */ class SmsMessageCallbackEventTest extends TestCase { - public function testConstructor() + public function testConstructor(): void { $event = 'incomingSms'; $from = new Identity(); @@ -38,13 +38,14 @@ public function testConstructor() ->setMessage($message) ->setTimestamp($timestamp) ->setVersion($version); + $callbackEvent = new SmsMessageCallbackEvent($callbackRequest); - $this->assertEquals($event, $callbackEvent->getEvent()); - $this->assertEquals($from, $callbackEvent->getFrom()); - $this->assertEquals($to, $callbackEvent->getTo()); - $this->assertEquals($message, $callbackEvent->getMessage()); - $this->assertEquals($timestamp, $callbackEvent->getTimestamp()); - $this->assertEquals($version, $callbackEvent->getVersion()); + self::assertEquals($event, $callbackEvent->getEvent()); + self::assertEquals($from, $callbackEvent->getFrom()); + self::assertEquals($to, $callbackEvent->getTo()); + self::assertEquals($message, $callbackEvent->getMessage()); + self::assertEquals($timestamp, $callbackEvent->getTimestamp()); + self::assertEquals($version, $callbackEvent->getVersion()); } } diff --git a/Tests/Form/Type/TypeTestCase.php b/Tests/Form/Type/AbstractTypeTestCase.php similarity index 86% rename from Tests/Form/Type/TypeTestCase.php rename to Tests/Form/Type/AbstractTypeTestCase.php index 71c54d7..bf5cdc6 100644 --- a/Tests/Form/Type/TypeTestCase.php +++ b/Tests/Form/Type/AbstractTypeTestCase.php @@ -16,11 +16,11 @@ use Symfony\Component\Form\Test\FormIntegrationTestCase; /** - * TypeTestCase + * AbstractTypeTestCase. * * @author Artem Henvald */ -abstract class TypeTestCase extends FormIntegrationTestCase +abstract class AbstractTypeTestCase extends FormIntegrationTestCase { /** @var FormBuilder */ protected $builder; @@ -28,7 +28,7 @@ abstract class TypeTestCase extends FormIntegrationTestCase /** @var EventDispatcher */ protected $dispatcher; - protected function setUp() + protected function setUp(): void { parent::setUp(); @@ -36,7 +36,7 @@ protected function setUp() $this->builder = new FormBuilder(null, null, $this->dispatcher, $this->factory); } - public static function assertDateTimeEquals(\DateTime $expected, \DateTime $actual) + public static function assertDateTimeEquals(\DateTime $expected, \DateTime $actual): void { self::assertEquals($expected->format('c'), $actual->format('c')); } diff --git a/Tests/Form/Type/CallbackRequestTypeTest.php b/Tests/Form/Type/CallbackRequestTypeTest.php index a56e134..82b75b9 100644 --- a/Tests/Form/Type/CallbackRequestTypeTest.php +++ b/Tests/Form/Type/CallbackRequestTypeTest.php @@ -21,27 +21,27 @@ * * @author Artem Henvald */ -class CallbackRequestTypeTest extends TypeTestCase +class CallbackRequestTypeTest extends AbstractTypeTestCase { - public function testGetBlockPrefix() + public function testGetBlockPrefix(): void { - $this->assertEmpty((new CallbackRequestType)->getBlockPrefix()); + self::assertEmpty((new CallbackRequestType)->getBlockPrefix()); } - public function testFormBuilder() + public function testFormBuilder(): void { $form = $this->factory->createBuilder(CallbackRequestType::class)->getForm(); - $this->assertEquals(6, $form->count()); - $this->assertInstanceOf(FormInterface::class, $form->get('event')); - $this->assertInstanceOf(FormInterface::class, $form->get('from')); - $this->assertInstanceOf(FormInterface::class, $form->get('to')); - $this->assertInstanceOf(FormInterface::class, $form->get('message')); - $this->assertInstanceOf(FormInterface::class, $form->get('timestamp')); - $this->assertInstanceOf(FormInterface::class, $form->get('version')); + self::assertEquals(6, $form->count()); + self::assertInstanceOf(FormInterface::class, $form->get('event')); + self::assertInstanceOf(FormInterface::class, $form->get('from')); + self::assertInstanceOf(FormInterface::class, $form->get('to')); + self::assertInstanceOf(FormInterface::class, $form->get('message')); + self::assertInstanceOf(FormInterface::class, $form->get('timestamp')); + self::assertInstanceOf(FormInterface::class, $form->get('version')); } - public function testGetDefaultOptions() + public function testGetDefaultOptions(): void { $type = new CallbackRequestType(); @@ -51,11 +51,11 @@ public function testGetDefaultOptions() $options = $optionResolver->resolve(); - $this->assertFalse($options['csrf_protection']); - $this->assertEquals(CallbackRequest::class, $options['data_class']); + self::assertFalse($options['csrf_protection']); + self::assertEquals(CallbackRequest::class, $options['data_class']); } - public function testSubmitValidData() + public function testSubmitValidData(): void { $data = [ 'event' => 'incomingSms', @@ -85,23 +85,23 @@ public function testSubmitValidData() // Submit the data to the form directly $form->submit($data); - $this->assertTrue($form->isSynchronized()); + self::assertTrue($form->isSynchronized()); - /** @var \Fresh\SinchBundle\Model\CallbackRequest $formData */ + /** @var CallbackRequest $formData */ $formData = $form->getData(); - $this->assertEquals($identity, $formData); - $this->assertInternalType('string', $formData->getEvent()); - $this->assertInternalType('object', $formData->getFrom()); - $this->assertInternalType('object', $formData->getTo()); - $this->assertInternalType('string', $formData->getMessage()); - $this->assertInternalType('object', $formData->getTimestamp()); - $this->assertInternalType('integer', $formData->getVersion()); + self::assertEquals($identity, $formData); + self::assertIsString($formData->getEvent()); + self::assertIsObject($formData->getFrom()); + self::assertIsObject($formData->getTo()); + self::assertIsString($formData->getMessage()); + self::assertIsObject($formData->getTimestamp()); + self::assertIsInt($formData->getVersion()); $view = $form->createView(); $children = $view->children; foreach (\array_keys($data) as $key) { - $this->assertArrayHasKey($key, $children); + self::assertArrayHasKey($key, $children); } } } diff --git a/Tests/Form/Type/IdentityTypeTest.php b/Tests/Form/Type/IdentityTypeTest.php index 9bbb480..20018fc 100644 --- a/Tests/Form/Type/IdentityTypeTest.php +++ b/Tests/Form/Type/IdentityTypeTest.php @@ -20,23 +20,23 @@ * * @author Artem Henvald */ -class IdentityTypeTest extends TypeTestCase +class IdentityTypeTest extends AbstractTypeTestCase { - public function testGetBlockPrefix() + public function testGetBlockPrefix(): void { - $this->assertEmpty((new IdentityType)->getBlockPrefix()); + self::assertEmpty((new IdentityType())->getBlockPrefix()); } - public function testFormBuilder() + public function testFormBuilder(): void { $form = $this->factory->createBuilder(IdentityType::class)->getForm(); - $this->assertEquals(2, $form->count()); - $this->assertInstanceOf(FormInterface::class, $form->get('type')); - $this->assertInstanceOf(FormInterface::class, $form->get('endpoint')); + self::assertEquals(2, $form->count()); + self::assertInstanceOf(FormInterface::class, $form->get('type')); + self::assertInstanceOf(FormInterface::class, $form->get('endpoint')); } - public function testGetDefaultOptions() + public function testGetDefaultOptions(): void { $type = new IdentityType(); @@ -46,11 +46,11 @@ public function testGetDefaultOptions() $options = $optionResolver->resolve(); - $this->assertFalse($options['csrf_protection']); - $this->assertEquals(Identity::class, $options['data_class']); + self::assertFalse($options['csrf_protection']); + self::assertEquals(Identity::class, $options['data_class']); } - public function testSubmitValidData() + public function testSubmitValidData(): void { $data = [ 'type' => 'number', @@ -59,25 +59,27 @@ public function testSubmitValidData() $form = $this->factory->create(IdentityType::class); - $identity = (new Identity())->setType('number') - ->setEndpoint('+46700000000'); + $identity = (new Identity()) + ->setType('number') + ->setEndpoint('+46700000000') + ; // Submit the data to the form directly $form->submit($data); - $this->assertTrue($form->isSynchronized()); + self::assertTrue($form->isSynchronized()); - /** @var \Fresh\SinchBundle\Model\Identity $formData */ + /** @var Identity $formData */ $formData = $form->getData(); - $this->assertEquals($identity, $formData); - $this->assertInternalType('string', $formData->getType()); - $this->assertInternalType('string', $formData->getEndpoint()); + self::assertEquals($identity, $formData); + self::assertIsString($formData->getType()); + self::assertIsString($formData->getEndpoint()); $view = $form->createView(); $children = $view->children; foreach (\array_keys($data) as $key) { - $this->assertArrayHasKey($key, $children); + self::assertArrayHasKey($key, $children); } } } diff --git a/Tests/Helper/SinchSupportedCountriesTest.php b/Tests/Helper/SinchSupportedCountriesTest.php index e60d950..c25b2ef 100644 --- a/Tests/Helper/SinchSupportedCountriesTest.php +++ b/Tests/Helper/SinchSupportedCountriesTest.php @@ -20,13 +20,13 @@ */ class SinchSupportedCountriesTest extends TestCase { - public function testSupportedCountry() + public function testSupportedCountry(): void { - $this->assertTrue(SinchSupportedCountries::isCountrySupported('UA')); + self::assertTrue(SinchSupportedCountries::isCountrySupported('UA')); } - public function testUnsupportedCountry() + public function testUnsupportedCountry(): void { - $this->assertFalse(SinchSupportedCountries::isCountrySupported('YO')); + self::assertFalse(SinchSupportedCountries::isCountrySupported('YO')); } } diff --git a/Tests/Model/CallbackRequestTest.php b/Tests/Model/CallbackRequestTest.php index 48346aa..4dd53d6 100644 --- a/Tests/Model/CallbackRequestTest.php +++ b/Tests/Model/CallbackRequestTest.php @@ -21,57 +21,57 @@ */ class CallbackRequestTest extends TestCase { - public function testConstructor() + public function testConstructor(): void { $callbackRequest = new CallbackRequest(); - $this->assertNull($callbackRequest->getEvent()); - $this->assertNull($callbackRequest->getFrom()); - $this->assertNull($callbackRequest->getTo()); - $this->assertNull($callbackRequest->getMessage()); - $this->assertNull($callbackRequest->getTimestamp()); - $this->assertNull($callbackRequest->getVersion()); + self::assertNull($callbackRequest->getEvent()); + self::assertNull($callbackRequest->getFrom()); + self::assertNull($callbackRequest->getTo()); + self::assertNull($callbackRequest->getMessage()); + self::assertNull($callbackRequest->getTimestamp()); + self::assertNull($callbackRequest->getVersion()); } - public function testSetGetEvent() + public function testSetGetEvent(): void { $event = 'incomingSms'; $callbackRequest = (new CallbackRequest())->setEvent($event); - $this->assertEquals($event, $callbackRequest->getEvent()); + self::assertEquals($event, $callbackRequest->getEvent()); } - public function testSetGetTo() + public function testSetGetTo(): void { $to = new Identity(); $callbackRequest = (new CallbackRequest())->setTo($to); - $this->assertEquals($to, $callbackRequest->getTo()); + self::assertEquals($to, $callbackRequest->getTo()); } - public function testSetGetFrom() + public function testSetGetFrom(): void { $from = new Identity(); $callbackRequest = (new CallbackRequest())->setFrom($from); - $this->assertEquals($from, $callbackRequest->getFrom()); + self::assertEquals($from, $callbackRequest->getFrom()); } - public function testSetGetMessage() + public function testSetGetMessage(): void { $message = 'Hello world'; $callbackRequest = (new CallbackRequest())->setMessage($message); - $this->assertEquals($message, $callbackRequest->getMessage()); + self::assertEquals($message, $callbackRequest->getMessage()); } - public function testSetGetTimestamp() + public function testSetGetTimestamp(): void { $timestamp = new \DateTime('now'); $callbackRequest = (new CallbackRequest())->setTimestamp($timestamp); - $this->assertEquals($timestamp, $callbackRequest->getTimestamp()); + self::assertEquals($timestamp, $callbackRequest->getTimestamp()); } - public function testSetGetVersion() + public function testSetGetVersion(): void { $version = 1; $callbackRequest = (new CallbackRequest())->setVersion($version); - $this->assertEquals($version, $callbackRequest->getVersion()); + self::assertEquals($version, $callbackRequest->getVersion()); } } diff --git a/Tests/Model/IdentityTest.php b/Tests/Model/IdentityTest.php index 1d5bbbb..3620d86 100644 --- a/Tests/Model/IdentityTest.php +++ b/Tests/Model/IdentityTest.php @@ -20,25 +20,25 @@ */ class IdentityTest extends TestCase { - public function testConstructor() + public function testConstructor(): void { $identity = new Identity(); - $this->assertNull($identity->getType()); - $this->assertNull($identity->getEndpoint()); + self::assertNull($identity->getType()); + self::assertNull($identity->getEndpoint()); } - public function testSetGetType() + public function testSetGetType(): void { $type = 'number'; $identity = (new Identity())->setType($type); - $this->assertEquals($type, $identity->getType()); + self::assertEquals($type, $identity->getType()); } - public function testSetGetEndpoint() + public function testSetGetEndpoint(): void { $endpoint = '+46700000000'; $identity = (new Identity())->setEndpoint($endpoint); - $this->assertEquals($endpoint, $identity->getEndpoint()); + self::assertEquals($endpoint, $identity->getEndpoint()); } } diff --git a/Tests/Service/SinchExceptionResolverTest.php b/Tests/Service/SinchExceptionResolverTest.php index 07abe15..f8bbb1e 100644 --- a/Tests/Service/SinchExceptionResolverTest.php +++ b/Tests/Service/SinchExceptionResolverTest.php @@ -21,7 +21,6 @@ use Fresh\SinchBundle\Exception\Unauthorized\SinchIllegalAuthorizationHeaderException; use Fresh\SinchBundle\Helper\SinchErrorCode; use Fresh\SinchBundle\Service\SinchExceptionResolver; -use GuzzleHttp\Exception\ClientException; use PHPUnit\Framework\TestCase; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; @@ -35,93 +34,102 @@ */ class SinchExceptionResolverTest extends TestCase { - public function testSinchParameterValidationException() + public function testSinchParameterValidationException(): void { $e = $this->getClientException(Response::HTTP_BAD_REQUEST, SinchErrorCode::PARAMETER_VALIDATION); - $this->assertInstanceOf(SinchParameterValidationException::class, SinchExceptionResolver::createAppropriateSinchException($e)); + self::assertInstanceOf(SinchParameterValidationException::class, SinchExceptionResolver::createAppropriateSinchException($e)); } - public function testSinchInvalidRequestException() + public function testSinchInvalidRequestException(): void { $e = $this->getClientException(Response::HTTP_BAD_REQUEST, SinchErrorCode::INVALID_REQUEST); - $this->assertInstanceOf(SinchInvalidRequestException::class, SinchExceptionResolver::createAppropriateSinchException($e)); + self::assertInstanceOf(SinchInvalidRequestException::class, SinchExceptionResolver::createAppropriateSinchException($e)); } - public function testSinchMissingParameterException() + public function testSinchMissingParameterException(): void { $e = $this->getClientException(Response::HTTP_BAD_REQUEST, SinchErrorCode::MISSING_PARAMETER); - $this->assertInstanceOf(SinchMissingParameterException::class, SinchExceptionResolver::createAppropriateSinchException($e)); + self::assertInstanceOf(SinchMissingParameterException::class, SinchExceptionResolver::createAppropriateSinchException($e)); } - public function testSinchIllegalAuthorizationHeaderException() + public function testSinchIllegalAuthorizationHeaderException(): void { $e = $this->getClientException(Response::HTTP_UNAUTHORIZED, SinchErrorCode::ILLEGAL_AUTHORIZATION_HEADER); - $this->assertInstanceOf(SinchIllegalAuthorizationHeaderException::class, SinchExceptionResolver::createAppropriateSinchException($e)); + self::assertInstanceOf(SinchIllegalAuthorizationHeaderException::class, SinchExceptionResolver::createAppropriateSinchException($e)); } - public function testSinchPaymentRequiredException() + public function testSinchPaymentRequiredException(): void { $e = $this->getClientException(Response::HTTP_PAYMENT_REQUIRED, SinchErrorCode::THERE_IS_NOT_ENOUGH_FUNDS_TO_SEND_THE_MESSAGE); - $this->assertInstanceOf(SinchPaymentRequiredException::class, SinchExceptionResolver::createAppropriateSinchException($e)); + self::assertInstanceOf(SinchPaymentRequiredException::class, SinchExceptionResolver::createAppropriateSinchException($e)); } - public function testSinchForbiddenRequestException() + public function testSinchForbiddenRequestException(): void { $e = $this->getClientException(Response::HTTP_FORBIDDEN, SinchErrorCode::FORBIDDEN_REQUEST); - $this->assertInstanceOf(SinchForbiddenRequestException::class, SinchExceptionResolver::createAppropriateSinchException($e)); + self::assertInstanceOf(SinchForbiddenRequestException::class, SinchExceptionResolver::createAppropriateSinchException($e)); } - public function testSinchInvalidAuthorizationSchemeException() + public function testSinchInvalidAuthorizationSchemeException(): void { $e = $this->getClientException(Response::HTTP_FORBIDDEN, SinchErrorCode::INVALID_AUTHORIZATION_SCHEME_FOR_CALLING_THE_METHOD); - $this->assertInstanceOf(SinchInvalidAuthorizationSchemeException::class, SinchExceptionResolver::createAppropriateSinchException($e)); + self::assertInstanceOf(SinchInvalidAuthorizationSchemeException::class, SinchExceptionResolver::createAppropriateSinchException($e)); } - public function testSinchNoVerifiedPhoneNumberException() + public function testSinchNoVerifiedPhoneNumberException(): void { $e = $this->getClientException(Response::HTTP_FORBIDDEN, SinchErrorCode::NO_VERIFIED_PHONE_NUMBER_ON_YOUR_SINCH_ACCOUNT); - $this->assertInstanceOf(SinchNoVerifiedPhoneNumberException::class, SinchExceptionResolver::createAppropriateSinchException($e)); + self::assertInstanceOf(SinchNoVerifiedPhoneNumberException::class, SinchExceptionResolver::createAppropriateSinchException($e)); $e = $this->getClientException(Response::HTTP_FORBIDDEN, SinchErrorCode::SANDBOX_SMS_ONLY_ALLOWED_TO_BE_SENT_TO_VERIFIED_NUMBERS); - $this->assertInstanceOf(SinchNoVerifiedPhoneNumberException::class, SinchExceptionResolver::createAppropriateSinchException($e)); + self::assertInstanceOf(SinchNoVerifiedPhoneNumberException::class, SinchExceptionResolver::createAppropriateSinchException($e)); } - public function testSinchInternalErrorException() + public function testSinchInternalErrorException(): void { $e = $this->getClientException(Response::HTTP_INTERNAL_SERVER_ERROR, SinchErrorCode::INTERNAL_ERROR); - $this->assertInstanceOf(SinchInternalErrorException::class, SinchExceptionResolver::createAppropriateSinchException($e)); + self::assertInstanceOf(SinchInternalErrorException::class, SinchExceptionResolver::createAppropriateSinchException($e)); } - public function testStandardException() + public function testStandardException(): void { $e = $this->getClientException(Response::HTTP_GATEWAY_TIMEOUT, 0); - $this->assertInstanceOf(\Exception::class, SinchExceptionResolver::createAppropriateSinchException($e)); + self::assertInstanceOf(\Exception::class, SinchExceptionResolver::createAppropriateSinchException($e)); } /** - * Get client exception - * * @param int $statusCode Status code * @param int $errorCode Error code * * @return ClientException */ - private function getClientException($statusCode, $errorCode) + private function getClientException($statusCode, $errorCode): ClientException { - $request = $this->getMockBuilder(RequestInterface::class)->disableOriginalConstructor()->getMock(); - $response = $this->getMockBuilder(ResponseInterface::class)->disableOriginalConstructor()->getMock(); - $body = $this->getMockBuilder(StreamInterface::class)->disableOriginalConstructor()->getMock(); - - $response->expects($this->once())->method('getStatusCode')->willReturn($statusCode); - $response->expects($this->once())->method('getBody')->will($this->returnValue($body)); - - $body->expects($this->once())->method('getContents')->will($this->returnValue(<<createMock(RequestInterface::class); + $response = $this->createMock(ResponseInterface::class); + $body = $this->createMock(StreamInterface::class); + + $response + ->expects(self::once()) + ->method('getStatusCode') + ->willReturn($statusCode) + ; + $response + ->expects(self::once()) + ->method('getBody') + ->willReturn($body) + ; + + $body + ->expects(self::once()) + ->method('getContents') + ->willReturn(<< - - ./Tests From 887b4e70faf8f95da2c302f1796482b4227a9955 Mon Sep 17 00:00:00 2001 From: Artem Henvald Date: Wed, 4 Sep 2019 11:03:03 +0300 Subject: [PATCH 2/7] Update README --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 28b757b..92d2a64 100644 --- a/README.md +++ b/README.md @@ -20,8 +20,8 @@ Provides integration with **[Sinch.com](https://www.sinch.com)** SMS API. ## Requirements -* PHP 7.1 *and later* -* Symfony 4.0 *and later* +* PHP 7.3 *and later* +* Symfony 4.3 *and later* ## Installation From 947090e213510e6957f202a5dda784bbf95fa37e Mon Sep 17 00:00:00 2001 From: Artem Henvald Date: Sun, 27 Dec 2020 10:30:08 +0200 Subject: [PATCH 3/7] Update README.md --- README.md | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/README.md b/README.md index 92d2a64..cc9436d 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ Provides integration with **[Sinch.com](https://www.sinch.com)** SMS API. ![Sinch Logo](/Resources/images/sinch-logo.png) [![Scrutinizer Quality Score](https://img.shields.io/scrutinizer/g/fre5h/SinchBundle.svg?style=flat-square)](https://scrutinizer-ci.com/g/fre5h/SinchBundle/) -[![Build Status](https://img.shields.io/travis/fre5h/SinchBundle/master.svg?style=flat-square)](https://travis-ci.org/fre5h/SinchBundle) +[![Build Status](https://img.shields.io/travis/fre5h/SinchBundle/master.svg?style=flat-square)](https://travis-ci.com/fre5h/SinchBundle) [![CodeCov](https://img.shields.io/codecov/c/github/fre5h/SinchBundle.svg?style=flat-square)](https://codecov.io/github/fre5h/SinchBundle) [![License](https://img.shields.io/packagist/l/fresh/sinch-bundle.svg?style=flat-square)](https://packagist.org/packages/fresh/sinch-bundle) [![Latest Stable Version](https://img.shields.io/packagist/v/fresh/sinch-bundle.svg?style=flat-square)](https://packagist.org/packages/fresh/sinch-bundle) @@ -15,9 +15,6 @@ Provides integration with **[Sinch.com](https://www.sinch.com)** SMS API. [![StyleCI](https://styleci.io/repos/44092074/shield?style=flat-square)](https://styleci.io/repos/44092074) [![Gitter](https://img.shields.io/badge/gitter-join%20chat-brightgreen.svg?style=flat-square)](https://gitter.im/fre5h/SinchBundle) -[![SensioLabsInsight](https://insight.sensiolabs.com/projects/2303fcfb-2e4b-45b3-8b37-6d1e7598acf4/small.png)](https://insight.sensiolabs.com/projects/2303fcfb-2e4b-45b3-8b37-6d1e7598acf4) -[![knpbundles.com](http://knpbundles.com/fre5h/SinchBundle/badge-short)](http://knpbundles.com/fre5h/SinchBundle) - ## Requirements * PHP 7.3 *and later* From 49592297ce3384e79bfe7c93018d079744563b92 Mon Sep 17 00:00:00 2001 From: Artem Henvald Date: Sun, 27 Dec 2020 10:30:43 +0200 Subject: [PATCH 4/7] Update .travis.yml --- .travis.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 914ec86..4a621a8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,8 +4,11 @@ sudo: false php: - 7.3 + - 7.4 + - 8.0 env: + - SYMFONY_VERSION=4.4.* - SYMFONY_VERSION=4.3.* before_install: @@ -18,7 +21,7 @@ install: script: - ./vendor/bin/phpcs ./ -p --encoding=utf-8 --extensions=php --ignore="vendor|Tests" --standard=./vendor/escapestudios/symfony2-coding-standard/Symfony - ./vendor/bin/phpunit -c phpunit.xml.dist --coverage-clover=coverage.xml - - ./vendor/bin/phpstan analyse -l 7 --no-progress -c phpstan.neon ./ + - ./vendor/bin/phpstan analyse -l 8 --no-progress -c phpstan.neon ./ after_success: - bash <(curl -s https://codecov.io/bash) From 8ac7bbb077a4879c3d98a8a539fc60d854209b9a Mon Sep 17 00:00:00 2001 From: Artem Henvald Date: Sun, 27 Dec 2020 10:31:00 +0200 Subject: [PATCH 5/7] Update phpstan.neon --- phpstan.neon | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpstan.neon b/phpstan.neon index 239d7f8..b47882e 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -3,7 +3,7 @@ includes: - 'vendor/phpstan/phpstan-phpunit/rules.neon' - 'vendor/phpstan/phpstan-doctrine/extension.neon' parameters: - level: 7 + level: 8 excludes_analyse: - '%rootDir%/../../../Tests/*' - '%rootDir%/../../../vendor/*' From 7d911008065526f16b745cf46741f74f168445d9 Mon Sep 17 00:00:00 2001 From: Artem Henvald Date: Sun, 27 Dec 2020 10:31:41 +0200 Subject: [PATCH 6/7] Update composer.json --- composer.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/composer.json b/composer.json index 95221fd..d64c533 100644 --- a/composer.json +++ b/composer.json @@ -26,12 +26,12 @@ "symfony/serializer-pack": "^1.0" }, "require-dev": { - "escapestudios/symfony2-coding-standard": "^3.9", + "escapestudios/symfony2-coding-standard": "^3.11", "matthiasnoback/symfony-config-test": "^4.0", - "phpstan/phpstan": "^0.11", - "phpstan/phpstan-doctrine":"^0.11", - "phpstan/phpstan-phpunit": "^0.11", - "phpunit/phpunit": "^8.3" + "phpstan/phpstan": "^0.12", + "phpstan/phpstan-doctrine":"^0.12", + "phpstan/phpstan-phpunit": "^0.12", + "phpunit/phpunit": "^9.5" }, "autoload": { "psr-4": { From 9091cc2254da73c6028f0f564347f78418cbca84 Mon Sep 17 00:00:00 2001 From: Artem Henvald Date: Sun, 27 Dec 2020 10:32:04 +0200 Subject: [PATCH 7/7] Update phpunit.xml.dist --- phpunit.xml.dist | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 69b72ec..e3a9d8f 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,7 +1,7 @@