diff --git a/.gitattributes b/.gitattributes index 8e80cde..1bbefab 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,10 +1,10 @@ # Files and directories which won't be included in .zip archive during running `composer install --prefer-dist` +/.github export-ignore /.gitattributes export-ignore /.gitignore export-ignore /.scrutinizer.yml export-ignore /.styleci.yml export-ignore /.travis.yml export-ignore -/CONTRIBUTING.md export-ignore /phpunit.xml.dist export-ignore /Tests export-ignore diff --git a/.gitignore b/.gitignore index 57872d0..2ee246e 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ /vendor/ +phpunit.xml +composer.lock diff --git a/.scrutinizer.yml b/.scrutinizer.yml index 2010119..bf2471e 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -1,7 +1,5 @@ checks: - php: - code_rating: true - duplication: true + php: true filter: excluded_paths: diff --git a/.travis.yml b/.travis.yml index ebdd8ed..2cb9b48 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,21 +3,21 @@ language: php sudo: false php: - - 5.6 - - 7.0 - - 7.1 + - 7.1 + - 7.2 env: - - SYMFONY_VERSION=2.8.* - - SYMFONY_VERSION=3.0.* - - SYMFONY_VERSION=3.1.* + - SYMFONY_VERSION=3.4.* -before_script: +before_install: - composer self-update - - composer install --dev --prefer-dist --no-interaction + - composer require --no-update symfony/symfony "$SYMFONY_VERSION" + +install: + - composer install --no-interaction --prefer-dist script: - - ./vendor/bin/phpcs ./ -p --encoding=utf-8 --extensions=php --ignore=vendor --ignore=Tests --standard=./vendor/escapestudios/symfony2-coding-standard/Symfony2 + - ./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 after_success: diff --git a/Controller/SinchController.php b/Controller/SinchController.php index b1ea45b..56e1a76 100644 --- a/Controller/SinchController.php +++ b/Controller/SinchController.php @@ -2,7 +2,7 @@ /* * This file is part of the FreshSinchBundle * - * (c) Artem Genvald + * (c) Artem Henvald * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -22,7 +22,7 @@ /** * SinchController. * - * @author Artem Genvald + * @author Artem Henvald */ class SinchController { @@ -47,7 +47,7 @@ public function __construct(FormFactory $formFactory, EventDispatcherInterface $ * * @return Response */ - public function callbackAction(Request $request) + public function callbackAction(Request $request): Response { try { $callbackRequest = new CallbackRequest(); diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 6b90d8c..8be0abb 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -2,7 +2,7 @@ /* * This file is part of the FreshSinchBundle * - * (c) Artem Genvald + * (c) Artem Henvald * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -16,7 +16,7 @@ /** * Configuration. * - * @author Artem Genvald + * @author Artem Henvald */ class Configuration implements ConfigurationInterface { diff --git a/DependencyInjection/FreshSinchExtension.php b/DependencyInjection/FreshSinchExtension.php index fcb3c26..f6e13e5 100644 --- a/DependencyInjection/FreshSinchExtension.php +++ b/DependencyInjection/FreshSinchExtension.php @@ -2,7 +2,7 @@ /* * This file is part of the FreshSinchBundle * - * (c) Artem Genvald + * (c) Artem Henvald * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -18,7 +18,7 @@ /** * FreshSinchExtension. * - * @author Artem Genvald + * @author Artem Henvald */ class FreshSinchExtension extends Extension { @@ -38,12 +38,4 @@ public function load(array $configs, ContainerBuilder $container) $container->setParameter('sinch.secret', $config['secret']); $container->setParameter('sinch.from', $config['from']); } - - /** - * {@inheritdoc} - */ - public function getAlias() - { - return 'fresh_sinch'; - } } diff --git a/Event/SinchEvents.php b/Event/SinchEvents.php index 147c05f..674043c 100644 --- a/Event/SinchEvents.php +++ b/Event/SinchEvents.php @@ -2,7 +2,7 @@ /* * This file is part of the FreshSinchBundle * - * (c) Artem Genvald + * (c) Artem Henvald * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -13,12 +13,10 @@ /** * SinchEvents. * - * @author Artem Genvald + * @author Artem Henvald */ final class SinchEvents { - // region SMS sending - /** * This event is triggered before the SMS is going to be sent. * @@ -33,16 +31,10 @@ final class SinchEvents */ const POST_SMS_SEND = 'sinch.sms.post_send'; - // endregion - - // region Callback - /** * This event is triggered callback from Sinch is received. * * @see \Fresh\SinchBundle\Event\SmsMessageCallbackEvent Listeners receive an instance of this class */ const CALLBACK_RECEIVED = 'sinch.callback.received'; - - // endregion } diff --git a/Event/SmsEvent.php b/Event/SmsEvent.php index 9c211c8..dd34dae 100644 --- a/Event/SmsEvent.php +++ b/Event/SmsEvent.php @@ -2,7 +2,7 @@ /* * This file is part of the FreshSinchBundle * - * (c) Artem Genvald + * (c) Artem Henvald * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -15,7 +15,7 @@ /** * SmsEvent. * - * @author Artem Genvald + * @author Artem Henvald */ class SmsEvent extends Event { @@ -33,7 +33,7 @@ class SmsEvent extends Event * @param string $message * @param string|null $from */ - public function __construct($number, $message, $from = null) + public function __construct(string $number, string $message, ?string $from = null) { $this->number = $number; $this->message = $message; @@ -43,7 +43,7 @@ public function __construct($number, $message, $from = null) /** * @return string */ - public function getNumber() + public function getNumber(): string { return $this->number; } @@ -53,7 +53,7 @@ public function getNumber() * * @return $this */ - public function setNumber($number) + public function setNumber(string $number): self { $this->number = $number; @@ -63,7 +63,7 @@ public function setNumber($number) /** * @return string */ - public function getMessage() + public function getMessage(): string { return $this->message; } @@ -73,7 +73,7 @@ public function getMessage() * * @return $this */ - public function setMessage($message) + public function setMessage(string $message): self { $this->message = $message; @@ -83,7 +83,7 @@ public function setMessage($message) /** * @return null|string */ - public function getFrom() + public function getFrom(): ?string { return $this->from; } @@ -93,7 +93,7 @@ public function getFrom() * * @return $this */ - public function setFrom($from) + public function setFrom(?string $from): self { $this->from = $from; diff --git a/Event/SmsMessageCallbackEvent.php b/Event/SmsMessageCallbackEvent.php index a6413bf..f185c4b 100644 --- a/Event/SmsMessageCallbackEvent.php +++ b/Event/SmsMessageCallbackEvent.php @@ -2,7 +2,7 @@ /* * This file is part of the FreshSinchBundle * - * (c) Artem Genvald + * (c) Artem Henvald * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -17,7 +17,7 @@ /** * SmsMessageCallbackEvent. * - * @author Artem Genvald + * @author Artem Henvald */ class SmsMessageCallbackEvent extends Event { @@ -35,7 +35,7 @@ public function __construct(CallbackRequest $callbackRequest) /** * @return string */ - public function getEvent() + public function getEvent(): string { return $this->callbackRequest->getEvent(); } @@ -43,7 +43,7 @@ public function getEvent() /** * @return Identity */ - public function getTo() + public function getTo(): Identity { return $this->callbackRequest->getTo(); } @@ -51,7 +51,7 @@ public function getTo() /** * @return Identity */ - public function getFrom() + public function getFrom(): Identity { return $this->callbackRequest->getFrom(); } @@ -59,7 +59,7 @@ public function getFrom() /** * @return string */ - public function getMessage() + public function getMessage(): string { return $this->callbackRequest->getMessage(); } @@ -67,7 +67,7 @@ public function getMessage() /** * @return \DateTime */ - public function getTimestamp() + public function getTimestamp(): \DateTime { return $this->callbackRequest->getTimestamp(); } @@ -75,7 +75,7 @@ public function getTimestamp() /** * @return int */ - public function getVersion() + public function getVersion(): int { return $this->callbackRequest->getVersion(); } diff --git a/Exception/BadRequest/SinchInvalidRequestException.php b/Exception/BadRequest/SinchInvalidRequestException.php index 486c1fe..fbc6a36 100644 --- a/Exception/BadRequest/SinchInvalidRequestException.php +++ b/Exception/BadRequest/SinchInvalidRequestException.php @@ -2,7 +2,7 @@ /* * This file is part of the FreshSinchBundle * - * (c) Artem Genvald + * (c) Artem Henvald * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -15,7 +15,7 @@ /** * SinchInvalidRequestException. * - * @author Artem Genvald + * @author Artem Henvald */ class SinchInvalidRequestException extends SinchException { diff --git a/Exception/BadRequest/SinchMissingParameterException.php b/Exception/BadRequest/SinchMissingParameterException.php index 4f1408a..117ce6f 100644 --- a/Exception/BadRequest/SinchMissingParameterException.php +++ b/Exception/BadRequest/SinchMissingParameterException.php @@ -2,7 +2,7 @@ /* * This file is part of the FreshSinchBundle * - * (c) Artem Genvald + * (c) Artem Henvald * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -15,7 +15,7 @@ /** * SinchMissingParameterException. * - * @author Artem Genvald + * @author Artem Henvald */ class SinchMissingParameterException extends SinchException { diff --git a/Exception/BadRequest/SinchParameterValidationException.php b/Exception/BadRequest/SinchParameterValidationException.php index 115e878..6d1819f 100644 --- a/Exception/BadRequest/SinchParameterValidationException.php +++ b/Exception/BadRequest/SinchParameterValidationException.php @@ -2,7 +2,7 @@ /* * This file is part of the FreshSinchBundle * - * (c) Artem Genvald + * (c) Artem Henvald * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -15,7 +15,7 @@ /** * SinchParameterValidationException. * - * @author Artem Genvald + * @author Artem Henvald */ class SinchParameterValidationException extends SinchException { diff --git a/Exception/Forbidden/SinchForbiddenRequestException.php b/Exception/Forbidden/SinchForbiddenRequestException.php index 731d303..7f2e076 100644 --- a/Exception/Forbidden/SinchForbiddenRequestException.php +++ b/Exception/Forbidden/SinchForbiddenRequestException.php @@ -2,7 +2,7 @@ /* * This file is part of the FreshSinchBundle * - * (c) Artem Genvald + * (c) Artem Henvald * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -15,7 +15,7 @@ /** * SinchForbiddenRequestException. * - * @author Artem Genvald + * @author Artem Henvald */ class SinchForbiddenRequestException extends SinchException { diff --git a/Exception/Forbidden/SinchInvalidAuthorizationSchemeException.php b/Exception/Forbidden/SinchInvalidAuthorizationSchemeException.php index c60f216..6d8a0a6 100644 --- a/Exception/Forbidden/SinchInvalidAuthorizationSchemeException.php +++ b/Exception/Forbidden/SinchInvalidAuthorizationSchemeException.php @@ -2,7 +2,7 @@ /* * This file is part of the FreshSinchBundle * - * (c) Artem Genvald + * (c) Artem Henvald * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -15,7 +15,7 @@ /** * SinchInvalidAuthorizationSchemeException. * - * @author Artem Genvald + * @author Artem Henvald */ class SinchInvalidAuthorizationSchemeException extends SinchException { diff --git a/Exception/Forbidden/SinchNoVerifiedPhoneNumberException.php b/Exception/Forbidden/SinchNoVerifiedPhoneNumberException.php index ee55222..c11169d 100644 --- a/Exception/Forbidden/SinchNoVerifiedPhoneNumberException.php +++ b/Exception/Forbidden/SinchNoVerifiedPhoneNumberException.php @@ -2,7 +2,7 @@ /* * This file is part of the FreshSinchBundle * - * (c) Artem Genvald + * (c) Artem Henvald * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -15,7 +15,7 @@ /** * SinchNoVerifiedPhoneNumberException. * - * @author Artem Genvald + * @author Artem Henvald */ class SinchNoVerifiedPhoneNumberException extends SinchException { diff --git a/Exception/InternalServerError/SinchInternalErrorException.php b/Exception/InternalServerError/SinchInternalErrorException.php index c0a4a04..1b3cf34 100644 --- a/Exception/InternalServerError/SinchInternalErrorException.php +++ b/Exception/InternalServerError/SinchInternalErrorException.php @@ -2,7 +2,7 @@ /* * This file is part of the FreshSinchBundle * - * (c) Artem Genvald + * (c) Artem Henvald * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -15,7 +15,7 @@ /** * SinchInternalErrorException. * - * @author Artem Genvald + * @author Artem Henvald */ class SinchInternalErrorException extends SinchException { diff --git a/Exception/PaymentRequired/SinchPaymentRequiredException.php b/Exception/PaymentRequired/SinchPaymentRequiredException.php index bcbbaea..afe9944 100644 --- a/Exception/PaymentRequired/SinchPaymentRequiredException.php +++ b/Exception/PaymentRequired/SinchPaymentRequiredException.php @@ -2,7 +2,7 @@ /* * This file is part of the FreshSinchBundle * - * (c) Artem Genvald + * (c) Artem Henvald * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -15,7 +15,7 @@ /** * SinchPaymentRequiredException. * - * @author Artem Genvald + * @author Artem Henvald */ class SinchPaymentRequiredException extends SinchException { diff --git a/Exception/SinchException.php b/Exception/SinchException.php index 1c8dbbb..6bb5229 100644 --- a/Exception/SinchException.php +++ b/Exception/SinchException.php @@ -2,7 +2,7 @@ /* * This file is part of the FreshSinchBundle * - * (c) Artem Genvald + * (c) Artem Henvald * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -13,7 +13,7 @@ /** * SinchException. * - * @author Artem Genvald + * @author Artem Henvald */ class SinchException extends \RuntimeException { diff --git a/Exception/Unauthorized/SinchIllegalAuthorizationHeaderException.php b/Exception/Unauthorized/SinchIllegalAuthorizationHeaderException.php index 29d51d7..1e4d57f 100644 --- a/Exception/Unauthorized/SinchIllegalAuthorizationHeaderException.php +++ b/Exception/Unauthorized/SinchIllegalAuthorizationHeaderException.php @@ -2,7 +2,7 @@ /* * This file is part of the FreshSinchBundle * - * (c) Artem Genvald + * (c) Artem Henvald * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -15,7 +15,7 @@ /** * SinchIllegalAuthorizationHeaderException. * - * @author Artem Genvald + * @author Artem Henvald */ class SinchIllegalAuthorizationHeaderException extends SinchException { diff --git a/Form/Type/CallbackRequestType.php b/Form/Type/CallbackRequestType.php index 4b80182..a605e05 100644 --- a/Form/Type/CallbackRequestType.php +++ b/Form/Type/CallbackRequestType.php @@ -2,7 +2,7 @@ /* * This file is part of the FreshSinchBundle * - * (c) Artem Genvald + * (c) Artem Henvald * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -20,7 +20,7 @@ /** * CallbackRequestType. * - * @author Artem Genvald + * @author Artem Henvald */ class CallbackRequestType extends AbstractType { diff --git a/Form/Type/IdentityType.php b/Form/Type/IdentityType.php index 1f30d92..3d9c8cd 100644 --- a/Form/Type/IdentityType.php +++ b/Form/Type/IdentityType.php @@ -2,7 +2,7 @@ /* * This file is part of the FreshSinchBundle * - * (c) Artem Genvald + * (c) Artem Henvald * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -19,7 +19,7 @@ /** * IdentityType. * - * @author Artem Genvald + * @author Artem Henvald */ class IdentityType extends AbstractType { diff --git a/FreshSinchBundle.php b/FreshSinchBundle.php index 6288f52..a314c76 100644 --- a/FreshSinchBundle.php +++ b/FreshSinchBundle.php @@ -2,7 +2,7 @@ /* * This file is part of the FreshSinchBundle * - * (c) Artem Genvald + * (c) Artem Henvald * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -15,7 +15,7 @@ /** * FreshSinchBundle. * - * @author Artem Genvald + * @author Artem Henvald */ class FreshSinchBundle extends Bundle { diff --git a/Helper/SinchCallbackEvents.php b/Helper/SinchCallbackEvents.php index d946fce..b0ac36b 100644 --- a/Helper/SinchCallbackEvents.php +++ b/Helper/SinchCallbackEvents.php @@ -2,7 +2,7 @@ /* * This file is part of the FreshSinchBundle * - * (c) Artem Genvald + * (c) Artem Henvald * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -13,9 +13,16 @@ /** * Sinch Callback Events. * - * @author Artem Genvald + * @author Artem Henvald */ final class SinchCallbackEvents { const INCOMING_SMS = 'incomingSms'; + + /** + * Constructor. + */ + private function __construct() + { + } } diff --git a/Helper/SinchErrorCode.php b/Helper/SinchErrorCode.php index 2007a83..2e0cd13 100644 --- a/Helper/SinchErrorCode.php +++ b/Helper/SinchErrorCode.php @@ -2,7 +2,7 @@ /* * This file is part of the FreshSinchBundle * - * (c) Artem Genvald + * (c) Artem Henvald * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -13,7 +13,7 @@ /** * SinchErrorCode. * - * @author Artem Genvald + * @author Artem Henvald */ final class SinchErrorCode { @@ -31,4 +31,11 @@ final class SinchErrorCode const SANDBOX_SMS_ONLY_ALLOWED_TO_BE_SENT_TO_VERIFIED_NUMBERS = 40303; const INTERNAL_ERROR = 50000; + + /** + * Constructor. + */ + private function __construct() + { + } } diff --git a/Helper/SinchSmsStatus.php b/Helper/SinchSmsStatus.php index 4358be5..f944bc2 100644 --- a/Helper/SinchSmsStatus.php +++ b/Helper/SinchSmsStatus.php @@ -2,7 +2,7 @@ /* * This file is part of the FreshSinchBundle * - * (c) Artem Genvald + * (c) Artem Henvald * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -13,7 +13,7 @@ /** * Sinch SMS Status. * - * @author Artem Genvald + * @author Artem Henvald */ final class SinchSmsStatus { @@ -21,4 +21,11 @@ final class SinchSmsStatus const SUCCESSFUL = 'successful'; const FAULTED = 'faulted'; const UNKNOWN = 'unknown'; + + /** + * Constructor. + */ + private function __construct() + { + } } diff --git a/Helper/SinchSupportedCountries.php b/Helper/SinchSupportedCountries.php index 68f5d2e..7ddb36a 100644 --- a/Helper/SinchSupportedCountries.php +++ b/Helper/SinchSupportedCountries.php @@ -2,7 +2,7 @@ /* * This file is part of the FreshSinchBundle * - * (c) Artem Genvald + * (c) Artem Henvald * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -13,17 +13,16 @@ /** * SinchSupportedCountries. * - * @author Artem Genvald + * @author Artem Henvald */ class SinchSupportedCountries { /** - * List of supported countries by Sinch. - * * @var array + * * @static */ - public static $supportedCountries = [ + const SUPPORTED_COUNTRIES = [ 'AF' => 'Afghanistan', 'AM' => 'Armenia', 'AR' => 'Argentina', @@ -132,14 +131,12 @@ class SinchSupportedCountries ]; /** - * Check if country is supported. - * * @param string $countryCode * * @return bool */ - public static function isCountrySupported($countryCode) + public static function isCountrySupported(string $countryCode): bool { - return isset(self::$supportedCountries[$countryCode]); + return isset(self::SUPPORTED_COUNTRIES[$countryCode]); } } diff --git a/LICENSE b/LICENSE index 3a83bd9..a4cf6cc 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2015-2017 Artem Genvald +Copyright (c) 2015-2017 Artem Henvald Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/Model/CallbackRequest.php b/Model/CallbackRequest.php index 37b90a9..e8d6624 100644 --- a/Model/CallbackRequest.php +++ b/Model/CallbackRequest.php @@ -2,7 +2,7 @@ /* * This file is part of the FreshSinchBundle * - * (c) Artem Genvald + * (c) Artem Henvald * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -15,7 +15,7 @@ /** * CallbackRequest Model. * - * @author Artem Genvald + * @author Artem Henvald * * @see https://www.sinch.com/docs/sms/#incomingsms */ @@ -72,9 +72,9 @@ class CallbackRequest private $version; /** - * @return string + * @return string|null */ - public function getEvent() + public function getEvent(): ?string { return $this->event; } @@ -84,7 +84,7 @@ public function getEvent() * * @return $this */ - public function setEvent($event) + public function setEvent(string $event): self { $this->event = $event; @@ -94,7 +94,7 @@ public function setEvent($event) /** * @return Identity */ - public function getTo() + public function getTo(): ?Identity { return $this->to; } @@ -104,7 +104,7 @@ public function getTo() * * @return $this */ - public function setTo(Identity $to) + public function setTo(Identity $to): self { $this->to = $to; @@ -114,7 +114,7 @@ public function setTo(Identity $to) /** * @return Identity */ - public function getFrom() + public function getFrom(): ?Identity { return $this->from; } @@ -124,7 +124,7 @@ public function getFrom() * * @return $this */ - public function setFrom(Identity $from) + public function setFrom(Identity $from): self { $this->from = $from; @@ -132,9 +132,9 @@ public function setFrom(Identity $from) } /** - * @return string + * @return string|null */ - public function getMessage() + public function getMessage(): ?string { return $this->message; } @@ -144,7 +144,7 @@ public function getMessage() * * @return $this */ - public function setMessage($message) + public function setMessage(string $message): self { $this->message = $message; @@ -154,7 +154,7 @@ public function setMessage($message) /** * @return \DateTime */ - public function getTimestamp() + public function getTimestamp(): ?\DateTime { return $this->timestamp; } @@ -164,7 +164,7 @@ public function getTimestamp() * * @return $this */ - public function setTimestamp(\DateTime $timestamp) + public function setTimestamp(\DateTime $timestamp): self { $this->timestamp = $timestamp; @@ -172,9 +172,9 @@ public function setTimestamp(\DateTime $timestamp) } /** - * @return int + * @return string|null */ - public function getVersion() + public function getVersion(): ?int { return $this->version; } @@ -184,7 +184,7 @@ public function getVersion() * * @return $this */ - public function setVersion($version) + public function setVersion(int $version): self { $this->version = $version; diff --git a/Model/Identity.php b/Model/Identity.php index de6ff91..931452e 100644 --- a/Model/Identity.php +++ b/Model/Identity.php @@ -2,7 +2,7 @@ /* * This file is part of the FreshSinchBundle * - * (c) Artem Genvald + * (c) Artem Henvald * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -15,7 +15,7 @@ /** * Identity Model. * - * @author Artem Genvald + * @author Artem Henvald * * @see https://www.sinch.com/docs/sms/#incomingsms */ @@ -38,9 +38,9 @@ class Identity private $endpoint; /** - * @return string + * @return string|null */ - public function getType() + public function getType(): ?string { return $this->type; } @@ -50,7 +50,7 @@ public function getType() * * @return $this */ - public function setType($type) + public function setType(string $type): self { $this->type = $type; @@ -58,9 +58,9 @@ public function setType($type) } /** - * @return string + * @return string|null */ - public function getEndpoint() + public function getEndpoint(): ?string { return $this->endpoint; } @@ -70,7 +70,7 @@ public function getEndpoint() * * @return $this */ - public function setEndpoint($endpoint) + public function setEndpoint(string $endpoint): self { $this->endpoint = $endpoint; diff --git a/README.md b/README.md index 8d65686..3456c0a 100644 --- a/README.md +++ b/README.md @@ -7,12 +7,11 @@ 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.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.org/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) [![Total Downloads](https://img.shields.io/packagist/dt/fresh/sinch-bundle.svg?style=flat-square)](https://packagist.org/packages/fresh/sinch-bundle) -[![Dependency Status](https://img.shields.io/versioneye/d/php/fresh:sinch-bundle.svg?style=flat-square)](https://www.versioneye.com/user/projects/562fcca536d0ab00190015a7) [![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) @@ -21,9 +20,8 @@ Provides integration with **[Sinch.com](https://www.sinch.com)** SMS API. ## Requirements -* PHP 5.6 *and later* -* Symfony 2.8.6 *and later* -* Guzzle PHP HTTP Client *6.1.** +* PHP 7.1 *and later* +* Symfony 3.4 *and later* ## Installation @@ -31,23 +29,9 @@ Provides integration with **[Sinch.com](https://www.sinch.com)** SMS API. Sing up in [Sinch.com](https://www.sinch.com) and [create a new app](https://www.sinch.com/dashboard/#/quickstart). -### Install via Composer +### Add dependency via Composer -```php composer.phar require fresh/sinch-bundle='dev-master'``` - -### Register the bundle - -To start using the bundle, register it in `app/AppKernel.php`: - -```php -public function registerBundles() -{ - $bundles = [ - // Other bundles... - new Fresh\SinchBundle\FreshSinchBundle(), - ]; -} -``` +```composer req fresh/sinch-bundle='dev-master'``` ### Add key and secret to parameters.yml @@ -55,12 +39,12 @@ Add the following lines to your `parameters.yml.dist` file: ```yml parameters: - sinch.key: EnterKeyForYourSinchApp + sinch.key: EnterKeyForYourSinchApp sinch.secret: EnterSecretForYourSinchApp ``` -During the composer update you have to enter your own key and secret for your Sinch application, which you can find -in your [Sinch dashboard](https://www.sinch.com/dashboard/#/apps). +During the composer update you have to enter your own key and secret for your Sinch application, +which you can find in your [Sinch dashboard](https://www.sinch.com/dashboard/#/apps). ### Update config.yml @@ -68,59 +52,66 @@ Add the following lines to `config.yml` file: ```yml fresh_sinch: - key: "%sinch.key%" + key: "%sinch.key%" secret: "%sinch.secret%" ``` -## Using +## Usage ### Example of sending SMS ```php -$sinch = $this->get('sinch'); - -// Set the outbound number where you want to send the SMS -$phoneNumber = '+13155555552'; -$messageId = $sinch->sendSMS($phoneNumber, 'Your message'); - -// If success then the ID of sent message is returned (it is an integer value) -echo $messageId; +use Fresh\SinchBundle\Service\Sinch; + +class Foo { + public function bar(Sinch $sinch) { + // Set the outbound number where you want to send the SMS + $messageId = $sinch->sendSMS('+13155555552', 'Your message'); + + // If success then the ID of sent message is returned (it is an integer value) + echo $messageId; + } +} ``` ### Example of checking SMS status -#### Get the status of SMS - -```php -$sinch = $this->get('sinch'); - -// The ID of Sinch message you get after successful SMS sending -$messageId = '+13155555552'; - -// Status is a string with one of these values: pending, successful, faulted, unknown -$status = $sinch->getStatusOfSMS($messageId); -``` - -#### Helper methods for checking concrete SMS status - ```php -// Returns true or false -$sinch->smsIsSentSuccessfully($messageId); -$sinch->smsIsPending($messageId); -$sinch->smsIsFaulted($messageId); -$sinch->smsInUnknownStatus($messageId); +use Fresh\SinchBundle\Service\Sinch; + +class Foo { + public function bar(Sinch $sinch) { + $messageId = 123456789; // The ID of Sinch message you get after successful SMS sending + + // Status is a string with one of these values: pending, successful, faulted, unknown + $status = $sinch->getStatusOfSMS($messageId); + + // Other helper methods, return true of false + $sinch->smsIsSentSuccessfully($messageId); + $sinch->smsIsPending($messageId); + $sinch->smsIsFaulted($messageId); + $sinch->smsInUnknownStatus($messageId); + } +} ``` #### Catching and processing Sinch exceptions ```php -try { - $messageId = $sinch->sendSMS($phoneNumber, 'Your message'); - // Some logic related to SMS processing... -} catch (\Fresh\SinchBundle\Exception\SinchPaymentRequiredException $e) { - $logger->error('SMS was not sent. Looks like your Sinch account run out of money.'); - // Here you can, for example, send urgent emails to admin users - // to notify that your Sinch account run out of money +use Fresh\SinchBundle\Exception\PaymentRequired\SinchPaymentRequiredException; +use Fresh\SinchBundle\Service\Sinch; + +class Foo { + public function bar(Sinch $sinch) { + try { + $messageId = $sinch->sendSMS($phoneNumber, 'Your message'); + // Some logic related to SMS processing... + } catch (SinchPaymentRequiredException $e) { + $logger->error('SMS was not sent. Looks like your Sinch account run out of money.'); + // Here you can, for example, send urgent emails to admin users + // to notify that your Sinch account run out of money + } + } } ``` diff --git a/Resources/config/routing.yml b/Resources/config/routing.yml index 2a3cf08..a566843 100644 --- a/Resources/config/routing.yml +++ b/Resources/config/routing.yml @@ -1,4 +1,4 @@ sinch_callback: - path: /sinch/callback - defaults: { _controller: sinch_controller:callbackAction } + path: /sinch/callback + defaults: { _controller: sinch_controller:callbackAction } methods: POST diff --git a/Resources/config/services.yml b/Resources/config/services.yml index b2bd8ea..464cc70 100644 --- a/Resources/config/services.yml +++ b/Resources/config/services.yml @@ -1,19 +1,22 @@ parameters: sinch.controller.class: Fresh\SinchBundle\Controller\SinchController - sinch.service.class: Fresh\SinchBundle\Service\SinchService + sinch.service.class: Fresh\SinchBundle\Service\Sinch services: - sinch_controller: - class: "%sinch.controller.class%" - arguments: - - "@form.factory" - - "@event_dispatcher" + _defaults: + autowire: true + autoconfigure: true + public: false + bind: + $host: "%sinch.host%" + $key: "%sinch.key%" + $secret: "%sinch.secret%" + $from: "%sinch.from%" - sinch: - class: "%sinch.service.class%" - arguments: - - "@event_dispatcher" - - "%sinch.host%" - - "%sinch.key%" - - "%sinch.secret%" - - "%sinch.from%" + Fresh\SinchBundle\Controller\: + resource: '../../Controller/' + tags: + - 'controller.service_arguments' + + Fresh\SinchBundle\Service\Sinch: + class: Fresh\SinchBundle\Service\Sinch diff --git a/Service/HTTPClientInterface.php b/Service/HTTPClientInterface.php index 2b00f06..8ce527c 100644 --- a/Service/HTTPClientInterface.php +++ b/Service/HTTPClientInterface.php @@ -2,7 +2,7 @@ /* * This file is part of the FreshSinchBundle * - * (c) Artem Genvald + * (c) Artem Henvald * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -13,29 +13,25 @@ /** * HTTPClientInterface. * - * @author Artem Genvald + * @author Artem Henvald */ interface HTTPClientInterface { /** - * POST method. - * * @param string $uri * @param array $body * @param array $headers * * @return mixed */ - public function post($uri, $body = [], $headers = []); + public function post(string $uri, array $body = [], array $headers = []); /** - * GET method. - * * @param string $uri * @param array $queryParameters * @param array $headers * * @return mixed */ - public function get($uri, $queryParameters = [], $headers = []); + public function get(string $uri, array $queryParameters = [], array $headers = []); } diff --git a/Service/HTTPClientService.php b/Service/HTTPClientService.php index 7e12c6e..8fc6bcc 100644 --- a/Service/HTTPClientService.php +++ b/Service/HTTPClientService.php @@ -2,7 +2,7 @@ /* * This file is part of the FreshSinchBundle * - * (c) Artem Genvald + * (c) Artem Henvald * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -13,14 +13,14 @@ /** * HTTPClientInterface. * - * @author Artem Genvald + * @author Artem Henvald */ class HTTPClientService implements HTTPClientInterface { /** * {@inheritdoc} */ - public function post($uri, $body = [], $headers = []) + public function post(string $uri, array $body = [], array $headers = []) { // @todo } @@ -28,7 +28,7 @@ public function post($uri, $body = [], $headers = []) /** * {@inheritdoc} */ - public function get($uri, $queryParameters = [], $headers = []) + public function get(string $uri, array $queryParameters = [], array $headers = []) { // @todo } diff --git a/Service/SinchService.php b/Service/Sinch.php similarity index 79% rename from Service/SinchService.php rename to Service/Sinch.php index 6c33210..3f043cf 100644 --- a/Service/SinchService.php +++ b/Service/Sinch.php @@ -2,7 +2,7 @@ /* * This file is part of the FreshSinchBundle * - * (c) Artem Genvald + * (c) Artem Henvald * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -16,19 +16,17 @@ use Fresh\SinchBundle\Helper\SinchSmsStatus; use GuzzleHttp\Client; use GuzzleHttp\Exception\ClientException; -use GuzzleHttp\Exception\GuzzleException; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\HttpFoundation\Response; /** - * SinchService. + * Sinch Service. * - * @author Artem Genvald + * @author Artem Henvald */ -class SinchService +class Sinch { const URL_FOR_SENDING_SMS = '/v1/sms/'; - const URL_FOR_CHECKING_SMS_STATUS = '/v1/message/status/'; /** @var Client */ @@ -65,12 +63,10 @@ public function __construct(EventDispatcherInterface $dispatcher, $host, $key, $ $this->from = $from; $this->guzzleHTTPClient = new Client([ - 'base_uri' => rtrim($this->host, '/'), + 'base_uri' => \rtrim($this->host, '/'), ]); } - // region Public API - /** * @param string $phoneNumber * @param string $messageText @@ -79,11 +75,10 @@ public function __construct(EventDispatcherInterface $dispatcher, $host, $key, $ * @return int Message ID * * @throws SinchException - * @throws GuzzleException */ - public function sendSMS($phoneNumber, $messageText, $from = null) + public function sendSMS(string $phoneNumber, string $messageText, ?string $from = null): ?int { - $uri = self::URL_FOR_SENDING_SMS.$phoneNumber; // @todo validate phone number + // @todo validate phone number $body = [ 'auth' => [$this->key, $this->secret], @@ -102,7 +97,7 @@ public function sendSMS($phoneNumber, $messageText, $from = null) $smsEvent = new SmsEvent($phoneNumber, $messageText, $from); $this->dispatcher->dispatch(SinchEvents::PRE_SMS_SEND, $smsEvent); - $response = $this->guzzleHTTPClient->post($uri, $body); + $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); @@ -114,9 +109,9 @@ public function sendSMS($phoneNumber, $messageText, $from = null) && 'application/json; charset=utf-8' === $response->getHeaderLine('Content-Type') ) { $content = $response->getBody()->getContents(); - $content = json_decode($content, true); + $content = \json_decode($content, true); - if (isset($content['messageId']) && array_key_exists('messageId', $content)) { + if (isset($content['messageId']) && \array_key_exists('messageId', $content)) { $messageId = $content['messageId']; } } @@ -128,31 +123,25 @@ public function sendSMS($phoneNumber, $messageText, $from = null) * @param int $messageId * * @return string - * - * @throws GuzzleException */ - public function getStatusOfSMS($messageId) + public function getStatusOfSMS(int $messageId): string { $response = $this->sendRequestToCheckStatusOfSMS($messageId); $result = ''; - if (isset($response['status']) && array_key_exists('status', $response)) { + if (isset($response['status']) && \array_key_exists('status', $response)) { $result = $response['status']; } return $result; } - // endregion - - // region Check status helpers - /** * @param int $messageId * * @return bool */ - public function smsIsSentSuccessfully($messageId) + public function smsIsSentSuccessfully(int $messageId): bool { $response = $this->sendRequestToCheckStatusOfSMS($messageId); @@ -169,7 +158,7 @@ public function smsIsSentSuccessfully($messageId) * * @return bool */ - public function smsIsPending($messageId) + public function smsIsPending(int $messageId): bool { $response = $this->sendRequestToCheckStatusOfSMS($messageId); @@ -186,7 +175,7 @@ public function smsIsPending($messageId) * * @return bool */ - public function smsIsFaulted($messageId) + public function smsIsFaulted(int $messageId): bool { $response = $this->sendRequestToCheckStatusOfSMS($messageId); @@ -203,7 +192,7 @@ public function smsIsFaulted($messageId) * * @return bool */ - public function smsInUnknownStatus($messageId) + public function smsInUnknownStatus(int $messageId): bool { $response = $this->sendRequestToCheckStatusOfSMS($messageId); @@ -215,28 +204,20 @@ public function smsInUnknownStatus($messageId) return $result; } - // endregion - - // region Private functions - /** * @param int $messageId * * @return array|null - * - * @throws SinchException */ - private function sendRequestToCheckStatusOfSMS($messageId) + private function sendRequestToCheckStatusOfSMS(int $messageId): ?array { - $uri = self::URL_FOR_CHECKING_SMS_STATUS.$messageId; - $body = [ 'auth' => [$this->key, $this->secret], 'headers' => ['X-Timestamp' => (new \DateTime('now'))->format('c')], ]; try { - $response = $this->guzzleHTTPClient->get($uri, $body); + $response = $this->guzzleHTTPClient->get(self::URL_FOR_CHECKING_SMS_STATUS.$messageId, $body); } catch (ClientException $e) { throw SinchExceptionResolver::createAppropriateSinchException($e); } @@ -247,11 +228,9 @@ private function sendRequestToCheckStatusOfSMS($messageId) && 'application/json; charset=utf-8' === $response->getHeaderLine('Content-Type') ) { $content = $response->getBody()->getContents(); - $result = json_decode($content, true); + $result = \json_decode($content, true); } return $result; } - - // endregion } diff --git a/Service/SinchExceptionResolver.php b/Service/SinchExceptionResolver.php index 365508f..7589046 100644 --- a/Service/SinchExceptionResolver.php +++ b/Service/SinchExceptionResolver.php @@ -2,7 +2,7 @@ /* * This file is part of the FreshSinchBundle * - * (c) Artem Genvald + * (c) Artem Henvald * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -27,7 +27,7 @@ /** * SinchExceptionResolver. * - * @author Artem Genvald + * @author Artem Henvald */ class SinchExceptionResolver { @@ -36,9 +36,9 @@ class SinchExceptionResolver * * @return \Exception|SinchException */ - public static function createAppropriateSinchException(ClientException $e) + public static function createAppropriateSinchException(ClientException $e): \Exception { - $response = json_decode($e->getResponse()->getBody()->getContents(), true); + $response = \json_decode($e->getResponse()->getBody()->getContents(), true); $responseStatusCode = $e->getCode(); $errorCode = (int) $response['errorCode']; @@ -49,18 +49,23 @@ public static function createAppropriateSinchException(ClientException $e) 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; } @@ -77,19 +82,22 @@ public static function createAppropriateSinchException(ClientException $e) * * @return SinchException|null */ - private static function getSinchExceptionForBadRequest($errorCode, $errorMessage) + private static function getSinchExceptionForBadRequest(int $errorCode, string $errorMessage): ?SinchException { $exception = null; 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; } @@ -102,7 +110,7 @@ private static function getSinchExceptionForBadRequest($errorCode, $errorMessage * * @return SinchException|null */ - private static function getSinchExceptionForUnauthorized($errorCode, $errorMessage) + private static function getSinchExceptionForUnauthorized(int $errorCode, string $errorMessage): ?SinchException { $exception = null; @@ -121,7 +129,7 @@ private static function getSinchExceptionForUnauthorized($errorCode, $errorMessa * * @return SinchException|null */ - private static function getSinchExceptionForPaymentRequired($errorCode, $errorMessage) + private static function getSinchExceptionForPaymentRequired(int $errorCode, string $errorMessage): ?SinchException { $exception = null; @@ -138,20 +146,23 @@ private static function getSinchExceptionForPaymentRequired($errorCode, $errorMe * * @return SinchException|null */ - private static function getSinchExceptionForForbidden($errorCode, $errorMessage) + private static function getSinchExceptionForForbidden(int $errorCode, string $errorMessage): ?SinchException { $exception = null; 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; } @@ -164,7 +175,7 @@ private static function getSinchExceptionForForbidden($errorCode, $errorMessage) * * @return SinchException|null */ - private static function getSinchExceptionForInternalServerError($errorCode, $errorMessage) + private static function getSinchExceptionForInternalServerError(int $errorCode, string $errorMessage): ?SinchException { $exception = null; diff --git a/Tests/Controller/SinchControllerTest.php b/Tests/Controller/SinchControllerTest.php index fab24e1..da3a67a 100644 --- a/Tests/Controller/SinchControllerTest.php +++ b/Tests/Controller/SinchControllerTest.php @@ -2,7 +2,7 @@ /* * This file is part of the FreshSinchBundle * - * (c) Artem Genvald + * (c) Artem Henvald * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -21,30 +21,22 @@ /** * SinchControllerTest. * - * @author Artem Genvald + * @author Artem Henvald */ class SinchControllerTest extends WebTestCase { const DEFAULT_SINCH_CALLBACK_URL = '/sinch/callback'; - /** - * @var \PHPUnit_Framework_MockObject_MockObject|TraceableEventDispatcher - */ + /** @var \PHPUnit_Framework_MockObject_MockObject|TraceableEventDispatcher */ private $eventDispatcher; - /** - * @var \PHPUnit_Framework_MockObject_MockObject|FormFactory - */ + /** @var \PHPUnit_Framework_MockObject_MockObject|FormFactory */ private $formFactory; - /** - * @var \PHPUnit_Framework_MockObject_MockObject|Form - */ + /** @var \PHPUnit_Framework_MockObject_MockObject|Form */ private $form; - /** - * @var SinchController - */ + /** @var SinchController */ private $controller; protected function setUp() diff --git a/Tests/DependencyInjection/ConfigurationTest.php b/Tests/DependencyInjection/ConfigurationTest.php index 936c9a6..efe5b41 100644 --- a/Tests/DependencyInjection/ConfigurationTest.php +++ b/Tests/DependencyInjection/ConfigurationTest.php @@ -2,7 +2,7 @@ /* * This file is part of the FreshSinchBundle * - * (c) Artem Genvald + * (c) Artem Henvald * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -12,13 +12,14 @@ use Fresh\SinchBundle\DependencyInjection\Configuration; use Matthias\SymfonyConfigTest\PhpUnit\ConfigurationTestCaseTrait; +use PHPUnit\Framework\TestCase; /** * ConfigurationTest. * - * @author Artem Genvald + * @author Artem Henvald */ -class ConfigurationTest extends \PHPUnit_Framework_TestCase +class ConfigurationTest extends TestCase { use ConfigurationTestCaseTrait; @@ -50,16 +51,16 @@ public function testValidConfigurationWithHost() $this->assertProcessedConfigurationEquals( [ [ - 'host' => 'https://test.com', - 'key' => '1234567890', + 'host' => 'https://test.com', + 'key' => '1234567890', 'secret' => 'qwerty', ], ], [ - 'host' => 'https://test.com', - 'key' => '1234567890', + 'host' => 'https://test.com', + 'key' => '1234567890', 'secret' => 'qwerty', - 'from' => null, + 'from' => null, ] ); } @@ -69,15 +70,15 @@ public function testValidConfigurationWithoutFrom() $this->assertProcessedConfigurationEquals( [ [ - 'key' => '1234567890', + 'key' => '1234567890', 'secret' => 'qwerty', ], ], [ - 'host' => 'https://messagingapi.sinch.com', - 'key' => '1234567890', + 'host' => 'https://messagingapi.sinch.com', + 'key' => '1234567890', 'secret' => 'qwerty', - 'from' => null, + 'from' => null, ] ); } @@ -87,16 +88,16 @@ public function testValidConfigurationWithFrom() $this->assertProcessedConfigurationEquals( [ [ - 'key' => '1234567890', + 'key' => '1234567890', 'secret' => 'qwerty', - 'from' => 'Santa Claus', + 'from' => 'Santa Claus', ], ], [ - 'host' => 'https://messagingapi.sinch.com', - 'key' => '1234567890', + 'host' => 'https://messagingapi.sinch.com', + 'key' => '1234567890', 'secret' => 'qwerty', - 'from' => 'Santa Claus', + 'from' => 'Santa Claus', ] ); } diff --git a/Tests/DependencyInjection/FreshSinchExtensionTest.php b/Tests/DependencyInjection/FreshSinchExtensionTest.php index b42e37a..ccc500a 100644 --- a/Tests/DependencyInjection/FreshSinchExtensionTest.php +++ b/Tests/DependencyInjection/FreshSinchExtensionTest.php @@ -2,7 +2,7 @@ /* * This file is part of the FreshSinchBundle * - * (c) Artem Genvald + * (c) Artem Henvald * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -10,26 +10,25 @@ namespace Fresh\SinchBundle\Tests\DependencyInjection; +use Fresh\SinchBundle\Controller\SinchController; use Fresh\SinchBundle\DependencyInjection\FreshSinchExtension; -use Symfony\Component\Config\Resource\FileResource; +use Fresh\SinchBundle\Service\Sinch; +use PHPUnit\Framework\TestCase; use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException; use Symfony\Component\Yaml\Parser; /** * FreshSinchExtensionTest. * - * @author Artem Genvald + * @author Artem Henvald */ -class FreshSinchExtensionTest extends \PHPUnit_Framework_TestCase +class FreshSinchExtensionTest extends TestCase { - /** - * @var FreshSinchExtension $extension Extension - */ + /** @var FreshSinchExtension */ private $extension; - /** - * @var ContainerBuilder $container Container - */ + /** @var ContainerBuilder */ private $container; protected function setUp() @@ -41,12 +40,11 @@ protected function setUp() public function testLoadExtension() { - $yaml - = <<parse($yaml); @@ -56,24 +54,19 @@ public function testLoadExtension() $this->container->set('form.factory', new \stdClass()); $this->container->compile(); - // Check loaded resources - $resources = $this->container->getResources(); - $resourceList = []; - foreach ($resources as $resource) { - if ($resource instanceof FileResource) { - $path = $resource->getResource(); - $resourceList[] = substr($path, strrpos($path, '/') + 1); - } - } - $this->assertContains('services.yml', $resourceList); + $this->assertArrayHasKey(Sinch::class, $this->container->getRemovedIds()); + $this->assertArrayHasKey(SinchController::class, $this->container->getRemovedIds()); + + $this->assertArrayNotHasKey(Sinch::class, $this->container->getDefinitions()); + $this->assertArrayNotHasKey(SinchController::class, $this->container->getDefinitions()); + + $this->expectException(ServiceNotFoundException::class); + $this->container->get(Sinch::class); + $this->container->get(SinchController::class); - // Check auto generated parameters $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')); - - // Check that service has been loaded - $this->assertTrue($this->container->has('sinch')); } } diff --git a/Tests/Event/SmsEventTest.php b/Tests/Event/SmsEventTest.php index df70da9..2c109b4 100644 --- a/Tests/Event/SmsEventTest.php +++ b/Tests/Event/SmsEventTest.php @@ -2,7 +2,7 @@ /* * This file is part of the FreshSinchBundle * - * (c) Artem Genvald + * (c) Artem Henvald * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -11,17 +11,18 @@ namespace Fresh\SinchBundle\Tests\Event; use Fresh\SinchBundle\Event\SmsEvent; +use PHPUnit\Framework\TestCase; /** * SmsEventTest. * - * @author Artem Genvald + * @author Artem Henvald */ -class SmsEventTest extends \PHPUnit_Framework_TestCase +class SmsEventTest extends TestCase { public function testConstructorWithoutFrom() { - $number = '+46700000000'; + $number = '+46700000000'; $message = 'Hello world'; $smsEvent = new SmsEvent($number, $message); @@ -32,9 +33,9 @@ public function testConstructorWithoutFrom() public function testConstructorWithFrom() { - $number = '+46700000000'; + $number = '+46700000000'; $message = 'Hello world'; - $from = 'Santa Claus'; + $from = 'Santa Claus'; $smsEvent = new SmsEvent($number, $message, $from); @@ -47,7 +48,7 @@ public function testSetGetNumber() { $smsEvent = new SmsEvent('', ''); - $number = '+46700000000'; + $number = '+46700000000'; $smsEvent->setNumber($number); $this->assertEquals($number, $smsEvent->getNumber()); } @@ -56,7 +57,7 @@ public function testSetGetMessage() { $smsEvent = new SmsEvent('', ''); - $message = 'Hello world'; + $message = 'Hello world'; $smsEvent->setMessage($message); $this->assertEquals($message, $smsEvent->getMessage()); } @@ -65,7 +66,7 @@ public function testSetGetFrom() { $smsEvent = new SmsEvent('', ''); - $from = 'Santa Claus'; + $from = 'Santa Claus'; $smsEvent->setFrom($from); $this->assertEquals($from, $smsEvent->getFrom()); } diff --git a/Tests/Event/SmsMessageCallbackEventTest.php b/Tests/Event/SmsMessageCallbackEventTest.php index bdcfec6..5e8b430 100644 --- a/Tests/Event/SmsMessageCallbackEventTest.php +++ b/Tests/Event/SmsMessageCallbackEventTest.php @@ -2,7 +2,7 @@ /* * This file is part of the FreshSinchBundle * - * (c) Artem Genvald + * (c) Artem Henvald * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -13,22 +13,23 @@ use Fresh\SinchBundle\Event\SmsMessageCallbackEvent; use Fresh\SinchBundle\Model\CallbackRequest; use Fresh\SinchBundle\Model\Identity; +use PHPUnit\Framework\TestCase; /** * SmsMessageCallbackEventTest. * - * @author Artem Genvald + * @author Artem Henvald */ -class SmsMessageCallbackEventTest extends \PHPUnit_Framework_TestCase +class SmsMessageCallbackEventTest extends TestCase { public function testConstructor() { - $event = 'incomingSms'; - $from = new Identity(); - $to = new Identity(); - $message = 'Hello world'; + $event = 'incomingSms'; + $from = new Identity(); + $to = new Identity(); + $message = 'Hello world'; $timestamp = new \DateTime('now'); - $version = 1; + $version = 1; $callbackRequest = (new CallbackRequest()) ->setEvent($event) diff --git a/Tests/Fixtures/App/AppKernel.php b/Tests/Fixtures/App/AppKernel.php index 394af64..c1c51a7 100644 --- a/Tests/Fixtures/App/AppKernel.php +++ b/Tests/Fixtures/App/AppKernel.php @@ -2,7 +2,7 @@ /* * This file is part of the FreshSinchBundle * - * (c) Artem Genvald + * (c) Artem Henvald * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/Tests/Form/Type/CallbackRequestTypeTest.php b/Tests/Form/Type/CallbackRequestTypeTest.php index 2a8148a..a56e134 100644 --- a/Tests/Form/Type/CallbackRequestTypeTest.php +++ b/Tests/Form/Type/CallbackRequestTypeTest.php @@ -2,7 +2,7 @@ /* * This file is part of the FreshSinchBundle * - * (c) Artem Genvald + * (c) Artem Henvald * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -19,13 +19,13 @@ /** * CallbackRequestTypeTest. * - * @author Artem Genvald + * @author Artem Henvald */ class CallbackRequestTypeTest extends TypeTestCase { public function testGetBlockPrefix() { - $this->assertNull((new CallbackRequestType)->getBlockPrefix()); + $this->assertEmpty((new CallbackRequestType)->getBlockPrefix()); } public function testFormBuilder() @@ -58,18 +58,18 @@ public function testGetDefaultOptions() public function testSubmitValidData() { $data = [ - 'event' => 'incomingSms', - 'to' => [ - 'type' => 'number', + 'event' => 'incomingSms', + 'to' => [ + 'type' => 'number', 'endpoint' => '+46700000001', ], - 'from' => [ - 'type' => 'number', + 'from' => [ + 'type' => 'number', 'endpoint' => '+46700000000', ], - 'message' => 'Hello world', + 'message' => 'Hello world', 'timestamp' => '2014-12-01T12:00:00Z', - 'version' => 1, + 'version' => 1, ]; $form = $this->factory->create(CallbackRequestType::class); @@ -100,7 +100,7 @@ public function testSubmitValidData() $view = $form->createView(); $children = $view->children; - foreach (array_keys($data) as $key) { + foreach (\array_keys($data) as $key) { $this->assertArrayHasKey($key, $children); } } diff --git a/Tests/Form/Type/IdentityTypeTest.php b/Tests/Form/Type/IdentityTypeTest.php index 2aafa98..9bbb480 100644 --- a/Tests/Form/Type/IdentityTypeTest.php +++ b/Tests/Form/Type/IdentityTypeTest.php @@ -2,7 +2,7 @@ /* * This file is part of the FreshSinchBundle * - * (c) Artem Genvald + * (c) Artem Henvald * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -18,13 +18,13 @@ /** * IdentityTypeTest. * - * @author Artem Genvald + * @author Artem Henvald */ class IdentityTypeTest extends TypeTestCase { public function testGetBlockPrefix() { - $this->assertNull((new IdentityType)->getBlockPrefix()); + $this->assertEmpty((new IdentityType)->getBlockPrefix()); } public function testFormBuilder() @@ -53,7 +53,7 @@ public function testGetDefaultOptions() public function testSubmitValidData() { $data = [ - 'type' => 'number', + 'type' => 'number', 'endpoint' => '+46700000000', ]; @@ -76,7 +76,7 @@ public function testSubmitValidData() $view = $form->createView(); $children = $view->children; - foreach (array_keys($data) as $key) { + foreach (\array_keys($data) as $key) { $this->assertArrayHasKey($key, $children); } } diff --git a/Tests/Form/Type/TypeTestCase.php b/Tests/Form/Type/TypeTestCase.php index 2864f26..71c54d7 100644 --- a/Tests/Form/Type/TypeTestCase.php +++ b/Tests/Form/Type/TypeTestCase.php @@ -2,7 +2,7 @@ /* * This file is part of the FreshSinchBundle * - * (c) Artem Genvald + * (c) Artem Henvald * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -18,18 +18,14 @@ /** * TypeTestCase * - * @author Artem Genvald + * @author Artem Henvald */ abstract class TypeTestCase extends FormIntegrationTestCase { - /** - * @var FormBuilder - */ + /** @var FormBuilder */ protected $builder; - /** - * @var EventDispatcher - */ + /** @var EventDispatcher */ protected $dispatcher; protected function setUp() @@ -37,7 +33,7 @@ protected function setUp() parent::setUp(); $this->dispatcher = $this->createMock(EventDispatcherInterface::class); - $this->builder = new FormBuilder(null, null, $this->dispatcher, $this->factory); + $this->builder = new FormBuilder(null, null, $this->dispatcher, $this->factory); } public static function assertDateTimeEquals(\DateTime $expected, \DateTime $actual) diff --git a/Tests/Helper/SinchSupportedCountriesTest.php b/Tests/Helper/SinchSupportedCountriesTest.php index c82a0ab..e60d950 100644 --- a/Tests/Helper/SinchSupportedCountriesTest.php +++ b/Tests/Helper/SinchSupportedCountriesTest.php @@ -2,7 +2,7 @@ /* * This file is part of the FreshSinchBundle * - * (c) Artem Genvald + * (c) Artem Henvald * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -11,13 +11,14 @@ namespace Fresh\SinchBundle\Tests\Helper; use Fresh\SinchBundle\Helper\SinchSupportedCountries; +use PHPUnit\Framework\TestCase; /** * SinchSupportedCountriesTest. * - * @author Artem Genvald + * @author Artem Henvald */ -class SinchSupportedCountriesTest extends \PHPUnit_Framework_TestCase +class SinchSupportedCountriesTest extends TestCase { public function testSupportedCountry() { diff --git a/Tests/Model/CallbackRequestTest.php b/Tests/Model/CallbackRequestTest.php index 38e2eb0..48346aa 100644 --- a/Tests/Model/CallbackRequestTest.php +++ b/Tests/Model/CallbackRequestTest.php @@ -2,7 +2,7 @@ /* * This file is part of the FreshSinchBundle * - * (c) Artem Genvald + * (c) Artem Henvald * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -12,13 +12,14 @@ use Fresh\SinchBundle\Model\CallbackRequest; use Fresh\SinchBundle\Model\Identity; +use PHPUnit\Framework\TestCase; /** * CallbackRequestTest. * - * @author Artem Genvald + * @author Artem Henvald */ -class CallbackRequestTest extends \PHPUnit_Framework_TestCase +class CallbackRequestTest extends TestCase { public function testConstructor() { diff --git a/Tests/Model/IdentityTest.php b/Tests/Model/IdentityTest.php index e28c391..1d5bbbb 100644 --- a/Tests/Model/IdentityTest.php +++ b/Tests/Model/IdentityTest.php @@ -2,7 +2,7 @@ /* * This file is part of the FreshSinchBundle * - * (c) Artem Genvald + * (c) Artem Henvald * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -11,13 +11,14 @@ namespace Fresh\SinchBundle\Tests\Model; use Fresh\SinchBundle\Model\Identity; +use PHPUnit\Framework\TestCase; /** * IdentityTest. * - * @author Artem Genvald + * @author Artem Henvald */ -class IdentityTest extends \PHPUnit_Framework_TestCase +class IdentityTest extends TestCase { public function testConstructor() { diff --git a/Tests/Service/SinchExceptionResolverTest.php b/Tests/Service/SinchExceptionResolverTest.php index e0ed3c6..07abe15 100644 --- a/Tests/Service/SinchExceptionResolverTest.php +++ b/Tests/Service/SinchExceptionResolverTest.php @@ -2,7 +2,7 @@ /* * This file is part of the FreshSinchBundle * - * (c) Artem Genvald + * (c) Artem Henvald * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -22,6 +22,7 @@ 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; use Psr\Http\Message\StreamInterface; @@ -30,12 +31,10 @@ /** * FreshSinchExtensionTest. * - * @author Artem Genvald + * @author Artem Henvald */ -class SinchExceptionResolverTest extends \PHPUnit_Framework_TestCase +class SinchExceptionResolverTest extends TestCase { - // region Bad Request exceptions - public function testSinchParameterValidationException() { $e = $this->getClientException(Response::HTTP_BAD_REQUEST, SinchErrorCode::PARAMETER_VALIDATION); @@ -54,30 +53,18 @@ public function testSinchMissingParameterException() $this->assertInstanceOf(SinchMissingParameterException::class, SinchExceptionResolver::createAppropriateSinchException($e)); } - // endregion - - // region Unauthorized exceptions - public function testSinchIllegalAuthorizationHeaderException() { $e = $this->getClientException(Response::HTTP_UNAUTHORIZED, SinchErrorCode::ILLEGAL_AUTHORIZATION_HEADER); $this->assertInstanceOf(SinchIllegalAuthorizationHeaderException::class, SinchExceptionResolver::createAppropriateSinchException($e)); } - // endregion - - // region Payment Required exceptions - public function testSinchPaymentRequiredException() { $e = $this->getClientException(Response::HTTP_PAYMENT_REQUIRED, SinchErrorCode::THERE_IS_NOT_ENOUGH_FUNDS_TO_SEND_THE_MESSAGE); $this->assertInstanceOf(SinchPaymentRequiredException::class, SinchExceptionResolver::createAppropriateSinchException($e)); } - // endregion - - // region Forbidden exceptions - public function testSinchForbiddenRequestException() { $e = $this->getClientException(Response::HTTP_FORBIDDEN, SinchErrorCode::FORBIDDEN_REQUEST); @@ -99,28 +86,18 @@ public function testSinchNoVerifiedPhoneNumberException() $this->assertInstanceOf(SinchNoVerifiedPhoneNumberException::class, SinchExceptionResolver::createAppropriateSinchException($e)); } - // endregion - - // region Internal Server Error exceptions - public function testSinchInternalErrorException() { $e = $this->getClientException(Response::HTTP_INTERNAL_SERVER_ERROR, SinchErrorCode::INTERNAL_ERROR); $this->assertInstanceOf(SinchInternalErrorException::class, SinchExceptionResolver::createAppropriateSinchException($e)); } - // endregion - - // region Standard exceptions - public function testStandardException() { $e = $this->getClientException(Response::HTTP_GATEWAY_TIMEOUT, 0); $this->assertInstanceOf(\Exception::class, SinchExceptionResolver::createAppropriateSinchException($e)); } - // endregion - /** * Get client exception * @@ -131,9 +108,9 @@ public function testStandardException() */ private function getClientException($statusCode, $errorCode) { - $request = $this->getMockBuilder(RequestInterface::class)->disableOriginalConstructor()->getMock(); + $request = $this->getMockBuilder(RequestInterface::class)->disableOriginalConstructor()->getMock(); $response = $this->getMockBuilder(ResponseInterface::class)->disableOriginalConstructor()->getMock(); - $body = $this->getMockBuilder(StreamInterface::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)); diff --git a/Tests/Service/SinchServiceTest.php b/Tests/Service/SinchTest.php similarity index 61% rename from Tests/Service/SinchServiceTest.php rename to Tests/Service/SinchTest.php index a59d62b..194acc4 100644 --- a/Tests/Service/SinchServiceTest.php +++ b/Tests/Service/SinchTest.php @@ -2,7 +2,7 @@ /* * This file is part of the FreshSinchBundle * - * (c) Artem Genvald + * (c) Artem Henvald * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -10,14 +10,14 @@ namespace Service; -use Fresh\SinchBundle\Service\SinchService; +use Fresh\SinchBundle\Service\Sinch; /** - * SinchServiceTest. + * SinchTest. * - * @author Artem Genvald + * @author Artem Henvald */ -class SinchServiceTest +class SinchTest { public function testSendSms() { diff --git a/composer.json b/composer.json index 7fdbe6f..f9e36f5 100644 --- a/composer.json +++ b/composer.json @@ -17,17 +17,17 @@ "issues": "https://github.com/fre5h/SinchBundle/issues" }, "require": { - "php": ">=5.6.0", + "php": "^7.1.3", "symfony/config": "^3.4", - "symfony/event-dispatcher": "^3.4", + "symfony/event-dispatcher": "^3.4", "symfony/form": "^3.4", "symfony/framework-bundle": "^3.4", - "guzzlehttp/guzzle": "^6.2.1" + "guzzlehttp/guzzle": "^6.3" }, "require-dev": { - "phpunit/phpunit": "5.6.*", + "phpunit/phpunit": "6.5.*", "escapestudios/symfony2-coding-standard": "^3.0", - "matthiasnoback/symfony-config-test": "2.0.*" + "matthiasnoback/symfony-config-test": "3.1.*" }, "autoload": { "psr-4": { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index e36cf4d..a109626 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,21 +1,10 @@ - - - - - - ./Tests