Skip to content

expectException fails with getMockForAbstractClass #3752

@moritz-h

Description

@moritz-h
Q A
PHPUnit version 8.2.x
PHP version 7.2.19
Installation Method Composer

I have an abstract class which may throws an exception within the constructor. The test case for this class calls expectException() and then getMockForAbstractClass(). The test result is error, because the (actually expected) exception is thrown.
This occurs with phpunit >8.2.0. With 8.1.6 everything was working as expected.

Here is a minimal example:

<?php

use PHPUnit\Framework\TestCase;

abstract class AbstractFooBar
{
    public function __construct()
    {
        throw new InvalidArgumentException('test');
    }
}

class AbstractFooBarTest extends TestCase
{
    public function testConstructorException()
    {
        $this->expectException(InvalidArgumentException::class);
        $this->getMockForAbstractClass(AbstractFooBar::class);
    }
}

Metadata

Metadata

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions