From 6f81140307043864190ec725a0ee01478cddd256 Mon Sep 17 00:00:00 2001 From: Paul Rijke Date: Mon, 24 Jul 2023 14:13:20 +0200 Subject: [PATCH 1/3] Made the bundle 5.4 compatible --- composer.json | 21 +++---- phpunit.xml | 4 +- .../Tests/Helper/JsonHelperTest.php | 6 +- .../Tests/Messaging/MessageTest.php | 17 +++--- .../Tests/Messaging/MessagingServiceTest.php | 9 +-- .../Tests/Messaging/SendMessageResultTest.php | 5 +- .../DependencyInjection/Configuration.php | 2 +- .../DependencyInjection/ConfigurationTest.php | 5 +- .../Tests/Service/MessagingServiceTest.php | 60 ++++++++++++++++--- 9 files changed, 89 insertions(+), 40 deletions(-) diff --git a/composer.json b/composer.json index 17e64bd..b38d9e1 100644 --- a/composer.json +++ b/composer.json @@ -16,20 +16,21 @@ } }, "require": { - "php": ">=5.6", + "php": ">=7.4", "guzzlehttp/guzzle": "^6.0", - "symfony/config": ">=2.7,<4.0 || ^4.0", - "symfony/dependency-injection": ">=2.7,<4.0 || ^4.0", - "symfony/http-kernel": ">=2.7,<4.0 || ^4.0" + "symfony/config": "^4.0 || ^5.0", + "symfony/dependency-injection": "^4.0 || ^5.0", + "symfony/http-kernel": "^5.0", + "symfony/event-dispatcher": "^5.0", + "symfony/console": "^5.0" }, "require-dev": { - "matthiasnoback/symfony-config-test": "^2.2", + "matthiasnoback/symfony-config-test": "^4.3", "phpmd/phpmd": "^2.6", - "phpunit/phpunit": "^5.7", - "sensiolabs/security-checker": "^3.0", - "sebastian/phpcpd": "^2.0", + "phpunit/phpunit": "^8.5", + "sensiolabs/security-checker": "^v6.0.3", "squizlabs/php_codesniffer": "^1.0", - "symfony/phpunit-bridge": "^3.0 || ^4.0", - "mockery/mockery": "~0.9.5" + "symfony/phpunit-bridge": "^3.0 || ^4.0 || ^5.0" , + "mockery/mockery": "^1.6.4" } } diff --git a/phpunit.xml b/phpunit.xml index 016b6f3..9b512fb 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -8,7 +8,6 @@ convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" - syntaxCheck="false" bootstrap="vendor/autoload.php"> @@ -26,6 +25,7 @@ - + + diff --git a/src/Surfnet/MessageBirdApiClient/Tests/Helper/JsonHelperTest.php b/src/Surfnet/MessageBirdApiClient/Tests/Helper/JsonHelperTest.php index b3f9504..3f38002 100644 --- a/src/Surfnet/MessageBirdApiClient/Tests/Helper/JsonHelperTest.php +++ b/src/Surfnet/MessageBirdApiClient/Tests/Helper/JsonHelperTest.php @@ -18,7 +18,7 @@ namespace Surfnet\Stepup\Tests\Helper; -use PHPUnit_Framework_TestCase as TestCase; +use PHPUnit\Framework\TestCase; use Surfnet\MessageBirdApiClient\Exception\InvalidArgumentException; use Surfnet\MessageBirdApiClient\Exception\JsonException; use Surfnet\MessageBirdApiClient\Helper\JsonHelper; @@ -34,7 +34,7 @@ class JsonHelperTest extends TestCase */ public function jsonHelperCanOnlyDecodeStrings($nonString) { - $this->setExpectedException(InvalidArgumentException::class); + $this->expectException(InvalidArgumentException::class); JsonHelper::decode($nonString); } @@ -56,7 +56,7 @@ public function jsonHelperDecodesStringsToArrays() */ public function jsonHelperThrowsAnExceptionWhenThereIsASyntaxError() { - $this->setExpectedException(JsonException::class, 'Syntax error'); + $this->expectException(JsonException::class, 'Syntax error'); $jsonWithMissingDoubleQuotes = '{ hello : world }'; JsonHelper::decode($jsonWithMissingDoubleQuotes); } diff --git a/src/Surfnet/MessageBirdApiClient/Tests/Messaging/MessageTest.php b/src/Surfnet/MessageBirdApiClient/Tests/Messaging/MessageTest.php index e23f99d..12c5442 100644 --- a/src/Surfnet/MessageBirdApiClient/Tests/Messaging/MessageTest.php +++ b/src/Surfnet/MessageBirdApiClient/Tests/Messaging/MessageTest.php @@ -18,9 +18,10 @@ namespace Surfnet\MessageBirdApiClient\Tests\Messaging; +use PHPUnit\Framework\TestCase; use Surfnet\MessageBirdApiClient\Messaging\Message; -class MessageTest extends \PHPUnit_Framework_TestCase +class MessageTest extends TestCase { /** * @dataProvider invalidOriginatorTypes @@ -28,7 +29,7 @@ class MessageTest extends \PHPUnit_Framework_TestCase */ public function testItThrowsAnExceptionWhenGivenAnOriginatorOfAnInvalidType($originator) { - $this->setExpectedException('Surfnet\MessageBirdApiClient\Exception\InvalidArgumentException'); + $this->expectException('Surfnet\MessageBirdApiClient\Exception\InvalidArgumentException'); new Message($originator, '31612345678', 'body'); } @@ -39,7 +40,7 @@ public function testItThrowsAnExceptionWhenGivenAnOriginatorOfAnInvalidType($ori */ public function testItThrowsAnExceptionWhenGivenAnIncorrectlyFormattedOriginator($originator) { - $this->setExpectedException('Surfnet\MessageBirdApiClient\Exception\DomainException'); + $this->expectException('Surfnet\MessageBirdApiClient\Exception\DomainException'); new Message($originator, '31612345678', 'body'); } @@ -50,7 +51,9 @@ public function testItThrowsAnExceptionWhenGivenAnIncorrectlyFormattedOriginator */ public function testItAcceptsValidOriginator($originator) { - new Message($originator, '31612345678', 'body'); + $message = new Message($originator, '31612345678', 'body'); + $this->assertInstanceOf(Message::class, $message); + } /** @@ -59,7 +62,7 @@ public function testItAcceptsValidOriginator($originator) */ public function testThrowsAnInvalidArgumentExceptionWhenGivenANonStringRecipient($recipient) { - $this->setExpectedException('Surfnet\MessageBirdApiClient\Exception\InvalidArgumentException'); + $this->expectException('Surfnet\MessageBirdApiClient\Exception\InvalidArgumentException'); new Message('SURFnet', $recipient, 'body'); } @@ -70,7 +73,7 @@ public function testThrowsAnInvalidArgumentExceptionWhenGivenANonStringRecipient */ public function testItThrowsOnIncorrectlyFormattedRecipient($recipient) { - $this->setExpectedException('Surfnet\MessageBirdApiClient\Exception\DomainException'); + $this->expectException('Surfnet\MessageBirdApiClient\Exception\DomainException'); new Message('SURFnet', $recipient, 'body'); } @@ -81,7 +84,7 @@ public function testItThrowsOnIncorrectlyFormattedRecipient($recipient) */ public function testItDetectsInvalidBody($body) { - $this->setExpectedException('Surfnet\MessageBirdApiClient\Exception\InvalidArgumentException'); + $this->expectException('Surfnet\MessageBirdApiClient\Exception\InvalidArgumentException'); new Message('SURFnet', '31612345678', $body); } diff --git a/src/Surfnet/MessageBirdApiClient/Tests/Messaging/MessagingServiceTest.php b/src/Surfnet/MessageBirdApiClient/Tests/Messaging/MessagingServiceTest.php index 2327086..bed5d70 100644 --- a/src/Surfnet/MessageBirdApiClient/Tests/Messaging/MessagingServiceTest.php +++ b/src/Surfnet/MessageBirdApiClient/Tests/Messaging/MessagingServiceTest.php @@ -21,10 +21,11 @@ use GuzzleHttp\Client; use GuzzleHttp\Handler\MockHandler; use GuzzleHttp\Psr7\Response; +use PHPUnit\Framework\TestCase; use Surfnet\MessageBirdApiClient\Messaging\Message; use Surfnet\MessageBirdApiClient\Messaging\MessagingService; -class MessagingServiceTest extends \PHPUnit_Framework_TestCase +class MessagingServiceTest extends TestCase { public function testItSendsAMessage() { @@ -84,7 +85,7 @@ public function testHandlesInvalidAccessKey() */ public function testThrowsApiDomainExceptionsOnOther4xxStatusCodes($statusCode, $fixture, $errorString) { - $this->setExpectedException('Surfnet\MessageBirdApiClient\Exception\ApiRuntimeException', $errorString); + $this->expectException('Surfnet\MessageBirdApiClient\Exception\ApiRuntimeException', $errorString); $handler = new MockHandler([ new Response($statusCode, [], file_get_contents($fixture)) @@ -118,7 +119,7 @@ public function testHandlesOther5xxStatusCodes($statusCode, $fixture, $errorStri public function testThrowsApiRuntimeExceptionsOnBrokenJson() { - $this->setExpectedException('Surfnet\MessageBirdApiClient\Exception\ApiRuntimeException', 'valid JSON'); + $this->expectException('Surfnet\MessageBirdApiClient\Exception\ApiRuntimeException', 'valid JSON'); $handler = new MockHandler([ new Response(201, [], 'This is not valid JSON.') @@ -131,7 +132,7 @@ public function testThrowsApiRuntimeExceptionsOnBrokenJson() public function testThrowsApiRuntimeExceptionWhenUnknownStatusCode() { - $this->setExpectedException( + $this->expectException( 'Surfnet\MessageBirdApiClient\Exception\ApiRuntimeException', 'Unexpected MessageBird server behaviour' ); diff --git a/src/Surfnet/MessageBirdApiClient/Tests/Messaging/SendMessageResultTest.php b/src/Surfnet/MessageBirdApiClient/Tests/Messaging/SendMessageResultTest.php index 244c476..463a549 100644 --- a/src/Surfnet/MessageBirdApiClient/Tests/Messaging/SendMessageResultTest.php +++ b/src/Surfnet/MessageBirdApiClient/Tests/Messaging/SendMessageResultTest.php @@ -18,9 +18,10 @@ namespace Surfnet\MessageBirdApiClient\Tests\Messaging; +use PHPUnit\Framework\TestCase; use Surfnet\MessageBirdApiClient\Messaging\SendMessageResult; -class SendMessageResultTest extends \PHPUnit_Framework_TestCase +class SendMessageResultTest extends TestCase { /** * @dataProvider nonStringDeliveryStatuses @@ -28,7 +29,7 @@ class SendMessageResultTest extends \PHPUnit_Framework_TestCase */ public function testItOnlyAcceptsStringDeliveryStatus($deliveryStatus) { - $this->setExpectedException( + $this->expectException( 'Surfnet\MessageBirdApiClient\Exception\InvalidArgumentException', 'Delivery status must be string' ); diff --git a/src/Surfnet/MessageBirdApiClientBundle/DependencyInjection/Configuration.php b/src/Surfnet/MessageBirdApiClientBundle/DependencyInjection/Configuration.php index cf73c8d..6e72d6f 100644 --- a/src/Surfnet/MessageBirdApiClientBundle/DependencyInjection/Configuration.php +++ b/src/Surfnet/MessageBirdApiClientBundle/DependencyInjection/Configuration.php @@ -26,7 +26,7 @@ */ class Configuration implements ConfigurationInterface { - public function getConfigTreeBuilder() + public function getConfigTreeBuilder(): TreeBuilder { $treeBuilder = new TreeBuilder('surfnet_message_bird_api_client'); diff --git a/src/Surfnet/MessageBirdApiClientBundle/Tests/DependencyInjection/ConfigurationTest.php b/src/Surfnet/MessageBirdApiClientBundle/Tests/DependencyInjection/ConfigurationTest.php index ac10dcf..2f3ef69 100644 --- a/src/Surfnet/MessageBirdApiClientBundle/Tests/DependencyInjection/ConfigurationTest.php +++ b/src/Surfnet/MessageBirdApiClientBundle/Tests/DependencyInjection/ConfigurationTest.php @@ -19,9 +19,10 @@ namespace Surfnet\MessageBirdApiClientBundle\Tests\DependencyInjection; use Matthias\SymfonyConfigTest\PhpUnit\ConfigurationTestCaseTrait; +use PHPUnit\Framework\TestCase; use Surfnet\MessageBirdApiClientBundle\DependencyInjection\Configuration; -class ConfigurationTest extends \PHPUnit_Framework_TestCase +class ConfigurationTest extends TestCase { use ConfigurationTestCaseTrait; @@ -57,7 +58,7 @@ public function testAuthorizationIsRequired() { $this->assertConfigurationIsInvalid( ['surfnet_message_bird_api_client' => []], - 'child node "authorization"' + 'child config "authorization"' ); } diff --git a/src/Surfnet/MessageBirdApiClientBundle/Tests/Service/MessagingServiceTest.php b/src/Surfnet/MessageBirdApiClientBundle/Tests/Service/MessagingServiceTest.php index 11fba93..1c28f12 100644 --- a/src/Surfnet/MessageBirdApiClientBundle/Tests/Service/MessagingServiceTest.php +++ b/src/Surfnet/MessageBirdApiClientBundle/Tests/Service/MessagingServiceTest.php @@ -20,11 +20,13 @@ use Mockery as m; use Mockery\Matcher\MatcherAbstract; +use PHPUnit\Framework\TestCase; +use Psr\Log\LoggerInterface; use Surfnet\MessageBirdApiClient\Messaging\Message; use Surfnet\MessageBirdApiClient\Messaging\SendMessageResult; use Surfnet\MessageBirdApiClientBundle\Service\MessagingService; -class MessagingServiceTest extends \PHPUnit_Framework_TestCase +class MessagingServiceTest extends TestCase { public function testItReturnsSuccessfully() { @@ -46,14 +48,30 @@ public function testItLogsInvalidMessages() $message = new Message('SURFnet', '31612345678', 'body'); $result = new SendMessageResult(SendMessageResult::STATUS_NOT_SENT, [['code' => SendMessageResult::ERROR_INVALID_PARAMS, 'description' => '']]); - $libraryService = m::mock('Surfnet\MessageBirdApiClient\Messaging\MessagingService') - ->shouldReceive('send')->once()->with($message)->andReturn($result) + // Create a mock for Surfnet\MessageBirdApiClient\Messaging\MessagingService + $libraryService = $this->getMockBuilder('Surfnet\MessageBirdApiClient\Messaging\MessagingService') + ->disableOriginalConstructor() ->getMock(); - $logger = m::mock('Psr\Log\LoggerInterface') - ->shouldReceive('notice')->once($this->expectStringContains('Invalid message sent to MessageBird')) + + // Set the expectation on the send method to be called once with $message and return $result + $libraryService->expects($this->once()) + ->method('send') + ->with($message) + ->willReturn($result); + + // Create a mock for Psr\Log\LoggerInterface + $logger = $this->getMockBuilder('Psr\Log\LoggerInterface') ->getMock(); + // Set the expectation on the critical method to be called once with a message containing 'Invalid access key used for MessageBird' + $logger->expects($this->once()) + ->method('notice') + ->with($this->stringContains('Invalid message sent to MessageBird')); + + // Create the MessagingService instance with the mocks $service = new MessagingService($libraryService, $logger); + + // Invoke the send method that should trigger logging $service->send($message); } @@ -62,14 +80,30 @@ public function testItLogsInvalidAccessKeys() $message = new Message('SURFnet', '31612345678', 'body'); $result = new SendMessageResult(SendMessageResult::STATUS_NOT_SENT, [['code' => SendMessageResult::ERROR_REQUEST_NOT_ALLOWED, 'description' => '']]); - $libraryService = m::mock('Surfnet\MessageBirdApiClient\Messaging\MessagingService') - ->shouldReceive('send')->once()->with($message)->andReturn($result) + // Create a mock for Surfnet\MessageBirdApiClient\Messaging\MessagingService + $libraryService = $this->getMockBuilder('Surfnet\MessageBirdApiClient\Messaging\MessagingService') + ->disableOriginalConstructor() ->getMock(); - $logger = m::mock('Psr\Log\LoggerInterface') - ->shouldReceive('critical')->once($this->expectStringContains('Invalid access key used for MessageBird')) + + // Set the expectation on the send method to be called once with $message and return $result + $libraryService->expects($this->once()) + ->method('send') + ->with($message) + ->willReturn($result); + + // Create a mock for Psr\Log\LoggerInterface + $logger = $this->getMockBuilder(LoggerInterface::class) ->getMock(); + // Set the expectation on the critical method to be called once with a message containing 'Invalid access key used for MessageBird' + $logger->expects($this->once()) + ->method('critical') + ->with($this->stringContains('Invalid access key used for MessageBird')); + + // Create the MessagingService instance with the mocks $service = new MessagingService($libraryService, $logger); + + // Invoke the send method that should trigger logging $service->send($message); } @@ -83,4 +117,12 @@ private function expectStringContains($contains) return strpos($string, $contains) !== false; }); } + + protected function tearDown(): void + { + m::close(); + parent::tearDown(); + } + + } From 811f0c623614673133da24dc30d5f32e47f89d3a Mon Sep 17 00:00:00 2001 From: Paul Rijke Date: Tue, 30 Apr 2024 12:00:52 +0200 Subject: [PATCH 2/3] Upgrade to latest version of symfony and dependencies --- CHANGELOG.md | 3 ++ composer.json | 23 +++++++-------- .../Tests/Service/MessagingServiceTest.php | 29 ++++--------------- 3 files changed, 20 insertions(+), 35 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b2ed172..b2071cd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +# 5.0.0 +Support Symfony 5+ and php 8.2 + # 4.1.3 Make Configuration parser SF 5 compatible diff --git a/composer.json b/composer.json index b38d9e1..7893ada 100644 --- a/composer.json +++ b/composer.json @@ -16,21 +16,20 @@ } }, "require": { - "php": ">=7.4", - "guzzlehttp/guzzle": "^6.0", - "symfony/config": "^4.0 || ^5.0", - "symfony/dependency-injection": "^4.0 || ^5.0", - "symfony/http-kernel": "^5.0", - "symfony/event-dispatcher": "^5.0", - "symfony/console": "^5.0" + "php": ">=8.2", + "guzzlehttp/guzzle": "^7.0", + "symfony/config": "^5.0 || ^6.0 || ^7.0", + "symfony/dependency-injection": "^5.0 || ^6.0 || ^7.0", + "symfony/http-kernel": "^5.0 || ^6.0 || ^7.0", + "symfony/event-dispatcher": "^5.0 || ^6.0 || ^7.0", + "symfony/console": "^5.0 || ^6.0 || ^7.0" }, "require-dev": { - "matthiasnoback/symfony-config-test": "^4.3", + "matthiasnoback/symfony-config-test": "^4.3 || ^5.0", "phpmd/phpmd": "^2.6", - "phpunit/phpunit": "^8.5", + "phpunit/phpunit": "^9.6", "sensiolabs/security-checker": "^v6.0.3", - "squizlabs/php_codesniffer": "^1.0", - "symfony/phpunit-bridge": "^3.0 || ^4.0 || ^5.0" , - "mockery/mockery": "^1.6.4" + "squizlabs/php_codesniffer": "^3.0", + "symfony/phpunit-bridge": "^5.0 || ^6.0 || ^7.0" } } diff --git a/src/Surfnet/MessageBirdApiClientBundle/Tests/Service/MessagingServiceTest.php b/src/Surfnet/MessageBirdApiClientBundle/Tests/Service/MessagingServiceTest.php index 1c28f12..a123638 100644 --- a/src/Surfnet/MessageBirdApiClientBundle/Tests/Service/MessagingServiceTest.php +++ b/src/Surfnet/MessageBirdApiClientBundle/Tests/Service/MessagingServiceTest.php @@ -18,8 +18,6 @@ namespace Surfnet\MessageBirdApiClientBundle\Tests\Service; -use Mockery as m; -use Mockery\Matcher\MatcherAbstract; use PHPUnit\Framework\TestCase; use Psr\Log\LoggerInterface; use Surfnet\MessageBirdApiClient\Messaging\Message; @@ -32,11 +30,13 @@ public function testItReturnsSuccessfully() { $message = new Message('SURFnet', '31612345678', 'body'); $result = new SendMessageResult(SendMessageResult::STATUS_DELIVERED, []); + $libraryService = $this->createMock('Surfnet\MessageBirdApiClient\Messaging\MessagingService'); + $libraryService->expects($this->once()) + ->method('send') + ->with($message) + ->willReturn($result); - $libraryService = m::mock('Surfnet\MessageBirdApiClient\Messaging\MessagingService') - ->shouldReceive('send')->once()->with($message)->andReturn($result) - ->getMock(); - $logger = m::mock('Psr\Log\LoggerInterface'); + $logger = $this->createMock('Psr\Log\LoggerInterface'); $service = new MessagingService($libraryService, $logger); @@ -107,22 +107,5 @@ public function testItLogsInvalidAccessKeys() $service->send($message); } - /** - * @param string - * @return MatcherAbstract - */ - private function expectStringContains($contains) - { - return m::on(function ($string) use ($contains) { - return strpos($string, $contains) !== false; - }); - } - - protected function tearDown(): void - { - m::close(); - parent::tearDown(); - } - } From a0dfbc3a0c442c48316547b1689520f10779d0d6 Mon Sep 17 00:00:00 2001 From: Paul Rijke Date: Tue, 30 Apr 2024 12:14:11 +0200 Subject: [PATCH 3/3] Update travis --- .travis.yml | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index 60ff73a..c92ccb7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,10 +8,8 @@ language: php php: - - 5.6 - - 7.0 - - 7.1 - - 7.2 + - 8.2 + - 8.3 cache: directories: @@ -33,5 +31,4 @@ branches: matrix: allow_failures: - - php: 7.1 - - php: 7.2 + - php: 8.3