Skip to content

Commit

Permalink
Simplify unit test by using a real request object
Browse files Browse the repository at this point in the history
  • Loading branch information
Berdir committed Feb 1, 2016
1 parent 9e65ad8 commit 0328ba7
Showing 1 changed file with 2 additions and 28 deletions.
30 changes: 2 additions & 28 deletions tests/src/Unit/RedirectRequestSubscriberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,9 @@
use Drupal\redirect\EventSubscriber\RedirectRequestSubscriber;
use Drupal\Tests\UnitTestCase;
use PHPUnit_Framework_MockObject_MockObject;
use Symfony\Component\HttpFoundation\FileBag;
use Symfony\Component\HttpFoundation\HeaderBag;
use Symfony\Component\HttpFoundation\ParameterBag;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\ServerBag;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\Event\PostResponseEvent;

Expand Down Expand Up @@ -258,30 +255,7 @@ protected function getPostResponseEvent($headers = array()) {
* @return GetResponseEvent
*/
protected function getGetResponseEventStub($path_info, $query_string) {

$request = $this->getMockBuilder('Symfony\Component\HttpFoundation\Request')
->disableOriginalConstructor()
->getMock();
$request->expects($this->any())
->method('getQueryString')
->will($this->returnValue($query_string));
$request->expects($this->any())
->method('getPathInfo')
->will($this->returnValue($path_info));
$request->expects($this->any())
->method('getScriptName')
->will($this->returnValue('index.php'));
$request->expects($this->any())
->method('isMethod')
->with('GET')
->will($this->returnValue(TRUE));

$request->query = new ParameterBag();
$request->attributes = new ParameterBag();
$request->cookies = new ParameterBag();
$request->files = new FileBag();
$request->server = new ServerBag();
$request->headers = new HeaderBag();
$request = Request::create($path_info . '?' . $query_string, 'GET', [], [], [], ['SCRIPT_NAME' => 'index.php']);

$http_kernel = $this->getMockBuilder('\Symfony\Component\HttpKernel\HttpKernelInterface')
->getMock();
Expand Down

0 comments on commit 0328ba7

Please sign in to comment.