Skip to content

Commit 69025fd

Browse files
author
phprtc
authored
Merge pull request #24 from phprtc/misc
Improvements & Fixed failing test
2 parents 6fdb95c + 962ff48 commit 69025fd

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

src/Watcher.php

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ protected function inotifyWatchPath(string $path): void
136136
protected function inotifyRemovePathWatch(EventInfo $eventInfo): void
137137
{
138138
$descriptor = $eventInfo->getWatchDescriptor();
139-
if ($eventInfo->getWatchedItem()->getFullPath() != $this->watchedItems[$descriptor]){
139+
if ($eventInfo->getWatchedItem()->getFullPath() != $this->watchedItems[$descriptor]) {
140140
return;
141141
}
142142

@@ -234,7 +234,7 @@ public function watch(): void
234234

235235
// INDIVIDUAL LISTENERS
236236
foreach ($inotifyEvents as $inotifyEvent) {
237-
// var_export($inotifyEvent);
237+
// var_export($inotifyEvent);
238238
// Make sure that we support this event
239239
if (in_array($inotifyEvent['mask'], $this->watchedMasks)) {
240240
$this->fireEvent($inotifyEvent);
@@ -257,23 +257,33 @@ public function watch(): void
257257
/**
258258
* Add file extension filter
259259
*
260-
* @param string $extension
260+
* @param string|array $extension
261261
* @return $this
262262
*/
263-
public function addExtension(string $extension): Watcher
263+
public function addExtension(string|array $extension): Watcher
264264
{
265+
if (is_array($extension)) {
266+
$this->extensions = array_merge($this->extensions, $extension);
267+
return $this;
268+
}
269+
265270
$this->extensions[] = $extension;
266271
return $this;
267272
}
268273

269274
/**
270275
* Add path to watch
271276
*
272-
* @param string $path
277+
* @param string|array $path
273278
* @return $this
274279
*/
275-
public function addPath(string $path): Watcher
280+
public function addPath(string|array $path): Watcher
276281
{
282+
if (is_array($path)) {
283+
$this->paths = array_merge($this->paths, $path);
284+
return $this;
285+
}
286+
277287
$this->paths[] = $path;
278288
return $this;
279289
}

tests/WatcherTest.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,20 @@
44

55
use PHPUnit\Framework\TestCase;
66
use RTC\Watcher\Watching\EventInfo;
7+
use Swoole\Timer;
78
use function Co\run;
89

910
class WatcherTest extends TestCase
1011
{
12+
protected function setUp(): void
13+
{
14+
parent::setUp();
15+
16+
if (!file_exists(__DIR__ . '/bait')) {
17+
mkdir(__DIR__ . '/bait');
18+
}
19+
}
20+
1121
public function testFileAndDirectoryCreation(): void
1222
{
1323
run(function () {
@@ -152,7 +162,6 @@ public function testCreateChangeDeleteOnTheFly(): void
152162
touch($baitFile);
153163
file_put_contents($baitFile, uniqid());
154164
unlink($baitFile);
155-
rmdir($baitDir);
156165
});
157166
}
158167
}

0 commit comments

Comments
 (0)