diff --git a/Request.php b/Request.php index 5fa7c07a4..617628aa6 100644 --- a/Request.php +++ b/Request.php @@ -382,7 +382,7 @@ public static function create(string $uri, string $method = 'GET', array $parame */ public static function setFactory(?callable $callable): void { - self::$requestFactory = $callable; + self::$requestFactory = null === $callable ? null : $callable(...); } /** diff --git a/Tests/RequestTest.php b/Tests/RequestTest.php index ad5b29850..68cb6ee43 100644 --- a/Tests/RequestTest.php +++ b/Tests/RequestTest.php @@ -2197,6 +2197,23 @@ public function testFactory() Request::setFactory(null); } + public function testFactoryCallable() + { + $requestFactory = new class { + public function createRequest(): Request + { + return new NewRequest(); + } + }; + + Request::setFactory([$requestFactory, 'createRequest']); + + $this->assertEquals('foo', Request::create('/')->getFoo()); + + Request::setFactory(null); + + } + /** * @dataProvider getLongHostNames */