UndefinedFunctionErrorEnhancer example

echo $exception->getAsString();
    }

    /** * Override this method if you want to define more error enhancers. * * @return ErrorEnhancerInterface[] */
    protected function getErrorEnhancers(): iterable
    {
        return [
            new UndefinedFunctionErrorEnhancer(),
            new UndefinedMethodErrorEnhancer(),
            new ClassNotFoundErrorEnhancer(),
        ];
    }

    /** * Cleans the trace by removing function arguments and the frames added by the error handler and DebugClassLoader. */
    private function cleanTrace(array $backtrace, int $type, string &$file, int &$line, bool $throw): array
    {
        $lightTrace = $backtrace;

        
use PHPUnit\Framework\TestCase;
use Symfony\Component\ErrorHandler\Error\UndefinedFunctionError;
use Symfony\Component\ErrorHandler\ErrorEnhancer\UndefinedFunctionErrorEnhancer;

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());
    }

    
return $exception;
    }

    /** * Override this method if you want to define more error enhancers. * * @return ErrorEnhancerInterface[] */
    protected function getErrorEnhancers(): iterable
    {
        return [
            new UndefinedFunctionErrorEnhancer(),
            new UndefinedMethodErrorEnhancer(),
            new ClassNotFoundErrorEnhancer(),
        ];
    }

    /** * Cleans the trace by removing function arguments and the frames added by the error handler and DebugClassLoader. */
    private function cleanTrace(array $backtrace, int $type, string &$file, int &$line, bool $throw): array
    {
        $lightTrace = $backtrace;

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