Why an "Undefined offset" throws an exception in one machine, but shows a notice in another?

I am getting different results on my local machine than on Travis for a simple test.

Here is the test:

class FooTest extends TestCase
{
    public function testArrayKeyUndefined(): void
    {
        $a = [1 => 'a', 2 => 'b', 3 => 'c'];
        $this->assertEquals('a', $a[1]);
        $this->assertEquals('c', $a[3]);
        $this->expectException(ErrorException::class);
        $b = $a[99];
    }
}

on my local machine, the test passes. On Travis (with PHP 7.2 and 7.3), it does not:

FooTest::testArrayKeyUndefined
Undefined offset: 99

my phpunit.xml.dist file includes this

<phpunit
    backupGlobals="false"
    backupStaticAttributes="false"
    colors="true"
    convertErrorsToExceptions="true"
    convertNoticesToExceptions="true"
    convertWarningsToExceptions="true"
    processIsolation="false"
    stopOnFailure="false"
    bootstrap="./src/lib/bootstrap.php"
>

I am actually using simple-phpunit with Symfony 5. This loads PHPUnit 8.3.5

Other tests that expect real exceptions are working as expected. Only the ErrorException is not working at Travis (but still working on my local machine).

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *