|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of the Cubiche/Async component. |
|
5
|
|
|
* |
|
6
|
|
|
* Copyright (c) Cubiche |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
namespace Cubiche\Core\Async\Tests\Units; |
|
12
|
|
|
|
|
13
|
|
|
use Cubiche\Core\Delegate\Delegate; |
|
14
|
|
|
use Cubiche\Tests\TestCase as BaseTestCase; |
|
15
|
|
|
use mageekguy\atoum\adapter as Adapter; |
|
16
|
|
|
use mageekguy\atoum\annotations\extractor as Extractor; |
|
17
|
|
|
use mageekguy\atoum\asserter\generator as Generator; |
|
18
|
|
|
use mageekguy\atoum\mock\aggregator as MockAggregator; |
|
19
|
|
|
use mageekguy\atoum\test\assertion\manager as Manager; |
|
20
|
|
|
use mageekguy\atoum\tools\variable\analyzer as Analyzer; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Test Case class. |
|
24
|
|
|
* |
|
25
|
|
|
* @author Karel Osorio Ramírez <[email protected]> |
|
26
|
|
|
*/ |
|
27
|
|
|
abstract class TestCase extends BaseTestCase |
|
28
|
|
|
{ |
|
29
|
|
|
/** |
|
30
|
|
|
* @param Adapter $adapter |
|
31
|
|
|
* @param Extractor $annotationExtractor |
|
32
|
|
|
* @param Generator $asserterGenerator |
|
33
|
|
|
* @param Manager $assertionManager |
|
34
|
|
|
* @param Closure $reflectionClassFactory |
|
35
|
|
|
* @param Closure $phpExtensionFactory |
|
36
|
|
|
* @param Analyzer $analyzer |
|
37
|
|
|
*/ |
|
38
|
|
|
public function __construct( |
|
39
|
|
|
Adapter $adapter = null, |
|
40
|
|
|
Extractor $annotationExtractor = null, |
|
41
|
|
|
Generator $asserterGenerator = null, |
|
42
|
|
|
Manager $assertionManager = null, |
|
43
|
|
|
\Closure $reflectionClassFactory = null, |
|
44
|
|
|
\Closure $phpExtensionFactory = null, |
|
45
|
|
|
Analyzer $analyzer = null |
|
46
|
|
|
) { |
|
47
|
|
|
parent::__construct( |
|
48
|
|
|
$adapter, |
|
49
|
|
|
$annotationExtractor, |
|
50
|
|
|
$asserterGenerator, |
|
51
|
|
|
$assertionManager, |
|
52
|
|
|
$reflectionClassFactory, |
|
53
|
|
|
$phpExtensionFactory, |
|
54
|
|
|
$analyzer |
|
55
|
|
|
); |
|
56
|
|
|
|
|
57
|
|
|
$this |
|
58
|
|
|
->getAssertionManager() |
|
59
|
|
|
->setHandler('delegateCall', function (MockAggregator $mock) { |
|
60
|
|
|
return $this->delegateCall($mock); |
|
61
|
|
|
}) |
|
62
|
|
|
; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* @param callable $callable |
|
67
|
|
|
* |
|
68
|
|
|
* @return \Cubiche\Core\Delegate\Delegate |
|
69
|
|
|
*/ |
|
70
|
|
|
protected function callableMock(callable $callable) |
|
71
|
|
|
{ |
|
72
|
|
|
$mockName = '\mock\\'.Delegate::class; |
|
73
|
|
|
|
|
74
|
|
|
return new $mockName($callable); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* @return \Cubiche\Core\Delegate\Delegate |
|
79
|
|
|
*/ |
|
80
|
|
|
protected function delegateMock($return = null) |
|
81
|
|
|
{ |
|
82
|
|
|
return $this->callableMock(function ($value = null) use ($return) { |
|
83
|
|
|
return $return === null ? $value : $return; |
|
84
|
|
|
}); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* @param mixed $return |
|
89
|
|
|
* |
|
90
|
|
|
* @return \Cubiche\Core\Delegate\Delegate |
|
91
|
|
|
*/ |
|
92
|
|
|
protected function delegateMockWithReturn($return) |
|
93
|
|
|
{ |
|
94
|
|
|
return $this->delegateMock($return); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* @param mixed $return |
|
|
|
|
|
|
99
|
|
|
* |
|
100
|
|
|
* @return \Cubiche\Core\Delegate\Delegate |
|
101
|
|
|
*/ |
|
102
|
|
|
protected function delegateMockWithException(\Exception $e) |
|
103
|
|
|
{ |
|
104
|
|
|
return $this->callableMock(function () use ($e) { |
|
105
|
|
|
throw $e; |
|
106
|
|
|
}); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* @param MockAggregator $mock |
|
111
|
|
|
* |
|
112
|
|
|
* @return mixed |
|
113
|
|
|
*/ |
|
114
|
|
|
protected function delegateCall(MockAggregator $mock) |
|
115
|
|
|
{ |
|
116
|
|
|
return $this->mock($mock)->call('__invoke'); |
|
117
|
|
|
} |
|
118
|
|
|
} |
|
119
|
|
|
|
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
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.