| 148 |
lars |
1 |
<?php declare(strict_types=1);
|
|
|
2 |
/*
|
|
|
3 |
* This file is part of PHPUnit.
|
|
|
4 |
*
|
|
|
5 |
* (c) Sebastian Bergmann <sebastian@phpunit.de>
|
|
|
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 PHPUnit\Framework\MockObject;
|
|
|
11 |
|
|
|
12 |
use PHPUnit\Framework\MockObject\Builder\InvocationMocker as InvocationMockerBuilder;
|
|
|
13 |
use PHPUnit\Framework\MockObject\Rule\InvocationOrder;
|
|
|
14 |
|
|
|
15 |
/**
|
|
|
16 |
* @internal This trait is not covered by the backward compatibility promise for PHPUnit
|
|
|
17 |
*/
|
|
|
18 |
trait Api
|
|
|
19 |
{
|
|
|
20 |
/**
|
|
|
21 |
* @var ConfigurableMethod[]
|
|
|
22 |
*/
|
|
|
23 |
private static $__phpunit_configurableMethods;
|
|
|
24 |
|
|
|
25 |
/**
|
|
|
26 |
* @var object
|
|
|
27 |
*/
|
|
|
28 |
private $__phpunit_originalObject;
|
|
|
29 |
|
|
|
30 |
/**
|
|
|
31 |
* @var bool
|
|
|
32 |
*/
|
|
|
33 |
private $__phpunit_returnValueGeneration = true;
|
|
|
34 |
|
|
|
35 |
/**
|
|
|
36 |
* @var InvocationHandler
|
|
|
37 |
*/
|
|
|
38 |
private $__phpunit_invocationMocker;
|
|
|
39 |
|
|
|
40 |
/** @noinspection MagicMethodsValidityInspection */
|
|
|
41 |
public static function __phpunit_initConfigurableMethods(ConfigurableMethod ...$configurableMethods): void
|
|
|
42 |
{
|
|
|
43 |
if (isset(static::$__phpunit_configurableMethods)) {
|
|
|
44 |
throw new ConfigurableMethodsAlreadyInitializedException(
|
|
|
45 |
'Configurable methods is already initialized and can not be reinitialized'
|
|
|
46 |
);
|
|
|
47 |
}
|
|
|
48 |
|
|
|
49 |
static::$__phpunit_configurableMethods = $configurableMethods;
|
|
|
50 |
}
|
|
|
51 |
|
|
|
52 |
/** @noinspection MagicMethodsValidityInspection */
|
|
|
53 |
public function __phpunit_setOriginalObject($originalObject): void
|
|
|
54 |
{
|
|
|
55 |
$this->__phpunit_originalObject = $originalObject;
|
|
|
56 |
}
|
|
|
57 |
|
|
|
58 |
/** @noinspection MagicMethodsValidityInspection */
|
|
|
59 |
public function __phpunit_setReturnValueGeneration(bool $returnValueGeneration): void
|
|
|
60 |
{
|
|
|
61 |
$this->__phpunit_returnValueGeneration = $returnValueGeneration;
|
|
|
62 |
}
|
|
|
63 |
|
|
|
64 |
/** @noinspection MagicMethodsValidityInspection */
|
|
|
65 |
public function __phpunit_getInvocationHandler(): InvocationHandler
|
|
|
66 |
{
|
|
|
67 |
if ($this->__phpunit_invocationMocker === null) {
|
|
|
68 |
$this->__phpunit_invocationMocker = new InvocationHandler(
|
|
|
69 |
static::$__phpunit_configurableMethods,
|
|
|
70 |
$this->__phpunit_returnValueGeneration
|
|
|
71 |
);
|
|
|
72 |
}
|
|
|
73 |
|
|
|
74 |
return $this->__phpunit_invocationMocker;
|
|
|
75 |
}
|
|
|
76 |
|
|
|
77 |
/** @noinspection MagicMethodsValidityInspection */
|
|
|
78 |
public function __phpunit_hasMatchers(): bool
|
|
|
79 |
{
|
|
|
80 |
return $this->__phpunit_getInvocationHandler()->hasMatchers();
|
|
|
81 |
}
|
|
|
82 |
|
|
|
83 |
/** @noinspection MagicMethodsValidityInspection */
|
|
|
84 |
public function __phpunit_verify(bool $unsetInvocationMocker = true): void
|
|
|
85 |
{
|
|
|
86 |
$this->__phpunit_getInvocationHandler()->verify();
|
|
|
87 |
|
|
|
88 |
if ($unsetInvocationMocker) {
|
|
|
89 |
$this->__phpunit_invocationMocker = null;
|
|
|
90 |
}
|
|
|
91 |
}
|
|
|
92 |
|
|
|
93 |
public function expects(InvocationOrder $matcher): InvocationMockerBuilder
|
|
|
94 |
{
|
|
|
95 |
return $this->__phpunit_getInvocationHandler()->expects($matcher);
|
|
|
96 |
}
|
|
|
97 |
}
|