Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 2 |
CRAP | |
28.57% |
2 / 7 |
InstanceMockPass | |
0.00% |
0 / 1 |
|
0.00% |
0 / 2 |
6.28 | |
28.57% |
2 / 7 |
apply | |
0.00% |
0 / 1 |
2.50 | |
50.00% |
2 / 4 |
|||
appendToClass | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 3 |
<?php | |
namespace Mockery\Generator\StringManipulation\Pass; | |
use Mockery\Generator\MockConfiguration; | |
class InstanceMockPass | |
{ | |
const INSTANCE_MOCK_CODE = <<<MOCK | |
protected \$_mockery_ignoreVerification = true; | |
public function __construct() | |
{ | |
\$this->_mockery_ignoreVerification = false; | |
\$associatedRealObject = \Mockery::fetchMock(__CLASS__); | |
\$directors = \$associatedRealObject->mockery_getExpectations(); | |
foreach (\$directors as \$method=>\$director) { | |
\$expectations = \$director->getExpectations(); | |
// get the director method needed | |
\$existingDirector = \$this->mockery_getExpectationsFor(\$method); | |
if (!\$existingDirector) { | |
\$existingDirector = new \Mockery\ExpectationDirector(\$method, \$this); | |
\$this->mockery_setExpectationsFor(\$method, \$existingDirector); | |
} | |
foreach (\$expectations as \$expectation) { | |
\$clonedExpectation = clone \$expectation; | |
\$existingDirector->addExpectation(\$clonedExpectation); | |
} | |
} | |
\Mockery::getContainer()->rememberMock(\$this); | |
} | |
MOCK; | |
public function apply($code, MockConfiguration $config) | |
{ | |
if ($config->isInstanceMock()) { | |
$code = $this->appendToClass($code, static::INSTANCE_MOCK_CODE); | |
} | |
return $code; | |
} | |
protected function appendToClass($class, $code) | |
{ | |
$lastBrace = strrpos($class, "}"); | |
$class = substr($class, 0, $lastBrace) . $code . "\n }\n"; | |
return $class; | |
} | |
} |