Skip to content

Commit c9d1655

Browse files
committed
Support methods prefixed with underscore
Fixes #108 While it was a common convention to prefix "private" methods with an underscore in earlier version of php, with support for method visibility this is no longer common. Additionally there are a number of exception such as the Soap library where this convention did not hold and code was not mockable.
1 parent bbcd738 commit c9d1655

2 files changed

Lines changed: 4 additions & 19 deletions

File tree

src/Prophecy/Doubler/Generator/ClassMirror.php

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,6 @@
3131
*/
3232
class ClassMirror
3333
{
34-
private static $reflectableMethods = array(
35-
'__construct',
36-
'__destruct',
37-
'__sleep',
38-
'__wakeup',
39-
'__toString',
40-
'__call',
41-
'__invoke'
42-
);
43-
4434
/**
4535
* Reflects provided arguments into class node.
4636
*
@@ -109,11 +99,6 @@ private function reflectClassToNode(ReflectionClass $class, Node\ClassNode $node
10999
}
110100

111101
foreach ($class->getMethods(ReflectionMethod::IS_PUBLIC) as $method) {
112-
if (0 === strpos($method->getName(), '_')
113-
&& !in_array($method->getName(), self::$reflectableMethods)) {
114-
continue;
115-
}
116-
117102
if (true === $method->isFinal()) {
118103
$node->addUnextendableMethod($method->getName());
119104
continue;

tests/Doubler/Generator/ClassMirrorTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -307,18 +307,18 @@ public function it_reflects_all_interfaces_methods()
307307
/**
308308
* @test
309309
*/
310-
public function it_ignores_virtually_private_methods()
310+
public function it_does_not_ignores_virtually_private_methods()
311311
{
312312
$class = new \ReflectionClass('Fixtures\Prophecy\WithVirtuallyPrivateMethod');
313313

314314
$mirror = new ClassMirror();
315315

316316
$classNode = $mirror->reflect($class, array());
317317

318-
$this->assertCount(2, $classNode->getMethods());
318+
$this->assertCount(3, $classNode->getMethods());
319319
$this->assertTrue($classNode->hasMethod('isAbstract'));
320320
$this->assertTrue($classNode->hasMethod('__toString'));
321-
$this->assertFalse($classNode->hasMethod('_getName'));
321+
$this->assertTrue($classNode->hasMethod('_getName'));
322322
}
323323

324324
/**
@@ -614,7 +614,7 @@ public function it_can_not_double_an_enum()
614614
}
615615

616616
$this->expectException(ClassMirrorException::class);
617-
617+
618618
$classNode = (new ClassMirror())->reflect(new \ReflectionClass('Fixtures\Prophecy\Enum'), []);
619619
}
620620

0 commit comments

Comments
 (0)