it_throws_exception_on_missing_service()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Devmachine\Bundle\ServicesInjectorBundle\Tests\Request;
4
5
use Devmachine\Bundle\ServicesInjectorBundle\Request\Services;
6
use Devmachine\Bundle\ServicesInjectorBundle\ServiceLocator\CallableServiceLocator;
7
8
class ServicesTest extends \PHPUnit_Framework_TestCase
9
{
10
    /**
11
     * @test
12
     *
13
     * @expectedException \InvalidArgumentException
14
     */
15
    public function it_throws_exception_on_missing_service()
16
    {
17
        $services = new Services([], new CallableServiceLocator(function ($id) {}));
0 ignored issues
show
Unused Code introduced by
The parameter $id is not used and could be removed. ( Ignorable by Annotation )

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

17
        $services = new Services([], new CallableServiceLocator(function (/** @scrutinizer ignore-unused */ $id) {}));

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
18
        $services->get('twig');
19
    }
20
21
    /**
22
     * @test
23
     */
24
    public function it_proxies_mapped_service_id()
25
    {
26
        $locator = $this->getMock('Devmachine\Bundle\ServicesInjectorBundle\ServiceLocator\ServiceLocator');
27
        $locator
28
            ->expects($this->once())
29
            ->method('get')
30
            ->with($this->equalTo('router'))
31
        ;
32
33
        (new Services(['url_generator' => 'router'], $locator))->get('url_generator');
34
    }
35
36
    /**
37
     * @test
38
     *
39
     * @expectedException \InvalidArgumentException
40
     * @expectedExceptionMessage Service with alias "foo" is not registered.
41
     */
42
    public function it_throws_exception_on_aliased_method_call_with_invalid_service()
43
    {
44
        $services = new Services([], new CallableServiceLocator(function ($id) {}));
0 ignored issues
show
Unused Code introduced by
The parameter $id is not used and could be removed. ( Ignorable by Annotation )

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

44
        $services = new Services([], new CallableServiceLocator(function (/** @scrutinizer ignore-unused */ $id) {}));

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
45
        $services->getFoo();
0 ignored issues
show
Bug introduced by
The method getFoo() does not exist on Devmachine\Bundle\Servic...Bundle\Request\Services. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

45
        $services->/** @scrutinizer ignore-call */ getFoo();
Loading history...
46
    }
47
48
    /**
49
     * @test
50
     */
51
    public function it_maps_method_call_service_retrieval()
52
    {
53
        $ids = [];
54
        $map = ['url_generator' => 'router', 'template' => 'twig'];
55
56
        $services = new Services($map, new CallableServiceLocator(function ($id) use (&$ids) { $ids[] = $id; }));
57
        $services->getUrlGenerator();
0 ignored issues
show
Bug introduced by
The method getUrlGenerator() does not exist on Devmachine\Bundle\Servic...Bundle\Request\Services. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

57
        $services->/** @scrutinizer ignore-call */ getUrlGenerator();
Loading history...
58
        $services->getTemplate();
0 ignored issues
show
Bug introduced by
The method getTemplate() does not exist on Devmachine\Bundle\Servic...Bundle\Request\Services. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

58
        $services->/** @scrutinizer ignore-call */ getTemplate();
Loading history...
59
60
        $this->assertSame(['router', 'twig'], $ids);
61
    }
62
}
63