DictionarySpec::it_is_initializable()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace spec\Knp\DictionaryBundle\Templating\Extension;
6
7
use Knp\DictionaryBundle\Dictionary;
8
use Knp\DictionaryBundle\Dictionary\Collection;
9
use Knp\DictionaryBundle\Templating\Extension;
10
use PhpSpec\ObjectBehavior;
11
use Webmozart\Assert\Assert;
12
13
final class DictionarySpec extends ObjectBehavior
14
{
15
    function let(Dictionary $dico1, Dictionary $dico2)
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...
16
    {
17
        $dico1->offsetGet('foo')->willReturn('bar');
18
        $dico1->getName()->willReturn('test');
19
20
        $dico2->offsetGet('foo')->willReturn(false);
21
        $dico2->getName()->willReturn('other');
22
23
        $this->beConstructedWith(new Collection($dico1->getWrappedObject(), $dico2->getWrappedObject()));
0 ignored issues
show
Bug introduced by
The method getWrappedObject() does not exist on Knp\DictionaryBundle\Dictionary. ( Ignorable by Annotation )

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

23
        $this->beConstructedWith(new Collection($dico1->/** @scrutinizer ignore-call */ getWrappedObject(), $dico2->getWrappedObject()));

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...
24
    }
25
26
    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...
27
    {
28
        $this->shouldHaveType(Extension\Dictionary::class);
29
    }
30
31
    function it_has_a_filter_and_a_function()
32
    {
33
        $filters   = $this->getFilters();
0 ignored issues
show
Bug introduced by
The method getFilters() does not exist on spec\Knp\DictionaryBundl...xtension\DictionarySpec. 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

33
        /** @scrutinizer ignore-call */ 
34
        $filters   = $this->getFilters();
Loading history...
34
        $functions = $this->getFunctions();
0 ignored issues
show
Bug introduced by
The method getFunctions() does not exist on spec\Knp\DictionaryBundl...xtension\DictionarySpec. 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

34
        /** @scrutinizer ignore-call */ 
35
        $functions = $this->getFunctions();
Loading history...
35
36
        $filters[0]->getName()->shouldReturn('dictionary');
37
        $functions[0]->getName()->shouldReturn('dictionary');
38
    }
39
40
    function it_returns_a_dictionary_by_its_name($dico1, $dico2)
41
    {
42
        $functions = $this->getFunctions();
43
        $callable  = current($functions->getWrappedObject())->getCallable();
44
45
        Assert::eq($callable('test'), $dico1->getWrappedObject());
46
        Assert::eq($callable('other'), $dico2->getWrappedObject());
47
    }
48
49
    function it_returns_a_value_from_a_dictionary()
50
    {
51
        $filters  = $this->getFilters();
52
        $callable = current($filters->getWrappedObject())->getCallable();
53
54
        Assert::eq($callable('foo', 'test'), 'bar');
55
        Assert::eq($callable('foo', 'other'), false);
56
    }
57
}
58