Skip to content
This repository was archived by the owner on Feb 20, 2023. It is now read-only.

Commit f6942d1

Browse files
Closes #156
1 parent f055539 commit f6942d1

4 files changed

Lines changed: 23 additions & 1 deletion

File tree

src/Framework/MockObject/Generator.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -898,6 +898,10 @@ protected function generateMockedMethodDefinitionFromExisting($templateDir, Refl
898898
$modifier = 'public';
899899
}
900900

901+
if ($method->isStatic()) {
902+
$modifier .= ' static';
903+
}
904+
901905
if ($method->returnsReference()) {
902906
$reference = '&';
903907
} else {
@@ -962,7 +966,6 @@ protected function canMockMethod(ReflectionMethod $method)
962966
{
963967
if ($method->isConstructor() ||
964968
$method->isFinal() ||
965-
$method->isStatic() ||
966969
isset($this->blacklistedMethodNames[$method->getName()])) {
967970
return FALSE;
968971
}

tests/MockObjectTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -758,6 +758,18 @@ public function testCreateTwoMocksOfOneWsdlFile()
758758
$mock = $this->getMockFromWsdl(__DIR__ . '/_files/GoogleSearch.wsdl');
759759
}
760760

761+
/**
762+
* @see https://github.com/sebastianbergmann/phpunit-mock-objects/issues/156
763+
* @ticket 156
764+
*/
765+
public function testInterfaceWithStaticMethodCanBeStubbed()
766+
{
767+
$this->assertInstanceOf(
768+
'InterfaceWithStaticMethod',
769+
$this->getMock('InterfaceWithStaticMethod')
770+
);
771+
}
772+
761773
private function resetMockObjects()
762774
{
763775
$refl = new ReflectionObject($this);
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
interface InterfaceWithStaticMethod
3+
{
4+
public static function staticMethod();
5+
}
6+

tests/autoload.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ function($class) {
1919
'framework_mockobject_invocation_statictest' => '/MockObject/Invocation/StaticTest.php',
2020
'framework_mockobjecttest' => '/MockObjectTest.php',
2121
'framework_proxyobjecttest' => '/ProxyObjectTest.php',
22+
'interfacewithstaticmethod' => '/_files/InterfaceWithStaticMethod.php',
2223
'methodcallback' => '/_files/MethodCallback.php',
2324
'methodcallbackbyreference' => '/_files/MethodCallbackByReference.php',
2425
'mockable' => '/_files/Mockable.php',

0 commit comments

Comments
 (0)