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

[HHVM] Cannot mock abstract classes which don't fully implement an interface #223

Closed
colinodell opened this issue Apr 13, 2015 · 8 comments

Comments

@colinodell
Copy link

I'm experiencing an issue which seems to be caused by commit c684a8a and/or HHVM. I'm essentially unable to mock an abstract class which doesn't fully implement an interface.

You can replicate the issue by defining an interface with two methods:

interface TestInterface
{
    public function foo();

    public function bar();
}

And then create an abstract instance which only implements one of the methods:

abstract class AbstractTestClass implements TestInterface
{
    public function foo()
    {
        return 'foo';
    }
}

Running a test like this fails:

$mock = $this->getMockForAbstractClass('AbstractTestClass');
$this->assertEquals('foo', $mock->foo());

// Fatal error: Class Mock_AbstractTestClass_727654a9 contains abstract method (bar) and must therefore be declared abstract or implement the remaining methods

This behavior only occurs when using 2.3.1 on HHVM (I'm using 3.6.1). 2.3.0 works just fine because it doesn't contain commit d4cc5f0b. Also, this behavior does not seem to occur in PHP on 2.3.1.

@colinodell
Copy link
Author

Oops, that's the wrong error message. One moment, let me fix that.

@colinodell
Copy link
Author

Error message has been corrected:

Fatal error: Class Mock_AbstractTestClass_727654a9 contains abstract method (bar) and must therefore be declared abstract or implement the remaining methods

You can see a real-world instance of this occurring in my project's Travis build:

@colinodell
Copy link
Author

Yeah, this looks like an HHVM issue. You could either wait until it's fixed or (temporarily) revert that change.

@Tobion
Copy link

Tobion commented Apr 23, 2015

+1

@sgolemon
Copy link

@colinodell Not knowing the innards of PHPUnit, I'm unclear why this is an HHVM issue. Is Mock_AbstractTestClass_727654a9 declaring a bar method? If not then it has to be abstract.. that's working-as-intended as far as I can see from here...

@sgolemon
Copy link

Nevermind, looks like @fredemmott already looked into it and it's been fixed in the 3.8 branch.
https://twitter.com/fredemmott/status/609034548328976384

@dave1010
Copy link

It looks like this was fixed in hhvm by this: facebook/hhvm@b786320

I haven't verified this yet.

@colinodell
Copy link
Author

@sgolemon HHVM contained a bug in their ReflectionClass implementation: facebook/hhvm#5170

weierophinney added a commit to weierophinney/zf-oauth2 that referenced this issue Jul 6, 2015
HHVM < 3.8 has a bug in its Reflection API that breaks the behavior of
`getMockForAbstractClass()` ([see phpunit-mock-objects #223](sebastianbergmann/phpunit-mock-objects#223)).
weierophinney added a commit to weierophinney/zf-oauth2 that referenced this issue Jul 6, 2015
- Skip a test in HHVM < 3.8. HHVM < 3.8 has a bug in its Reflection API that breaks the behavior of `getMockForAbstractClass()` ([see phpunit-mock-objects #223](sebastianbergmann/phpunit-mock-objects#223)).
- Use a valid PDO connection option when testing passing connection options to PDO.
chappy84 added a commit to chappy84/google-analytics-server-side that referenced this issue Jul 12, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants