2022-02-23 15:58:18 +00:00
|
|
|
<?php declare(strict_types=1);
|
2012-01-27 08:29:07 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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;
|
2018-11-12 14:23:32 +00:00
|
|
|
use Composer\Test\TestCase;
|
2012-01-27 08:29:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* ErrorHandler test case
|
|
|
|
*/
|
|
|
|
class ErrorHandlerTest extends TestCase
|
|
|
|
{
|
2021-12-08 16:03:05 +00:00
|
|
|
public function setUp(): void
|
2020-02-07 06:35:07 +00:00
|
|
|
{
|
|
|
|
ErrorHandler::register();
|
|
|
|
}
|
|
|
|
|
2021-12-09 16:09:07 +00:00
|
|
|
protected function tearDown(): void
|
2020-02-07 06:35:07 +00:00
|
|
|
{
|
2021-12-09 16:09:07 +00:00
|
|
|
parent::tearDown();
|
2020-02-07 06:35:07 +00:00
|
|
|
restore_error_handler();
|
|
|
|
}
|
|
|
|
|
2012-01-27 08:29:07 +00:00
|
|
|
/**
|
|
|
|
* Test ErrorHandler handles notices
|
|
|
|
*/
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testErrorHandlerCaptureNotice(): void
|
2012-01-27 08:29:07 +00:00
|
|
|
{
|
2020-09-11 09:27:26 +00:00
|
|
|
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
|
|
|
}
|
2012-01-27 08:29:07 +00:00
|
|
|
|
|
|
|
$array = array('foo' => 'bar');
|
2021-03-09 14:49:40 +00:00
|
|
|
// @phpstan-ignore-next-line
|
2012-01-27 08:29:07 +00:00
|
|
|
$array['baz'];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test ErrorHandler handles warnings
|
|
|
|
*/
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testErrorHandlerCaptureWarning(): void
|
2012-01-27 08:29:07 +00:00
|
|
|
{
|
2020-05-20 12:39:14 +00:00
|
|
|
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
|
|
|
}
|
2012-01-27 08:29:07 +00:00
|
|
|
|
2021-06-03 09:29:00 +00:00
|
|
|
// @phpstan-ignore-next-line
|
2012-01-27 08:29:07 +00:00
|
|
|
array_merge(array(), 'string');
|
|
|
|
}
|
2012-04-08 14:55:45 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test ErrorHandler handles warnings
|
2020-02-07 06:35:07 +00:00
|
|
|
* @doesNotPerformAssertions
|
2012-04-08 14:55:45 +00:00
|
|
|
*/
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testErrorHandlerRespectsAtOperator(): void
|
2012-04-08 14:55:45 +00:00
|
|
|
{
|
|
|
|
@trigger_error('test', E_USER_NOTICE);
|
|
|
|
}
|
2012-01-27 08:29:07 +00:00
|
|
|
}
|