Skip to content

Commit 0bd1f3c

Browse files
authored
chore(): Remove cache dependency and move others to dev dependencies (#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
1 parent 762bb73 commit 0bd1f3c

4 files changed

Lines changed: 74 additions & 20 deletions

File tree

composer.json

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,24 @@
1515
"homepage": "https://careers.jobcloud.ch/en/our-team/?term=133"
1616
}
1717
],
18-
"config": {
19-
"sort-packages": true
20-
},
2118
"require": {
2219
"php": ">=7.4",
2320
"ext-json": "*",
24-
"pimple/pimple": "^3.2",
25-
"symfony/cache": "^5.0",
26-
"nyholm/psr7": "^1.2",
27-
"kriswallsmith/buzz": "^1.0",
28-
"psr/http-message": "^1.0"
21+
"psr/http-message": "^1.0",
22+
"psr/http-client": "^1.0.1"
2923
},
3024
"require-dev": {
31-
"squizlabs/php_codesniffer": "^3.4.2",
32-
"phpunit/phpunit": "^9.5",
25+
"infection/infection": "^0.21",
26+
"kriswallsmith/buzz": "^1.0",
27+
"nyholm/psr7": "^1.2",
28+
"php-mock/php-mock-phpunit": "^2.6",
3329
"phpstan/phpstan": "^0.12",
30+
"phpunit/phpunit": "^9.5",
31+
"pimple/pimple": "^3.2",
3432
"rregeer/phpunit-coverage-check": "^0.3.1",
35-
"infection/infection": "^0.21"
33+
"squizlabs/php_codesniffer": "^3.4.2"
34+
},
35+
"config": {
36+
"sort-packages": true
3637
}
3738
}

phpunit.xml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<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">
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
4+
backupGlobals="false"
5+
backupStaticAttributes="false"
6+
colors="true"
7+
convertErrorsToExceptions="true"
8+
convertNoticesToExceptions="true"
9+
convertWarningsToExceptions="true"
10+
processIsolation="false"
11+
stopOnFailure="false"
12+
bootstrap="vendor/autoload.php"
13+
executionOrder="random"
14+
resolveDependencies="true">
315
<coverage>
416
<include>
517
<directory>src</directory>

src/ServiceProvider/KafkaSchemaRegistryApiClientProvider.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@
44

55
use Buzz\Client\Curl;
66
use Jobcloud\Kafka\SchemaRegistryClient\ErrorHandler;
7+
use Jobcloud\Kafka\SchemaRegistryClient\ErrorHandlerInterface;
78
use Jobcloud\Kafka\SchemaRegistryClient\HttpClient;
9+
use Jobcloud\Kafka\SchemaRegistryClient\HttpClientInterface;
810
use Jobcloud\Kafka\SchemaRegistryClient\KafkaSchemaRegistryApiClient;
11+
use Jobcloud\Kafka\SchemaRegistryClient\KafkaSchemaRegistryApiClientInterface;
912
use LogicException;
1013
use Nyholm\Psr7\Factory\Psr17Factory;
1114
use Pimple\Container;
@@ -35,26 +38,26 @@ public function register(Container $container): void
3538
{
3639
$this->checkRequiredOffsets($container);
3740

38-
if (false === isset($container[self::REQUEST_FACTORY])) {
39-
$container[self::REQUEST_FACTORY] = static function (Container $container) {
41+
if (false === isset($container[self::REQUEST_FACTORY]) && class_exists('Nyholm\Psr7\Factory\Psr17Factory')) {
42+
$container[self::REQUEST_FACTORY] = static function (): RequestFactoryInterface {
4043
return new Psr17Factory();
4144
};
4245
}
4346

44-
if (false === isset($container[self::CLIENT])) {
45-
$container[self::CLIENT] = static function (Container $container) {
47+
if (false === isset($container[self::CLIENT]) && class_exists('Buzz\Client\Curl')) {
48+
$container[self::CLIENT] = static function (Container $container): ClientInterface {
4649
return new Curl($container[self::REQUEST_FACTORY]);
4750
};
4851
}
4952

5053
if (false === isset($container[self::ERROR_HANDLER])) {
51-
$container[self::ERROR_HANDLER] = static function () {
54+
$container[self::ERROR_HANDLER] = static function (): ErrorHandlerInterface {
5255
return new ErrorHandler();
5356
};
5457
}
5558

5659
if (false === isset($container[self::HTTP_CLIENT])) {
57-
$container[self::HTTP_CLIENT] = static function (Container $container) {
60+
$container[self::HTTP_CLIENT] = static function (Container $container): HttpClientInterface {
5861
/** @var ClientInterface $client */
5962
$client = $container[self::CLIENT];
6063

@@ -73,7 +76,9 @@ public function register(Container $container): void
7376
}
7477

7578
if (false === isset($container[self::API_CLIENT])) {
76-
$container[self::API_CLIENT] = static function (Container $container) {
79+
$container[self::API_CLIENT] = static function (
80+
Container $container
81+
): KafkaSchemaRegistryApiClientInterface {
7782
/** @var HttpClient $client */
7883
$client = $container[self::HTTP_CLIENT];
7984

@@ -84,7 +89,6 @@ public function register(Container $container): void
8489

8590
private function checkRequiredOffsets(Container $container): void
8691
{
87-
8892
if (false === isset($container[self::CONTAINER_KEY][self::SETTING_KEY_BASE_URL])) {
8993
throw new LogicException(
9094
sprintf(

tests/KafkaSchemaRegistryApiClientProviderTest.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
use Jobcloud\Kafka\SchemaRegistryClient\KafkaSchemaRegistryApiClientInterface;
88
use Jobcloud\Kafka\SchemaRegistryClient\ServiceProvider\KafkaSchemaRegistryApiClientProvider;
99
use LogicException;
10+
use phpmock\phpunit\MockObjectProxy;
11+
use phpmock\phpunit\PHPMock;
12+
use PHPUnit\Framework\MockObject\MockObject;
1013
use PHPUnit\Framework\TestCase;
1114
use Pimple\Container;
1215
use Psr\Http\Message\RequestFactoryInterface;
@@ -16,10 +19,32 @@
1619
*/
1720
class KafkaSchemaRegistryApiClientProviderTest extends TestCase
1821
{
22+
use PHPMock;
1923
use ReflectionAccessTrait;
2024

25+
/**
26+
* @var MockObject|MockObjectProxy
27+
*/
28+
private $classExistsMock;
29+
30+
protected function setUp(): void
31+
{
32+
parent::setUp(); // TODO: Change the autogenerated stub
33+
34+
$this->classExistsMock = $this->getFunctionMock(
35+
'Jobcloud\Kafka\SchemaRegistryClient\ServiceProvider',
36+
'class_exists'
37+
);
38+
}
39+
40+
2141
public function testDefaultContainersAndServicesSetWithMinimalConfig(): void
2242
{
43+
$this->classExistsMock->expects(self::exactly(2))->withConsecutive(
44+
['Nyholm\Psr7\Factory\Psr17Factory'],
45+
['Buzz\Client\Curl']
46+
)->willReturn(true);
47+
2348
$container = new Container();
2449

2550
self::assertArrayNotHasKey('kafka.schema.registry', $container);
@@ -62,6 +87,11 @@ public function testDefaultContainersAndServicesSetWithMinimalConfig(): void
6287

6388
public function testSuccessWithMissingAuth(): void
6489
{
90+
$this->classExistsMock->expects(self::exactly(2))->withConsecutive(
91+
['Nyholm\Psr7\Factory\Psr17Factory'],
92+
['Buzz\Client\Curl']
93+
)->willReturn(true);
94+
6595
$container = new Container();
6696

6797
$container['kafka.schema.registry'] = [
@@ -83,6 +113,8 @@ public function testSuccessWithMissingAuth(): void
83113

84114
public function testFailOnMissingBaseUrlInContainer(): void
85115
{
116+
$this->classExistsMock->expects(self::never());
117+
86118
$container = new Container();
87119

88120
$container['kafka.schema.registry'] = [
@@ -98,6 +130,11 @@ public function testFailOnMissingBaseUrlInContainer(): void
98130

99131
public function testUserNameAndPasswordFromSettingsArePassedToHttpClient(): void
100132
{
133+
$this->classExistsMock->expects(self::exactly(2))->withConsecutive(
134+
['Nyholm\Psr7\Factory\Psr17Factory'],
135+
['Buzz\Client\Curl']
136+
)->willReturn(true);
137+
101138
$container = new Container();
102139

103140
$container['kafka.schema.registry'] = [

0 commit comments

Comments
 (0)