Skip to content

Commit 219e572

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 f9e07be commit 219e572

File tree

2 files changed

+3
-17
lines changed

2 files changed

+3
-17
lines changed

src/Prophecy/Doubler/Generator/ClassMirror.php

-14
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,6 @@
3131
*/
3232
class ClassMirror
3333
{
34-
private const REFLECTABLE_METHODS = array(
35-
'__construct',
36-
'__destruct',
37-
'__sleep',
38-
'__wakeup',
39-
'__toString',
40-
'__call',
41-
'__invoke'
42-
);
4334

4435
/**
4536
* Reflects provided arguments into class node.
@@ -116,11 +107,6 @@ private function reflectClassToNode(ReflectionClass $class, Node\ClassNode $node
116107
}
117108

118109
foreach ($class->getMethods(ReflectionMethod::IS_PUBLIC) as $method) {
119-
if (0 === strpos($method->getName(), '_')
120-
&& !in_array($method->getName(), self::REFLECTABLE_METHODS)) {
121-
continue;
122-
}
123-
124110
if (true === $method->isFinal()) {
125111
$node->addUnextendableMethod($method->getName());
126112
continue;

tests/Doubler/Generator/ClassMirrorTest.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -302,18 +302,18 @@ public function it_reflects_all_interfaces_methods()
302302
/**
303303
* @test
304304
*/
305-
public function it_ignores_virtually_private_methods()
305+
public function it_does_not_ignores_virtually_private_methods()
306306
{
307307
$class = new \ReflectionClass('Fixtures\Prophecy\WithVirtuallyPrivateMethod');
308308

309309
$mirror = new ClassMirror();
310310

311311
$classNode = $mirror->reflect($class, array());
312312

313-
$this->assertCount(2, $classNode->getMethods());
313+
$this->assertCount(3, $classNode->getMethods());
314314
$this->assertTrue($classNode->hasMethod('isAbstract'));
315315
$this->assertTrue($classNode->hasMethod('__toString'));
316-
$this->assertFalse($classNode->hasMethod('_getName'));
316+
$this->assertTrue($classNode->hasMethod('_getName'));
317317
}
318318

319319
/**

0 commit comments

Comments
 (0)