Skip to content

Commit

Permalink
[1.x] Fixes property/method forwarding.
Browse files Browse the repository at this point in the history
  • Loading branch information
DarkGhostHunter committed Mar 3, 2024
1 parent 0bbee7c commit 0675d17
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/Discoverer.php
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,15 @@ public function getIterator(): Traversable
}

/**
* Handle dynamic calls to the retrieved classes.
* Handle dynamic property access to the retrieved classes Collection.
*/
public function __get(string $name): mixed
{
return $this->classes()->{$name};
}

/**
* Handle dynamic calls to the retrieved classes Collection.
*/
public function __call(string $name, array $arguments): mixed
{
Expand Down
14 changes: 14 additions & 0 deletions tests/DiscoverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -255,4 +255,18 @@ public function test_iterator_is_collection(): void

static::assertInstanceOf(Collection::class, Discover::in('Events')->getIterator());
}

public function test_forwards_property_access_to_collection(): void
{
$this->mockAllFiles();

static::assertInstanceOf(Collection::class, Discover::in('Events')->map->name);
}

public function test_forwards_call_to_collection(): void
{
$this->mockAllFiles();

static::assertInstanceOf(Collection::class, Discover::in('Events')->map(fn($c) => $c->name));
}
}

0 comments on commit 0675d17

Please sign in to comment.