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