From 9afb144c6778a3f005901dd8ffea4efcd6bcb1de Mon Sep 17 00:00:00 2001 From: TiMESPLiNTER Date: Thu, 12 Aug 2021 15:31:51 +0200 Subject: [PATCH 1/4] chore(): Remove cache dependency and move others to dev dependencies --- composer.json | 18 ++++++++-------- .../KafkaSchemaRegistryApiClientProvider.php | 21 ++++++++++++------- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/composer.json b/composer.json index b3fc3cd..f35141c 100644 --- a/composer.json +++ b/composer.json @@ -15,23 +15,23 @@ "homepage": "https://careers.jobcloud.ch/en/our-team/?term=133" } ], - "config": { - "sort-packages": true - }, "require": { "php": ">=7.4", "ext-json": "*", - "pimple/pimple": "^3.2", - "symfony/cache": "^5.0", - "nyholm/psr7": "^1.2", - "kriswallsmith/buzz": "^1.0", - "psr/http-message": "^1.0" + "psr/http-message": "^1.0", + "psr/http-client": "^1.0.1" }, "require-dev": { "squizlabs/php_codesniffer": "^3.4.2", "phpunit/phpunit": "^9.5", "phpstan/phpstan": "^0.12", "rregeer/phpunit-coverage-check": "^0.3.1", - "infection/infection": "^0.21" + "infection/infection": "^0.21", + "nyholm/psr7": "^1.2", + "kriswallsmith/buzz": "^1.0", + "pimple/pimple": "^3.2" + }, + "config": { + "sort-packages": true } } diff --git a/src/ServiceProvider/KafkaSchemaRegistryApiClientProvider.php b/src/ServiceProvider/KafkaSchemaRegistryApiClientProvider.php index 26281ca..a4650d0 100644 --- a/src/ServiceProvider/KafkaSchemaRegistryApiClientProvider.php +++ b/src/ServiceProvider/KafkaSchemaRegistryApiClientProvider.php @@ -2,10 +2,14 @@ namespace Jobcloud\Kafka\SchemaRegistryClient\ServiceProvider; +use Buzz\Client\AbstractClient; use Buzz\Client\Curl; use Jobcloud\Kafka\SchemaRegistryClient\ErrorHandler; +use Jobcloud\Kafka\SchemaRegistryClient\ErrorHandlerInterface; use Jobcloud\Kafka\SchemaRegistryClient\HttpClient; +use Jobcloud\Kafka\SchemaRegistryClient\HttpClientInterface; use Jobcloud\Kafka\SchemaRegistryClient\KafkaSchemaRegistryApiClient; +use Jobcloud\Kafka\SchemaRegistryClient\KafkaSchemaRegistryApiClientInterface; use LogicException; use Nyholm\Psr7\Factory\Psr17Factory; use Pimple\Container; @@ -35,26 +39,26 @@ public function register(Container $container): void { $this->checkRequiredOffsets($container); - if (false === isset($container[self::REQUEST_FACTORY])) { - $container[self::REQUEST_FACTORY] = static function (Container $container) { + if (false === isset($container[self::REQUEST_FACTORY]) && class_exists('Nyholm\Psr7\Factory\Psr17Factory')) { + $container[self::REQUEST_FACTORY] = static function (): RequestFactoryInterface { return new Psr17Factory(); }; } - if (false === isset($container[self::CLIENT])) { - $container[self::CLIENT] = static function (Container $container) { + if (false === isset($container[self::CLIENT]) && class_exists('Buzz\Client\Curl')) { + $container[self::CLIENT] = static function (Container $container): ClientInterface { return new Curl($container[self::REQUEST_FACTORY]); }; } if (false === isset($container[self::ERROR_HANDLER])) { - $container[self::ERROR_HANDLER] = static function () { + $container[self::ERROR_HANDLER] = static function (): ErrorHandlerInterface { return new ErrorHandler(); }; } if (false === isset($container[self::HTTP_CLIENT])) { - $container[self::HTTP_CLIENT] = static function (Container $container) { + $container[self::HTTP_CLIENT] = static function (Container $container): HttpClientInterface { /** @var ClientInterface $client */ $client = $container[self::CLIENT]; @@ -73,7 +77,9 @@ public function register(Container $container): void } if (false === isset($container[self::API_CLIENT])) { - $container[self::API_CLIENT] = static function (Container $container) { + $container[self::API_CLIENT] = static function ( + Container $container + ): KafkaSchemaRegistryApiClientInterface { /** @var HttpClient $client */ $client = $container[self::HTTP_CLIENT]; @@ -84,7 +90,6 @@ public function register(Container $container): void private function checkRequiredOffsets(Container $container): void { - if (false === isset($container[self::CONTAINER_KEY][self::SETTING_KEY_BASE_URL])) { throw new LogicException( sprintf( From 2d565652a05ccf0d02547709260876afd8cc0b87 Mon Sep 17 00:00:00 2001 From: TiMESPLiNTER Date: Thu, 12 Aug 2021 15:33:17 +0200 Subject: [PATCH 2/4] chore(): Remove unused use statement --- src/ServiceProvider/KafkaSchemaRegistryApiClientProvider.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/ServiceProvider/KafkaSchemaRegistryApiClientProvider.php b/src/ServiceProvider/KafkaSchemaRegistryApiClientProvider.php index a4650d0..d8eef03 100644 --- a/src/ServiceProvider/KafkaSchemaRegistryApiClientProvider.php +++ b/src/ServiceProvider/KafkaSchemaRegistryApiClientProvider.php @@ -2,7 +2,6 @@ namespace Jobcloud\Kafka\SchemaRegistryClient\ServiceProvider; -use Buzz\Client\AbstractClient; use Buzz\Client\Curl; use Jobcloud\Kafka\SchemaRegistryClient\ErrorHandler; use Jobcloud\Kafka\SchemaRegistryClient\ErrorHandlerInterface; From d1a4bb10bb12d057c2664d53f4acc003020bdbfd Mon Sep 17 00:00:00 2001 From: TiMESPLiNTER Date: Thu, 12 Aug 2021 16:52:07 +0200 Subject: [PATCH 3/4] chore(): Improve mutant kill rate --- composer.json | 13 +++++++------ tests/KafkaSchemaRegistryApiClientProviderTest.php | 8 ++++++++ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/composer.json b/composer.json index f35141c..c8507af 100644 --- a/composer.json +++ b/composer.json @@ -22,14 +22,15 @@ "psr/http-client": "^1.0.1" }, "require-dev": { - "squizlabs/php_codesniffer": "^3.4.2", - "phpunit/phpunit": "^9.5", - "phpstan/phpstan": "^0.12", - "rregeer/phpunit-coverage-check": "^0.3.1", "infection/infection": "^0.21", - "nyholm/psr7": "^1.2", "kriswallsmith/buzz": "^1.0", - "pimple/pimple": "^3.2" + "nyholm/psr7": "^1.2", + "php-mock/php-mock-phpunit": "^2.6", + "phpstan/phpstan": "^0.12", + "phpunit/phpunit": "^9.5", + "pimple/pimple": "^3.2", + "rregeer/phpunit-coverage-check": "^0.3.1", + "squizlabs/php_codesniffer": "^3.4.2" }, "config": { "sort-packages": true diff --git a/tests/KafkaSchemaRegistryApiClientProviderTest.php b/tests/KafkaSchemaRegistryApiClientProviderTest.php index 61f0c82..265fc8d 100644 --- a/tests/KafkaSchemaRegistryApiClientProviderTest.php +++ b/tests/KafkaSchemaRegistryApiClientProviderTest.php @@ -7,6 +7,7 @@ use Jobcloud\Kafka\SchemaRegistryClient\KafkaSchemaRegistryApiClientInterface; use Jobcloud\Kafka\SchemaRegistryClient\ServiceProvider\KafkaSchemaRegistryApiClientProvider; use LogicException; +use phpmock\phpunit\PHPMock; use PHPUnit\Framework\TestCase; use Pimple\Container; use Psr\Http\Message\RequestFactoryInterface; @@ -16,10 +17,17 @@ */ class KafkaSchemaRegistryApiClientProviderTest extends TestCase { + use PHPMock; use ReflectionAccessTrait; public function testDefaultContainersAndServicesSetWithMinimalConfig(): void { + $classExists = $this->getFunctionMock('Jobcloud\Kafka\SchemaRegistryClient\ServiceProvider', 'class_exists'); + $classExists->expects(self::exactly(2))->withConsecutive( + ['Nyholm\Psr7\Factory\Psr17Factory'], + ['Buzz\Client\Curl'] + )->willReturn(true); + $container = new Container(); self::assertArrayNotHasKey('kafka.schema.registry', $container); From dc90a86f0dd64b1b62a6a1d3fb89492af81a419e Mon Sep 17 00:00:00 2001 From: TiMESPLiNTER Date: Thu, 12 Aug 2021 17:20:46 +0200 Subject: [PATCH 4/4] chore(): Fix infection testing problems --- phpunit.xml | 14 +++++++- ...fkaSchemaRegistryApiClientProviderTest.php | 33 +++++++++++++++++-- 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/phpunit.xml b/phpunit.xml index 478d6bf..3dfbd31 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,5 +1,17 @@ - + src diff --git a/tests/KafkaSchemaRegistryApiClientProviderTest.php b/tests/KafkaSchemaRegistryApiClientProviderTest.php index 265fc8d..32067ab 100644 --- a/tests/KafkaSchemaRegistryApiClientProviderTest.php +++ b/tests/KafkaSchemaRegistryApiClientProviderTest.php @@ -7,7 +7,9 @@ use Jobcloud\Kafka\SchemaRegistryClient\KafkaSchemaRegistryApiClientInterface; use Jobcloud\Kafka\SchemaRegistryClient\ServiceProvider\KafkaSchemaRegistryApiClientProvider; use LogicException; +use phpmock\phpunit\MockObjectProxy; use phpmock\phpunit\PHPMock; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Pimple\Container; use Psr\Http\Message\RequestFactoryInterface; @@ -20,10 +22,25 @@ class KafkaSchemaRegistryApiClientProviderTest extends TestCase use PHPMock; use ReflectionAccessTrait; + /** + * @var MockObject|MockObjectProxy + */ + private $classExistsMock; + + protected function setUp(): void + { + parent::setUp(); // TODO: Change the autogenerated stub + + $this->classExistsMock = $this->getFunctionMock( + 'Jobcloud\Kafka\SchemaRegistryClient\ServiceProvider', + 'class_exists' + ); + } + + public function testDefaultContainersAndServicesSetWithMinimalConfig(): void { - $classExists = $this->getFunctionMock('Jobcloud\Kafka\SchemaRegistryClient\ServiceProvider', 'class_exists'); - $classExists->expects(self::exactly(2))->withConsecutive( + $this->classExistsMock->expects(self::exactly(2))->withConsecutive( ['Nyholm\Psr7\Factory\Psr17Factory'], ['Buzz\Client\Curl'] )->willReturn(true); @@ -70,6 +87,11 @@ public function testDefaultContainersAndServicesSetWithMinimalConfig(): void public function testSuccessWithMissingAuth(): void { + $this->classExistsMock->expects(self::exactly(2))->withConsecutive( + ['Nyholm\Psr7\Factory\Psr17Factory'], + ['Buzz\Client\Curl'] + )->willReturn(true); + $container = new Container(); $container['kafka.schema.registry'] = [ @@ -91,6 +113,8 @@ public function testSuccessWithMissingAuth(): void public function testFailOnMissingBaseUrlInContainer(): void { + $this->classExistsMock->expects(self::never()); + $container = new Container(); $container['kafka.schema.registry'] = [ @@ -106,6 +130,11 @@ public function testFailOnMissingBaseUrlInContainer(): void public function testUserNameAndPasswordFromSettingsArePassedToHttpClient(): void { + $this->classExistsMock->expects(self::exactly(2))->withConsecutive( + ['Nyholm\Psr7\Factory\Psr17Factory'], + ['Buzz\Client\Curl'] + )->willReturn(true); + $container = new Container(); $container['kafka.schema.registry'] = [