1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Doctrine\Tests\Common\Persistence; |
4
|
|
|
|
5
|
|
|
use Doctrine\Common\Persistence\ObjectManagerDecorator; |
6
|
|
|
use Doctrine\Common\Persistence\ObjectManager; |
7
|
|
|
|
8
|
|
|
class NullObjectManagerDecorator extends ObjectManagerDecorator |
9
|
|
|
{ |
10
|
|
|
public function __construct(ObjectManager $wrapped) |
11
|
|
|
{ |
12
|
|
|
$this->wrapped = $wrapped; |
13
|
|
|
} |
14
|
|
|
} |
15
|
|
|
|
16
|
|
|
class ObjectManagerDecoratorTest extends \PHPUnit\Framework\TestCase |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @var \PHPUnit_Framework_MockObject_MockObject|ObjectManager |
20
|
|
|
*/ |
21
|
|
|
private $wrapped; |
22
|
|
|
private $decorated; |
23
|
|
|
|
24
|
|
|
public function setUp() |
25
|
|
|
{ |
26
|
|
|
$this->wrapped = $this->createMock(ObjectManager::class); |
27
|
|
|
$this->decorated = new NullObjectManagerDecorator($this->wrapped); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function getMethodParameters() |
31
|
|
|
{ |
32
|
|
|
$class = new \ReflectionClass(ObjectManager::class); |
33
|
|
|
$voidMethods = [ |
34
|
|
|
'persist', |
35
|
|
|
'remove', |
36
|
|
|
'clear', |
37
|
|
|
'detach', |
38
|
|
|
'refresh', |
39
|
|
|
'flush', |
40
|
|
|
'initializeObject', |
41
|
|
|
]; |
42
|
|
|
|
43
|
|
|
$methods = []; |
44
|
|
|
foreach ($class->getMethods() as $method) { |
45
|
|
|
$isVoidMethod = in_array($method->getName(), $voidMethods, true); |
46
|
|
|
if ($method->getNumberOfRequiredParameters() === 0) { |
47
|
|
|
$methods[] = [$method->getName(), [], $isVoidMethod]; |
48
|
|
|
} elseif ($method->getNumberOfRequiredParameters() > 0) { |
49
|
|
|
$methods[] = [$method->getName(), array_fill(0, $method->getNumberOfRequiredParameters(), 'req') ?: [], $isVoidMethod]; |
50
|
|
|
} |
51
|
|
|
if ($method->getNumberOfParameters() != $method->getNumberOfRequiredParameters()) { |
52
|
|
|
$methods[] = [$method->getName(), array_fill(0, $method->getNumberOfParameters(), 'all') ?: [], $isVoidMethod]; |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
return $methods; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @dataProvider getMethodParameters |
61
|
|
|
*/ |
62
|
|
|
public function testAllMethodCallsAreDelegatedToTheWrappedInstance($method, array $parameters, $isVoidMethod) |
63
|
|
|
{ |
64
|
|
|
$returnedValue = $isVoidMethod ? null : 'INNER VALUE FROM ' . $method; |
65
|
|
|
$stub = $this->wrapped |
66
|
|
|
->expects($this->once()) |
67
|
|
|
->method($method) |
68
|
|
|
->will($this->returnValue($returnedValue)); |
69
|
|
|
|
70
|
|
|
call_user_func_array([$stub, 'with'], $parameters); |
71
|
|
|
|
72
|
|
|
self::assertSame($returnedValue, call_user_func_array([$this->decorated, $method], $parameters)); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|