| 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 | 52.63% covered (warning) | 52.63% | 10 / 19
ClassPass | 0.00% covered (danger) | 0.00% | 0 / 1 | 0.00% covered (danger) | 0.00% | 0 / 1 | 7.66 | 52.63% covered (warning) | 52.63% | 10 / 19
apply($code, MockConfiguration $config) | 0.00% covered (danger) | 0.00% | 0 / 1 | 7.66 | 52.63% covered (warning) | 52.63% | 10 / 19

1 | <?php
2 |
3 | namespace Mockery\Generator\StringManipulation\Pass;
4 |
5 | use Mockery\Generator\MockConfiguration;
6 |
7 | class ClassPass implements Pass
8 | {
9 | public function apply($code, MockConfiguration $config)
10 | {
11 | $target = $config->getTargetClass();
12 |
13 | if (!$target) {
14 | return $code;
15 | }
16 |
17 | if ($target->isFinal()) {
18 | return $code;
19 | }
20 |
21 | $className = ltrim($target->getName(), "\\");
22 | if (!class_exists($className)) {
23 |
24 | $targetCode = '<?php ';
25 |
26 | if ($target->inNamespace()) {
27 | $targetCode.= 'namespace ' . $target->getNamespaceName(). '; ';
28 | }
29 |
30 | $targetCode.= 'class ' . $target->getShortName() . ' {} ';
31 |
32 | /*
33 | * We could eval here, but it doesn't play well with the way
34 | * PHPUnit tries to backup global state and the require definition
35 | * loader
36 | */
37 | $tmpfname = tempnam(sys_get_temp_dir(), "Mockery");
38 | file_put_contents($tmpfname, $targetCode);
39 | require $tmpfname;
40 | }
41 |
42 | $code = str_replace(
43 | "implements MockInterface",
44 | "extends \\" . $className . " implements MockInterface",
45 | $code
46 | );
47 |
48 | return $code;
49 | }
50 | }