1
0
Fork 0
composer/tests/Composer/Test/Util/ErrorHandlerTest.php

78 lines
1.9 KiB
PHP
Raw Normal View History

2022-02-23 15:58:18 +00:00
<?php declare(strict_types=1);
/*
* This file is part of Composer.
*
* (c) Nils Adermann <naderman@naderman.de>
* Jordi Boggiano <j.boggiano@seld.be>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Composer\Test\Util;
use Composer\Util\ErrorHandler;
use Composer\Test\TestCase;
/**
* ErrorHandler test case
*/
class ErrorHandlerTest extends TestCase
{
2021-12-08 16:03:05 +00:00
public function setUp(): void
{
ErrorHandler::register();
}
protected function tearDown(): void
{
parent::tearDown();
restore_error_handler();
}
/**
* Test ErrorHandler handles notices
*/
public function testErrorHandlerCaptureNotice(): void
{
if (\PHP_VERSION_ID >= 80000) {
2021-12-09 19:55:26 +00:00
self::expectException('\ErrorException');
self::expectExceptionMessage('Undefined array key "baz"');
2020-09-11 09:27:26 +00:00
} else {
2021-12-09 19:55:26 +00:00
self::expectException('\ErrorException');
self::expectExceptionMessage('Undefined index: baz');
2020-09-11 09:27:26 +00:00
}
2022-08-17 12:20:07 +00:00
$array = ['foo' => 'bar'];
// @phpstan-ignore offsetAccess.notFound, expr.resultUnused
$array['baz'];
}
/**
* Test ErrorHandler handles warnings
*/
public function testErrorHandlerCaptureWarning(): void
{
if (\PHP_VERSION_ID >= 80000) {
2021-12-09 19:55:26 +00:00
self::expectException('TypeError');
self::expectExceptionMessage('array_merge');
2020-05-20 12:39:14 +00:00
} else {
2021-12-09 19:55:26 +00:00
self::expectException('ErrorException');
self::expectExceptionMessage('array_merge');
2020-05-20 12:39:14 +00:00
}
// @phpstan-ignore function.resultUnused, argument.type
2022-08-17 12:20:07 +00:00
array_merge([], 'string');
}
2012-04-08 14:55:45 +00:00
/**
* Test ErrorHandler handles warnings
* @doesNotPerformAssertions
2012-04-08 14:55:45 +00:00
*/
public function testErrorHandlerRespectsAtOperator(): void
2012-04-08 14:55:45 +00:00
{
@trigger_error('test', E_USER_NOTICE);
}
}