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: 34: 35: 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: }
51: