MockIterator   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 5
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 2
c 0
b 0
f 0
dl 0
loc 5
rs 10
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A getIterator() 0 3 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\Iterator;
9
use PhpSpec\ObjectBehavior;
10
use Symfony\Component\DependencyInjection\Container;
11
12
final class IteratorSpec 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(Iterator::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' => 'iterator'])->shouldReturn(true);
0 ignored issues
show
Bug introduced by
The method supports() does not exist on spec\Knp\DictionaryBundl...ry\Factory\IteratorSpec. 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' => 'iterator'])->shouldReturn(true);
Loading history...
32
    }
33
34
    function it_creates_a_dictionary($container, MockIterator $service)
35
    {
36
        $config = [
37
            'service' => 'service.id',
38
        ];
39
40
        $container->get('service.id')->willReturn($service);
41
        $service->getIterator()->willReturn(new \ArrayIterator([
0 ignored issues
show
Bug introduced by
The method willReturn() does not exist on Traversable. It seems like you code against a sub-type of Traversable such as RectorPrefix202506\Nette\Utils\Finder or RectorPrefix202506\Nette\Utils\Html or RectorPrefix202506\Nette\Utils\ArrayList or RectorPrefix202506\Nette\Iterators\CachingIterator. ( Ignorable by Annotation )

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

41
        $service->getIterator()->/** @scrutinizer ignore-call */ willReturn(new \ArrayIterator([
Loading history...
42
            'foo1' => 'bar1',
43
            'foo2' => 'bar2',
44
            'foo3' => 'bar3',
45
        ]));
46
47
        $dictionary = $this->create('yolo', $config);
0 ignored issues
show
Bug introduced by
The method create() does not exist on spec\Knp\DictionaryBundl...ry\Factory\IteratorSpec. 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

47
        /** @scrutinizer ignore-call */ 
48
        $dictionary = $this->create('yolo', $config);
Loading history...
48
49
        $dictionary->getName()->shouldBe('yolo');
50
        $dictionary->getValues()->shouldBe([
51
            'foo1' => 'bar1',
52
            'foo2' => 'bar2',
53
            'foo3' => 'bar3',
54
        ]);
55
    }
56
}
57
58
abstract class MockIterator implements \IteratorAggregate
59
{
60
    public function getIterator()
61
    {
62
        return yield from [];
63
    }
64
}
65