diff --git a/composer.json b/composer.json index 4aadb43..5785042 100644 --- a/composer.json +++ b/composer.json @@ -3,13 +3,13 @@ "license": "MIT", "require": { "php": "~7.1", - "nette/application": "~2.4", - "nette/security": "~2.4", - "nette/forms": "~2.4", + "nette/application": "~3.0", + "nette/security": "~3.0", + "nette/forms": "~3.0", "nette/tester": "~2.0" }, "require-dev": { - "nextras/secured-links": "^1.4", + "nextras/secured-links": "@dev", "mangoweb/tester-infrastructure": "@dev", "phpstan/phpstan-shim": "^0.9.2", "mangoweb/tester-http-mocks": "@dev", diff --git a/src/Bridges/Infrastructure/PresenterTesterExtension.php b/src/Bridges/Infrastructure/PresenterTesterExtension.php index c337524..733bea2 100644 --- a/src/Bridges/Infrastructure/PresenterTesterExtension.php +++ b/src/Bridges/Infrastructure/PresenterTesterExtension.php @@ -9,7 +9,8 @@ use Nette\Application\IPresenterFactory; use Nette\Application\IRouter; use Nette\DI\CompilerExtension; -use Nette\DI\Statement; +use Nette\DI\Definitions\ServiceDefinition; +use Nette\DI\Definitions\Statement; use Nette\Http\IRequest; use Nette\Http\Session; use Nette\Security\User; @@ -50,12 +51,13 @@ public function beforeCompile() { $config = $this->validateConfig($this->defaults); $builder = $this->getContainerBuilder();; - $builder->getDefinition($this->prefix('presenterTester')) - ->setArguments([ - 'baseUrl' => $config['baseUrl'], - 'identityFactory' => $config['identityFactory'], - 'listeners' => $builder->findByType(IPresenterTesterListener::class), - ]); + $definition = $builder->getDefinition($this->prefix('presenterTester')); + assert($definition instanceof ServiceDefinition); + $definition->setArguments([ + 'baseUrl' => $config['baseUrl'], + 'identityFactory' => $config['identityFactory'], + 'listeners' => $builder->findByType(IPresenterTesterListener::class), + ]); } @@ -65,7 +67,6 @@ private function requireService(string $class) $name = preg_replace('#\W+#', '_', $class); $builder->addDefinition($this->prefix($name)) ->setClass($class) - ->setDynamic() ->addTag(MangoTesterExtension::TAG_REQUIRE); } } diff --git a/src/PresenterAssert.php b/src/PresenterAssert.php index 760ffc9..99ea58f 100644 --- a/src/PresenterAssert.php +++ b/src/PresenterAssert.php @@ -3,6 +3,7 @@ namespace Mangoweb\Tester\PresenterTester; use Nette\Application\Request; +use Nette\Application\UI; use Nette\StaticClass; use Tester\Assert; @@ -12,14 +13,18 @@ class PresenterAssert use StaticClass; - public static function assertRequestMatch(Request $expected, ?Request $actual, bool $onlyIntersectedParameters = true): void + public static function assertRequestMatch(Request $expected, ?array $actual, bool $onlyIntersectedParameters = true): void { Assert::notSame(null, $actual); assert($actual !== null); - Assert::same($expected->getPresenterName(), $actual->getPresenterName()); + + $presenter = $actual[UI\Presenter::PRESENTER_KEY] ?? null; + Assert::same($expected->getPresenterName(), $presenter); + unset($actual[UI\Presenter::PRESENTER_KEY]); + $expectedParameters = $expected->getParameters(); - $actualParameters = $actual->getParameters(); - foreach ($actualParameters as $key => $actualParameter) { + + foreach ($actual as $key => $actualParameter) { if (!isset($expectedParameters[$key])) { if ($onlyIntersectedParameters) { continue; diff --git a/src/PresenterTester.php b/src/PresenterTester.php index f92be96..805f304 100644 --- a/src/PresenterTester.php +++ b/src/PresenterTester.php @@ -81,8 +81,8 @@ public function execute(TestPresenterRequest $testRequest): TestPresenterResult $applicationRequest = $this->createApplicationRequest($testRequest); $presenter = $this->createPresenter($testRequest); if ($applicationRequest->getMethod() === 'GET') { - $matchedRequest = $this->router->match($this->httpRequest); - PresenterAssert::assertRequestMatch($applicationRequest, $matchedRequest); + $params = $this->router->match($this->httpRequest); + PresenterAssert::assertRequestMatch($applicationRequest, $params); } try { @@ -172,8 +172,9 @@ protected function loginUser(TestPresenterRequest $request): void protected function setupHttpRequest(TestPresenterRequest $request): void { $appRequest = $this->createApplicationRequest($request); - $refUrl = (new UrlScript($this->baseUrl))->setScriptPath('/'); - $url = (new UrlScript($this->router->constructUrl($appRequest, $refUrl)))->setScriptPath('/'); + $refUrl = new UrlScript($this->baseUrl, '/'); + + $url = new UrlScript($this->router->constructUrl($appRequest->toArray(), $refUrl), '/'); \Closure::bind(function () use ($request, $url) { /** @var Request $this */ diff --git a/tests/inc/presenters/ExamplePresenter.php b/tests/inc/presenters/ExamplePresenter.php index 61cb6f2..f639161 100644 --- a/tests/inc/presenters/ExamplePresenter.php +++ b/tests/inc/presenters/ExamplePresenter.php @@ -18,6 +18,9 @@ public function actionError() } + /** + * @crossOrigin + */ public function handleSignal(string $value) { $this->sendResponse(new TextResponse('signal processed with ' . $value));