Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

GH-7007: Synchronized Service alternative, backwards compatible. #7707

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 7 commits into from
Prev Previous commit
Next Next commit
[GH-7707] Added tests for RequestStack and documentation for new clas…
…ses.
  • Loading branch information
beberlei committed Apr 30, 2013
commit 0ef36646355c0aa9448f538c2f1a627904ceb43e
14 changes: 14 additions & 0 deletions 14 src/Symfony/Component/HttpKernel/Event/RequestFinishedEvent.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\HttpKernel\Event;

/**
* Triggered whenever a request is fully processed.
*
* @author Benjamin Eberlei <kontakt@beberlei.de>
*/
class RequestFinishedEvent extends KernelEvent
{
}
11 changes: 11 additions & 0 deletions 11 src/Symfony/Component/HttpKernel/RequestContext.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\HttpKernel;

/**
Expand All @@ -8,6 +17,8 @@
* Facade for RequestStack that prevents modification of the stack,
* so that users don't accidentily push()/pop() from the stack and
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

accidently

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

accidentally

* mess up the request cycle.
*
* @author Benjamin Eberlei <kontakt@beberlei.de>
*/
class RequestContext
{
Expand Down
21 changes: 18 additions & 3 deletions 21 src/Symfony/Component/HttpKernel/RequestStack.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\HttpKernel;

use Symfony\Component\HttpFoundation\Request;
Expand All @@ -8,6 +17,8 @@
* Request stack that controls the lifecycle of requests.
*
* Notifies services of changes in the stack.
*
* @author Benjamin Eberlei <kontakt@beberlei.de>
*/
class RequestStack
{
Expand All @@ -34,18 +45,22 @@ public function pop()
}

/**
* @return Request
* @return Request|null
*/
public function getCurrentRequest()
{
return end($this->requests);
return end($this->requests) ?: null;
}

/**
* @return Request
* @return Request|null
*/
public function getMasterRequest()
{
if (!$this->requests) {
return null;
}

return $this->requests[0];
}

Expand Down
76 changes: 76 additions & 0 deletions 76 src/Symfony/Component/HttpKernel/Tests/RequestStackTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\HttpKernel\Tests;

use Symfony\Component\HttpKernel\RequestStack;
use Symfony\Component\HttpFoundation\Request;

class RequestStackTest extends \PHPUnit_Framework_TestCase
{
public function testPushThenPopReturnsSameRequest()
{
$request = Request::create('/');

$stack = new RequestStack();
$stack->push($request);

$this->assertSame($request, $stack->pop());
$this->assertNull($stack->pop());
}

public function testPopEmptyStackReturnsNull()
{
$stack = new RequestStack();

$this->assertNull($stack->pop());
}

public function testGetCurrentRequest()
{
$request = Request::create('/');
$stack = new RequestStack();

$this->assertNull($stack->getCurrentRequest());

$stack->push($request);

$this->assertSame($request, $stack->getCurrentRequest());
$this->assertSame($request, $stack->getCurrentRequest());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this duplication intentional? To verify that getCurrentRequest does not mutate anything?

}

public function testGetMasterRequest()
{
$request = Request::create('/');
$stack = new RequestStack();

$this->assertNull($stack->getMasterRequest());

$stack->push($request);

$this->assertSame($request, $stack->getMasterRequest());
$this->assertSame($request, $stack->getMasterRequest());
}

public function testGetParentRequest()
{
$request = Request::create('/');
$subrequest = Request::create('/');

$stack = new RequestStack();
$stack->push($request);
$stack->push($subrequest);

$this->assertSame($request, $stack->getParentRequest());
$this->assertSame($subrequest, $stack->pop());
$this->assertSame($request, $stack->pop());
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.