Skip to content

Commit

Permalink
Fix type check for array based callables
Browse files Browse the repository at this point in the history
  • Loading branch information
philipobenito committed Nov 20, 2024
1 parent 0ff7fcf commit 1926646
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Route implements
public function __construct(
protected array|string $method,
protected string $path,
callable|string|RequestHandlerInterface $handler,
callable|array|string|RequestHandlerInterface $handler,
protected ?RouteGroup $group = null,
protected array $vars = []
) {
Expand Down
34 changes: 32 additions & 2 deletions tests/RouteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,43 @@ public function testRouteSetsAndResolvesInvokableClassCallable(): void
$this->assertIsCallable($route->getCallable());
}

public function testRouteSetsAndResolvesClassMethodCallable(): void
public function testRouteSetsAndResolvesClassMethodArrayCallable(): void
{
$callable = [new Controller(), 'action'];
$route = new Route('GET', '/', $callable);
$this->assertIsCallable($route->getCallable());
}

public function testRouteSetsAndResolvesLazilyLoadedClassMethodArrayCallableWithoutContainer(): void
{
$callable = [new Controller(), 'action'];
$route = new Route('GET', '/', $callable);
$this->assertIsCallable($route->getCallable());
}

public function testRouteSetsAndResolvesLazilyLoadedClassMethodArrayCallableWithContainer(): void
{
$container = $this->createMock(ContainerInterface::class);

$container
->expects($this->once())
->method('has')
->with($this->equalTo(Controller::class))
->willReturn(true)
;

$container
->expects($this->once())
->method('get')
->with($this->equalTo(Controller::class))
->willReturn(new Controller())
;

$callable = [Controller::class, 'action'];
$route = new Route('GET', '/', $callable);
$this->assertIsCallable($route->getCallable($container));
}

public function testRouteSetsAndResolvesNamedFunctionCallable(): void
{
$callable = 'League\Route\Fixture\namedFunctionCallable';
Expand All @@ -53,7 +83,7 @@ public function testRouteSetsAndResolvesClassMethodCallableAsStringViaContainer(
;

$callable = 'League\Route\Fixture\Controller::action';
$route = new Route('GET', '/', $callable);
$route = new Route('GET', '/', $callable);

$newCallable = $route->getCallable($container);
$this->assertIsArray($newCallable);
Expand Down

0 comments on commit 1926646

Please sign in to comment.