Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
CRAP | |
66.67% |
6 / 9 |
RemoveBuiltinMethodsThatAreFinalPass | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
5.93 | |
66.67% |
6 / 9 |
apply | |
0.00% |
0 / 1 |
5.93 | |
66.67% |
6 / 9 |
<?php | |
namespace Mockery\Generator\StringManipulation\Pass; | |
use Mockery\Generator\MockConfiguration; | |
/** | |
* The standard Mockery\Mock class includes some methods to ease mocking, such | |
* as __wakeup, however if the target has a final __wakeup method, it can't be | |
* mocked. This pass removes the builtin methods where they are final on the | |
* target | |
*/ | |
class RemoveBuiltinMethodsThatAreFinalPass | |
{ | |
protected $methods = array( | |
'__wakeup' => '/public function __wakeup\(\)\s+\{.*?\}/sm', | |
); | |
public function apply($code, MockConfiguration $config) | |
{ | |
$target = $config->getTargetClass(); | |
if (!$target) { | |
return $code; | |
} | |
foreach ($target->getMethods() as $method) { | |
if ($method->isFinal() && isset($this->methods[$method->getName()])) { | |
$code = preg_replace($this->methods[$method->getName()], '', $code); | |
} | |
} | |
return $code; | |
} | |
} |