|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* File containing the ContentBasedMatcherFactoryTest class. |
|
5
|
|
|
* |
|
6
|
|
|
* @copyright Copyright (C) eZ Systems AS. All rights reserved. |
|
7
|
|
|
* @license For full copyright and license information view LICENSE file distributed with this source code. |
|
8
|
|
|
*/ |
|
9
|
|
|
namespace eZ\Publish\Core\MVC\Symfony\Matcher\Tests; |
|
10
|
|
|
|
|
11
|
|
|
use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\ConfigResolver; |
|
12
|
|
|
use eZ\Publish\Core\MVC\Symfony\Matcher\ClassNameMatcherFactory; |
|
13
|
|
|
use eZ\Publish\Core\MVC\Symfony\Matcher\DynamicallyConfiguredMatcherFactoryDecorator; |
|
14
|
|
|
use eZ\Publish\Core\MVC\Symfony\View\ContentView; |
|
15
|
|
|
use PHPUnit\Framework\TestCase; |
|
16
|
|
|
|
|
17
|
|
|
class DynamicallyConfiguredMatcherFactoryDecoratorTest extends TestCase |
|
18
|
|
|
{ |
|
19
|
|
|
/** @var \eZ\Publish\Core\MVC\Symfony\Matcher\ConfigurableMatcherFactoryInterface */ |
|
20
|
|
|
private $innerMatcherFactory; |
|
21
|
|
|
|
|
22
|
|
|
/** @var \eZ\Publish\Core\MVC\ConfigResolverInterface */ |
|
23
|
|
|
private $configResolver; |
|
24
|
|
|
|
|
25
|
|
|
public function setUp(): void |
|
26
|
|
|
{ |
|
27
|
|
|
$innerMatcherFactory = $this->createMock(ClassNameMatcherFactory::class); |
|
28
|
|
|
$configResolver = $this->createMock(ConfigResolver::class); |
|
29
|
|
|
|
|
30
|
|
|
$this->innerMatcherFactory = $innerMatcherFactory; |
|
|
|
|
|
|
31
|
|
|
$this->configResolver = $configResolver; |
|
|
|
|
|
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @dataProvider matchConfigProvider |
|
36
|
|
|
*/ |
|
37
|
|
|
public function testMatch($parameterName, $namespace, $scope, $viewsConfiguration, $matchedConfig): void |
|
38
|
|
|
{ |
|
39
|
|
|
$view = $this->createMock(ContentView::class); |
|
40
|
|
|
$this->configResolver->expects($this->atLeastOnce())->method('getParameter')->with($parameterName, $namespace, |
|
|
|
|
|
|
41
|
|
|
$scope)->willReturn($viewsConfiguration); |
|
42
|
|
|
$this->innerMatcherFactory->expects($this->once())->method('match')->with($view)->willReturn($matchedConfig); |
|
|
|
|
|
|
43
|
|
|
|
|
44
|
|
|
$matcherFactory = new DynamicallyConfiguredMatcherFactoryDecorator( |
|
45
|
|
|
$this->innerMatcherFactory, |
|
46
|
|
|
$this->configResolver, |
|
47
|
|
|
$parameterName, |
|
48
|
|
|
$namespace, |
|
49
|
|
|
$scope |
|
50
|
|
|
); |
|
51
|
|
|
|
|
52
|
|
|
$this->assertEquals($matchedConfig, $matcherFactory->match($view)); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function matchConfigProvider(): array |
|
56
|
|
|
{ |
|
57
|
|
|
return [ |
|
58
|
|
|
[ |
|
59
|
|
|
'location_view', |
|
60
|
|
|
null, |
|
61
|
|
|
null, |
|
62
|
|
|
[ |
|
63
|
|
|
'full' => [ |
|
64
|
|
|
'test' => [ |
|
65
|
|
|
'template' => 'foo.html.twig', |
|
66
|
|
|
'match' => [ |
|
67
|
|
|
\stdClass::class => true, |
|
68
|
|
|
], |
|
69
|
|
|
], |
|
70
|
|
|
], |
|
71
|
|
|
], |
|
72
|
|
|
[ |
|
73
|
|
|
'template' => 'foo.html.twig', |
|
74
|
|
|
'match' => [ |
|
75
|
|
|
\stdClass::class => true, |
|
76
|
|
|
], |
|
77
|
|
|
], |
|
78
|
|
|
], |
|
79
|
|
|
]; |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..