enhance example


        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());
    }
$message = 'Uncaught Exception: '.$message;
            }

            try {
                $this->loggers[$type][0]->log($this->loggers[$type][1]$message['exception' => $exception]);
            } catch (\Throwable $handlerException) {
            }
        }

        if (!$exception instanceof OutOfMemoryError) {
            foreach ($this->getErrorEnhancers() as $errorEnhancer) {
                if ($e = $errorEnhancer->enhance($exception)) {
                    $exception = $e;
                    break;
                }
            }
        }

        $exceptionHandler = $this->exceptionHandler;
        $this->exceptionHandler = [$this, 'renderException'];

        if (null === $exceptionHandler || $exceptionHandler === $this->exceptionHandler) {
            $this->exceptionHandler = null;
        }
 + $raw_variables;

    $expected = $defaults;
    $expected['id'] = 'something_better!';
    $expected['_raw_variables'] = new InputBag($raw_variables);

    $this->paramConverterManager->expects($this->once())
      ->method('convert')
      ->with($this->isType('array'))
      ->willReturn($expected);

    $result = $this->paramConversionEnhancer->enhance($defaultsnew Request());

    $this->assertEquals($expected$result);

    // Now run with the results as the new defaults to ensure that the     // conversion is just run once.     $result = $this->paramConversionEnhancer->enhance($resultnew Request());

    $this->assertEquals($expected$result);
  }

  /** * @covers ::copyRawVariables */

  public function testEnhancer() {
    $route_enhancer = new EntityRouteEnhancer();

    // Set a controller to ensure it is not overridden.     $request = new Request();
    $defaults = [];
    $defaults['_controller'] = 'Drupal\Tests\Core\Controller\TestController::content';
    $defaults['_entity_form'] = 'entity_test.default';
    $defaults['_route_object'] = (new Route('/test', $defaults));
    $new_defaults = $route_enhancer->enhance($defaults$request);
    $this->assertEquals($defaults['_controller']$new_defaults['_controller'], '_controller did not get overridden.');

    // Set _entity_form and ensure that the form is set.     $defaults = [];
    $defaults['_entity_form'] = 'entity_test.default';
    $defaults['_route_object'] = (new Route('/test', $defaults));
    $new_defaults = $route_enhancer->enhance($defaults$request);
    $this->assertEquals('controller.entity_form:getContentResult', $new_defaults['_controller']);

    // Set _entity_list and ensure that the entity list controller is set.     $defaults = [];
    

  protected function applyRouteEnhancers($defaults, Request $request) {
    foreach ($this->enhancers as $enhancer) {
      $defaults = $enhancer->enhance($defaults$request);
    }

    return $defaults;
  }

  /** * Applies all route filters to a given route collection. * * This method reduces the sets of routes further down, for example by * checking the HTTP method. * * @param \Symfony\Component\Routing\RouteCollection $collection * The route collection. * @param \Symfony\Component\HttpFoundation\Request $request * The request. * * @return \Symfony\Component\Routing\RouteCollection * The filtered/sorted route collection. */
$defaults = [
      'section_storage' => $section_storage->reveal(),
      RouteObjectInterface::ROUTE_OBJECT => $route,
    ];

    $expected = [
      'section_storage' => 'the_return_value',
      RouteObjectInterface::ROUTE_OBJECT => $route,
    ];

    $enhancer = new LayoutTempstoreRouteEnhancer($layout_tempstore_repository->reveal());
    $result = $enhancer->enhance($defaultsnew Request());
    $this->assertEquals($expected$result);
  }

}
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 [
            [
/** * @covers ::enhance */
  public function testEnhanceWithoutParameter() {
    $route = new Route('/test-path/{entity_test}');

    $request = Request::create('/test-path');

    $defaults = [];
    $defaults[RouteObjectInterface::ROUTE_OBJECT] = $route;
    $this->assertEquals($defaults$this->routeEnhancer->enhance($defaults$request));
  }

  /** * @covers ::enhance */
  public function testEnhanceWithoutEntityRevision() {
    $route = new Route('/test-path/{entity_test}', [][]['parameters' => ['entity_test' => ['type' => 'entity:entity_test']]]);
    $request = Request::create('/test-path/123');
    $entity = $this->prophesize(EntityInterface::class);

    $defaults = [];
    
echo $exception->getAsString();
    }

    public function enhanceError(\Throwable $exception): \Throwable
    {
        if ($exception instanceof OutOfMemoryError) {
            return $exception;
        }

        foreach ($this->getErrorEnhancers() as $errorEnhancer) {
            if ($e = $errorEnhancer->enhance($exception)) {
                return $e;
            }
        }

        return $exception;
    }

    /** * Override this method if you want to define more error enhancers. * * @return ErrorEnhancerInterface[] */
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 [
            [
                
Home | Imprint | This part of the site doesn't use cookies.