Skip to content

Instantly share code, notes, and snippets.

@larowlan
Created March 4, 2014 03:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save larowlan/9339613 to your computer and use it in GitHub Desktop.
Save larowlan/9339613 to your computer and use it in GitHub Desktop.
<?php
namespace Foo\Bar\Whistle;
use Drupal\Core\RequestInfo;
class Sniffer {
public function getMine($request) {
$raw = RequestInfo::getRawVariables($request);
return $raw->get('bar');
}
}
<?php
namespace Foo\Bar\Whistle\Tests;
use Foo\Bar\Whistle\Sniffer;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\ParameterBag;
class ConsumerTest {
protected $sniffer;
public function setUp() {
$this->sniffer = new Sniffer();
}
public function testGetMine() {
$request = new Request();
$bag = new ParameterBag();
$bag->set('bar', 'goat');
$request->attributes->set('_raw_variables', $bag);
$this->assertEquals($this->sniffer->getMine($request), 'goat');
}
}
<?php
namespace Drupal\Core\Routing;
use Symfony\Component\HttpFoundation\Request;
class RequestInfo {
// Gets the raw variables.
public static method getRawVariables(Request $request) {
return $request->attributes->get('_raw_variables');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment