FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
tapper/tests/Unit/EventBusTest.php at master · tapperphp/tapper · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
tapperphp
/
tapper
Public
Notifications
You must be signed in to change notification settings
Fork
1
Star
7
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
tapper
/
tests
/
Unit
/
EventBusTest.php
Copy path
More file actions
More file actions
Latest commit
History
History
History
145 lines (113 loc) · 4.06 KB
Breadcrumbs
tapper
/
tests
/
Unit
/
EventBusTest.php
Copy path
File metadata and controls
145 lines (113 loc) · 4.06 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<?php
declare
(strict_types=
1
);
use
PhpTui
\
Term
\
Event
\
CharKeyEvent
;
use
PhpTui
\
Term
\
Event
\
CodedKeyEvent
;
use
PhpTui
\
Term
\
Event
\
FunctionKeyEvent
;
use
PhpTui
\
Term
\
Event
\
MouseEvent
;
use
PhpTui
\
Term
\
KeyCode
;
use
PhpTui
\
Term
\
KeyModifiers
;
use
PhpTui
\
Term
\
MouseButton
;
use
PhpTui
\
Term
\
MouseEventKind
;
use
Tapper
\
Console
\
EventBus
;
describe
(
'
string/int events
'
,
function
() {
it
(
'
dispatches a registered string event to its listener
'
,
function
() {
$
bus
=
new
EventBus
;
$
received
=
null
;
$
bus
->
listen
(
'
custom
'
,
function
(
$
data
)
use
(&
$
received
) {
$
received
=
$
data
;
});
$
bus
->
emit
(
'
custom
'
, [
'
foo
'
=>
'
bar
'
]);
expect
(
$
received
)->
toBe
([
'
foo
'
=>
'
bar
'
]);
});
it
(
'
does nothing when emitting an event with no listeners
'
,
function
() {
$
bus
=
new
EventBus
;
$
bus
->
emit
(
'
nobody-listens
'
);
expect
(
true
)->
toBeTrue
();
});
it
(
'
calls every listener registered for the same event, in order
'
,
function
() {
$
bus
=
new
EventBus
;
$
calls
= [];
$
bus
->
listen
(
'
tick
'
,
function
()
use
(&
$
calls
) {
$
calls
[] =
'
first
'
;
});
$
bus
->
listen
(
'
tick
'
,
function
()
use
(&
$
calls
) {
$
calls
[] =
'
second
'
;
});
$
bus
->
emit
(
'
tick
'
);
expect
(
$
calls
)->
toBe
([
'
first
'
,
'
second
'
]);
});
});
describe
(
'
KeyCode/MouseEventKind registration
'
,
function
() {
it
(
'
registers a KeyCode listener under its enum name
'
,
function
() {
$
bus
=
new
EventBus
;
$
fired
=
false
;
$
bus
->
listen
(KeyCode::Enter,
function
()
use
(&
$
fired
) {
$
fired
=
true
;
});
$
bus
->
emit
(
'
Enter
'
);
expect
(
$
fired
)->
toBeTrue
();
});
it
(
'
registers a MouseEventKind listener under a "Mouse"-prefixed name
'
,
function
() {
$
bus
=
new
EventBus
;
$
fired
=
false
;
$
bus
->
listen
(MouseEventKind::Down,
function
()
use
(&
$
fired
) {
$
fired
=
true
;
});
$
bus
->
emit
(
'
MouseDown
'
);
expect
(
$
fired
)->
toBeTrue
();
});
});
describe
(
'
CharKeyEvent dispatch
'
,
function
() {
it
(
'
dispatches keyed by the typed character and merges modifiers into the data
'
,
function
() {
$
bus
=
new
EventBus
;
$
received
=
null
;
$
bus
->
listen
(
'
a
'
,
function
(
$
data
)
use
(&
$
received
) {
$
received
=
$
data
;
});
$
bus
->
emit
(CharKeyEvent::
new
(
'
a
'
, KeyModifiers::
SHIFT
));
expect
(
$
received
)->
toBe
([
'
modifiers
'
=> KeyModifiers::
SHIFT
]);
});
it
(
'
lets extra data passed to emit override the default modifiers key
'
,
function
() {
$
bus
=
new
EventBus
;
$
received
=
null
;
$
bus
->
listen
(
'
b
'
,
function
(
$
data
)
use
(&
$
received
) {
$
received
=
$
data
;
});
$
bus
->
emit
(CharKeyEvent::
new
(
'
b
'
), [
'
modifiers
'
=>
'
overridden
'
]);
expect
(
$
received
)->
toBe
([
'
modifiers
'
=>
'
overridden
'
]);
});
});
describe
(
'
CodedKeyEvent dispatch
'
,
function
() {
it
(
'
dispatches keyed by the KeyCode enum name
'
,
function
() {
$
bus
=
new
EventBus
;
$
fired
=
false
;
$
bus
->
listen
(KeyCode::Esc->
name
,
function
()
use
(&
$
fired
) {
$
fired
=
true
;
});
$
bus
->
emit
(CodedKeyEvent::
new
(KeyCode::Esc));
expect
(
$
fired
)->
toBeTrue
();
});
});
describe
(
'
FunctionKeyEvent dispatch
'
,
function
() {
it
(
'
dispatches keyed by "F{number}"
'
,
function
() {
$
bus
=
new
EventBus
;
$
fired
=
false
;
$
bus
->
listen
(
'
F5
'
,
function
()
use
(&
$
fired
) {
$
fired
=
true
;
});
$
bus
->
emit
(FunctionKeyEvent::
new
(
5
));
expect
(
$
fired
)->
toBeTrue
();
});
});
describe
(
'
MouseEvent dispatch
'
,
function
() {
it
(
'
dispatches keyed by "Mouse{kind}" and passes the event back in the data
'
,
function
() {
$
bus
=
new
EventBus
;
$
received
=
null
;
$
bus
->
listen
(
'
MouseScrollUp
'
,
function
(
$
data
)
use
(&
$
received
) {
$
received
=
$
data
;
});
$
event
= MouseEvent::
new
(MouseEventKind::ScrollUp, MouseButton::None, column:
3
, row:
4
, modifiers:
0
);
$
bus
->
emit
(
$
event
);
expect
(
$
received
)->
toBe
([
'
event
'
=>
$
event
]);
});
});
Back
|
FazBrowse Home
|
New Git URL