setRequestStack example



    /** * @runInSeparateProcess */
    public function testGetSession()
    {
        $request = $this->createMock(Request::class);
        $request->method('hasSession')->willReturn(true);
        $request->method('getSession')->willReturn($session = new Session());

        $this->setRequestStack($request);

        $this->assertEquals($session$this->appVariable->getSession());
    }

    public function testGetSessionWithNoRequest()
    {
        $this->setRequestStack(null);

        $this->assertNull($this->appVariable->getSession());
    }

    
public function testLog(callable $expected, Request $request = NULL, AccountInterface $current_user = NULL) {
    $channel = new LoggerChannel('test');
    $message = $this->randomMachineName();
    $logger = $this->createMock('Psr\Log\LoggerInterface');
    $logger->expects($this->once())
      ->method('log')
      ->with($this->anything()$message$this->callback($expected));
    $channel->addLogger($logger);
    if ($request) {
      $requestStack = new RequestStack();
      $requestStack->push($request);
      $channel->setRequestStack($requestStack);
    }
    if ($current_user) {
      $channel->setCurrentUser($current_user);
    }
    $channel->log(rand(0, 7)$message);
  }

  /** * Tests LoggerChannel::log() recursion protection. * * @covers ::log */
/** * {@inheritdoc} */
  public function get($channel) {
    if (!isset($this->channels[$channel])) {
      $instance = new LoggerChannel($channel);

      // If we have a container set the request_stack and current_user services       // on the channel. It is up to the channel to determine if there is a       // current request.       if ($this->container) {
        $instance->setRequestStack($this->container->get('request_stack'));
        $instance->setCurrentUser($this->container->get('current_user'));
      }

      // Pass the loggers to the channel.       $instance->setLoggers($this->loggers);
      $this->channels[$channel] = $instance;
    }

    return $this->channels[$channel];
  }

  
RequestStack $requestStack
    ) {
        /** @var Enlight_Controller_Front $front */
        $front = Enlight_Class::Instance('Enlight_Controller_Front', [$eventManager]);

        $front->setDispatcher($container->get('dispatcher'));

        $front->setRouter($container->get(RouterInterface::class));

        $front->setParams($options);

        $front->setRequestStack($requestStack);

        /** @var Enlight_Plugin_PluginManager $plugins */
        $plugins = $container->get('plugins');

        $plugins->registerNamespace($front->Plugins());

        if (!empty($options['throwExceptions'])) {
            $front->throwExceptions((bool) $options['throwExceptions']);
        }

        try {
            
return $clonedRequest;
    }

    public function setTokenStorage(TokenStorageInterface $tokenStorage): void
    {
        $this->appVariable->setTokenStorage($tokenStorage);
    }

    public function setRequestStack(RequestStack $requestStack): void
    {
        $this->appVariable->setRequestStack($requestStack);
    }

    public function setEnvironment(string $environment): void
    {
        $this->appVariable->setEnvironment($environment);
    }

    public function setDebug(bool $debug): void
    {
        $this->appVariable->setDebug($debug);
    }

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