diff --git a/composer.json b/composer.json
index eb6c93e17..f1e927258 100644
--- a/composer.json
+++ b/composer.json
@@ -33,7 +33,7 @@
"nette/security": "^3.0",
"latte/latte": "^2.10.2 || ^3.0.12",
"tracy/tracy": "^2.6",
- "mockery/mockery": "^1.0",
+ "mockery/mockery": "^1.0 || ^2.0",
"phpstan/phpstan-nette": "^0.12",
"jetbrains/phpstorm-attributes": "dev-master"
},
diff --git a/tests/Bridges.Latte3/TemplateFactory.nonce.control.phpt b/tests/Bridges.Latte3/UIExtension.nonce.control.phpt
similarity index 71%
rename from tests/Bridges.Latte3/TemplateFactory.nonce.control.phpt
rename to tests/Bridges.Latte3/UIExtension.nonce.control.phpt
index b0db91521..0f19e5835 100644
--- a/tests/Bridges.Latte3/TemplateFactory.nonce.control.phpt
+++ b/tests/Bridges.Latte3/UIExtension.nonce.control.phpt
@@ -1,14 +1,13 @@
shouldReceive('create')->andReturn($latte);
-
$response = Mockery::mock(Nette\Http\IResponse::class);
$response->shouldReceive('getHeader')->with('Content-Security-Policy')->andReturn("hello 'nonce-abcd123==' world");
@@ -29,10 +23,9 @@ $control = Mockery::mock(UI\Control::class);
$control->shouldReceive('getPresenterIfExists')->andReturn(null);
$control->shouldIgnoreMissing();
-$factory = new ApplicationLatte\TemplateFactory($latteFactory);
-$factory->createTemplate($control);
-
+$latte = new Latte\Engine;
$latte->setLoader(new Latte\Loaders\StringLoader);
+$latte->addExtension(new Nette\Bridges\ApplicationLatte\UIExtension($control));
Assert::match(
'',
diff --git a/tests/Bridges.Latte3/TemplateFactory.nonce.presenter.phpt b/tests/Bridges.Latte3/UIExtension.nonce.presenter.phpt
similarity index 74%
rename from tests/Bridges.Latte3/TemplateFactory.nonce.presenter.phpt
rename to tests/Bridges.Latte3/UIExtension.nonce.presenter.phpt
index 05abfedca..ca0dace3a 100644
--- a/tests/Bridges.Latte3/TemplateFactory.nonce.presenter.phpt
+++ b/tests/Bridges.Latte3/UIExtension.nonce.presenter.phpt
@@ -1,14 +1,13 @@
shouldReceive('create')->andReturn($latte);
-
$response = Mockery::mock(Nette\Http\IResponse::class);
$response->shouldReceive('getHeader')->with('Content-Security-Policy')->andReturn("hello 'nonce-abcd123==' world");
@@ -32,10 +26,9 @@ $presenter->shouldReceive('getPresenterIfExists')->andReturn($presenter);
$presenter->shouldReceive('getHttpResponse')->andReturn($response);
$presenter->shouldIgnoreMissing();
-$factory = new ApplicationLatte\TemplateFactory($latteFactory);
-$factory->createTemplate($presenter);
-
+$latte = new Latte\Engine;
$latte->setLoader(new Latte\Loaders\StringLoader);
+$latte->addExtension(new Nette\Bridges\ApplicationLatte\UIExtension($presenter));
Assert::match(
'',
diff --git a/tests/Bridges.Latte3/expected/isLinkCurrent.php b/tests/Bridges.Latte3/expected/isLinkCurrent.php
index 3871205c8..a86390a52 100644
--- a/tests/Bridges.Latte3/expected/isLinkCurrent.php
+++ b/tests/Bridges.Latte3/expected/isLinkCurrent.php
@@ -26,7 +26,7 @@
global->fn->isLinkCurrent)('default') ? 'current' : null])) ? ' class="' . LR\Filters::escapeHtmlAttr(implode(" ", array_unique($ʟ_tmp))) . '"' : "" /* line 9 */;
+ echo ($ʟ_tmp = array_filter([($this->global->fn->isLinkCurrent)(%a%'default') ? 'current' : null])) ? ' class="' . LR\Filters::escapeHtmlAttr(implode(" ", array_unique($ʟ_tmp))) . '"' : "" /* line 9 */;
echo '>custom function
';
%A%
diff --git a/tests/Bridges.Latte3/isLinkCurrent().phpt b/tests/Bridges.Latte3/isLinkCurrent().phpt
index bd101c6c1..fd567a251 100644
--- a/tests/Bridges.Latte3/isLinkCurrent().phpt
+++ b/tests/Bridges.Latte3/isLinkCurrent().phpt
@@ -17,20 +17,14 @@ if (version_compare(Latte\Engine::VERSION, '3', '<')) {
Tester\Environment::bypassFinals();
-$latte = new Latte\Engine;
-
-$latteFactory = Mockery::mock(Nette\Bridges\ApplicationLatte\LatteFactory::class);
-$latteFactory->shouldReceive('create')->andReturn($latte);
-
$presenter = Mockery::mock(Nette\Application\UI\Presenter::class);
$presenter->shouldReceive('getPresenterIfExists')->andReturn($presenter);
$presenter->shouldReceive('getHttpResponse')->andReturn((Mockery::mock(Nette\Http\IResponse::class))->shouldIgnoreMissing());
$presenter->shouldIgnoreMissing();
-$factory = new Nette\Bridges\ApplicationLatte\TemplateFactory($latteFactory);
-$factory->createTemplate($presenter);
-
+$latte = new Latte\Engine;
$latte->setLoader(new Latte\Loaders\StringLoader);
+$latte->addExtension(new Nette\Bridges\ApplicationLatte\UIExtension($presenter));
Assert::matchFile(
__DIR__ . '/expected/isLinkCurrent.php',
diff --git a/tests/Bridges.Latte3/{ifCurrent}.phpt b/tests/Bridges.Latte3/{ifCurrent}.phpt
index e2606d7fa..48fed1caa 100644
--- a/tests/Bridges.Latte3/{ifCurrent}.phpt
+++ b/tests/Bridges.Latte3/{ifCurrent}.phpt
@@ -16,18 +16,14 @@ Tester\Environment::bypassFinals();
$latte = new Latte\Engine;
-$latteFactory = Mockery::mock(Nette\Bridges\ApplicationLatte\LatteFactory::class);
-$latteFactory->shouldReceive('create')->andReturn($latte);
-
$presenter = Mockery::mock(Nette\Application\UI\Presenter::class);
$presenter->shouldReceive('getPresenterIfExists')->andReturn($presenter);
$presenter->shouldReceive('getHttpResponse')->andReturn((Mockery::mock(Nette\Http\IResponse::class))->shouldIgnoreMissing());
$presenter->shouldIgnoreMissing();
-$factory = new Nette\Bridges\ApplicationLatte\TemplateFactory($latteFactory);
-$factory->createTemplate($presenter);
-
+$latte = new Latte\Engine;
$latte->setLoader(new Latte\Loaders\StringLoader);
+$latte->addExtension(new Nette\Bridges\ApplicationLatte\UIExtension($presenter));
Assert::matchFile(
__DIR__ . '/expected/ifCurrent.php',
diff --git a/tests/UI/Component.redirect().phpt b/tests/UI/Component.redirect().phpt
index 2a749c432..46be12e32 100644
--- a/tests/UI/Component.redirect().phpt
+++ b/tests/UI/Component.redirect().phpt
@@ -26,7 +26,7 @@ class TestPresenter extends Application\UI\Presenter
public function sendResponse(Application\Response $response): void
{
- $this->response = $response;
+ parent::sendResponse($this->response = $response);
}
}
@@ -43,7 +43,10 @@ $presenter->injectPrimary(
test('', function () use ($presenter) {
- $presenter->redirect('foo');
+ try {
+ $presenter->redirect('foo');
+ } catch (Throwable $e) {
+ }
Assert::type(Nette\Application\Responses\RedirectResponse::class, $presenter->response);
Assert::same(302, $presenter->response->getCode());
Assert::same('http://localhost/?action=foo&presenter=test', $presenter->response->getUrl());
@@ -51,7 +54,10 @@ test('', function () use ($presenter) {
test('', function () use ($presenter) {
- $presenter->redirect('foo', ['arg' => 1]);
+ try {
+ $presenter->redirect('foo', ['arg' => 1]);
+ } catch (Throwable $e) {
+ }
Assert::type(Nette\Application\Responses\RedirectResponse::class, $presenter->response);
Assert::same(302, $presenter->response->getCode());
Assert::same('http://localhost/?arg=1&action=foo&presenter=test', $presenter->response->getUrl());
@@ -59,7 +65,10 @@ test('', function () use ($presenter) {
test('', function () use ($presenter) {
- $presenter->redirect('foo', 2);
+ try {
+ $presenter->redirect('foo', 2);
+ } catch (Throwable $e) {
+ }
Assert::type(Nette\Application\Responses\RedirectResponse::class, $presenter->response);
Assert::same(302, $presenter->response->getCode());
Assert::same('http://localhost/?val=2&action=foo&presenter=test', $presenter->response->getUrl());
@@ -67,7 +76,10 @@ test('', function () use ($presenter) {
test('', function () use ($presenter) {
- $presenter->redirectPermanent('foo', 2);
+ try {
+ $presenter->redirectPermanent('foo', 2);
+ } catch (Throwable $e) {
+ }
Assert::type(Nette\Application\Responses\RedirectResponse::class, $presenter->response);
Assert::same(301, $presenter->response->getCode());
Assert::same('http://localhost/?val=2&action=foo&presenter=test', $presenter->response->getUrl());
@@ -75,7 +87,10 @@ test('', function () use ($presenter) {
test('', function () use ($presenter) {
- $presenter->redirectPermanent('foo', ['arg' => 1]);
+ try {
+ $presenter->redirectPermanent('foo', ['arg' => 1]);
+ } catch (Throwable $e) {
+ }
Assert::type(Nette\Application\Responses\RedirectResponse::class, $presenter->response);
Assert::same(301, $presenter->response->getCode());
Assert::same('http://localhost/?arg=1&action=foo&presenter=test', $presenter->response->getUrl());
diff --git a/tests/UI/Presenter.getParameters.phpt b/tests/UI/ComponentReflection.getParameters().phpt
similarity index 96%
rename from tests/UI/Presenter.getParameters.phpt
rename to tests/UI/ComponentReflection.getParameters().phpt
index 7a600e5f5..8c95daae0 100644
--- a/tests/UI/Presenter.getParameters.phpt
+++ b/tests/UI/ComponentReflection.getParameters().phpt
@@ -1,9 +1,5 @@
testSection;
- }
-}
-
-class MockSessionSection extends Nette\Http\SessionSection
-{
- public $testedKeyExistence;
-
- public $storedKey;
-
- public $storedValue;
-
- public $testExpiration;
-
- public $testExpirationVariables;
-
-
- public function __construct()
- {
- }
-
-
- public function __isset(string $name): bool
- {
- $this->testedKeyExistence = $name;
- return false;
- }
-
-
- public function __set(string $name, $value): void
- {
- $this->storedKey = $name;
- $this->storedValue = $value;
- }
-
-
- public function setExpiration($expiraton, $variables = null)
- {
- $this->testExpiration = $expiraton;
- $this->testExpirationVariables = $variables;
- }
-
-
- public function offsetExists($name): bool
- {
- return $this->__isset($name);
- }
+test('ok', function () {
+ $testedKeyExistence = $storedKey = $storedValue = $testExpiration = $testExpirationVariables = null;
- public function offsetSet($name, $value): void
- {
- $this->__set($name, $value);
- }
+ $sessionSectionMock = Mockery::mock(Nette\Http\SessionSection::class);
+ $sessionSectionMock->shouldReceive('setExpiration')
+ ->andReturnUsing(function ($expiration, $variables = null) use (&$testExpiration, &$testExpirationVariables, $sessionSectionMock) {
+ $testExpiration = $expiration;
+ $testExpirationVariables = $variables;
+ return $sessionSectionMock;
+ });
+ $sessionSectionMock->shouldReceive('offsetExists')
+ ->andReturnUsing(function ($name) use (&$testedKeyExistence) {
+ $testedKeyExistence = $name;
+ return false;
+ });
- public function offsetGet($name)
- {
- }
-
-
- public function offsetUnset($name): void
- {
- }
-}
+ $sessionSectionMock->shouldReceive('offsetSet')
+ ->andReturnUsing(function ($name, $value) use (&$storedKey, &$storedValue) {
+ $storedKey = $name;
+ $storedValue = $value;
+ });
-class MockUser extends Security\User
-{
- public function __construct()
- {
- }
+ $sessionMock = Mockery::mock(Nette\Http\Session::class);
+ $sessionMock->shouldReceive('getSection')
+ ->andReturn($sessionSectionMock);
+ $userMock = Mockery::mock(Nette\Security\User::class);
+ $userMock->shouldReceive('getId')
+ ->andReturn('test_id');
- public function getId()
- {
- return 'test_id';
- }
-}
-test('', function () {
$presenter = new TestPresenter;
$presenter->injectPrimary(
null,
@@ -124,26 +62,52 @@ test('', function () {
new Application\Routers\SimpleRouter,
new Http\Request(new Http\UrlScript),
new Http\Response,
- $session = new MockSession,
- $user = new MockUser
+ $sessionMock,
+ $userMock
);
- $section = $session->testSection = new MockSessionSection($session);
-
$applicationRequest = new Application\Request('', '', []);
$presenter->run($applicationRequest);
$expiration = '+1 year';
$key = $presenter->storeRequest($expiration);
- Assert::same($expiration, $section->testExpiration);
- Assert::same($key, $section->testExpirationVariables);
- Assert::same($key, $section->testedKeyExistence);
- Assert::same($key, $section->storedKey);
- Assert::same([$user->getId(), $applicationRequest], $section->storedValue);
+ Assert::same($expiration, $testExpiration);
+ Assert::same($key, $testExpirationVariables);
+ Assert::same($key, $testedKeyExistence);
+ Assert::same($key, $storedKey);
+ Assert::same([$userMock->getId(), $applicationRequest], $storedValue);
});
-test('', function () {
+
+test('no user', function () {
+ $testedKeyExistence = $storedKey = $storedValue = $testExpiration = $testExpirationVariables = null;
+
+ $sessionSectionMock = Mockery::mock(Nette\Http\SessionSection::class);
+ $sessionSectionMock->shouldReceive('setExpiration')
+ ->andReturnUsing(function ($expiration, $variables = null) use (&$testExpiration, &$testExpirationVariables, $sessionSectionMock) {
+ $testExpiration = $expiration;
+ $testExpirationVariables = $variables;
+ return $sessionSectionMock;
+ });
+
+ $sessionSectionMock->shouldReceive('offsetExists')
+ ->andReturnUsing(function ($name) use (&$testedKeyExistence) {
+ $testedKeyExistence = $name;
+ return false;
+ });
+
+ $sessionSectionMock->shouldReceive('offsetSet')
+ ->andReturnUsing(function ($name, $value) use (&$storedKey, &$storedValue) {
+ $storedKey = $name;
+ $storedValue = $value;
+ });
+
+ $sessionMock = Mockery::mock(Nette\Http\Session::class);
+ $sessionMock->shouldReceive('getSection')
+ ->andReturn($sessionSectionMock);
+
+
$presenter = new TestPresenter;
$presenter->injectPrimary(
null,
@@ -151,20 +115,18 @@ test('', function () {
new Application\Routers\SimpleRouter,
new Http\Request(new Http\UrlScript),
new Http\Response,
- $session = new MockSession
+ $sessionMock
);
- $section = $session->testSection = new MockSessionSection($session);
-
$applicationRequest = new Application\Request('', '', []);
$presenter->run($applicationRequest);
$expiration = '+1 year';
$key = $presenter->storeRequest($expiration);
- Assert::same($expiration, $section->testExpiration);
- Assert::same($key, $section->testExpirationVariables);
- Assert::same($key, $section->testedKeyExistence);
- Assert::same($key, $section->storedKey);
- Assert::same([null, $applicationRequest], $section->storedValue);
+ Assert::same($expiration, $testExpiration);
+ Assert::same($key, $testExpirationVariables);
+ Assert::same($key, $testedKeyExistence);
+ Assert::same($key, $storedKey);
+ Assert::same([null, $applicationRequest], $storedValue);
});
diff --git a/tests/bootstrap.php b/tests/bootstrap.php
index 91c483705..4861eb612 100644
--- a/tests/bootstrap.php
+++ b/tests/bootstrap.php
@@ -14,6 +14,7 @@
// configure environment
Tester\Environment::setup();
date_default_timezone_set('Europe/Prague');
+Mockery::setLoader(new Mockery\Loader\RequireLoader(getTempDir()));
// output buffer level check