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\StringManipulation\Pass; |
22
|
|
|
|
23
|
|
|
use Mockery\Generator\MockConfiguration; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Internal classes can not be instantiated with the newInstanceWithoutArgs |
27
|
|
|
* reflection method, so need the serialization hack. If the class also |
28
|
|
|
* implements Serializable, we need to replace the standard unserialize method |
29
|
|
|
* definition with a dummy |
30
|
|
|
*/ |
31
|
|
|
class RemoveUnserializeForInternalSerializableClassesPass |
32
|
|
|
{ |
33
|
|
|
const DUMMY_METHOD_DEFINITION = 'public function unserialize($string) {} '; |
34
|
|
|
|
35
|
397 |
|
public function apply($code, MockConfiguration $config) |
36
|
|
|
{ |
37
|
397 |
|
$target = $config->getTargetClass(); |
38
|
|
|
|
39
|
397 |
|
if (!$target) { |
40
|
28 |
|
return $code; |
41
|
|
|
} |
42
|
|
|
|
43
|
373 |
|
if (!$target->hasInternalAncestor() || !$target->implementsInterface("Serializable")) { |
44
|
372 |
|
return $code; |
45
|
|
|
} |
46
|
|
|
|
47
|
1 |
|
$code = $this->appendToClass($code, self::DUMMY_METHOD_DEFINITION); |
48
|
|
|
|
49
|
1 |
|
return $code; |
50
|
|
|
} |
51
|
|
|
|
52
|
1 |
|
protected function appendToClass($class, $code) |
53
|
|
|
{ |
54
|
1 |
|
$lastBrace = strrpos($class, "}"); |
55
|
1 |
|
$class = substr($class, 0, $lastBrace) . $code . "\n }\n"; |
56
|
1 |
|
return $class; |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|