KeyValueSpec::let()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
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\KeyValue;
9
use Knp\DictionaryBundle\ValueTransformer;
10
use PhpSpec\ObjectBehavior;
11
12
final class KeyValueSpec extends ObjectBehavior
13
{
14
    function let(ValueTransformer $transformer)
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($transformer);
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(KeyValue::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' => 'key_value'])->shouldReturn(true);
0 ignored issues
show
Bug introduced by
The method supports() does not exist on spec\Knp\DictionaryBundl...ry\Factory\KeyValueSpec. 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' => 'key_value'])->shouldReturn(true);
Loading history...
32
    }
33
34
    function it_throws_exception_if_no_content_is_provided()
35
    {
36
        $this
37
            ->shouldThrow(\InvalidArgumentException::class)
38
            ->during('create', ['yolo', []])
39
        ;
40
    }
41
42
    function it_creates_a_dictionary($transformer)
43
    {
44
        $config = [
45
            'content' => [
46
                'foo1' => 'bar1',
47
                'foo2' => 'bar2',
48
                'foo3' => 'bar3',
49
            ],
50
        ];
51
52
        $transformer->transform('bar1')->willReturn('bar1');
53
        $transformer->transform('bar2')->willReturn('bar2');
54
        $transformer->transform('bar3')->willReturn('bar3');
55
        $transformer->transform('foo1')->willReturn('foo1');
56
        $transformer->transform('foo2')->willReturn('foo2');
57
        $transformer->transform('foo3')->willReturn('foo3');
58
59
        $dictionary = $this->create('yolo', $config);
0 ignored issues
show
Bug introduced by
The method create() does not exist on spec\Knp\DictionaryBundl...ry\Factory\KeyValueSpec. 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

59
        /** @scrutinizer ignore-call */ 
60
        $dictionary = $this->create('yolo', $config);
Loading history...
60
61
        $dictionary->getName()->shouldBe('yolo');
62
        $dictionary->getValues()->shouldBe([
63
            'foo1' => 'bar1',
64
            'foo2' => 'bar2',
65
            'foo3' => 'bar3',
66
        ]);
67
    }
68
}
69