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 [email protected] 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\Pass; |
24
|
|
|
use Mockery\Generator\StringManipulation\Pass\RemoveDestructorPass; |
25
|
|
|
use Mockery\Generator\StringManipulation\Pass\CallTypeHintPass; |
26
|
|
|
use Mockery\Generator\StringManipulation\Pass\MagicMethodTypeHintsPass; |
27
|
|
|
use Mockery\Generator\StringManipulation\Pass\ClassNamePass; |
28
|
|
|
use Mockery\Generator\StringManipulation\Pass\ClassPass; |
29
|
|
|
use Mockery\Generator\StringManipulation\Pass\TraitPass; |
30
|
|
|
use Mockery\Generator\StringManipulation\Pass\InstanceMockPass; |
31
|
|
|
use Mockery\Generator\StringManipulation\Pass\InterfacePass; |
32
|
|
|
use Mockery\Generator\StringManipulation\Pass\MethodDefinitionPass; |
33
|
|
|
use Mockery\Generator\StringManipulation\Pass\RemoveBuiltinMethodsThatAreFinalPass; |
34
|
|
|
use Mockery\Generator\StringManipulation\Pass\RemoveUnserializeForInternalSerializableClassesPass; |
35
|
|
|
use Mockery\Generator\StringManipulation\Pass\AvoidMethodClashPass; |
36
|
|
|
|
37
|
|
|
class StringManipulationGenerator implements Generator |
38
|
|
|
{ |
39
|
|
|
protected $passes = array(); |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Creates a new StringManipulationGenerator with the default passes |
43
|
|
|
* |
44
|
|
|
* @return StringManipulationGenerator |
45
|
|
|
*/ |
46
|
409 |
|
public static function withDefaultPasses() |
47
|
|
|
{ |
48
|
409 |
|
return new static([ |
49
|
409 |
|
new CallTypeHintPass(), |
50
|
409 |
|
new MagicMethodTypeHintsPass(), |
51
|
409 |
|
new ClassPass(), |
52
|
409 |
|
new TraitPass(), |
53
|
409 |
|
new ClassNamePass(), |
54
|
409 |
|
new InstanceMockPass(), |
55
|
409 |
|
new InterfacePass(), |
56
|
409 |
|
new AvoidMethodClashPass(), |
57
|
409 |
|
new MethodDefinitionPass(), |
58
|
409 |
|
new RemoveUnserializeForInternalSerializableClassesPass(), |
59
|
409 |
|
new RemoveBuiltinMethodsThatAreFinalPass(), |
60
|
409 |
|
new RemoveDestructorPass(), |
61
|
|
|
]); |
62
|
|
|
} |
63
|
|
|
|
64
|
409 |
|
public function __construct(array $passes) |
65
|
|
|
{ |
66
|
409 |
|
$this->passes = $passes; |
67
|
409 |
|
} |
68
|
|
|
|
69
|
407 |
|
public function generate(MockConfiguration $config) |
70
|
|
|
{ |
71
|
407 |
|
$code = file_get_contents(__DIR__ . '/../Mock.php'); |
72
|
407 |
|
$className = $config->getName() ?: $config->generateName(); |
73
|
|
|
|
74
|
406 |
|
$namedConfig = $config->rename($className); |
75
|
|
|
|
76
|
406 |
|
foreach ($this->passes as $pass) { |
77
|
406 |
|
$code = $pass->apply($code, $namedConfig); |
78
|
|
|
} |
79
|
|
|
|
80
|
406 |
|
return new MockDefinition($namedConfig, $code); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
public function addPass(Pass $pass) |
84
|
|
|
{ |
85
|
|
|
$this->passes[] = $pass; |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|