3
3
namespace Pd \AsyncControl \UI ;
4
4
5
5
use Mockery ;
6
- use Nette \Application \UI \ITemplate ;
7
- use Nette \Application \UI \ITemplateFactory ;
6
+
7
+ use Nette \Bridges \ApplicationLatte \TemplateFactory ;
8
+ use Nette \Bridges \ApplicationLatte \Template ;
8
9
use Nette \Application \UI \Presenter ;
9
10
use Tester \Assert ;
10
11
use Tester \TestCase ;
11
12
12
13
13
14
require_once __DIR__ . '/../../vendor/autoload.php ' ;
14
15
16
+ \Tester \Environment::bypassFinals ();
15
17
18
+ /**
19
+ * @testCase
20
+ */
16
21
final class AsyncControlTest extends TestCase
17
22
{
18
23
19
- const VALID_SIGNAL = 'control-form-submit ' ;
20
- const FRAGMENT_PARAMETER = '_escaped_fragment_ ' ;
21
-
22
24
23
- public function testHandleAjax ()
25
+ public function testHandleAjax (): void
24
26
{
25
27
$ presenter = Mockery::mock (Presenter::class);
26
28
$ presenter ->shouldReceive ('isAjax ' )->once ()->andReturn (TRUE );
27
- $ presenter ->shouldReceive ('getPayload ' )->andReturn ($ payload = new \stdClass );
29
+ $ presenter ->shouldReceive ('getPayload ' )->andReturn ($ payload = new \stdClass () );
28
30
$ presenter ->shouldReceive ('sendPayload ' )->once ();
29
- /**
30
- * @var AsyncControl|Mockery\Mock $control
31
- */
32
- $ control = Mockery::mock (AsyncControl::class)->makePartial ();
31
+
32
+ $ control = Mockery::mock (AsyncControl::class)->makePartial ()->shouldAllowMockingProtectedMethods ();
33
33
$ control ->shouldReceive ('getPresenter ' )->andReturn ($ presenter );
34
34
$ renderedContent = 'rendered content ' ;
35
- $ control ->shouldReceive ('renderAsync ' )->once ()->andReturnUsing (function () use ($ renderedContent ) {
35
+ $ control ->shouldReceive ('doRender ' )->once ()->andReturnUsing (function () use ($ renderedContent ) {
36
36
echo $ renderedContent ;
37
37
})
38
38
;
@@ -43,15 +43,13 @@ final class AsyncControlTest extends TestCase
43
43
}
44
44
45
45
46
- public function testHandleNoAjax ()
46
+ public function testHandleNoAjax (): void
47
47
{
48
48
$ presenter = Mockery::mock (Presenter::class);
49
49
$ presenter ->shouldReceive ('isAjax ' )->once ()->andReturn (FALSE );
50
50
$ presenter ->shouldNotReceive ('getPayload ' );
51
51
$ presenter ->shouldNotReceive ('sendPayload ' );
52
- /**
53
- * @var AsyncControl|Mockery\Mock $control
54
- */
52
+
55
53
$ control = Mockery::mock (AsyncControl::class)->makePartial ();
56
54
$ control ->shouldReceive ('getPresenter ' )->andReturn ($ presenter );
57
55
$ control ->shouldNotReceive ('renderAsync ' );
@@ -60,82 +58,39 @@ final class AsyncControlTest extends TestCase
60
58
}
61
59
62
60
63
- public function testRenderAsyncLoadLink ()
61
+ public function testRenderAsyncLoadsLink (): void
64
62
{
65
- /**
66
- * @var AsyncControl|Mockery\Mock $control
67
- */
68
63
$ control = Mockery::mock (AsyncControl::class)->makePartial ();
69
64
70
- $ template = Mockery::mock (ITemplate::class);
65
+ $ template = Mockery::mock (Template::class);
66
+ $ template ->shouldReceive ('add ' )->once ()->with ('link ' , Mockery::type (AsyncControlLink::class));
71
67
$ template ->shouldReceive ('setFile ' )->once ()->withAnyArgs ();
72
68
$ template ->shouldReceive ('render ' )->once ();
73
69
74
- $ templateFactory = Mockery::mock (ITemplateFactory ::class);
70
+ $ templateFactory = Mockery::mock (TemplateFactory ::class);
75
71
$ templateFactory ->shouldReceive ('createTemplate ' )->once ()->with ($ control )->andReturn ($ template );
76
72
77
73
$ presenter = Mockery::mock (Presenter::class);
78
- $ presenter ->shouldReceive ('getParameter ' )->once ()->with (self ::FRAGMENT_PARAMETER )->andReturn (NULL );
79
- $ presenter ->shouldReceive ('getParameter ' )->once ()->with (Presenter::SIGNAL_KEY )->andReturn (NULL );
80
74
$ presenter ->shouldReceive ('getTemplateFactory ' )->once ()->andReturn ($ templateFactory );
81
75
82
- $ control ->shouldReceive ('getPresenter ' )->andReturn ($ presenter );
83
- $ control ->shouldReceive ('getUniqueId ' )->once ()->andReturn ('control ' );
84
- $ control ->renderAsync ();
85
- }
86
-
87
-
88
- public function testRenderWithSignal ()
89
- {
90
- $ presenter = Mockery::mock (Presenter::class);
91
- $ presenter ->shouldReceive ('getParameter ' )->once ()->with (self ::FRAGMENT_PARAMETER )->andReturn (NULL );
92
- $ presenter ->shouldReceive ('getParameter ' )->once ()->with (Presenter::SIGNAL_KEY )->andReturn (self ::VALID_SIGNAL );
93
- /**
94
- * @var AsyncControl|Mockery\Mock $control
95
- */
96
- $ control = Mockery::mock (AsyncControl::class)->makePartial ();
97
- $ control ->shouldReceive ('getPresenter ' )->andReturn ($ presenter );
98
- $ control ->shouldReceive ('getUniqueId ' )->once ()->andReturn ('control ' );
99
- $ control ->shouldReceive ('render ' )->once ();
100
- $ control ->renderAsync ();
101
- }
102
-
103
-
104
- public function testRenderWithFragment ()
105
- {
106
- $ presenter = Mockery::mock (Presenter::class);
107
- $ presenter ->shouldReceive ('getParameter ' )->once ()->with (self ::FRAGMENT_PARAMETER )->andReturn ('' );
108
- /**
109
- * @var AsyncControl|Mockery\Mock $control
110
- */
111
- $ control = Mockery::mock (AsyncControl::class)->makePartial ();
112
- $ control ->shouldReceive ('getPresenter ' )->andReturn ($ presenter );
113
- $ control ->shouldReceive ('render ' )->once ();
76
+ $ control ->shouldReceive ('getPresenter ' )->once ()->andReturn ($ presenter );
114
77
$ control ->renderAsync ();
115
78
}
116
79
117
80
118
- public function testRenderAsyncRenderer ()
81
+ public function testRenderAsyncRenderer (): void
119
82
{
120
- $ presenter = Mockery::mock (Presenter::class);
121
- $ presenter ->shouldReceive ('getParameter ' )->once ()->with (self ::FRAGMENT_PARAMETER )->andReturn (NULL );
122
- $ presenter ->shouldReceive ('getParameter ' )->once ()->with (Presenter::SIGNAL_KEY )->andReturn (self ::VALID_SIGNAL );
123
- /**
124
- * @var AsyncControl|Mockery\Mock $control
125
- */
126
- $ control = Mockery::mock (AsyncControl::class)->makePartial ();
127
- $ control ->shouldReceive ('getPresenter ' )->andReturn ($ presenter );
128
- $ control ->shouldReceive ('getUniqueId ' )->once ()->andReturn ('control ' );
83
+ $ control = Mockery::mock (AsyncControl::class)->makePartial ()->shouldAllowMockingProtectedMethods ();
129
84
$ asyncRendered = FALSE ;
130
85
$ control ->setAsyncRenderer (function () use (&$ asyncRendered ) {
131
86
$ asyncRendered = TRUE ;
132
87
});
133
- $ control ->renderAsync ();
88
+ $ control ->doRender ();
134
89
Assert::equal (TRUE , $ asyncRendered );
135
90
}
136
91
137
92
138
- protected function tearDown ()
93
+ protected function tearDown (): void
139
94
{
140
95
parent ::tearDown ();
141
96
Mockery::close ();
0 commit comments