8
8
9
9
class Connection implements ConnectionInterface
10
10
{
11
- /** @var Request */
11
+ /**
12
+ * The request instance.
13
+ *
14
+ * @var Request
15
+ */
12
16
public $ httpRequest ;
13
17
18
+ /**
19
+ * The sent data through the connection.
20
+ *
21
+ * @var array
22
+ */
14
23
public $ sentData = [];
15
24
25
+ /**
26
+ * The raw (unencoded) sent data.
27
+ *
28
+ * @var array
29
+ */
16
30
public $ sentRawData = [];
17
31
32
+ /**
33
+ * Wether the connection has been closed.
34
+ *
35
+ * @var bool
36
+ */
18
37
public $ closed = false ;
19
38
39
+ /**
40
+ * Send the data through the connection.
41
+ *
42
+ * @param mixed $data
43
+ * @return void
44
+ */
20
45
public function send ($ data )
21
46
{
22
47
$ this ->sentData [] = json_decode ($ data , true );
23
48
$ this ->sentRawData [] = $ data ;
24
49
}
25
50
51
+ /**
52
+ * Mark the connection as closed.
53
+ *
54
+ * @return void
55
+ */
26
56
public function close ()
27
57
{
28
58
$ this ->closed = true ;
29
59
}
30
60
61
+ /**
62
+ * Assert that an event got sent.
63
+ *
64
+ * @param string $name
65
+ * @param array $additionalParameters
66
+ * @return void
67
+ */
31
68
public function assertSentEvent (string $ name , array $ additionalParameters = [])
32
69
{
33
70
$ event = collect ($ this ->sentData )->firstWhere ('event ' , '= ' , $ name );
@@ -41,6 +78,12 @@ public function assertSentEvent(string $name, array $additionalParameters = [])
41
78
}
42
79
}
43
80
81
+ /**
82
+ * Assert that an event got not sent.
83
+ *
84
+ * @param string $name
85
+ * @return void
86
+ */
44
87
public function assertNotSentEvent (string $ name )
45
88
{
46
89
$ event = collect ($ this ->sentData )->firstWhere ('event ' , '= ' , $ name );
@@ -50,6 +93,11 @@ public function assertNotSentEvent(string $name)
50
93
);
51
94
}
52
95
96
+ /**
97
+ * Assert the connection is closed.
98
+ *
99
+ * @return void
100
+ */
53
101
public function assertClosed ()
54
102
{
55
103
PHPUnit::assertTrue ($ this ->closed );
0 commit comments