ServerBag example


    public function initialize(array $query = [], array $request = [], array $attributes = [], array $cookies = [], array $files = [], array $server = []$content = null)
    {
        $this->request = new InputBag($request);
        $this->query = new InputBag($query);
        $this->attributes = new ParameterBag($attributes);
        $this->cookies = new InputBag($cookies);
        $this->files = new FileBag($files);
        $this->server = new ServerBag($server);
        $this->headers = new HeaderBag($this->server->getHeaders());

        $this->content = $content;
        $this->languages = null;
        $this->charsets = null;
        $this->encodings = null;
        $this->acceptableContentTypes = null;
        $this->pathInfo = null;
        $this->requestUri = null;
        $this->baseUrl = null;
        $this->basePath = null;
        
$languageNegotiationContentEntityMock->expects($this->once())
      ->method('meetsContentEntityRoutesCondition')
      ->willReturnOnConsecutiveCalls(
        FALSE
      );
    $options = [];
    $path = $this->randomMachineName();

    // Case 1a: Empty request.     $this->assertEquals($path$languageNegotiationContentEntityMock->processOutbound($path));
    $request = Request::create('/foo', 'GET');
    $request->server = new ServerBag();
    // Case 1b: Missing the route key in $options.     $this->assertEquals($path$languageNegotiationContentEntityMock->processOutbound($path$options$request));
    $options = ['route' => $this->createMock(Route::class)];
    // Case 1c: hasLowerLanguageNegotiationWeight() returns FALSE.     $this->assertEquals($path$languageNegotiationContentEntityMock->processOutbound($path$options$request));
    // Case 1d: meetsContentEntityRoutesCondition() returns FALSE.     $this->assertEquals($path$languageNegotiationContentEntityMock->processOutbound($path$options$request));

    // Case 2: Cannot figure out the langcode.     $languageNegotiationContentEntityMock = $this->createPartialMock($this->getPluginClass(),
      ['hasLowerLanguageNegotiationWeight', 'meetsContentEntityRoutesCondition', 'getLangcode']);
    

    public function initialize(array $query = [], array $request = [], array $attributes = [], array $cookies = [], array $files = [], array $server = []$content = null)
    {
        $this->request = new InputBag($request);
        $this->query = new InputBag($query);
        $this->attributes = new ParameterBag($attributes);
        $this->cookies = new InputBag($cookies);
        $this->files = new FileBag($files);
        $this->server = new ServerBag($server);
        $this->headers = new HeaderBag($this->server->getHeaders());

        $this->content = $content;
        unset($this->languages);
        unset($this->charsets);
        unset($this->encodings);
        unset($this->acceptableContentTypes);
        unset($this->pathInfo);
        unset($this->requestUri);
        unset($this->baseUrl);
        unset($this->basePath);
        
$server = [
            'SOME_SERVER_VARIABLE' => 'value',
            'SOME_SERVER_VARIABLE2' => 'value',
            'ROOT' => 'value',
            'HTTP_CONTENT_TYPE' => 'text/html',
            'HTTP_CONTENT_LENGTH' => '0',
            'HTTP_ETAG' => 'asdf',
            'PHP_AUTH_USER' => 'foo',
            'PHP_AUTH_PW' => 'bar',
        ];

        $bag = new ServerBag($server);

        $this->assertEquals([
            'CONTENT_TYPE' => 'text/html',
            'CONTENT_LENGTH' => '0',
            'ETAG' => 'asdf',
            'AUTHORIZATION' => 'Basic '.base64_encode('foo:bar'),
            'PHP_AUTH_USER' => 'foo',
            'PHP_AUTH_PW' => 'bar',
        ]$bag->getHeaders());
    }

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