Skip to content
This repository was archived by the owner on Nov 23, 2019. It is now read-only.

Commit e8a9424

Browse files
authored
Merge pull request #13 from acelaya/develop
Develop
2 parents be309f9 + 99deb38 commit e8a9424

15 files changed

+119
-39
lines changed

.gitattributes

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/.gitattributes export-ignore
2+
/.gitignore export-ignore
3+
/.phpstorm.meta.php export-ignore
4+
/.scrutinizer.yml export-ignore
5+
/.travis.yml export-ignore
6+
/phpcs.xml export-ignore
7+
/phpunit.xml.dist export-ignore
8+
/composer.lock export-ignore
9+
/infection.json export-ignore
10+
/CHANGELOG.md export-ignore
11+
/test export-ignore

.travis.yml

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,37 @@ language: php
22

33
branches:
44
only:
5-
- master
6-
- develop
5+
- /.*/
76

8-
php:
9-
- 7.1
10-
- 7.2
7+
matrix:
8+
include:
9+
- php: 7.1
10+
env:
11+
- DEPS=lowest
12+
- php: 7.1
13+
env:
14+
- DEPS=latest
15+
- php: 7.2
16+
env:
17+
- DEPS=lowest
18+
- php: 7.2
19+
env:
20+
- DEPS=latest
1121

1222
before_script:
1323
- composer self-update
1424
- composer install --no-interaction
25+
- if [[ $DEPS == 'latest' ]]; then composer update --no-interaction ; fi
26+
- if [[ $DEPS == 'lowest' ]]; then composer update --no-interaction --prefer-lowest --prefer-stable ; fi
27+
- composer show
1528

1629
script:
1730
- mkdir build
18-
- composer check
31+
- if [[ $DEPS == 'latest' ]]; then composer ac:ci ; fi
32+
- if [[ $DEPS == 'lowest' ]]; then composer ac:test ; fi
1933

2034
after_script:
21-
- wget https://scrutinizer-ci.com/ocular.phar
22-
- php ocular.phar code-coverage:upload --format=php-clover build/clover.xml
35+
- if [[ $DEPS == 'latest' ]]; then wget https://scrutinizer-ci.com/ocular.phar ; fi
36+
- if [[ $DEPS == 'latest' ]]; then php ocular.phar code-coverage:upload --format=php-clover build/clover.xml ; fi
2337

2438
sudo: false

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
## CHANGELOG
22

3+
### 2.2.0
4+
5+
**Enhancements:**
6+
7+
* [9: Add compatibility with expressive 3](https://github.com/acelaya/ze-content-based-error-handler/issues/9)
8+
9+
**Tasks:**
10+
11+
* [10: Add infection to the CI pipeline](https://github.com/acelaya/ze-content-based-error-handler/issues/10)
12+
* [11: Improve build matrix so that it passes build for lowest and latest supported dependencies](https://github.com/acelaya/ze-content-based-error-handler/issues/11)
13+
314
### 2.1.1
415

516
**Enhancements:**

composer.json

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@
1212
"require": {
1313
"php": "^7.1",
1414
"psr/log": "^1.0",
15-
"zendframework/zend-expressive": "^2.1",
15+
"zendframework/zend-expressive": "^3.0 || ^2.1",
1616
"zendframework/zend-servicemanager": "^3.0"
1717
},
1818
"require-dev": {
19+
"infection/infection": "^0.8.1",
1920
"phpstan/phpstan": "^0.9.1",
20-
"phpunit/phpunit": "^6.0",
21+
"phpunit/phpunit": "^7.0",
2122
"slevomat/coding-standard": "^4.1",
2223
"squizlabs/php_codesniffer": "^3.1"
2324
},
@@ -39,16 +40,20 @@
3940
}
4041
},
4142
"scripts": {
42-
"check": [
43-
"@cs",
44-
"@stan",
45-
"@test"
43+
"ac:ci": [
44+
"@ac:cs",
45+
"@ac:stan",
46+
"@ac:test",
47+
"@ac:infection"
4648
],
47-
"cs": "phpcs",
48-
"cs-fix": "phpcbf",
49-
"stan": "phpstan analyse src/ --level=6",
50-
"test": "phpunit --coverage-clover build/clover.xml --colors=always",
51-
"pretty-test": "phpunit --coverage-html build/coverage"
49+
50+
"ac:cs": "phpcs",
51+
"ac:cs-fix": "phpcbf",
52+
"ac:stan": "phpstan analyse src/ --level=6",
53+
"ac:test": "phpunit --coverage-clover build/clover.xml --colors=always",
54+
"ac:pretty-test": "phpunit --coverage-html build/coverage",
55+
"ac:infection": "infection --threads=4 --min-msi=90 --log-verbosity=2 --only-covered",
56+
"ac:infection-show": "infection --threads=4 --min-msi=90 --log-verbosity=2 --only-covered --show-mutations"
5257
},
5358
"extra": {
5459
"zf": {

infection.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"source": {
3+
"directories": [
4+
"src"
5+
]
6+
},
7+
"timeout": 10,
8+
"logs": {
9+
"text": "build/infection/infection-log.txt",
10+
"summary": "build/infection/summary-log.txt",
11+
"debug": "build/infection/debug-log.txt"
12+
},
13+
"phpUnit": {
14+
"configDir": "."
15+
}
16+
}

src/ConfigProvider.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@
1616

1717
class ConfigProvider
1818
{
19-
public function __invoke()
19+
public function __invoke(): array
2020
{
2121
return [
2222
'dependencies' => $this->createDependenciesConfig(),
2323
'error_handler' => $this->createErrorHandlerConfig(),
2424
];
2525
}
2626

27-
private function createDependenciesConfig()
27+
private function createDependenciesConfig(): array
2828
{
2929
return [
3030
'factories' => [
@@ -39,7 +39,7 @@ private function createDependenciesConfig()
3939
];
4040
}
4141

42-
private function createErrorHandlerConfig()
42+
private function createErrorHandlerConfig(): array
4343
{
4444
return [
4545
'default_content_type' => 'text/html',

src/ErrorHandler/ContentBasedErrorResponseGenerator.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,12 @@ public function __invoke(?\Throwable $e, Request $request, Response $response):
7373
* @return callable
7474
* @throws InvalidArgumentException
7575
*/
76-
protected function resolveErrorHandlerFromAcceptHeader(Request $request): callable
76+
private function resolveErrorHandlerFromAcceptHeader(Request $request): callable
7777
{
7878
// Try to find an error handler for one of the accepted content types
7979
$accepts = $request->hasHeader('Accept') ? $request->getHeaderLine('Accept') : $this->defaultContentType;
8080
/** @var array $accepts */
81-
$accepts = explode(',', $accepts);
81+
$accepts = \explode(',', $accepts);
8282
foreach ($accepts as $accept) {
8383
if (! $this->errorHandlerManager->has($accept)) {
8484
continue;
@@ -93,10 +93,10 @@ protected function resolveErrorHandlerFromAcceptHeader(Request $request): callab
9393
}
9494

9595
// It wasn't possible to find an error handler
96-
throw new InvalidArgumentException(sprintf(
96+
throw new InvalidArgumentException(\sprintf(
9797
'It wasn\'t possible to find an error handler for ["%s"] content types. '
9898
. 'Make sure you have registered at least the default "%s" content type',
99-
implode('", "', $accepts),
99+
\implode('", "', $accepts),
100100
$this->defaultContentType
101101
));
102102
}

src/ErrorHandler/ErrorResponseGeneratorManager.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,20 @@
88

99
class ErrorResponseGeneratorManager extends AbstractPluginManager implements ErrorResponseGeneratorManagerInterface
1010
{
11+
/**
12+
* @param mixed $instance
13+
* @throws InvalidServiceException
14+
*/
1115
public function validate($instance)
1216
{
13-
if (is_callable($instance)) {
17+
if (\is_callable($instance)) {
1418
return;
1519
}
1620

17-
throw new InvalidServiceException(sprintf(
18-
'Only callables are valid plugins for "%s". "%s" provided',
21+
throw new InvalidServiceException(\sprintf(
22+
'Only callables are valid plugins for "%s", but "%s" was provided',
1923
__CLASS__,
20-
is_object($instance) ? get_class($instance) : gettype($instance)
24+
\is_object($instance) ? \get_class($instance) : \gettype($instance)
2125
));
2226
}
2327
}

src/ErrorHandler/Factory/ContentBasedErrorResponseGeneratorFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class ContentBasedErrorResponseGeneratorFactory
2828
public function __invoke(ContainerInterface $container)
2929
{
3030
$config = $container->has('config') ? $container->get('config') : [];
31-
$ehConfig = isset($config['error_handler']) ? $config['error_handler'] : [];
31+
$ehConfig = $config['error_handler'] ?? [];
3232

3333
$errorHandlerManager = $container->get(ErrorResponseGeneratorManager::class);
3434
$logger = $container->has(LoggerInterface::class) ? $container->get(LoggerInterface::class) : new NullLogger();
@@ -38,7 +38,7 @@ public function __invoke(ContainerInterface $container)
3838
$errorHandlerManager,
3939
$logger,
4040
$logMessageBuilder,
41-
isset($ehConfig['default_content_type']) ? $ehConfig['default_content_type'] : 'text/html'
41+
$ehConfig['default_content_type'] ?? 'text/html'
4242
);
4343
}
4444
}

src/ErrorHandler/Factory/ErrorHandlerManagerFactory.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ class ErrorHandlerManagerFactory
2424
public function __invoke(ContainerInterface $container)
2525
{
2626
$config = $container->has('config') ? $container->get('config') : [];
27-
$errorHandlerConfig = isset($config['error_handler']) ? $config['error_handler'] : [];
28-
$plugins = isset($errorHandlerConfig['plugins']) ? $errorHandlerConfig['plugins'] : [];
27+
$plugins = $config['error_handler']['plugins'] ?? [];
2928
return new ErrorResponseGeneratorManager($container, $plugins);
3029
}
3130
}

src/Exception/InvalidArgumentException.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,4 @@
55

66
class InvalidArgumentException extends \InvalidArgumentException implements ExceptionInterface
77
{
8-
98
}

src/Log/BasicLogMessageBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@ public function buildMessage(Request $request, Response $response, \Throwable $e
2323
return $base;
2424
}
2525

26-
return $base . ': ' . PHP_EOL . $err;
26+
return \sprintf('%s:%s%s', $base, PHP_EOL, $err);
2727
}
2828
}

test/ConfigProviderTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public function setUp()
2424
public function configIsCorrect()
2525
{
2626
$config = $this->configProvider->__invoke();
27+
$this->assertCount(2, $config);
2728
$this->assertArrayHasKey('dependencies', $config);
2829
$this->assertArrayHasKey('error_handler', $config);
2930
}

test/ErrorHandler/Factory/PlainTextResponseGeneratorFactoryTest.php

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,30 @@ public function setUp()
2222

2323
/**
2424
* @test
25+
* @dataProvider provideDebugs
26+
* @param array $config
27+
* @param bool $expectedIsDev
2528
*/
26-
public function serviceIsCreated()
29+
public function serviceIsCreated(array $config, bool $expectedIsDev)
2730
{
28-
$instance = $this->factory->__invoke(new ServiceManager([]));
31+
$instance = $this->factory->__invoke(new ServiceManager(['services' => [
32+
'config' => $config,
33+
]]));
34+
35+
$ref = new \ReflectionObject($instance);
36+
$isDev = $ref->getProperty('isDevelopmentMode');
37+
$isDev->setAccessible(true);
38+
2939
$this->assertInstanceOf(ErrorResponseGenerator::class, $instance);
40+
$this->assertEquals($expectedIsDev, $isDev->getValue($instance));
41+
}
42+
43+
public function provideDebugs(): array
44+
{
45+
return [
46+
[[], false],
47+
[['debug' => true], true],
48+
[['debug' => false], false],
49+
];
3050
}
3151
}

test/Log/BasicLogMessageBuilderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,6 @@ public function errorIsIncludedWhenProvided()
3636
{
3737
$err = new \Exception('A super critical error');
3838
$message = $this->messageBuilder->buildMessage(ServerRequestFactory::fromGlobals(), new Response(), $err);
39-
$this->assertEquals('Error occurred while dispatching request: ' . PHP_EOL . $err, $message);
39+
$this->assertEquals('Error occurred while dispatching request:' . PHP_EOL . $err, $message);
4040
}
4141
}

0 commit comments

Comments
 (0)