Skip to content
Snippets Groups Projects
Commit 57298fb1 authored by Dillenn Terumalai's avatar Dillenn Terumalai :speech_balloon:
Browse files

// WIP

parent 7095770b
Branches
Tags v1.0.1
No related merge requests found
Pipeline #2283 passed
......@@ -5,11 +5,18 @@ namespace Dterumal\Watcher\Events;
class FileEvent
{
/**
* The file directory
* The watcher identifier
*
* @var string
*/
public string $directory;
public string $watcher;
/**
* The file path
*
* @var string
*/
public string $path;
/**
* The file mask
......@@ -23,7 +30,7 @@ class FileEvent
*
* @var string
*/
public string $name;
public string $filename;
/**
* The file cookie
......@@ -35,21 +42,23 @@ class FileEvent
/**
* Create a new event instance.
*
* @param string $directory
* @param string $watcher
* @param string $filename
* @param int $mask
* @param string $name
* @param int $cookie
*/
public function __construct(
string $directory,
string $name,
string $watcher,
string $filename,
int $mask,
int $cookie
)
{
$this->directory = $directory;
$this->name = $name;
) {
$this->watcher = $watcher;
$this->filename = $filename;
$this->mask = $mask;
$this->cookie = $cookie;
$this->path = collect(config('watcher.watchers'))->first(function ($value, $key) {
return $key === $this->watcher;
})['path'];
}
}
......@@ -129,10 +129,10 @@ class Watcher
if (!empty($events)) {
foreach ($events as $event) {
[$directory, $filename, $mask, $cookie] = [$this->watchers[$event['wd']], $event['name'], $event['mask'], $event['cookie']];
[$watcher, $filename, $mask, $cookie] = [$this->watchers[$event['wd']], $event['name'], $event['mask'], $event['cookie']];
$this->raiseOnFileEvent(
$directory,
$watcher,
$filename,
$mask,
$cookie
......@@ -410,16 +410,16 @@ class Watcher
/**
* Raise after a watcher creation.
*
* @param string $directory
* @param string $watcher
* @param string $filename
* @param int $mask
* @param int $cookie
* @return void
*/
protected function raiseOnFileEvent(string $directory, string $filename, int $mask, int $cookie): void
protected function raiseOnFileEvent(string $watcher, string $filename, int $mask, int $cookie): void
{
$this->events->dispatch(new FileEvent(
$directory,
$watcher,
$filename,
$mask,
$cookie
......
......@@ -46,6 +46,9 @@ class WatcherCommandTest extends TestCase
{
Event::fake();
// Directory watched
$directory = storage_path('app');
// File created
$fooFile = storage_path('app/test.txt');
......@@ -71,11 +74,12 @@ class WatcherCommandTest extends TestCase
$this->assertSame(0, $exitCode);
// Check that the watcher was created
Event::assertDispatched(FileEvent::class, function ($event) {
return $event->directory === 'default' &&
Event::assertDispatched(FileEvent::class, function ($event) use ($directory) {
return $event->watcher === 'default' &&
$event->mask === 256 &&
$event->cookie === 0 &&
$event->name === 'test.txt';
$event->filename === 'test.txt' &&
$event->path === $directory;
});
}
......@@ -84,6 +88,9 @@ class WatcherCommandTest extends TestCase
{
Event::fake();
// Directory watched
$directory = storage_path('app');
// File created
$fooFile = storage_path('app/test.txt');
......@@ -109,11 +116,12 @@ class WatcherCommandTest extends TestCase
$this->assertSame(0, $exitCode);
// Check that the watcher was created
Event::assertDispatched(FileEvent::class, function ($event) {
return $event->directory === 'default' &&
Event::assertDispatched(FileEvent::class, function ($event) use ($directory) {
return $event->watcher === 'default' &&
$event->mask === 256 &&
$event->cookie === 0 &&
$event->name === 'test.txt';
$event->filename === 'test.txt' &&
$event->path === $directory;
});
// Check that the watcher was stopped
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment