Skip to content

Commit

Permalink
ensure mounted directories are unique
Browse files Browse the repository at this point in the history
  • Loading branch information
inmanturbo committed Mar 5, 2024
1 parent 8f4bbbd commit 273de44
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/MountedDirectories.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@ class MountedDirectories
*/
public function mount(array|string $paths, array|string $uses = []): void
{

$paths = collect(Arr::wrap($paths))
->filter(fn (string $path) => is_dir($path))
->values()
->map(fn (string $path) => new MountedDirectory($path, Arr::wrap($uses)));
->map(fn (string $path) => new MountedDirectory($path, Arr::wrap($uses)))
->filter(fn (MountedDirectory $newMountedDirectory) => ! collect($this->paths)
->contains(fn (MountedDirectory $mountedDirectory) => $mountedDirectory->path === $newMountedDirectory->path && $mountedDirectory->uses === $newMountedDirectory->uses));

$this->paths = array_merge($this->paths, $paths->all());

Expand Down
19 changes: 19 additions & 0 deletions tests/Unit/VoltTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,22 @@

expect($instance)->toBeInstanceOf(VoltManager::class);
});

it('will not store duplicate paths', function () {
/** @var VoltManager $managerInstance */
$managerInstance = Volt::getFacadeRoot();

expect(count($managerInstance->paths()))->toBe(0);

$managerInstance->mount([
$path1 = __DIR__ . '/resources/views/livewire',
]);

$managerInstance->mount([
$path1
]);

$managerInstance->mount($path1);

expect(count($managerInstance->paths()))->toBe(1);
});
Empty file.

0 comments on commit 273de44

Please sign in to comment.