-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTypeHintRequestResolverTest.php
57 lines (45 loc) · 1.89 KB
/
TypeHintRequestResolverTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
declare(strict_types=1);
namespace Qubus\Tests\Routing;
use Laminas\Diactoros\ServerRequest;
use PHPUnit\Framework\Assert;
use PHPUnit\Framework\TestCase;
use Qubus\Routing\TypeHintRequestResolver;
use ReflectionFunction;
class TypeHintRequestResolverTest extends TestCase
{
/** @test */
public function returnsResolvedParametersWhenNoRequestIsSet()
{
$reflectionFunction = new ReflectionFunction(function () {
});
$resolvedParameters = ['a' => 123, 'b' => 456];
$resolver = new TypeHintRequestResolver();
$params = $resolver->getParameters($reflectionFunction, [], $resolvedParameters);
Assert::assertSame($resolvedParameters, $params);
}
/** @test */
public function canResolveaRequest()
{
$request = new ServerRequest([], [], '/injected', 'GET');
$reflectionFunction = new ReflectionFunction(function (ServerRequest $request) {
});
$resolver = new TypeHintRequestResolver();
$resolver->setRequest($request);
$params = $resolver->getParameters($reflectionFunction, [], []);
Assert::assertSame('/injected', $params[0]->getUri()->getPath());
}
/** @test */
public function doesNotAttemptToResolveParamsThatHaveAlreadyBeenResolved()
{
$preResolvedRequest = new ServerRequest([], [], '/pre/resolved', 'GET');
$injectedRequest = new ServerRequest([], [], '/injected', 'GET');
$reflectionFunction = new ReflectionFunction(function (ServerRequest $request) {
});
$resolvedParameters = [0 => $preResolvedRequest];
$resolver = new TypeHintRequestResolver();
$resolver->setRequest($injectedRequest);
$params = $resolver->getParameters($reflectionFunction, [], $resolvedParameters);
Assert::assertSame('/pre/resolved', $params[0]->getUri()->getPath());
}
}