Skip to content
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

Avoid Request::factory() calls in test providers #627

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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