public function warningTriggeringExpectedBehaviour()
{
// reset last error
set_error_handler('var_dump', 0);
@$undef_var;
restore_error_handler();
$canary = error_get_last();
// precondition is that there was no error yet
$this->assertNotNull($canary, 'precondition not met');
// precondition of the error reporting level
$reporting = error_reporting();
// 22527 - E_ALL & ~E_DEPRECATED & ~E_STRICT (PHP 5.6)
// 32767 - E_ALL (Travis PHP 5.3, PHP 5.4)
$knownErrorLevels = array('E_ALL & ~E_DEPRECATED & ~E_STRICT (Deb Sury 5.6)' => 22527, 'E_ALL (Travis PHP 5.3, 5.4, 5.5)' => 32767);
$this->assertTrue(in_array($reporting, $knownErrorLevels), "error reporting as of {$reporting}");
// by default the class must be loaded with a different autoloader
$this->assertFalse(class_exists('Le_Foo_Le_Bar_Fine'));
// post-condition is that there was no error yet
$this->assertSame($canary, error_get_last());
// should not trigger an error if the class exists
$autoload = $this->create($this->getAutoloader());
$this->assertTrue(class_exists('Le_Foo_Le_Bar_Fine'));
$this->assertSame($canary, error_get_last());
// should trigger a warning if the class does not exists as file on disk per auto-loading
$restore = $this->noErrorExceptions();
$actual = class_exists('Le_Foo_Le_Bar_Nexiste_Pas');
$restore();
$this->assertFalse($actual);
$lastError = error_get_last();
if ($canary === $lastError) {
$this->markTestIncomplete('System does not triggers the expected warning on include');
}
$this->assertNotSame($canary, $lastError);
$this->assertArrayHasKey('type', $lastError);
$this->assertSame(2, $lastError['type']);
$this->assertArrayHasKey('message', $lastError);
$pattern = '~include\\(\\): Failed opening \'.*Rewrite/fixture/Le_Foo_Le_Bar_Nexiste_Pas\\.php\' for inclusion ~';
$this->assertRegExp($pattern, $lastError['message']);
}