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 class. |
25
|
|
|
*/ |
26
|
|
|
public function testClass() |
27
|
|
|
{ |
28
|
|
|
$this |
29
|
|
|
->testedClass |
30
|
|
|
->implements(VisiteeInterface::class) |
31
|
|
|
; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Test accept. |
36
|
|
|
* |
37
|
|
|
* @param VisiteeInterface $visitee |
38
|
|
|
* @param VisitorInterface $visitorMock |
39
|
|
|
* @param string $shouldVisitMethod |
40
|
|
|
* @param VisiteeInterface $withVisitee |
41
|
|
|
* |
42
|
|
|
* @dataProvider acceptVisitorDataProvider |
43
|
|
|
*/ |
44
|
|
|
public function testAcceptVisitor(VisiteeInterface $visitee, $visitorMock, $shouldVisitMethod, $withVisitee = null) |
45
|
|
|
{ |
46
|
|
|
$this |
47
|
|
|
->given($visitorMock, $shouldVisitMethod) |
48
|
|
|
->calling($visitorMock) |
49
|
|
|
->methods( |
50
|
|
|
function ($method) use ($shouldVisitMethod) { |
51
|
|
|
return $method === \strtolower($shouldVisitMethod); |
52
|
|
|
} |
53
|
|
|
) |
54
|
|
|
->return = 25 |
55
|
|
|
; |
56
|
|
|
|
57
|
|
|
$this |
58
|
|
|
->given($visitee, $withVisitee = $withVisitee === null ? $visitee : $withVisitee) |
59
|
|
|
->when($result = $visitee->accept($visitorMock)) |
60
|
|
|
->then() |
61
|
|
|
->mock($visitorMock) |
62
|
|
|
->call($shouldVisitMethod) |
63
|
|
|
->withArguments($withVisitee) |
64
|
|
|
->once() |
65
|
|
|
->integer($result) |
66
|
|
|
->isEqualTo(25) |
67
|
|
|
; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @return string[][] |
72
|
|
|
*/ |
73
|
|
|
protected function acceptVisitorDataProvider() |
74
|
|
|
{ |
75
|
|
|
$visitee = $this->newDefaultTestedInstance(); |
76
|
|
|
|
77
|
|
|
return array( |
78
|
|
|
array($visitee, $this->newMockInstance(VisitorInterface::class), 'visit'), |
79
|
|
|
); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|