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