Why does my script not trigger a notification when accessing a value in an undefined array?

I have a validation method that looks like this:

$row = $this->GetRowFromUserTable($id);
$this->assertLessThan(time(), time($row['last_update']));

When $ row is null, access to $ row ['last_update'] should start E_NOTICE, and this test should fail, but it is not.

This code crashes on the first statement, so I know that $ row is null (the binding is the same):

$row = $this->GetRowFromUserTable($id);
$this->assertNotNull($row);
$this->assertLessThan(time(), time($row['last_update']));

When I write this:

$row = $this->GetRowFromUserTable($id);
$this->assertEquals(E_ALL, error_reporting());
$this->assertLessThan(time(), time($row['last_update']));

it succeeds, so I'm also sure that error_reporting is right, and this situation should have something to do with PHPUnit.

I am using PHPUnit 3.5.6

I read this question: Can I get PHPUnit to crash if the code issues a notification? but the answer is to use a newer version of PHPUnit, but this answer is from 2009, so this is not it.

: IDE 6.9.1 NetBeans .

+3
3

Saidly "convertNoticesToExceptions" (+1).

$foo = $undefinedVariable; - , , // ?

, phpunit/php (, , ), :

<?php

class myTest extends PHPUnit_Framework_TestCase {
    public function testFoo() {
        $x = $foo;
        $this->assertTrue(true);
    }
}

( -no-configuration, , phpunit.dist.xml phpunit.xml)

phpunit --no-configuration foo.php 

:

PHPUnit 3.5.6 .

: 0 , : 2.50Mb

1 :

1) myTest:: testFoo Undefined: Foo

/home/user/foo.php:5 ​​

, litte

+2

, , E_NOTICE. undefined E_NOTICE, , .

+2

Do you have a convertNoticesToExceptions configuration property set to true?

+1
source

Source: https://habr.com/ru/post/1783844/


All Articles