Skip to content

Commit

Permalink
Merge pull request #627 from kohana/3.3/test/avoid-request-factory-ca…
Browse files Browse the repository at this point in the history
…lls-in-providers

Avoid Request::factory() calls in test providers
  • Loading branch information
acoulton committed Jul 27, 2015
2 parents 98615c5 + c37cf6f commit b158eae
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
2 changes: 1 addition & 1 deletion classes/Kohana/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ public function __construct($uri, $client_params = array(), $allow_external = TR
$uri = array_shift($split_uri);

// Initial request has global $_GET already applied
if (Request::$initial !== NULL)
if (Request::$initial === NULL)
{
if ($split_uri)
{
Expand Down
15 changes: 15 additions & 0 deletions tests/kohana/HTTPTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
class Kohana_HTTPTest extends Unittest_TestCase {

protected $_inital_request;

/**
* Sets up the environment
*/
Expand All @@ -24,8 +26,21 @@ public function setUp()
{
parent::setUp();
Kohana::$config->load('url')->set('trusted_hosts', array('www\.example\.com'));
$this->_initial_request = Request::$initial;
Request::$initial = new Request('/');
}

/**
* Tears down whatever is setUp
*/
// @codingStandardsIgnoreStart
public function tearDown()
// @codingStandardsIgnoreEnd
{
Request::$initial = $this->_initial_request;
parent::tearDown();
}
// @codingStandardsIgnoreStart

/**
* Defaults for this test
Expand Down
16 changes: 7 additions & 9 deletions tests/kohana/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -523,18 +523,18 @@ public function provider_headers_get()
{
$x_powered_by = 'Kohana Unit Test';
$content_type = 'application/x-www-form-urlencoded';
$request = new Request('foo/bar', array(), TRUE, array());

return array(
array(
$request = Request::factory('foo/bar')
->headers(array(
$request->headers(array(
'x-powered-by' => $x_powered_by,
'content-type' => $content_type
)
),
array(
'x-powered-by' => $x_powered_by,
'content-type' => $content_type
array(
'x-powered-by' => $x_powered_by,
'content-type' => $content_type
)
)
);
Expand Down Expand Up @@ -566,15 +566,13 @@ public function provider_headers_set()
{
return array(
array(
Request::factory(),
array(
'content-type' => 'application/x-www-form-urlencoded',
'x-test-header' => 'foo'
),
"Content-Type: application/x-www-form-urlencoded\r\nX-Test-Header: foo\r\n\r\n"
),
array(
Request::factory(),
array(
'content-type' => 'application/json',
'x-powered-by' => 'kohana'
Expand All @@ -589,13 +587,13 @@ public function provider_headers_set()
*
* @dataProvider provider_headers_set
*
* @param Request request object
* @param array header(s) to set to the request object
* @param string expected http header
* @return void
*/
public function test_headers_set(Request $request, $headers, $expected)
public function test_headers_set($headers, $expected)
{
$request = new Request(TRUE, array(), TRUE, array());
$request->headers($headers);
$this->assertSame($expected, (string) $request->headers());
}
Expand Down

0 comments on commit b158eae

Please sign in to comment.