| 148 |
lars |
1 |
<?php
|
|
|
2 |
/**
|
|
|
3 |
* Mockery
|
|
|
4 |
*
|
|
|
5 |
* LICENSE
|
|
|
6 |
*
|
|
|
7 |
* This source file is subject to the new BSD license that is bundled
|
|
|
8 |
* with this package in the file LICENSE.txt.
|
|
|
9 |
* It is also available through the world-wide-web at this URL:
|
|
|
10 |
* http://github.com/padraic/mockery/blob/master/LICENSE
|
|
|
11 |
* If you did not receive a copy of the license and are unable to
|
|
|
12 |
* obtain it through the world-wide-web, please send an email
|
|
|
13 |
* to padraic@php.net so we can send you a copy immediately.
|
|
|
14 |
*
|
|
|
15 |
* @category Mockery
|
|
|
16 |
* @package Mockery
|
|
|
17 |
* @copyright Copyright (c) 2010 Pádraic Brady (http://blog.astrumfutura.com)
|
|
|
18 |
* @license http://github.com/padraic/mockery/blob/master/LICENSE New BSD License
|
|
|
19 |
*/
|
|
|
20 |
|
|
|
21 |
namespace Mockery\Generator;
|
|
|
22 |
|
|
|
23 |
use Mockery\Generator\StringManipulation\Pass\CallTypeHintPass;
|
|
|
24 |
use Mockery\Generator\StringManipulation\Pass\ClassNamePass;
|
|
|
25 |
use Mockery\Generator\StringManipulation\Pass\ClassPass;
|
|
|
26 |
use Mockery\Generator\StringManipulation\Pass\ConstantsPass;
|
|
|
27 |
use Mockery\Generator\StringManipulation\Pass\InstanceMockPass;
|
|
|
28 |
use Mockery\Generator\StringManipulation\Pass\InterfacePass;
|
|
|
29 |
use Mockery\Generator\StringManipulation\Pass\MagicMethodTypeHintsPass;
|
|
|
30 |
use Mockery\Generator\StringManipulation\Pass\MethodDefinitionPass;
|
|
|
31 |
use Mockery\Generator\StringManipulation\Pass\Pass;
|
|
|
32 |
use Mockery\Generator\StringManipulation\Pass\RemoveBuiltinMethodsThatAreFinalPass;
|
|
|
33 |
use Mockery\Generator\StringManipulation\Pass\RemoveDestructorPass;
|
|
|
34 |
use Mockery\Generator\StringManipulation\Pass\RemoveUnserializeForInternalSerializableClassesPass;
|
|
|
35 |
use Mockery\Generator\StringManipulation\Pass\TraitPass;
|
|
|
36 |
use Mockery\Generator\StringManipulation\Pass\AvoidMethodClashPass;
|
|
|
37 |
|
|
|
38 |
class StringManipulationGenerator implements Generator
|
|
|
39 |
{
|
|
|
40 |
protected $passes = array();
|
|
|
41 |
|
|
|
42 |
/**
|
|
|
43 |
* Creates a new StringManipulationGenerator with the default passes
|
|
|
44 |
*
|
|
|
45 |
* @return StringManipulationGenerator
|
|
|
46 |
*/
|
|
|
47 |
public static function withDefaultPasses()
|
|
|
48 |
{
|
|
|
49 |
return new static([
|
|
|
50 |
new CallTypeHintPass(),
|
|
|
51 |
new MagicMethodTypeHintsPass(),
|
|
|
52 |
new ClassPass(),
|
|
|
53 |
new TraitPass(),
|
|
|
54 |
new ClassNamePass(),
|
|
|
55 |
new InstanceMockPass(),
|
|
|
56 |
new InterfacePass(),
|
|
|
57 |
new AvoidMethodClashPass(),
|
|
|
58 |
new MethodDefinitionPass(),
|
|
|
59 |
new RemoveUnserializeForInternalSerializableClassesPass(),
|
|
|
60 |
new RemoveBuiltinMethodsThatAreFinalPass(),
|
|
|
61 |
new RemoveDestructorPass(),
|
|
|
62 |
new ConstantsPass(),
|
|
|
63 |
]);
|
|
|
64 |
}
|
|
|
65 |
|
|
|
66 |
public function __construct(array $passes)
|
|
|
67 |
{
|
|
|
68 |
$this->passes = $passes;
|
|
|
69 |
}
|
|
|
70 |
|
|
|
71 |
public function generate(MockConfiguration $config)
|
|
|
72 |
{
|
|
|
73 |
$code = file_get_contents(__DIR__ . '/../Mock.php');
|
|
|
74 |
$className = $config->getName() ?: $config->generateName();
|
|
|
75 |
|
|
|
76 |
$namedConfig = $config->rename($className);
|
|
|
77 |
|
|
|
78 |
foreach ($this->passes as $pass) {
|
|
|
79 |
$code = $pass->apply($code, $namedConfig);
|
|
|
80 |
}
|
|
|
81 |
|
|
|
82 |
return new MockDefinition($namedConfig, $code);
|
|
|
83 |
}
|
|
|
84 |
|
|
|
85 |
public function addPass(Pass $pass)
|
|
|
86 |
{
|
|
|
87 |
$this->passes[] = $pass;
|
|
|
88 |
}
|
|
|
89 |
}
|