Skip to content
This repository was archived by the owner on Jul 6, 2024. It is now read-only.

Commit 8c60e15

Browse files
committed
ApiHttpProvider => ApiHttpServiceProvider
1 parent 224fe77 commit 8c60e15

File tree

8 files changed

+131
-63
lines changed

8 files changed

+131
-63
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ A simple http handler implementation for API.
1414
## Requirements
1515

1616
* php: ^7.2
17-
* chubbyphp/chubbyphp-deserialization: ^2.14
18-
* chubbyphp/chubbyphp-negotiation: ^1.4
19-
* chubbyphp/chubbyphp-serialization: ^2.11
17+
* chubbyphp/chubbyphp-deserialization: ^2.15
18+
* chubbyphp/chubbyphp-negotiation: ^1.5
19+
* chubbyphp/chubbyphp-serialization: ^2.12
2020
* psr/http-factory: ^1.0.1
2121
* psr/http-message: ^1.0.1
2222
* psr/http-server-middleware: ^1.0.1
@@ -26,7 +26,7 @@ A simple http handler implementation for API.
2626
Through [Composer](http://getcomposer.org) as [chubbyphp/chubbyphp-api-http][1].
2727

2828
```sh
29-
composer require chubbyphp/chubbyphp-api-http "^3.2"
29+
composer require chubbyphp/chubbyphp-api-http "^3.3"
3030
```
3131

3232
## Usage
@@ -35,7 +35,7 @@ composer require chubbyphp/chubbyphp-api-http "^3.2"
3535
* [RequestManager][3]
3636
* [ResponseManager][4]
3737
* [AcceptAndContentTypeMiddleware][5]
38-
* [ApiHttpProvider][6]
38+
* [ApiHttpServiceProvider][6]
3939
* [ApiProblemMapping (example)][7]
4040

4141
## Copyright
@@ -47,5 +47,5 @@ Dominik Zogg 2019
4747
[3]: doc/Manager/RequestManager.md
4848
[4]: doc/Manager/ResponseManager.md
4949
[5]: doc/Middleware/AcceptAndContentTypeMiddleware.md
50-
[6]: doc/Provider/ApiHttpProvider.md
50+
[6]: doc/ServiceProvider/ApiHttpServiceProvider.md
5151
[7]: doc/Serialization/ApiProblemMapping.md

composer.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
],
1212
"require": {
1313
"php": "^7.2",
14-
"chubbyphp/chubbyphp-deserialization": "^2.14",
15-
"chubbyphp/chubbyphp-negotiation": "^1.4",
16-
"chubbyphp/chubbyphp-serialization": "^2.11",
14+
"chubbyphp/chubbyphp-deserialization": "^2.15",
15+
"chubbyphp/chubbyphp-negotiation": "^1.5",
16+
"chubbyphp/chubbyphp-serialization": "^2.12",
1717
"psr/http-factory": "^1.0.1",
1818
"psr/http-message": "^1.0.1",
1919
"psr/http-server-middleware": "^1.0.1"
@@ -42,7 +42,7 @@
4242
},
4343
"extra": {
4444
"branch-alias": {
45-
"dev-master": "3.2-dev"
45+
"dev-master": "3.3-dev"
4646
}
4747
},
4848
"scripts": {
@@ -59,7 +59,7 @@
5959
],
6060
"test:cs": "mkdir -p build && vendor/bin/php-cs-fixer fix --dry-run --stop-on-violation --cache-file=build/phpcs.cache",
6161
"test:infection": "vendor/bin/infection --threads=$(nproc) --min-msi=100 --verbose --coverage=build/phpunit",
62-
"test:insights": "mkdir -p build && bash -c 'vendor/bin/phpinsights analyse -v --no-interaction --min-quality=92 --disable-security-check | tee build/phpinsights.log; if [ ${PIPESTATUS[0]} -ne \"0\" ]; then exit 1; fi'",
62+
"test:insights": "mkdir -p build && bash -c 'vendor/bin/phpinsights analyse -v --no-interaction --min-quality=94 --disable-security-check | tee build/phpinsights.log; if [ ${PIPESTATUS[0]} -ne \"0\" ]; then exit 1; fi'",
6363
"test:integration": "vendor/bin/phpunit --testsuite=Integration --cache-result-file=build/phpunit/phpunit.result.cache",
6464
"test:lint": "mkdir -p build && find src tests -name '*.php' -print0 | xargs -0 -n1 -P$(nproc) php -l | tee build/phplint.log",
6565
"test:loc": "mkdir -p build && vendor/bin/phploc src --verbose | tee build/phploc.log",

doc/Provider/ApiHttpProvider.md

Lines changed: 0 additions & 22 deletions
This file was deleted.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# ApiHttpServiceProvider
2+
3+
```php
4+
<?php
5+
6+
use Chubbyphp\ApiHttp\ServiceProvider\ApiHttpServiceProvider;
7+
use Chubbyphp\Deserialization\ServiceProvider\DeserializationServiceProvider;
8+
use Chubbyphp\Serialization\ServiceProvider\SerializationServiceProvider;
9+
use Pimple\Container;
10+
11+
$container = new Container();
12+
$container->register(new DeserializationServiceProvider());
13+
$container->register(new SerializationServiceProvider());
14+
$container->register(new ApiHttpServiceProvider());
15+
16+
$container['api-http.request.manager']->getDataFromRequestQuery(...);
17+
18+
$container['api-http.response.manager']->create(...);
19+
20+
$container['api-http.response.factory']->createResponse(...);
21+
// must be defined, implement the ResponseFactoryInterface
22+
```

src/Provider/ApiHttpProvider.php

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,6 @@
22

33
declare(strict_types=1);
44

5-
namespace Chubbyphp\ApiHttp\Provider;
5+
use Chubbyphp\ApiHttp\ServiceProvider\ApiHttpServiceProvider;
66

7-
use Chubbyphp\ApiHttp\Manager\RequestManager;
8-
use Chubbyphp\ApiHttp\Manager\ResponseManager;
9-
use Pimple\Container;
10-
use Pimple\ServiceProviderInterface;
11-
12-
final class ApiHttpProvider implements ServiceProviderInterface
13-
{
14-
public function register(Container $container): void
15-
{
16-
$container['api-http.request.manager'] = static function () use ($container) {
17-
return new RequestManager($container['deserializer']);
18-
};
19-
20-
$container['api-http.response.manager'] = static function () use ($container) {
21-
return new ResponseManager(
22-
$container['deserializer'],
23-
$container['api-http.response.factory'],
24-
$container['serializer']
25-
);
26-
};
27-
28-
$container['api-http.response.factory'] = static function (): void {
29-
throw new \RuntimeException('Missing response factory, define service "api-http.response.factory"');
30-
};
31-
}
32-
}
7+
class_alias(ApiHttpServiceProvider::class, 'Chubbyphp\ApiHttp\Provider\ApiHttpProvider');
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Chubbyphp\ApiHttp\ServiceProvider;
6+
7+
use Chubbyphp\ApiHttp\Manager\RequestManager;
8+
use Chubbyphp\ApiHttp\Manager\ResponseManager;
9+
use Pimple\Container;
10+
use Pimple\ServiceProviderInterface;
11+
12+
final class ApiHttpServiceProvider implements ServiceProviderInterface
13+
{
14+
public function register(Container $container): void
15+
{
16+
$container['api-http.request.manager'] = static function () use ($container) {
17+
return new RequestManager($container['deserializer']);
18+
};
19+
20+
$container['api-http.response.manager'] = static function () use ($container) {
21+
return new ResponseManager(
22+
$container['deserializer'],
23+
$container['api-http.response.factory'],
24+
$container['serializer']
25+
);
26+
};
27+
28+
$container['api-http.response.factory'] = static function (): void {
29+
throw new \RuntimeException('Missing response factory, define service "api-http.response.factory"');
30+
};
31+
}
32+
}

tests/Unit/Provider/ApiHttpProviderTest.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,24 @@ final class ApiHttpProviderTest extends TestCase
2525

2626
public function testRegister(): void
2727
{
28+
/** @var ResponseFactoryInterface $responseFactory */
29+
$responseFactory = $this->getMockByCalls(ResponseFactoryInterface::class);
30+
2831
$container = new Container();
2932
$container->register(new ApiHttpProvider());
3033
$container->register(new DeserializationProvider());
3134
$container->register(new SerializationProvider());
3235

33-
$container['api-http.response.factory'] = function () {
34-
return $this->getMockByCalls(ResponseFactoryInterface::class);
36+
$container['api-http.response.factory'] = function () use ($responseFactory) {
37+
return $responseFactory;
3538
};
3639

3740
self::assertTrue(isset($container['api-http.response.manager']));
3841
self::assertTrue(isset($container['api-http.response.factory']));
3942

4043
self::assertInstanceOf(RequestManager::class, $container['api-http.request.manager']);
4144
self::assertInstanceOf(ResponseManager::class, $container['api-http.response.manager']);
42-
self::assertInstanceOf(ResponseFactoryInterface::class, $container['api-http.response.factory']);
45+
self::assertSame($responseFactory, $container['api-http.response.factory']);
4346
}
4447

4548
public function testFactoryExpectException(): void
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Chubbyphp\Tests\ApiHttp\Unit\ServiceProvider;
6+
7+
use Chubbyphp\ApiHttp\Manager\RequestManager;
8+
use Chubbyphp\ApiHttp\Manager\ResponseManager;
9+
use Chubbyphp\ApiHttp\ServiceProvider\ApiHttpServiceProvider;
10+
use Chubbyphp\Deserialization\ServiceProvider\DeserializationServiceProvider;
11+
use Chubbyphp\Mock\MockByCallsTrait;
12+
use Chubbyphp\Serialization\ServiceProvider\SerializationServiceProvider;
13+
use PHPUnit\Framework\TestCase;
14+
use Pimple\Container;
15+
use Psr\Http\Message\ResponseFactoryInterface;
16+
17+
/**
18+
* @covers \Chubbyphp\ApiHttp\ServiceProvider\ApiHttpServiceProvider
19+
*
20+
* @internal
21+
*/
22+
final class ApiHttpServiceProviderTest extends TestCase
23+
{
24+
use MockByCallsTrait;
25+
26+
public function testRegister(): void
27+
{
28+
/** @var ResponseFactoryInterface $responseFactory */
29+
$responseFactory = $this->getMockByCalls(ResponseFactoryInterface::class);
30+
31+
$container = new Container();
32+
$container->register(new ApiHttpServiceProvider());
33+
$container->register(new DeserializationServiceProvider());
34+
$container->register(new SerializationServiceProvider());
35+
36+
$container['api-http.response.factory'] = function () use ($responseFactory) {
37+
return $responseFactory;
38+
};
39+
40+
self::assertTrue(isset($container['api-http.response.manager']));
41+
self::assertTrue(isset($container['api-http.response.factory']));
42+
43+
self::assertInstanceOf(RequestManager::class, $container['api-http.request.manager']);
44+
self::assertInstanceOf(ResponseManager::class, $container['api-http.response.manager']);
45+
self::assertSame($responseFactory, $container['api-http.response.factory']);
46+
}
47+
48+
public function testFactoryExpectException(): void
49+
{
50+
self::expectException(\RuntimeException::class);
51+
self::expectExceptionMessage('Missing response factory, define service "api-http.response.factory"');
52+
53+
$container = new Container();
54+
$container->register(new ApiHttpServiceProvider());
55+
56+
$container['api-http.response.factory'];
57+
}
58+
}

0 commit comments

Comments
 (0)