|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the Symfony package. |
| 5 | + * |
| 6 | + * (c) Fabien Potencier <[email protected]> |
| 7 | + * |
| 8 | + * For the full copyright and license information, please view the LICENSE |
| 9 | + * file that was distributed with this source code. |
| 10 | + */ |
| 11 | + |
| 12 | +namespace Symfony\Polyfill\Tests\Php85; |
| 13 | + |
| 14 | +use PHPUnit\Framework\TestCase; |
| 15 | + |
| 16 | +class Php85Test extends TestCase |
| 17 | +{ |
| 18 | + /** |
| 19 | + * @dataProvider provideHandler |
| 20 | + */ |
| 21 | + public function testGetErrorHandler($expected, $handler): void |
| 22 | + { |
| 23 | + set_error_handler($handler); |
| 24 | + try { |
| 25 | + $result = get_error_handler(); |
| 26 | + } finally { |
| 27 | + restore_error_handler(); |
| 28 | + } |
| 29 | + |
| 30 | + $this->assertSame($expected, $result); |
| 31 | + } |
| 32 | + |
| 33 | + public function testErrorStableReturnValue(): void |
| 34 | + { |
| 35 | + $this->assertSame(get_error_handler(), get_error_handler()); |
| 36 | + } |
| 37 | + |
| 38 | + /** |
| 39 | + * @dataProvider provideHandler |
| 40 | + */ |
| 41 | + public function testGetExceptionHandler($expected, $handler): void |
| 42 | + { |
| 43 | + set_exception_handler($handler); |
| 44 | + try { |
| 45 | + $result = get_exception_handler(); |
| 46 | + } finally { |
| 47 | + restore_exception_handler(); |
| 48 | + } |
| 49 | + |
| 50 | + $this->assertSame($expected, $result); |
| 51 | + } |
| 52 | + |
| 53 | + public function testExceptionStableReturnValue(): void |
| 54 | + { |
| 55 | + $this->assertSame(get_exception_handler(), get_exception_handler()); |
| 56 | + |
| 57 | + } |
| 58 | + |
| 59 | + public static function provideHandler() |
| 60 | + { |
| 61 | + // String handler |
| 62 | + yield ['var_dump', 'var_dump']; |
| 63 | + |
| 64 | + // Null handler |
| 65 | + yield [null, null]; |
| 66 | + |
| 67 | + // Static method array handler |
| 68 | + yield [[TestHandler::class, 'handleStatic'], [TestHandler::class, 'handleStatic']]; |
| 69 | + |
| 70 | + // Static method string handler |
| 71 | + yield ['Symfony\Polyfill\Tests\Php85\TestHandler::handleStatic', 'Symfony\Polyfill\Tests\Php85\TestHandler::handleStatic']; |
| 72 | + |
| 73 | + // Instance method array |
| 74 | + $handler = new TestHandler(); |
| 75 | + yield [[$handler, 'handle'], [$handler, 'handle']]; |
| 76 | + |
| 77 | + // Invokable object |
| 78 | + $handler = new TestHandlerInvokable(); |
| 79 | + yield [$handler, $handler]; |
| 80 | + } |
| 81 | +} |
| 82 | + |
| 83 | +class TestHandler |
| 84 | +{ |
| 85 | + public static function handleStatic() {} |
| 86 | + public function handle() {} |
| 87 | +} |
| 88 | + |
| 89 | +class TestHandlerInvokable |
| 90 | +{ |
| 91 | + public function __invoke() {} |
| 92 | +} |
0 commit comments