Skip to content

Commit

Permalink
chore(): Remove cache dependency and move others to dev dependencies (#…
Browse files Browse the repository at this point in the history
…11)

* chore(): Remove cache dependency and move others to dev dependencies

* chore(): Remove unused use statement

* chore(): Improve mutant kill rate

* chore(): Fix infection testing problems
  • Loading branch information
TiMESPLiNTER committed Oct 22, 2021
1 parent 762bb73 commit 0bd1f3c
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 20 deletions.
23 changes: 12 additions & 11 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,24 @@
"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",
"infection/infection": "^0.21",
"kriswallsmith/buzz": "^1.0",
"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",
"infection/infection": "^0.21"
"squizlabs/php_codesniffer": "^3.4.2"
},
"config": {
"sort-packages": true
}
}
14 changes: 13 additions & 1 deletion phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" backupStaticAttributes="false" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" bootstrap="vendor/autoload.php" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
bootstrap="vendor/autoload.php"
executionOrder="random"
resolveDependencies="true">
<coverage>
<include>
<directory>src</directory>
Expand Down
20 changes: 12 additions & 8 deletions src/ServiceProvider/KafkaSchemaRegistryApiClientProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@

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;
Expand Down Expand Up @@ -35,26 +38,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];

Expand All @@ -73,7 +76,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];

Expand All @@ -84,7 +89,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(
Expand Down
37 changes: 37 additions & 0 deletions tests/KafkaSchemaRegistryApiClientProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +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;
Expand All @@ -16,10 +19,32 @@
*/
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
{
$this->classExistsMock->expects(self::exactly(2))->withConsecutive(
['Nyholm\Psr7\Factory\Psr17Factory'],
['Buzz\Client\Curl']
)->willReturn(true);

$container = new Container();

self::assertArrayNotHasKey('kafka.schema.registry', $container);
Expand Down Expand Up @@ -62,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'] = [
Expand All @@ -83,6 +113,8 @@ public function testSuccessWithMissingAuth(): void

public function testFailOnMissingBaseUrlInContainer(): void
{
$this->classExistsMock->expects(self::never());

$container = new Container();

$container['kafka.schema.registry'] = [
Expand All @@ -98,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'] = [
Expand Down

0 comments on commit 0bd1f3c

Please sign in to comment.