Skip to content

Commit f503641

Browse files
committed
tests: improved tests
1 parent dafa250 commit f503641

11 files changed

+101
-151
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"nette/security": "^3.0",
3434
"latte/latte": "^2.10.2 || ^3.0.12",
3535
"tracy/tracy": "^2.6",
36-
"mockery/mockery": "^1.0",
36+
"mockery/mockery": "^1.0 || ^2.0",
3737
"phpstan/phpstan-nette": "^0.12",
3838
"jetbrains/phpstorm-attributes": "dev-master"
3939
},

tests/Bridges.Latte3/TemplateFactory.nonce.control.phpt renamed to tests/Bridges.Latte3/UIExtension.nonce.control.phpt

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
<?php
22

33
/**
4-
* Test: TemplateFactory nonce
4+
* Test: UIExtension nonce
55
* @phpVersion 8.0
66
*/
77

88
declare(strict_types=1);
99

1010
use Nette\Application\UI;
11-
use Nette\Bridges\ApplicationLatte;
1211
use Tester\Assert;
1312

1413
require __DIR__ . '/../bootstrap.php';
@@ -17,22 +16,16 @@ if (version_compare(Latte\Engine::VERSION, '3', '<')) {
1716
Tester\Environment::skip('Test for Latte 3');
1817
}
1918

20-
$latte = new Latte\Engine;
21-
22-
$latteFactory = Mockery::mock(ApplicationLatte\LatteFactory::class);
23-
$latteFactory->shouldReceive('create')->andReturn($latte);
24-
2519
$response = Mockery::mock(Nette\Http\IResponse::class);
2620
$response->shouldReceive('getHeader')->with('Content-Security-Policy')->andReturn("hello 'nonce-abcd123==' world");
2721

2822
$control = Mockery::mock(UI\Control::class);
2923
$control->shouldReceive('getPresenterIfExists')->andReturn(null);
3024
$control->shouldIgnoreMissing();
3125

32-
$factory = new ApplicationLatte\TemplateFactory($latteFactory);
33-
$factory->createTemplate($control);
34-
26+
$latte = new Latte\Engine;
3527
$latte->setLoader(new Latte\Loaders\StringLoader);
28+
$latte->addExtension(new Nette\Bridges\ApplicationLatte\UIExtension($control));
3629

3730
Assert::match(
3831
'<script></script>',

tests/Bridges.Latte3/TemplateFactory.nonce.presenter.phpt renamed to tests/Bridges.Latte3/UIExtension.nonce.presenter.phpt

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
<?php
22

33
/**
4-
* Test: TemplateFactory nonce
4+
* Test: UIExtension nonce
55
* @phpVersion 8.0
66
*/
77

88
declare(strict_types=1);
99

1010
use Nette\Application\UI;
11-
use Nette\Bridges\ApplicationLatte;
1211
use Tester\Assert;
1312

1413
require __DIR__ . '/../bootstrap.php';
@@ -19,11 +18,6 @@ if (version_compare(Latte\Engine::VERSION, '3', '<')) {
1918

2019
Tester\Environment::bypassFinals();
2120

22-
$latte = new Latte\Engine;
23-
24-
$latteFactory = Mockery::mock(ApplicationLatte\LatteFactory::class);
25-
$latteFactory->shouldReceive('create')->andReturn($latte);
26-
2721
$response = Mockery::mock(Nette\Http\IResponse::class);
2822
$response->shouldReceive('getHeader')->with('Content-Security-Policy')->andReturn("hello 'nonce-abcd123==' world");
2923

@@ -32,10 +26,9 @@ $presenter->shouldReceive('getPresenterIfExists')->andReturn($presenter);
3226
$presenter->shouldReceive('getHttpResponse')->andReturn($response);
3327
$presenter->shouldIgnoreMissing();
3428

35-
$factory = new ApplicationLatte\TemplateFactory($latteFactory);
36-
$factory->createTemplate($presenter);
37-
29+
$latte = new Latte\Engine;
3830
$latte->setLoader(new Latte\Loaders\StringLoader);
31+
$latte->addExtension(new Nette\Bridges\ApplicationLatte\UIExtension($presenter));
3932

4033
Assert::match(
4134
'<script nonce="abcd123=="></script>',

tests/Bridges.Latte3/expected/isLinkCurrent.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
<a href="';
2727
echo LR\Filters::escapeHtmlAttr($this->global->uiControl->link('default')) /* line 9 */;
2828
echo '"';
29-
echo ($ʟ_tmp = array_filter([($this->global->fn->isLinkCurrent)('default') ? 'current' : null])) ? ' class="' . LR\Filters::escapeHtmlAttr(implode(" ", array_unique($ʟ_tmp))) . '"' : "" /* line 9 */;
29+
echo ($ʟ_tmp = array_filter([($this->global->fn->isLinkCurrent)(%a%'default') ? 'current' : null])) ? ' class="' . LR\Filters::escapeHtmlAttr(implode(" ", array_unique($ʟ_tmp))) . '"' : "" /* line 9 */;
3030
echo '>custom function</a>
3131
';
3232
%A%

tests/Bridges.Latte3/isLinkCurrent().phpt

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,14 @@ if (version_compare(Latte\Engine::VERSION, '3', '<')) {
1717

1818
Tester\Environment::bypassFinals();
1919

20-
$latte = new Latte\Engine;
21-
22-
$latteFactory = Mockery::mock(Nette\Bridges\ApplicationLatte\LatteFactory::class);
23-
$latteFactory->shouldReceive('create')->andReturn($latte);
24-
2520
$presenter = Mockery::mock(Nette\Application\UI\Presenter::class);
2621
$presenter->shouldReceive('getPresenterIfExists')->andReturn($presenter);
2722
$presenter->shouldReceive('getHttpResponse')->andReturn((Mockery::mock(Nette\Http\IResponse::class))->shouldIgnoreMissing());
2823
$presenter->shouldIgnoreMissing();
2924

30-
$factory = new Nette\Bridges\ApplicationLatte\TemplateFactory($latteFactory);
31-
$factory->createTemplate($presenter);
32-
25+
$latte = new Latte\Engine;
3326
$latte->setLoader(new Latte\Loaders\StringLoader);
27+
$latte->addExtension(new Nette\Bridges\ApplicationLatte\UIExtension($presenter));
3428

3529
Assert::matchFile(
3630
__DIR__ . '/expected/isLinkCurrent.php',

tests/Bridges.Latte3/{ifCurrent}.phpt

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,14 @@ Tester\Environment::bypassFinals();
1616

1717
$latte = new Latte\Engine;
1818

19-
$latteFactory = Mockery::mock(Nette\Bridges\ApplicationLatte\LatteFactory::class);
20-
$latteFactory->shouldReceive('create')->andReturn($latte);
21-
2219
$presenter = Mockery::mock(Nette\Application\UI\Presenter::class);
2320
$presenter->shouldReceive('getPresenterIfExists')->andReturn($presenter);
2421
$presenter->shouldReceive('getHttpResponse')->andReturn((Mockery::mock(Nette\Http\IResponse::class))->shouldIgnoreMissing());
2522
$presenter->shouldIgnoreMissing();
2623

27-
$factory = new Nette\Bridges\ApplicationLatte\TemplateFactory($latteFactory);
28-
$factory->createTemplate($presenter);
29-
24+
$latte = new Latte\Engine;
3025
$latte->setLoader(new Latte\Loaders\StringLoader);
26+
$latte->addExtension(new Nette\Bridges\ApplicationLatte\UIExtension($presenter));
3127

3228
Assert::matchFile(
3329
__DIR__ . '/expected/ifCurrent.php',

tests/UI/Component.redirect().phpt

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class TestPresenter extends Application\UI\Presenter
2626

2727
public function sendResponse(Application\Response $response): void
2828
{
29-
$this->response = $response;
29+
parent::sendResponse($this->response = $response);
3030
}
3131
}
3232

@@ -43,39 +43,54 @@ $presenter->injectPrimary(
4343

4444

4545
test('', function () use ($presenter) {
46-
$presenter->redirect('foo');
46+
try {
47+
$presenter->redirect('foo');
48+
} catch (Throwable $e) {
49+
}
4750
Assert::type(Nette\Application\Responses\RedirectResponse::class, $presenter->response);
4851
Assert::same(302, $presenter->response->getCode());
4952
Assert::same('http://localhost/?action=foo&presenter=test', $presenter->response->getUrl());
5053
});
5154

5255

5356
test('', function () use ($presenter) {
54-
$presenter->redirect('foo', ['arg' => 1]);
57+
try {
58+
$presenter->redirect('foo', ['arg' => 1]);
59+
} catch (Throwable $e) {
60+
}
5561
Assert::type(Nette\Application\Responses\RedirectResponse::class, $presenter->response);
5662
Assert::same(302, $presenter->response->getCode());
5763
Assert::same('http://localhost/?arg=1&action=foo&presenter=test', $presenter->response->getUrl());
5864
});
5965

6066

6167
test('', function () use ($presenter) {
62-
$presenter->redirect('foo', 2);
68+
try {
69+
$presenter->redirect('foo', 2);
70+
} catch (Throwable $e) {
71+
}
6372
Assert::type(Nette\Application\Responses\RedirectResponse::class, $presenter->response);
6473
Assert::same(302, $presenter->response->getCode());
6574
Assert::same('http://localhost/?val=2&action=foo&presenter=test', $presenter->response->getUrl());
6675
});
6776

6877

6978
test('', function () use ($presenter) {
70-
$presenter->redirectPermanent('foo', 2);
79+
try {
80+
$presenter->redirectPermanent('foo', 2);
81+
} catch (Throwable $e) {
82+
}
7183
Assert::type(Nette\Application\Responses\RedirectResponse::class, $presenter->response);
7284
Assert::same(301, $presenter->response->getCode());
7385
Assert::same('http://localhost/?val=2&action=foo&presenter=test', $presenter->response->getUrl());
7486
});
7587

7688

7789
test('', function () use ($presenter) {
78-
$presenter->redirectPermanent('foo', ['arg' => 1]);
90+
try {
91+
$presenter->redirectPermanent('foo', ['arg' => 1]);
92+
} catch (Throwable $e) {
93+
}
7994
Assert::type(Nette\Application\Responses\RedirectResponse::class, $presenter->response);
8095
Assert::same(301, $presenter->response->getCode());
8196
Assert::same('http://localhost/?arg=1&action=foo&presenter=test', $presenter->response->getUrl());

tests/UI/Presenter.getParameters.phpt renamed to tests/UI/ComponentReflection.getParameters().phpt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
<?php
22

3-
/**
4-
* Test: Nette\Application\UI\Presenter::getRequestParams
5-
*/
6-
73
declare(strict_types=1);
84

95
use Nette\Application\Attributes\Parameter;

0 commit comments

Comments
 (0)