Tuesday, April 4, 2017

ReflectionException: Class PHPUnit_Framework_Error does not exist

ReflectionException: Class PHPUnit_Framework_Error does not exist

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testFailingInclude()
    {
        include 'not_existing_file.php';
    }

Solution 1:

/**
 * @expectedException \PHPUnit\Framework\Error\Warning
 */
public function testFailingInclude()
{
    include 'not_existing_file.php';
}

Solution 2:

public function testFailingInclude()
{
    $this->expectException(\PHPUnit\Framework\Error\Error::class);

    include 'not_existing_file.php';
}

No comments: