Passed
Push — master ( 8f03a2...1f874f )
by Kamil
02:46
created

ArgumentResolverSpec   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 1
cbo 3
dl 0
loc 74
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A let() 0 6 1
A it_should_be_argument_resolver() 0 5 1
A it_should_resolve_arguments() 0 53 1
1
<?php
2
declare(strict_types=1);
3
namespace spec\VirCom\Behat3ZendFramework3Extension\Context\Argument;
4
5
use VirCom\Behat3ZendFramework3Extension\Context\Argument\ArgumentResolver;
6
7
use Zend\Mvc\ApplicationInterface;
8
use Zend\ServiceManager\ServiceManager;
9
10
use Behat\Behat\Context\Argument\ArgumentResolver as ArgumentResolverInterface;
11
12
use ReflectionClass;
13
14
use PhpSpec\ObjectBehavior;
15
16
class ArgumentResolverSpec extends ObjectBehavior
17
{
18
    /**
19
     * @var ApplicationInterface
20
     */
21
    protected $application;
22
    
23
    public function let(
24
        ApplicationInterface $application
25
    ) {
26
        $this->application = $application;
27
        $this->beConstructedWith($this->application);
28
    }
29
    
30
    public function it_should_be_argument_resolver()
31
    {
32
        $this->shouldHaveType(ArgumentResolver::class);
33
        $this->shouldImplement(ArgumentResolverInterface::class);
34
    }
35
    
36
    public function it_should_resolve_arguments(
37
            ReflectionClass $reflectionClass,
38
       ServiceManager $serviceManager
39
    ) {
40
        $arguments = [
41
            '@Config',
42
            '@My\Example\Service',
43
            '1',
44
            'simple string',
45
        ];
46
        
47
        $result = [
48
            '@Config@',
49
            '@My\Example\Service@',
50
            '1',
51
            'simple string',
52
        ];
53
        
54
        $this->application->getServiceManager()
55
            ->shouldBeCalled()
56
            ->willReturn($serviceManager);
57
        
58
        $serviceManager->has()
59
            ->shouldBeCalled()
60
            ->withArguments([
61
                substr($arguments[0], 1),
62
            ])
63
            ->willReturn(true);
64
        
65
        $serviceManager->get()
66
            ->shouldBeCalled()
67
            ->withArguments([
68
                substr($arguments[0], 1),
69
            ])
70
            ->willReturn($result[0]);
71
        
72
        $serviceManager->has()
73
            ->shouldBeCalled()
74
            ->withArguments([
75
                substr($arguments[1], 1),
76
            ])
77
            ->willReturn(true);
78
        
79
        $serviceManager->get()
80
            ->shouldBeCalled()
81
            ->withArguments([
82
                substr($arguments[1], 1),
83
            ])
84
            ->willReturn($result[1]);
85
        
86
        $this->resolveArguments($reflectionClass, $arguments)
87
            ->shouldReturn($result);
88
    }
89
}
90