1 | <?php |
||
16 | abstract class AbstractServiceTest extends TestCase |
||
17 | { |
||
18 | /** |
||
19 | * Purely to attempt to make tests easier to read. |
||
20 | * |
||
21 | * As language parameter is ignored from providers and replced with values in tests, this is used to mark value of |
||
22 | * language argument instead of either askingproviders to use 0, or a valid language array which would then not be |
||
23 | * used. |
||
24 | */ |
||
25 | const LANG_ARG = 0; |
||
26 | |||
27 | /** |
||
28 | * @var \object|\PHPUnit_Framework_MockObject_MockObject |
||
29 | */ |
||
30 | protected $innerApiServiceMock; |
||
31 | |||
32 | /** |
||
33 | * @var object |
||
34 | */ |
||
35 | protected $service; |
||
36 | |||
37 | /** |
||
38 | * @var \eZ\Publish\Core\Repository\SiteAccessAware\Language\LanguageResolver|\PHPUnit_Framework_MockObject_MockObject |
||
39 | */ |
||
40 | protected $languageResolverMock; |
||
41 | |||
42 | abstract public function getAPIServiceClassName(); |
||
43 | |||
44 | abstract public function getSiteAccessAwareServiceClassName(); |
||
45 | |||
46 | public function setUp() |
||
47 | { |
||
48 | parent::setUp(); |
||
49 | $this->innerApiServiceMock = $this->getMockBuilder($this->getAPIServiceClassName())->getMock(); |
||
50 | $this->languageResolverMock = $this->getMockBuilder(LanguageResolver::class) |
||
51 | ->disableOriginalConstructor() |
||
52 | ->getMock(); |
||
53 | $serviceClassName = $this->getSiteAccessAwareServiceClassName(); |
||
54 | |||
55 | $this->service = new $serviceClassName( |
||
56 | $this->innerApiServiceMock, |
||
57 | $this->languageResolverMock |
||
58 | ); |
||
59 | } |
||
60 | |||
61 | protected function tearDown() |
||
62 | { |
||
63 | unset($this->service); |
||
64 | unset($this->languageResolverMock); |
||
65 | unset($this->innerApiServiceMock); |
||
66 | parent::tearDown(); |
||
67 | } |
||
68 | |||
69 | /** |
||
70 | * @return array See signature on {@link testForPassTrough} for arguments and their type. |
||
71 | */ |
||
72 | abstract public function providerForPassTroughMethods(); |
||
73 | |||
74 | /** |
||
75 | * Make sure these methods does nothing more then passing the arguments to inner service. |
||
76 | * |
||
77 | * Methods tested here are basically those without as languages argument. |
||
78 | * |
||
79 | * @dataProvider providerForPassTroughMethods |
||
80 | * |
||
81 | * @param string $method |
||
82 | * @param array $arguments |
||
83 | * @param bool $return |
||
84 | */ |
||
85 | final public function testForPassTrough($method, array $arguments, $return = true) |
||
86 | { |
||
87 | $this->innerApiServiceMock |
||
88 | ->expects($this->once()) |
||
89 | ->method($method) |
||
90 | ->with(...$arguments) |
||
91 | ->willReturn($return); |
||
92 | |||
93 | $actualReturn = $this->service->$method(...$arguments); |
||
94 | |||
95 | if ($return) { |
||
96 | $this->assertTrue($actualReturn); |
||
97 | } else { |
||
98 | $this->assertNull($actualReturn); |
||
99 | } |
||
100 | } |
||
101 | |||
102 | /** |
||
103 | * @return array See signature on {@link testForLanguagesLookup} for arguments and their type. |
||
104 | * NOTE: languages / prioritizedLanguage, can be set to 0, it will be replaced by tests methods. |
||
105 | */ |
||
106 | abstract public function providerForLanguagesLookupMethods(); |
||
107 | |||
108 | /** |
||
109 | * Method to be able to customize the logic for setting expected language argument during {@see testForLanguagesLookup()}. |
||
110 | * |
||
111 | * @param array $arguments |
||
112 | * @param int $languageArgumentIndex |
||
113 | * @param array $languages |
||
114 | * |
||
115 | * @return array |
||
116 | */ |
||
117 | protected function setLanguagesLookupExpectedArguments(array $arguments, $languageArgumentIndex, array $languages) |
||
123 | |||
124 | /** |
||
125 | * Method to be able to customize the logic for setting expected language argument during {@see testForLanguagesLookup()}. |
||
126 | * |
||
127 | * @param array $arguments |
||
128 | * @param int $languageArgumentIndex |
||
129 | * |
||
130 | * @return array |
||
131 | */ |
||
132 | protected function setLanguagesLookupArguments(array $arguments, $languageArgumentIndex) |
||
138 | |||
139 | /** |
||
140 | * Test that language aware methods does a language lookup when language is not set. |
||
141 | * |
||
142 | * @dataProvider providerForLanguagesLookupMethods |
||
143 | * |
||
144 | * @param string $method |
||
145 | * @param array $arguments |
||
146 | * @param bool $return |
||
147 | * @param int $languageArgumentIndex From 0 and up, so the array index on $arguments. |
||
148 | */ |
||
149 | final public function testForLanguagesLookup($method, array $arguments, $return, $languageArgumentIndex, callable $callback = null) |
||
179 | |||
180 | /** |
||
181 | * Method to be able to customize the logic for setting expected language argument during {@see testForLanguagesPassTrough()}. |
||
182 | * |
||
183 | * @param array $arguments |
||
184 | * @param int $languageArgumentIndex |
||
185 | * @param array $languages |
||
186 | * |
||
187 | * @return array |
||
188 | */ |
||
189 | protected function setLanguagesPassTroughArguments(array $arguments, $languageArgumentIndex, array $languages) |
||
195 | |||
196 | /** |
||
197 | * Make sure these methods does nothing more then passing the arguments to inner service. |
||
198 | * |
||
199 | * @dataProvider providerForLanguagesLookupMethods |
||
200 | * |
||
201 | * @param string $method |
||
202 | * @param array $arguments |
||
203 | * @param bool $return |
||
204 | * @param int $languageArgumentIndex From 0 and up, so the array index on $arguments. |
||
205 | */ |
||
206 | final public function testForLanguagesPassTrough($method, array $arguments, $return, $languageArgumentIndex, callable $callback = null) |
||
233 | } |
||
234 |