Completed
Push — master ( b994b4...59818d )
by Ivannis Suárez
04:15
created

VisiteeInterfaceTestCase   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 86
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 1

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 6
c 2
b 0
f 1
lcom 2
cbo 1
dl 0
loc 86
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A testCreate() 0 9 1
A visitorInterface() 0 4 1
A shouldVisitMethod() 0 4 1
B testAcceptVisitor() 0 26 1
A acceptVisitorDataProvider() 0 7 1
A newMockVisitorInterface() 0 4 1
1
<?php
2
/**
3
 * This file is part of the Cubiche package.
4
 *
5
 * Copyright (c) Cubiche
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace Cubiche\Core\Visitor\Tests\Units;
11
12
use Cubiche\Core\Visitor\VisiteeInterface;
13
use Cubiche\Core\Visitor\VisitorInterface;
14
use Cubiche\Tests\TestCase;
15
16
/**
17
 * Visitee Interface Test Case Class.
18
 *
19
 * @author Karel Osorio Ramírez <[email protected]>
20
 */
21
abstract class VisiteeInterfaceTestCase extends TestCase
22
{
23
    /**
24
     * Test create.
25
     */
26
    public function testCreate()
27
    {
28
        $this
29
            ->given($visitee = $this->newDefaultTestedInstance())
30
            ->then()
31
                ->object($visitee)
32
                    ->isInstanceOf(VisiteeInterface::class)
33
        ;
34
    }
35
36
    /**
37
     * Test accept.
38
     *
39
     * @param VisitorInterface $visitorMock
40
     * @param string           $shouldVisitMethod
41
     * @param string           $acceptVisitorMethod
0 ignored issues
show
Bug introduced by
There is no parameter named $acceptVisitorMethod. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
42
     *
43
     * @dataProvider acceptVisitorDataProvider
44
     */
45
    public function testAcceptVisitor($visitorMock, $shouldVisitMethod)
46
    {
47
        $this
48
            ->given($visitorMock, $shouldVisitMethod)
49
            ->calling($visitorMock)
50
                ->methods(
51
                    function ($method) use ($shouldVisitMethod) {
52
                        return $method === \strtolower($shouldVisitMethod);
53
                    }
54
                )
55
                ->return = 25
56
            ;
57
58
        $this
59
            /* @var \Cubiche\Core\Visitor\VisiteeInterface $visitee */
60
            ->given($visitee = $this->newDefaultTestedInstance())
61
            ->when($result = $visitee->accept($visitorMock))
62
            ->then()
63
                ->mock($visitorMock)
64
                    ->call($shouldVisitMethod)
65
                        ->withArguments($visitee)
66
                        ->once()
67
                ->integer($result)
68
                    ->isEqualTo(25)
69
        ;
70
    }
71
72
    /**
73
     * @return string[][]
74
     */
75
    protected function acceptVisitorDataProvider()
76
    {
77
        return array(
78
            array($this->newMockVisitorInterface(), $this->shouldVisitMethod()),
79
            array($this->newMockInstance(VisitorInterface::class), 'visit'),
80
        );
81
    }
82
83
    /**
84
     * @return string
85
     */
86
    protected function visitorInterface()
87
    {
88
        return VisitorInterface::class;
89
    }
90
91
    /**
92
     * @return string
93
     */
94
    protected function shouldVisitMethod()
95
    {
96
        return 'visit';
97
    }
98
99
    /**
100
     * @return object
101
     */
102
    protected function newMockVisitorInterface()
103
    {
104
        return $this->newMockInstance($this->visitorInterface());
105
    }
106
}
107