Skip to content

Commit

Permalink
Fix build against latest nette/application
Browse files Browse the repository at this point in the history
  • Loading branch information
xificurk committed Feb 2, 2024
1 parent 51b795e commit 418b9a6
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
6 changes: 6 additions & 0 deletions phpstan.tests.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,9 @@ parameters:
excludePaths:
- tests/temp/*
- tests/SecurityAnnotations/fixtures/*

ignoreErrors:
-
message: "#^Parameter .* of method Nette\\\\Application\\\\UI\\\\Presenter\\:\\:injectPrimary\\(\\) expects .*, .* given\\.$#"
count: 1
path: tests/SecurityAnnotations/SecurityAnnotationsTest.phpt
26 changes: 23 additions & 3 deletions tests/SecurityAnnotations/SecurityAnnotationsTest.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use Nepada\SecurityAnnotations;
use NepadaTests\SecurityAnnotations\Fixtures\SecuredPresenter;
use NepadaTests\TestCase;
use Nette;
use ReflectionMethod;
use Tester\Assert;

require_once __DIR__ . '/../bootstrap.php';
Expand All @@ -24,15 +25,34 @@ class SecurityAnnotationsTest extends TestCase
$requirementsChecker = Mockery::mock(SecurityAnnotations\RequirementsChecker::class);
$requirementsChecker->shouldReceive('protectElement')->times(3);

$presenter = new SecuredPresenter();
$presenter->injectPrimary(null, null, null, new Nette\Http\Request(new Nette\Http\UrlScript('http://example.com')), new Nette\Http\Response());
$presenter->injectRequirementsChecker($requirementsChecker);
$presenter = $this->createSecuredPresenter($requirementsChecker);
Assert::noError(function () use ($presenter): void {
$request = new Nette\Application\Request('SecuredPresenter', 'GET', ['action' => 'default']);
$presenter->run($request);
});
}

private function createSecuredPresenter(SecurityAnnotations\RequirementsChecker $requirementsChecker): SecuredPresenter
{
$presenter = new SecuredPresenter();

$primaryDependencies = [];
$rc = new ReflectionMethod($presenter, 'injectPrimary');
foreach ($rc->getParameters() as $parameter) {
if ($parameter->isDefaultValueAvailable()) {
continue;
}
$primaryDependencies[$parameter->getName()] = null;
}
$primaryDependencies['httpRequest'] = new Nette\Http\Request(new Nette\Http\UrlScript('http://example.com'));
$primaryDependencies['httpResponse'] = new Nette\Http\Response();

$presenter->injectPrimary(...$primaryDependencies);
$presenter->injectRequirementsChecker($requirementsChecker);

return $presenter;
}

}


Expand Down

0 comments on commit 418b9a6

Please sign in to comment.