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\Routing; |
12
|
|
|
|
13
|
|
|
use PHPUnit\Framework\TestCase; |
14
|
|
|
use Symfony\Component\Routing\RouterInterface; |
15
|
|
|
use Symfony\Component\Routing\RouteCollection; |
16
|
|
|
use Symfony\Component\Routing\Route; |
17
|
|
|
use Symfony\Component\Routing\RequestContext; |
18
|
|
|
use Yarhon\RouteGuardBundle\Routing\LocalizedRouteDetector; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @author Yaroslav Honcharuk <[email protected]> |
22
|
|
|
*/ |
23
|
|
|
class LocalizedRouteDetectorTest extends TestCase |
24
|
|
|
{ |
25
|
|
|
private $routeCollection; |
26
|
|
|
|
27
|
|
|
private $context; |
28
|
|
|
|
29
|
|
|
private $detector; |
30
|
|
|
|
31
|
|
|
public function setUp() |
32
|
|
|
{ |
33
|
|
|
$this->routeCollection = $this->createMock(RouteCollection::class); |
34
|
|
|
$this->context = $this->createMock(RequestContext::class); |
35
|
|
|
|
36
|
|
|
$router = $this->createMock(RouterInterface::class); |
37
|
|
|
|
38
|
|
|
$router->method('getRouteCollection') |
|
|
|
|
39
|
|
|
->willReturn($this->routeCollection); |
40
|
|
|
|
41
|
|
|
$router->method('getContext') |
42
|
|
|
->willReturn($this->context); |
43
|
|
|
|
44
|
|
|
$this->detector = new LocalizedRouteDetector($router); |
45
|
|
|
|
46
|
|
|
$this->context->method('getParameter') |
47
|
|
|
->with('_locale') |
48
|
|
|
->willReturn('en'); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function testByLocaleFromContext() |
52
|
|
|
{ |
53
|
|
|
$route = $this->createMock(Route::class); |
54
|
|
|
|
55
|
|
|
$route->method('getDefault') |
56
|
|
|
->with('_canonical_route') |
57
|
|
|
->willReturn('route1'); |
58
|
|
|
|
59
|
|
|
$this->routeCollection->method('get') |
60
|
|
|
->with('route1.en') |
61
|
|
|
->willReturn($route); |
62
|
|
|
|
63
|
|
|
$this->assertEquals('route1.en', $this->detector->getLocalizedName('route1')); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function testByLocaleFromParameters() |
67
|
|
|
{ |
68
|
|
|
$route = $this->createMock(Route::class); |
69
|
|
|
|
70
|
|
|
$route->method('getDefault') |
71
|
|
|
->with('_canonical_route') |
72
|
|
|
->willReturn('route1'); |
73
|
|
|
|
74
|
|
|
$this->routeCollection->method('get') |
75
|
|
|
->with('route1.fr') |
76
|
|
|
->willReturn($route); |
77
|
|
|
|
78
|
|
|
$this->assertEquals('route1.fr', $this->detector->getLocalizedName('route1', ['_locale' => 'fr'])); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
public function testNonLocalized() |
82
|
|
|
{ |
83
|
|
|
$this->routeCollection->method('get') |
84
|
|
|
->with('route1.fr') |
85
|
|
|
->willReturn(null); |
86
|
|
|
|
87
|
|
|
$this->assertNull($this->detector->getLocalizedName('route1', ['_locale' => 'fr'])); |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|
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.