| Code Coverage
| Classes and Traits | Functions and Methods | Lines
Total | 0.00% covered (danger) | 0.00% | 0 / 1 | 0.00% covered (danger) | 0.00% | 0 / 1 | CRAP | 62.50% covered (warning) | 62.50% | 5 / 8
RemoveBuiltinMethodsThatAreFinalPass | 0.00% covered (danger) | 0.00% | 0 / 1 | 0.00% covered (danger) | 0.00% | 0 / 1 | 6.32 | 62.50% covered (warning) | 62.50% | 5 / 8
apply($code, MockConfiguration $config) | 0.00% covered (danger) | 0.00% | 0 / 1 | 6.32 | 62.50% covered (warning) | 62.50% | 5 / 8

1 | <?php
2 |
3 | namespace Mockery\Generator\StringManipulation\Pass;
4 |
5 | use Mockery\Generator\MockConfiguration;
6 |
7 | /**
8 | * The standard Mockery\Mock class includes some methods to ease mocking, such
9 | * as __wakeup, however if the target has a final __wakeup method, it can't be
10 | * mocked. This pass removes the builtin methods where they are final on the
11 | * target
12 | */
13 | class RemoveBuiltinMethodsThatAreFinalPass
14 | {
15 | protected $methods = array(
16 | '__wakeup' => '/public function __wakeup\(\)\s+\{.*?\}/sm',
17 | );
18 |
19 | public function apply($code, MockConfiguration $config)
20 | {
21 | $target = $config->getTargetClass();
22 |
23 | if (!$target) {
24 | return $code;
25 | }
26 |
27 | foreach ($target->getMethods() as $method) {
28 | if ($method->isFinal() && isset($this->methods[$method->getName()])) {
29 | $code = preg_replace($this->methods[$method->getName()], '', $code);
30 | }
31 | }
32 |
33 | return $code;
34 | }
35 |
36 | }