Skip to content

Commit 951b977

Browse files
authored
Merge pull request #4 from Micro-PHP/v1.0.2-release
v1.0.2 - fix tests
2 parents c9b89a5 + b8ea298 commit 951b977

File tree

6 files changed

+21
-13
lines changed

6 files changed

+21
-13
lines changed

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
},
3535
"autoload-dev": {
3636
"psr-4": {
37-
"Micro\\Plugin\\Http\\Test\\": "tests/"
37+
"Micro\\Plugin\\Http\\Test\\Unit\\": "tests/Unit"
3838
}
3939
},
4040
"config": {
@@ -45,8 +45,8 @@
4545
},
4646
"scripts": {
4747
"coverage": "XDEBUG_MODE=coverage ./vendor/bin/phpunit --coverage-text",
48-
"php-cs-fix": "./vendor/bin/php-cs-fixer fix --verbose --using-cache=no",
49-
"php-cs-try": "./vendor/bin/php-cs-fixer fix --verbose --dry-run --using-cache=no",
48+
"php-cs-fix": "PHP_CS_FIXER_IGNORE_ENV=1 ./vendor/bin/php-cs-fixer fix --verbose --using-cache=no",
49+
"php-cs-try": "PHP_CS_FIXER_IGNORE_ENV=1 ./vendor/bin/php-cs-fixer fix --verbose --dry-run --using-cache=no",
5050
"phpstan": "./vendor/bin/phpstan analyze --no-progress",
5151
"phpunit": "./vendor/bin/phpunit",
5252
"psalm": "./vendor/bin/psalm --no-progress --show-info=true",

src/Business/Route/RouteBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public function build(): RouteInterface
116116
if (!$this->uri) {
117117
$this->uri = '';
118118

119-
$exceptions[] = 'Path can not be empty';
119+
$exceptions[] = 'Uri can not be empty.';
120120
}
121121

122122
if ($this->name && !preg_match('/^(.[aA-zZ_])/', $this->name)) {

src/Exception/RouteInvalidConfigurationException.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,12 @@ class RouteInvalidConfigurationException extends RouteConfigurationException
2828
*/
2929
public function __construct(string $routeName, array $messages, int $code = 0, ?\Throwable $previous = null)
3030
{
31-
$message = sprintf('Invalid route "%s" configuration.', $routeName);
31+
$message = <<<EOF
32+
Invalid route "%s" configuration:
33+
* %s
34+
EOF;
35+
36+
$message = sprintf($message, $routeName, implode("\r\n * ", $messages));
3237

3338
$this->messages = $messages;
3439
parent::__construct(

tests/Unit/Business/Route/RouteBuilderTest.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,12 @@ public function testBuild(
5656
$this->expectException($allowedException);
5757
}
5858

59-
$route = $builder->build();
59+
try {
60+
$route = $builder->build();
61+
} catch (RouteInvalidConfigurationException $configurationException) {
62+
$this->assertNotEmpty($configurationException->getMessages());
6063

61-
if ($allowedException) {
62-
return;
64+
throw $configurationException;
6365
}
6466

6567
$this->assertIsCallable($route->getController());
@@ -73,10 +75,11 @@ public function dataProvider()
7375
{
7476
return [
7577
['test', function () {}, '/{test}.{_format}', '/\/(.[aA-zZ0-9-_]+)\.(.[aA-zZ0-9-_]+)/', ['POST'], null],
78+
['test', function () {}, '/{test}-{date}.{_format}', '/\/(.[aA-zZ0-9-_]+)-(.[aA-zZ0-9-_]+)\.(.[aA-zZ0-9-_]+)/', ['POST'], null],
7679
[null, function () {}, '/{test}.{_format}', '/\/(.[aA-zZ0-9-_]+)\.(.[aA-zZ0-9-_]+)/', null, null],
7780
['test', null, '/{test}.{_format}', null, null, RouteInvalidConfigurationException::class],
7881
['test', function () {}, '/test', null, null, null],
79-
['test', function () {}, null, null, null, RouteInvalidConfigurationException::class],
82+
['test', null, null, null, null, RouteInvalidConfigurationException::class],
8083
];
8184
}
8285
}

tests/Unit/HttpCorePluginTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function testPlugin(string $parameter)
3030
$kernel = new AppKernel(
3131
$config,
3232
[
33-
TestPlugin::class,
33+
HttpTestPlugin::class,
3434
],
3535
'dev',
3636
);

tests/Unit/TestPlugin.php renamed to tests/Unit/HttpTestPlugin.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
/**
3030
* @author Stanislau Komar <[email protected]>
3131
*/
32-
class TestPlugin implements DependencyProviderInterface, HttpResponseTransformerPlugin, HttpRouteLocatorPluginInterface, PluginDependedInterface
32+
class HttpTestPlugin implements DependencyProviderInterface, HttpResponseTransformerPlugin, HttpRouteLocatorPluginInterface, PluginDependedInterface
3333
{
3434
private Container $container;
3535

@@ -77,7 +77,7 @@ public function test(Request $request)
7777
}
7878

7979
if ('bad_request' === $parameter) {
80-
throw new HttpBadRequestException($request);
80+
throw new HttpBadRequestException();
8181
}
8282

8383
return $parameter;
@@ -96,7 +96,7 @@ public function locate(): iterable
9696
->createRouteBuilder()
9797
->setUri('/{parameter}')
9898
->setName('test')
99-
->setController(TestPlugin::class)
99+
->setController(HttpTestPlugin::class)
100100
->build()
101101
;
102102
}

0 commit comments

Comments
 (0)