| 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 / 2 | CRAP | 33.33% covered (danger) | 33.33% | 2 / 6
InstanceMockPass | 0.00% covered (danger) | 0.00% | 0 / 1 | 0.00% covered (danger) | 0.00% | 0 / 2 | 5.67 | 33.33% covered (danger) | 33.33% | 2 / 6
apply($code, MockConfiguration $config) | 0.00% covered (danger) | 0.00% | 0 / 1 | 2.15 | 66.67% covered (warning) | 66.67% | 2 / 3
appendToClass($class, $code) | 0.00% covered (danger) | 0.00% | 0 / 1 | 2 | 0.00% covered (danger) | 0.00% | 0 / 3

1 | <?php
2 |
3 | namespace Mockery\Generator\StringManipulation\Pass;
4 |
5 | use Mockery\Generator\MockConfiguration;
6 |
7 | class InstanceMockPass
8 | {
9 | const INSTANCE_MOCK_CODE = <<<MOCK
10 |
11 | protected \$_mockery_ignoreVerification = true;
12 |
13 | public function __construct()
14 | {
15 | \$this->_mockery_ignoreVerification = false;
16 | \$associatedRealObject = \Mockery::fetchMock(__CLASS__);
17 | \$directors = \$associatedRealObject->mockery_getExpectations();
18 | foreach (\$directors as \$method=>\$director) {
19 | \$expectations = \$director->getExpectations();
20 | // get the director method needed
21 | \$existingDirector = \$this->mockery_getExpectationsFor(\$method);
22 | if (!\$existingDirector) {
23 | \$existingDirector = new \Mockery\ExpectationDirector(\$method, \$this);
24 | \$this->mockery_setExpectationsFor(\$method, \$existingDirector);
25 | }
26 | foreach (\$expectations as \$expectation) {
27 | \$clonedExpectation = clone \$expectation;
28 | \$existingDirector->addExpectation(\$clonedExpectation);
29 | }
30 | }
31 | \Mockery::getContainer()->rememberMock(\$this);
32 | }
33 | MOCK;
34 |
35 | public function apply($code, MockConfiguration $config)
36 | {
37 | if ($config->isInstanceMock()) {
38 | $code = $this->appendToClass($code, static::INSTANCE_MOCK_CODE);
39 | }
40 |
41 | return $code;
42 | }
43 |
44 | protected function appendToClass($class, $code)
45 | {
46 | $lastBrace = strrpos($class, "}");
47 | $class = substr($class, 0, $lastBrace) . $code . "\n }\n";
48 | return $class;
49 | }
50 | }