ChoosingDataLoaderFactoryTest   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 23
c 1
b 0
f 1
dl 0
loc 44
rs 10
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A shouldCreateCorrectLoaderWithParameter() 0 38 1
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);
0 ignored issues
show
Bug introduced by
The method method() does not exist on Symfony\Component\Depend...tion\ContainerInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

33
        $container->/** @scrutinizer ignore-call */ 
34
                    method("hasParameter")->willReturn(true);

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.

Loading history...
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