Skip to content

Commit

Permalink
nette 3 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
matej21 committed Apr 8, 2019
1 parent 7fa751d commit 2da53a2
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 20 deletions.
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
17 changes: 9 additions & 8 deletions src/Bridges/Infrastructure/PresenterTesterExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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),
]);
}


Expand All @@ -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);
}
}
13 changes: 9 additions & 4 deletions src/PresenterAssert.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Mangoweb\Tester\PresenterTester;

use Nette\Application\Request;
use Nette\Application\UI;
use Nette\StaticClass;
use Tester\Assert;

Expand All @@ -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;
Expand Down
9 changes: 5 additions & 4 deletions src/PresenterTester.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 */
Expand Down
3 changes: 3 additions & 0 deletions tests/inc/presenters/ExamplePresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ public function actionError()
}


/**
* @crossOrigin
*/
public function handleSignal(string $value)
{
$this->sendResponse(new TextResponse('signal processed with ' . $value));
Expand Down

0 comments on commit 2da53a2

Please sign in to comment.