13
13
14
14
namespace Micro \Plugin \Http \Test \Unit \Listener ;
15
15
16
- use Micro \Kernel \App \AppKernelInterface ;
17
- use Micro \Kernel \App \Business \Event \ApplicationReadyEvent ;
16
+ use Micro \Kernel \App \Business \Event \ApplicationReadyEventInterface ;
18
17
use Micro \Plugin \Http \Facade \HttpFacadeInterface ;
19
18
use Micro \Plugin \Http \Listener \ApplicationStartedListener ;
20
19
use PHPUnit \Framework \TestCase ;
@@ -26,35 +25,26 @@ class ApplicationStartedListenerTest extends TestCase
26
25
27
26
private HttpFacadeInterface $ httpFacade ;
28
27
29
- private ApplicationReadyEvent $ applicationReadyEvent ;
30
-
31
28
protected function setUp (): void
32
29
{
33
30
$ this ->httpFacade = $ this ->createMock (HttpFacadeInterface::class);
34
- $ this ->applicationStartedListener = $ this ->getMockBuilder (ApplicationStartedListener::class)
35
- ->setConstructorArgs ([
36
- $ this ->httpFacade ,
37
- ])
38
- ->onlyMethods ([
39
- 'isHttp ' ,
40
- ])
41
- ->getMock ();
31
+ $ this ->applicationStartedListener = new ApplicationStartedListener ($ this ->httpFacade );
32
+ }
42
33
43
- $ this ->applicationReadyEvent = new ApplicationReadyEvent (
44
- $ this ->createMock (AppKernelInterface::class),
45
- 'any ' ,
46
- );
34
+ protected function createEvent (bool $ isHttp )
35
+ {
36
+ $ evt = $ this ->createMock (ApplicationReadyEventInterface::class);
37
+ $ evt ->method ('systemEnvironment ' )->willReturn ($ isHttp ? 'http ' : 'cli ' );
38
+
39
+ return $ evt ;
47
40
}
48
41
49
42
/**
50
43
* @dataProvider dataProvider
51
44
*/
52
45
public function testOn (bool $ isHttp ): void
53
46
{
54
- $ this ->applicationStartedListener
55
- ->expects ($ this ->once ())
56
- ->method ('isHttp ' )
57
- ->willReturn ($ isHttp );
47
+ $ event = $ this ->createEvent ($ isHttp );
58
48
59
49
if (!$ isHttp ) {
60
50
$ this ->httpFacade
@@ -69,18 +59,7 @@ public function testOn(bool $isHttp): void
69
59
);
70
60
}
71
61
72
- $ this ->applicationStartedListener ->on ($ this ->applicationReadyEvent );
73
- }
74
-
75
- public function testIsHttp ()
76
- {
77
- $ this ->httpFacade ->expects ($ this ->never ())->method ('execute ' );
78
-
79
- $ appListener = new ApplicationStartedListener (
80
- $ this ->httpFacade
81
- );
82
-
83
- $ appListener ->on ($ this ->applicationReadyEvent );
62
+ $ this ->applicationStartedListener ->on ($ event );
84
63
}
85
64
86
65
public function dataProvider (): array
@@ -96,6 +75,6 @@ public function testSupports()
96
75
$ httpFacade = $ this ->createMock (HttpFacadeInterface::class);
97
76
$ listener = new ApplicationStartedListener ($ httpFacade );
98
77
99
- $ this ->assertTrue ($ listener ->supports ($ this ->applicationReadyEvent ));
78
+ $ this ->assertTrue ($ listener ->supports ($ this ->createEvent ( true ) ));
100
79
}
101
80
}
0 commit comments