1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* |
5
|
|
|
* (c) Yaroslav Honcharuk <[email protected]> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Yarhon\RouteGuardBundle\Tests\Security\TestBagResolver; |
12
|
|
|
|
13
|
|
|
use PHPUnit\Framework\TestCase; |
14
|
|
|
use Yarhon\RouteGuardBundle\Security\Test\AbstractTestBagInterface; |
15
|
|
|
use Yarhon\RouteGuardBundle\Security\Test\TestBagInterface; |
16
|
|
|
use Yarhon\RouteGuardBundle\Security\Test\TestInterface; |
17
|
|
|
use Yarhon\RouteGuardBundle\Routing\RouteContext; |
18
|
|
|
use Yarhon\RouteGuardBundle\Security\Http\RequestContextFactory; |
19
|
|
|
use Yarhon\RouteGuardBundle\Security\Http\RequestContext; |
20
|
|
|
use Yarhon\RouteGuardBundle\Security\Http\RequestDependentTestBagInterface; |
21
|
|
|
use Yarhon\RouteGuardBundle\Security\TestBagResolver\TestBagResolver; |
22
|
|
|
use Yarhon\RouteGuardBundle\Exception\RuntimeException; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @author Yaroslav Honcharuk <[email protected]> |
26
|
|
|
*/ |
27
|
|
|
class TestBagResolverTest extends TestCase |
28
|
|
|
{ |
29
|
|
|
private $requestContextFactory; |
30
|
|
|
|
31
|
|
|
private $resolver; |
32
|
|
|
|
33
|
|
|
public function setUp() |
34
|
|
|
{ |
35
|
|
|
$this->requestContextFactory = $this->createMock(RequestContextFactory::class); |
36
|
|
|
|
37
|
|
|
$this->resolver = new TestBagResolver($this->requestContextFactory); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function testResolveTestBag() |
41
|
|
|
{ |
42
|
|
|
$tests = [ |
43
|
|
|
$this->createMock(TestInterface::class), |
44
|
|
|
]; |
45
|
|
|
|
46
|
|
|
$testBag = $this->createMock(TestBagInterface::class); |
47
|
|
|
$testBag->method('getTests') |
|
|
|
|
48
|
|
|
->willReturn($tests); |
49
|
|
|
|
50
|
|
|
$routeContext = new RouteContext('index'); |
51
|
|
|
|
52
|
|
|
$resolved = $this->resolver->resolve($testBag, $routeContext); |
53
|
|
|
|
54
|
|
|
$this->assertSame($tests, $resolved); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function testResolveRequestDependentTestBag() |
58
|
|
|
{ |
59
|
|
|
$tests = [ |
60
|
|
|
$this->createMock(TestInterface::class), |
61
|
|
|
]; |
62
|
|
|
|
63
|
|
|
$requestContext = new RequestContext('/'); |
64
|
|
|
|
65
|
|
|
$this->requestContextFactory->method('createContext') |
66
|
|
|
->willReturn($requestContext); |
67
|
|
|
|
68
|
|
|
$testBag = $this->createMock(RequestDependentTestBagInterface::class); |
69
|
|
|
$testBag->method('getTests') |
70
|
|
|
->with($requestContext) |
71
|
|
|
->willReturn($tests); |
72
|
|
|
|
73
|
|
|
$routeContext = new RouteContext('index'); |
74
|
|
|
|
75
|
|
|
$resolved = $this->resolver->resolve($testBag, $routeContext); |
76
|
|
|
|
77
|
|
|
$this->assertSame($tests, $resolved); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public function testNoResolverException() |
81
|
|
|
{ |
82
|
|
|
$testBag = $this->createMock(AbstractTestBagInterface::class); |
83
|
|
|
|
84
|
|
|
$routeContext = new RouteContext('index'); |
85
|
|
|
|
86
|
|
|
$this->expectException(RuntimeException::class); |
87
|
|
|
$this->expectExceptionMessage(sprintf('No resolver exists for test bag instance of "%s".', get_class($testBag))); |
88
|
|
|
|
89
|
|
|
$this->resolver->resolve($testBag, $routeContext); |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.