1: <?php
2:
3: namespace Chromabits\Nucleus\Testing\Traits;
4:
5: use Chromabits\Nucleus\Exceptions\LackOfCoffeeException;
6: use Chromabits\Nucleus\Support\Std;
7: use Chromabits\Nucleus\Testing\Impersonator;
8: use Chromabits\Nucleus\Testing\Mocking\CallAndThrowExpectation;
9: use Chromabits\Nucleus\Testing\Mocking\CallExpectation;
10: use Closure;
11: use Mockery\MockInterface;
12:
13: 14: 15: 16: 17: 18:
19: trait ImpersonationTrait
20: {
21: 22: 23: 24: 25:
26: public function impersonator()
27: {
28: return Impersonator::define();
29: }
30:
31: 32: 33:
34: protected function getCommonProvisions()
35: {
36: return [];
37: }
38:
39: 40: 41: 42: 43: 44: 45:
46: public function impersonatorWithCommon()
47: {
48: $impersonator = $this->impersonator();
49:
50: Std::map(function ($value, $key) use ($impersonator) {
51: if (is_array($value) || $value instanceof Closure) {
52: $impersonator->mock($key, $value);
53:
54: return;
55: }
56:
57: $impersonator->provide($value);
58: }, $this->getCommonProvisions());
59:
60: return $impersonator;
61: }
62:
63: 64: 65: 66: 67: 68: 69: 70: 71: 72:
73: public function on(
74: $methodName,
75: array $arguments,
76: $return = null,
77: $times = 1
78: ) {
79: return Impersonator::on($methodName, $arguments, $return, $times);
80: }
81:
82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92:
93: public function throwOn(
94: $methodName,
95: array $arguments,
96: $exceptionClass,
97: $exceptionMessage = '',
98: $exceptionCode = 0
99: ) {
100: return Impersonator::throwOn(
101: $methodName,
102: $arguments,
103: $exceptionClass,
104: $exceptionMessage,
105: $exceptionCode
106: );
107: }
108:
109: 110: 111: 112: 113: 114: 115: 116:
117: public function expectationsToMock($type, $expectations)
118: {
119: return $this->impersonator()->expectationsToMock($type, $expectations);
120: }
121: }