|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Copyright (C) 2018 Gerrit Addiks. |
|
4
|
|
|
* This package (including this file) was released under the terms of the GPL-3.0. |
|
5
|
|
|
* You should have received a copy of the GNU General Public License along with this program. |
|
6
|
|
|
* If not, see <http://www.gnu.org/licenses/> or send me a mail so i can send you a copy. |
|
7
|
|
|
* @license GPL-3.0 |
|
8
|
|
|
* @author Gerrit Addiks <[email protected]> |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace Addiks\RDMBundle\Tests\DataLoader; |
|
12
|
|
|
|
|
13
|
|
|
use PHPUnit\Framework\TestCase; |
|
14
|
|
|
use Addiks\RDMBundle\DataLoader\ChoosingDataLoaderFactory; |
|
15
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
|
16
|
|
|
use Addiks\RDMBundle\DataLoader\DataLoaderInterface; |
|
17
|
|
|
|
|
18
|
|
|
final class ChoosingDataLoaderFactoryTest extends TestCase |
|
19
|
|
|
{ |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @test |
|
23
|
|
|
*/ |
|
24
|
|
|
public function shouldCreateCorrectLoaderWithParameter() |
|
25
|
|
|
{ |
|
26
|
|
|
/** @var ContainerInterface $container */ |
|
27
|
|
|
$container = $this->createMock(ContainerInterface::class); |
|
28
|
|
|
|
|
29
|
|
|
$serviceFoo = $this->createMock(DataLoaderInterface::class); |
|
30
|
|
|
$serviceBar = $this->createMock(DataLoaderInterface::class); |
|
31
|
|
|
$serviceDefault = $this->createMock(DataLoaderInterface::class); |
|
32
|
|
|
|
|
33
|
|
|
$container->method("hasParameter")->willReturn(true); |
|
|
|
|
|
|
34
|
|
|
$container->method("getParameter")->willReturn("bar"); |
|
35
|
|
|
|
|
36
|
|
|
$container->method("has")->will($this->returnValueMap([ |
|
37
|
|
|
['foo_service', true], |
|
38
|
|
|
['bar_service', true], |
|
39
|
|
|
['the_default_service', true] |
|
40
|
|
|
])); |
|
41
|
|
|
|
|
42
|
|
|
$container->method("get")->will($this->returnValueMap([ |
|
43
|
|
|
['foo_service', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $serviceFoo], |
|
44
|
|
|
['bar_service', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $serviceBar], |
|
45
|
|
|
['the_default_service', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $serviceDefault] |
|
46
|
|
|
])); |
|
47
|
|
|
|
|
48
|
|
|
$dataLoader = new ChoosingDataLoaderFactory( |
|
49
|
|
|
$container, |
|
50
|
|
|
[ |
|
51
|
|
|
'foo' => 'foo_service', |
|
52
|
|
|
'bar' => 'bar_service' |
|
53
|
|
|
], |
|
54
|
|
|
"some_parameter_name", |
|
55
|
|
|
"the_default_service" |
|
56
|
|
|
); |
|
57
|
|
|
|
|
58
|
|
|
/** @var DataLoaderInterface $actualDataLoader */ |
|
59
|
|
|
$actualDataLoader = $dataLoader->createDataLoader(); |
|
60
|
|
|
|
|
61
|
|
|
$this->assertSame($serviceBar, $actualDataLoader); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
} |
|
65
|
|
|
|
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.