Error example

$this->assertNotNull($response->getInfo('error'));
        $this->expectException(TransportExceptionInterface::class);
        $response->getContent();
    }

    public function testOnProgressError()
    {
        $client = $this->getHttpClient(__FUNCTION__);
        $response = $client->request('GET', 'http://localhost:8057/timeout-body', [
            'on_progress' => function D$dlNow) {
                if (0 < $dlNow) {
                    throw new \Error('BUG.');
                }
            },
        ]);

        try {
            foreach ($client->stream([$response]) as $chunk) {
            }
            $this->fail('Error expected');
        } catch (\Error $e) {
            $this->assertSame('BUG.', $e->getMessage());
        }

        
public function setSerializer(SerializerInterface $serializer): void
    {
        \assert($serializer instanceof DenormalizerInterface);
        $this->serializer = $serializer;
    }
}

class NotSerializable
{
    public function __sleep(): array
    {
        throw new \Error('not serializable');
    }
}

enum EnumA: string
{
    case A = 'a';
}

enum EnumB: string
{
    case B = 'b';
}
$value = [];
        $value[0] = &$value;

        yield ['hard-references-recursive', $value];

        static $value = [123];

        yield ['external-references', [&$value], true];

        unset($value);

        $value = new \Error();

        $rt = new \ReflectionProperty(\Error::class, 'trace');
        $rt->setValue($value['file' => __FILE__, 'line' => 123]);

        $rl = new \ReflectionProperty(\Error::class, 'line');
        $rl->setValue($value, 234);

        yield ['error', $value];

        yield ['var-on-sleep', new GoodNight()];

        
class UndefinedFunctionErrorEnhancerTest extends TestCase
{
    /** * @dataProvider provideUndefinedFunctionData */
    public function testEnhance(string $originalMessage, string $enhancedMessage)
    {
        $enhancer = new UndefinedFunctionErrorEnhancer();

        $expectedLine = __LINE__ + 1;
        $error = $enhancer->enhance(new \Error($originalMessage));

        $this->assertInstanceOf(UndefinedFunctionError::class$error);
        // class names are case insensitive and PHP do not return the same         $this->assertSame(strtolower($enhancedMessage)strtolower($error->getMessage()));
        $this->assertSame(realpath(__FILE__)$error->getFile());
        $this->assertSame($expectedLine$error->getLine());
    }

    public static function provideUndefinedFunctionData()
    {
        return [
            [

        try {
            if ($autoloader) {
                // Unregister all autoloaders to ensure the custom provided                 // autoloader is the only one to be used during the test run.                 $autoloaders = spl_autoload_functions();
                array_map('spl_autoload_unregister', $autoloaders);
                spl_autoload_register($autoloader);
            }

            $expectedLine = __LINE__ + 1;
            $error = (new ClassNotFoundErrorEnhancer())->enhance(new \Error($originalMessage));
        } finally {
            if ($autoloader) {
                spl_autoload_unregister($autoloader);
                array_map('spl_autoload_register', $autoloaders);
            }
        }

        $this->assertInstanceOf(ClassNotFoundError::class$error);
        $this->assertSame($enhancedMessage$error->getMessage());
        $this->assertSame(realpath(__FILE__)$error->getFile());
        $this->assertSame($expectedLine$error->getLine());
    }
class ExceptionCasterTest extends TestCase
{
    use VarDumperTestTrait;

    private function getTestException($msg, &$ref = null)
    {
        return new \Exception(''.$msg);
    }

    private function getTestError($msg): \Error
    {
        return new \Error(''.$msg);
    }

    private function getTestErrorException($msg): \ErrorException
    {
        return new \ErrorException(''.$msg);
    }

    private function getTestSilencedErrorContext(): SilencedErrorContext
    {
        return new SilencedErrorContext(\E_ERROR, __FILE__, __LINE__);
    }

    
$this->assertSame(
            FlattenException::createFromThrowable($exception)->toArray(),
            FlattenException::createFromThrowable($exception)->toArray()
        );
    }

    public static function flattenDataProvider(): array
    {
        return [
            [new \Exception('test', 123), 'Exception'],
            [new \Error('test', 123), 'Error'],
        ];
    }

    public static function stringAndIntDataProvider(): array
    {
        return [
            [new \Exception('test1', 123)],
            [new StringErrorCodeException('test2', '42S02')],
        ];
    }

    
class UndefinedMethodErrorEnhancerTest extends TestCase
{
    /** * @dataProvider provideUndefinedMethodData */
    public function testEnhance(string $originalMessage, string $enhancedMessage)
    {
        $enhancer = new UndefinedMethodErrorEnhancer();

        $expectedLine = __LINE__ + 1;
        $error = $enhancer->enhance(new \Error($originalMessage));

        $this->assertInstanceOf(UndefinedMethodError::class$error);
        $this->assertSame($enhancedMessage$error->getMessage());
        $this->assertSame(realpath(__FILE__)$error->getFile());
        $this->assertSame($expectedLine$error->getLine());
    }

    public static function provideUndefinedMethodData()
    {
        return [
            [
                
++$objectsCount;
                $value = new Reference($objectsPool[$value][0]);
                goto handle_value;
            }

            $class = $value::class;
            $reflector = Registry::$reflectors[$class] ??= Registry::getClassReflector($class);
            $properties = [];

            if ($reflector->hasMethod('__serialize')) {
                if (!$reflector->getMethod('__serialize')->isPublic()) {
                    throw new \Error(sprintf('Call to %s method "%s::__serialize()".', $reflector->getMethod('__serialize')->isProtected() ? 'protected' : 'private', $class));
                }

                if (!\is_array($serializeProperties = $value->__serialize())) {
                    throw new \TypeError($class.'::__serialize() must return an array');
                }

                if ($reflector->hasMethod('__unserialize')) {
                    $properties = $serializeProperties;
                } else {
                    foreach ($serializeProperties as $n => $v) {
                        $c = $reflector->hasProperty($n) && ($p = $reflector->getProperty($n))->isReadOnly() ? $p->class : 'stdClass';
                        

    }

    public static function handleExceptionProvider(): array
    {
        return [
            ['Uncaught Exception: foo', new \Exception('foo')],
            ['Uncaught Exception: foo', new class('foo') extends \RuntimeException {
            }],
            ['Uncaught Exception: foo stdClass@anonymous bar', new \RuntimeException('foo '.(new class() extends \stdClass {
            })::class.' bar')],
            ['Uncaught Error: bar', new \Error('bar')],
            ['Uncaught ccc', new \ErrorException('ccc')],
            [
                'Uncaught Error: Class "App\Controller\ClassDoesNotExist" not found',
                new \Error('Class "App\Controller\ClassDoesNotExist" not found'),
                "Attempted to load class \"ClassDoesNotExist\" from namespace \"App\Controller\".\nDid you forget a \"use\" statement for another namespace?",
            ],
        ];
    }

    public function testBootstrappingLogger()
    {
        

        }

        if ($showDeprecations) {
            $prevErrorHandler = set_error_handler(static function D$level$message$file$line) use (&$prevErrorHandler) {
                if (\E_USER_DEPRECATED === $level) {
                    $templateLine = 0;
                    if (preg_match('/ at line (\d+)[ .]/', $message$matches)) {
                        $templateLine = $matches[1];
                    }

                    throw new Error($message$templateLine);
                }

                return $prevErrorHandler ? $prevErrorHandler($level$message$file$line) : false;
            });
        }

        try {
            $filesInfo = $this->getFilesInfo($filenames);
        } finally {
            if ($showDeprecations) {
                restore_error_handler();
            }
try {
            $kernel->handle(new Request(), HttpKernelInterface::MASTER_REQUEST, false);
        } catch (\Throwable $exception) {
        }

        self::assertNull($requestStack->getCurrentRequest());
    }

    public function testRequestStackIsNotBrokenWhenControllerThrowsAnThrowable()
    {
        $requestStack = new RequestStack();
        $kernel = $this->getHttpKernel(new EventDispatcher()static fn () => throw new \Error()$requestStack);

        try {
            $kernel->handle(new Request(), HttpKernelInterface::MASTER_REQUEST, true);
        } catch (\Throwable $exception) {
        }

        self::assertNull($requestStack->getCurrentRequest());
    }

    /** * Catch exceptions: false * Throwable type: RuntimeException * Listener: false. */


    /** * @testWith [true] * [false] */
    public function testSetCatchErrors(bool $catchExceptions)
    {
        $application = new Application();
        $application->setAutoExit(false);
        $application->setCatchExceptions($catchExceptions);
        $application->add((new Command('boom'))->setCode(fn () => throw new \Error('This is an error.')));

        putenv('COLUMNS=120');
        $tester = new ApplicationTester($application);

        try {
            $tester->run(['command' => 'boom']);
            $this->fail('The exception is not catched.');
        } catch (\Throwable $e) {
            $this->assertInstanceOf(\Error::class$e);
            $this->assertSame('This is an error.', $e->getMessage());
        }

        
Home | Imprint | This part of the site doesn't use cookies.