Passed
Branch master (1f874f)
by Kamil
04:32 queued 02:22
created

it_should_resolve_arguments()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 53
Code Lines 38

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 53
rs 9.5797
cc 1
eloc 38
nc 1
nop 2

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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