Skip to content

Commit

Permalink
nette 3
Browse files Browse the repository at this point in the history
  • Loading branch information
janatjak committed Oct 3, 2020
1 parent dd6d266 commit 540d957
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 28 deletions.
11 changes: 5 additions & 6 deletions .travis.yml
Expand Up @@ -6,9 +6,8 @@ cache:
- $HOME/.composer/cache

php:
- 7.1
- 7.2
- 7.3
- 7.4

install:
- composer install --no-interaction --prefer-dist
Expand All @@ -19,17 +18,17 @@ script:
jobs:
include:
- stage: Code Static Analyze (phpstan)
php: 7.3
php: 7.4
script:
- php vendor/bin/phpstan analyse ./src ./tests --level 7
- php vendor/bin/phpstan analyse ./src ./tests --level max

- stage: Code Standard Checker
php: 7.3
php: 7.4
script:
- php vendor/bin/phpcs --standard=PSR12 ./src ./tests

- stage: Code Coverage
php: 7.3
php: 7.4
script:
- php vendor/bin/tester tests -p phpdbg --coverage ./coverage.xml --coverage-src ./src
after_script:
Expand Down
11 changes: 5 additions & 6 deletions composer.json
Expand Up @@ -16,15 +16,14 @@
}
],
"require": {
"php": "~7.1",
"nette/di": "~2.4 || ~3.0",
"nette/application": "^2.4 || ~3.0"
"php": ">=7.3",
"nette/di": "~3.0",
"nette/application": "~3.0"
},
"require-dev": {
"kdyby/console": "^2.7",
"nette/bootstrap": "~2.4 || ~3.0",
"nette/bootstrap": "~3.0",
"nette/tester": "~2.0",
"phpstan/phpstan": "^0.11",
"phpstan/phpstan": "^0.12",
"squizlabs/php_codesniffer": "^3.0",
"tracy/tracy": "^2.4"
},
Expand Down
1 change: 1 addition & 0 deletions src/DI/IPrependRouteProvider.php
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace FreezyBee\PrependRoute\DI;
Expand Down
7 changes: 4 additions & 3 deletions src/DI/PrependRouteExtension.php
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace FreezyBee\PrependRoute\DI;
Expand Down Expand Up @@ -32,16 +33,16 @@ public function afterCompile(ClassType $classType): void

$method = $classType->getMethod('createServiceRouting__router');

$newBody = '$mainService = new Nette\Application\Routers\RouteList;' . "\n";
$newBody = '$mainService = new Nette\Application\Routers\RouteList();' . "\n";

foreach ($routeDefs as $routeDef) {
foreach ($routeDef as $route) {
$newBody .= "\$mainService[] = \$this->getService('$route');\n";
}
}

$oldBody = preg_replace('/return \$service;$/', 'return $mainService;', $method->getBody() ?? '');
$oldBody = str_replace('return ', '$mainService[] = ', $method->getBody() ?? '');

$method->setBody("$newBody\$mainService[] = $oldBody");
$method->setBody("$newBody $oldBody return \$mainService;");
}
}
17 changes: 6 additions & 11 deletions tests/Integration/PrependTest.phpt
Expand Up @@ -5,7 +5,6 @@ namespace FreezyBee\PrependRoute\Tests\Integration;

require __DIR__ . '/../bootstrap.php';

use Kdyby\Console\CliRouter;
use Nette\Application\IRouter;
use Nette\Configurator;
use Nette\Http\Request;
Expand All @@ -28,20 +27,16 @@ class PrependTest extends TestCase
$configurator->addConfig(__DIR__ . '/../config.neon');
$container = $configurator->createContainer();

/** @var CliRouter $cliRoute */
$cliRoute = $container->getService('console.router');
$cliRoute->allowedMethods = [];

/** @var IRouter $router */
$router = $container->getService('router');

$request = $router->match(new Request(new UrlScript('prepend-path')));
Assert::same('PrependTest', $request->getPresenterName());
Assert::same(['action' => 'someAction'], $request->getParameters());
$request = $router->match(new Request(new UrlScript('/prepend-path', '/prepend-path')));
Assert::same('PrependTest', $request['presenter']);
Assert::same('someAction', $request['action']);

$request = $router->match(new Request(new UrlScript('test')));
Assert::same('Test', $request->getPresenterName());
Assert::same(['action' => 'default'], $request->getParameters());
$request = $router->match(new Request(new UrlScript('/test', '/test')));
Assert::same('Test', $request['presenter']);
Assert::same('default', $request['action']);
}
}

Expand Down
4 changes: 3 additions & 1 deletion tests/Utils/RouterFactory.php
@@ -1,11 +1,13 @@
<?php

declare(strict_types=1);

namespace FreezyBee\PrependRoute\Tests\Utils;

use Nette\Application\IRouter;
use Nette\Application\Routers\Route;
use Nette\Application\Routers\RouteList;
use Nette\Routing\Router;
use Nette\StaticClass;

/**
Expand All @@ -18,7 +20,7 @@ class RouterFactory
/**
* @return IRouter
*/
public static function createRouter(): IRouter
public static function createRouter(): Router
{
$router = new RouteList();
$router[] = new Route('[<presenter>][/<action=default>]', 'Test:');
Expand Down
1 change: 1 addition & 0 deletions tests/Utils/TestExtension.php
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace FreezyBee\PrependRoute\Tests\Utils;
Expand Down
1 change: 1 addition & 0 deletions tests/bootstrap.php
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

use Tester\Environment;
Expand Down
1 change: 0 additions & 1 deletion tests/config.neon
@@ -1,5 +1,4 @@
extensions:
console: Kdyby\Console\DI\ConsoleExtension
prependRoute: FreezyBee\PrependRoute\DI\PrependRouteExtension
test: FreezyBee\PrependRoute\Tests\Utils\TestExtension

Expand Down

0 comments on commit 540d957

Please sign in to comment.