InvokableSpec   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 19
c 1
b 0
f 0
dl 0
loc 43
rs 10
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A it_is_initializable() 0 3 1
A it_is_a_factory() 0 3 1
A let() 0 3 1
A it_supports_specific_config() 0 3 1
A it_creates_a_dictionary() 0 21 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace spec\Knp\DictionaryBundle\Dictionary\Factory;
6
7
use Knp\DictionaryBundle\Dictionary\Factory;
8
use Knp\DictionaryBundle\Dictionary\Factory\Invokable;
9
use PhpSpec\ObjectBehavior;
10
use Symfony\Component\DependencyInjection\Container;
11
12
final class InvokableSpec extends ObjectBehavior
13
{
14
    function let(Container $container)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
15
    {
16
        $this->beConstructedWith($container);
17
    }
18
19
    function it_is_initializable()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
20
    {
21
        $this->shouldHaveType(Invokable::class);
22
    }
23
24
    function it_is_a_factory()
25
    {
26
        $this->shouldHaveType(Factory::class);
27
    }
28
29
    function it_supports_specific_config()
30
    {
31
        $this->supports(['type' => 'callable'])->shouldReturn(true);
0 ignored issues
show
Bug introduced by
The method supports() does not exist on spec\Knp\DictionaryBundl...y\Factory\InvokableSpec. 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

31
        $this->/** @scrutinizer ignore-call */ 
32
               supports(['type' => 'callable'])->shouldReturn(true);
Loading history...
32
    }
33
34
    function it_creates_a_dictionary($container, MockInvokable $service)
35
    {
36
        $config = [
37
            'service' => 'service.id',
38
            'method'  => 'getYolo',
39
        ];
40
41
        $container->get('service.id')->willReturn($service);
42
        $service->getYolo()->willReturn([
43
            'foo1' => 'bar1',
44
            'foo2' => 'bar2',
45
            'foo3' => 'bar3',
46
        ]);
47
48
        $dictionary = $this->create('yolo', $config);
0 ignored issues
show
Bug introduced by
The method create() does not exist on spec\Knp\DictionaryBundl...y\Factory\InvokableSpec. 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

48
        /** @scrutinizer ignore-call */ 
49
        $dictionary = $this->create('yolo', $config);
Loading history...
49
50
        $dictionary->getName()->shouldBe('yolo');
51
        $dictionary->getValues()->shouldBe([
52
            'foo1' => 'bar1',
53
            'foo2' => 'bar2',
54
            'foo3' => 'bar3',
55
        ]);
56
    }
57
}
58
59
abstract class MockInvokable
60
{
61
    /**
62
     * @return mixed[]
63
     */
64
    public function getYolo(): array
65
    {
66
        return [];
67
    }
68
}
69