Walt Sorensen Walt Sorensen - 1 year ago 190
PHP Question

PHP Unit Fatal error: Call to undefined method PHPUnit_Framework_MockObject_InvocationMocker

I'm having an issue with php unit on hhvm where getmock() failing on phpunit 4.8.27 for a class with the following message

Fatal error: Call to undefined method PHPUnit_Framework_MockObject_InvocationMocker::getTableColumns() in /joomla-cms/libraries/joomla/table/table.php on line 241

Test Code failing is located at https://github.com/photodude/joomla-cms/blob/patch-1/tests/unit/suites/libraries/cms/installer/JInstallerAdapterTest.php#L111
for the test code this "fails/errors" the test with no Fatal error

$mockTableExtension = $this->getMock('JTableExtension', array('find', 'load'), array($this->getMockDatabase()));

but if I use the stored value

$mockDatabase = $this->getMockDatabase();

and type cast the
object to array I get the Fatal error listed above.

$mockTableExtension = $this->getMock('JTableExtension', array('find', 'load'), (array) $mockDatabase);

Travis test with the
object and object type cast to array var_dumped https://travis-ci.org/photodude/joomla-cms/jobs/172201634#L1427-L2178

Everything passes and works just fine in php, the issue is specific to testing on hhvm
Am I doing something wrong in the mock setup? or is there something else going on?

note: I recently tested this portion of the test suit on php unit 5.6 and got the same issue. So I'm not sure what we've don't wrong in the setup of these tests.

Answer Source

I found there is some issue with array($this->getMockDatabase()) in one of the tests on hhvm. Replacing array($this->getMockDatabase()) with array(self::$driver) all of the issues were resolved.

I also replaced the direct use of getMock with the getMockBuilder (for compatibility with phpunit 5.6)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download