@@ -31,8 +31,8 @@ public function setUp() {
31
31
*
32
32
* filter them out so we can compare changes properly
33
33
*
34
- * @param array $changes
35
- * @return array
34
+ * @param Change[] $changes
35
+ * @return Change[]
36
36
*/
37
37
private function filterModifiedChanges (array $ changes ) {
38
38
return array_values (array_filter ($ changes , function (Change $ change ) {
@@ -114,4 +114,40 @@ public function testStopped() {
114
114
$ process ->stop ();
115
115
$ this ->assertEquals ([], $ process ->getChanges ());
116
116
}
117
+
118
+ public function testListenAfterGetChanges () {
119
+ $ share = $ this ->server ->getShare ($ this ->config ->share );
120
+ $ process = $ share ->notify ('' );
121
+
122
+ usleep (1000 * 100 );// give it some time to start listening
123
+
124
+ $ share ->put (__FILE__ , 'source.txt ' );
125
+ $ share ->rename ('source.txt ' , 'target.txt ' );
126
+ $ share ->del ('target.txt ' );
127
+ usleep (1000 * 100 );// give it some time
128
+
129
+ $ changes = $ process ->getChanges ();
130
+ $ expected = [
131
+ new Change (INotifyHandler::NOTIFY_ADDED , 'source.txt ' ),
132
+ new Change (INotifyHandler::NOTIFY_RENAMED_OLD , 'source.txt ' ),
133
+ new Change (INotifyHandler::NOTIFY_RENAMED_NEW , 'target.txt ' ),
134
+ new Change (INotifyHandler::NOTIFY_REMOVED , 'target.txt ' ),
135
+ ];
136
+
137
+ $ this ->assertEquals ($ expected , $ this ->filterModifiedChanges ($ changes ));
138
+
139
+ usleep (1000 * 200 );
140
+
141
+ $ share ->put (__FILE__ , 'source2.txt ' );
142
+ $ share ->del ('source2.txt ' );
143
+
144
+ $ results = null ;
145
+
146
+ // the notify process buffers incoming messages so callback will be triggered for the above changes
147
+ $ process ->listen (function ($ change ) use (&$ results ) {
148
+ $ results = $ change ;
149
+ return false ; // stop listening
150
+ });
151
+ $ this ->assertNotNull ($ results );
152
+ }
117
153
}
0 commit comments