phpunit icon indicating copy to clipboard operation
phpunit copied to clipboard

getMockForAbstractClass throws error

Open tombevers opened this issue 15 years ago • 4 comments

When using $this->getMockForAbstractClass() with PHPUnit 3.6RC2 I get following error: "Invalid argument supplied for foreach()". This was working correclty in PHPUnit 3.5

tombevers avatar Sep 08 '11 07:09 tombevers

Please post the complete error message. Thanks.

sebastianbergmann avatar Sep 08 '11 07:09 sebastianbergmann

Well it acctualy does not throw an error but shows the error as the tests fails.

There was 1 error:

  1. PC_DataGrid_Column_Renderer_AbstractTest::testSimple Invalid argument supplied for foreach()

/tests/library/PC/DataGrid/Column/Renderer/AbstractTest.php:10

_abstract = $this->getMockForAbstractClass('PC_DataGrid_Column_Renderer_Abstract'); } public function testSimple() { $this->assertEquals('foo', 'foo'); } ``` }

tombevers avatar Sep 08 '11 07:09 tombevers

I cannot reproduce this issue:

sb@vmware ~ % cat AbstractTest.php 
<?php
abstract class AbstractClass
{
    public function foo()
    {
        return TRUE;
    }

    public abstract function bar();
}

class AbstractTest extends PHPUnit_Framework_TestCase
{
    public function testFoo()
    {
        $o = $this->getMockForAbstractClass('AbstractClass');
    }
}


sb@vmware ~ % phpunit AbstractTest
PHPUnit 3.6.0RC2 by Sebastian Bergmann.

.

Time: 0 seconds, Memory: 4.00Mb

OK (1 test, 0 assertions)

sebastianbergmann avatar Sep 08 '11 08:09 sebastianbergmann

Now I see it, in my abstract class there is no abstract function :s

tombevers avatar Sep 08 '11 08:09 tombevers