Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getMockForAbstractClass fails when abstract class contains no abstract methods #45

Closed
gavD opened this issue Oct 14, 2010 · 3 comments
Closed

Comments

@gavD
Copy link

gavD commented Oct 14, 2010

Version : PHPUnit 3.5
Platform : PHP 5.3.2-1ubuntu4.5 with Suhosin-Patch (cli) (built: Sep 17 2010 13:41:55)

I appreciate that an abstract class with no abstract methods may seem a little odd, we have such classes that we want to test through PHPUnit. This unit tests demonstrates what I mean.

<?php
abstract class HasAbstractMethod {
    function foo() {}
    abstract function bar();
}
abstract class HasNoAbstractMethods {
    function foo() {}
}

class BugReport_getMockForAbstractClass_NoAbstractMethods extends PHPUnit_Framework_TestCase {
    public function testCanUseGetMockForAbstractClassWhenClassHasAbstractMethods() {
        $c = $this->getMockForAbstractClass('HasAbstractMethod');
    }

    public function testCanUseGetMockForAbstractClassWhenClassHasNoAbstractMethods() {
        $c = $this->getMockForAbstractClass('HasNoAbstractMethods');
        // this test fails:
        //Argument 2 passed to PHPUnit_Framework_MockObject_Generator::generateMock() must be an array, null given, called in /usr/share/php/PHPUnit/Framework/MockObject/Generator.php on line 283
    }
}

Would be a fairly straightforward mix - just to pass in a blank array rather than null in Generator.php:

230c230
<                 $methods = array();

---
>                 $methods = NULL;
@blt04
Copy link

blt04 commented Oct 14, 2010

This is a duplicate of sebastianbergmann/phpunit-mock-objects#22

@alexanderilyin
Copy link

Seems that I faced with same issue.

@sebastianbergmann
Copy link
Owner

Please open a new ticket under the PHPUnit_MockObject project in case the problem still persists.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants