Fix PHP errors in test cases related to now using Symfony's HttpFoundation component.
This commit is contained in:
parent
86013f1b84
commit
feefa8d9c4
|
@ -189,7 +189,7 @@ public function testRestfulControllersRespondWithRestfulMethods()
|
|||
|
||||
$_SERVER['REQUEST_METHOD'] = 'PUT';
|
||||
|
||||
$this->assertEquals(404, Controller::call('restful@index')->status);
|
||||
$this->assertEquals(404, Controller::call('restful@index')->status());
|
||||
|
||||
$_SERVER['REQUEST_METHOD'] = 'POST';
|
||||
|
||||
|
|
|
@ -39,18 +39,18 @@ public function testSimpleRedirectSetsCorrectHeaders()
|
|||
{
|
||||
$redirect = Redirect::to('user/profile');
|
||||
|
||||
$this->assertEquals(302, $redirect->status);
|
||||
$this->assertEquals('http://localhost/user/profile', $redirect->headers['location']);
|
||||
$this->assertEquals(302, $redirect->status());
|
||||
$this->assertEquals('http://localhost/user/profile', $redirect->headers()->get('location'));
|
||||
|
||||
$redirect = Redirect::to('user/profile', 301, true);
|
||||
|
||||
$this->assertEquals(301, $redirect->status);
|
||||
$this->assertEquals('https://localhost/user/profile', $redirect->headers['location']);
|
||||
$this->assertEquals(301, $redirect->status());
|
||||
$this->assertEquals('https://localhost/user/profile', $redirect->headers()->get('location'));
|
||||
|
||||
$redirect = Redirect::to_secure('user/profile', 301);
|
||||
|
||||
$this->assertEquals(301, $redirect->status);
|
||||
$this->assertEquals('https://localhost/user/profile', $redirect->headers['location']);
|
||||
$this->assertEquals(301, $redirect->status());
|
||||
$this->assertEquals('https://localhost/user/profile', $redirect->headers()->get('location'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -64,10 +64,10 @@ public function testRedirectsCanBeGeneratedForNamedRoutes()
|
|||
Route::get('redirect/(:any)/(:any)', array('as' => 'redirect-2'));
|
||||
Route::get('secure/redirect', array('https' => true, 'as' => 'redirect-3'));
|
||||
|
||||
$this->assertEquals(301, Redirect::to_route('redirect', array(), 301, true)->status);
|
||||
$this->assertEquals('http://localhost/redirect', Redirect::to_route('redirect')->headers['location']);
|
||||
$this->assertEquals('https://localhost/secure/redirect', Redirect::to_route('redirect-3', array(), 302)->headers['location']);
|
||||
$this->assertEquals('http://localhost/redirect/1/2', Redirect::to_route('redirect-2', array('1', '2'))->headers['location']);
|
||||
$this->assertEquals(301, Redirect::to_route('redirect', array(), 301, true)->status());
|
||||
$this->assertEquals('http://localhost/redirect', Redirect::to_route('redirect')->headers()->get('location'));
|
||||
$this->assertEquals('https://localhost/secure/redirect', Redirect::to_route('redirect-3', array(), 302)->headers()->get('location'));
|
||||
$this->assertEquals('http://localhost/redirect/1/2', Redirect::to_route('redirect-2', array('1', '2'))->headers()->get('location'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
use Symfony\Component\HttpFoundation\LaravelRequest as RequestFoundation;
|
||||
|
||||
class SessionPayloadTokenStub {
|
||||
|
||||
public function token() { return 'Taylor'; }
|
||||
|
@ -19,6 +21,46 @@ public function tearDown()
|
|||
Session::$instance = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set one of the $_SERVER variables.
|
||||
*
|
||||
* @param string $key
|
||||
* @param string $value
|
||||
*/
|
||||
protected function setServerVar($key, $value)
|
||||
{
|
||||
$_SERVER[$key] = $value;
|
||||
|
||||
$this->restartRequest();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set one of the $_POST variables.
|
||||
*
|
||||
* @param string $key
|
||||
* @param string $value
|
||||
*/
|
||||
protected function setPostVar($key, $value)
|
||||
{
|
||||
$_POST[$key] = $value;
|
||||
|
||||
$this->restartRequest();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reinitialize the global request.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function restartRequest()
|
||||
{
|
||||
// FIXME: Ugly hack, but old contents from previous requests seem to
|
||||
// trip up the Foundation class.
|
||||
$_FILES = array();
|
||||
|
||||
Request::$foundation = RequestFoundation::createFromGlobals();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the Request::method method.
|
||||
*
|
||||
|
@ -26,11 +68,11 @@ public function tearDown()
|
|||
*/
|
||||
public function testMethodReturnsTheHTTPRequestMethod()
|
||||
{
|
||||
$_SERVER['REQUEST_METHOD'] = 'POST';
|
||||
$this->setServerVar('REQUEST_METHOD', 'POST');
|
||||
|
||||
$this->assertEquals('POST', Request::method());
|
||||
|
||||
$_POST[Request::spoofer] = 'PUT';
|
||||
$this->setPostVar(Request::spoofer, 'PUT');
|
||||
|
||||
$this->assertEquals('PUT', Request::method());
|
||||
}
|
||||
|
@ -42,7 +84,8 @@ public function testMethodReturnsTheHTTPRequestMethod()
|
|||
*/
|
||||
public function testServerMethodReturnsFromServerArray()
|
||||
{
|
||||
$_SERVER = array('TEST' => 'something', 'USER' => array('NAME' => 'taylor'));
|
||||
$this->setServerVar('TEST', 'something');
|
||||
$this->setServerVar('USER', array('NAME' => 'taylor'));
|
||||
|
||||
$this->assertEquals('something', Request::server('test'));
|
||||
$this->assertEquals('taylor', Request::server('user.name'));
|
||||
|
@ -55,33 +98,20 @@ public function testServerMethodReturnsFromServerArray()
|
|||
*/
|
||||
public function testIPMethodReturnsClientIPAddress()
|
||||
{
|
||||
$_SERVER['REMOTE_ADDR'] = 'something';
|
||||
$this->setServerVar('REMOTE_ADDR', 'something');
|
||||
$this->assertEquals('something', Request::ip());
|
||||
|
||||
$_SERVER['HTTP_CLIENT_IP'] = 'something';
|
||||
$this->setServerVar('HTTP_CLIENT_IP', 'something');
|
||||
$this->assertEquals('something', Request::ip());
|
||||
|
||||
$_SERVER['HTTP_X_FORWARDED_FOR'] = 'something';
|
||||
$this->setServerVar('HTTP_CLIENT_IP', 'something');
|
||||
$this->assertEquals('something', Request::ip());
|
||||
|
||||
$_SERVER = array();
|
||||
$this->restartRequest();
|
||||
$this->assertEquals('0.0.0.0', Request::ip());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the Request::protocol method.
|
||||
*
|
||||
* @group laravel
|
||||
*/
|
||||
public function testProtocolMethodReturnsProtocol()
|
||||
{
|
||||
$_SERVER['SERVER_PROTOCOL'] = 'taylor';
|
||||
$this->assertEquals('taylor', Request::protocol());
|
||||
|
||||
unset($_SERVER['SERVER_PROTOCOL']);
|
||||
$this->assertEquals('HTTP/1.1', Request::protocol());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the Request::secure method.
|
||||
*
|
||||
|
@ -89,11 +119,11 @@ public function testProtocolMethodReturnsProtocol()
|
|||
*/
|
||||
public function testSecureMethodsIndicatesIfHTTPS()
|
||||
{
|
||||
$_SERVER['HTTPS'] = 'on';
|
||||
$this->setServerVar('HTTPS', 'on');
|
||||
|
||||
$this->assertTrue(Request::secure());
|
||||
|
||||
$_SERVER['HTTPS'] = 'off';
|
||||
$this->setServerVar('HTTPS', 'off');
|
||||
|
||||
$this->assertFalse(Request::secure());
|
||||
}
|
||||
|
@ -107,7 +137,7 @@ public function testAjaxMethodIndicatesWhenAjax()
|
|||
{
|
||||
$this->assertFalse(Request::ajax());
|
||||
|
||||
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'xmlhttprequest';
|
||||
$this->setServerVar('HTTP_X_REQUESTED_WITH', 'XMLHttpRequest');
|
||||
|
||||
$this->assertTrue(Request::ajax());
|
||||
}
|
||||
|
|
|
@ -12,8 +12,9 @@ public function testMakeMethodProperlySetsContent()
|
|||
$response = Response::make('foo', 201, array('bar' => 'baz'));
|
||||
|
||||
$this->assertEquals('foo', $response->content);
|
||||
$this->assertEquals(201, $response->status);
|
||||
$this->assertEquals(array('bar' => 'baz'), $response->headers);
|
||||
$this->assertEquals(201, $response->status());
|
||||
$this->assertArrayHasKey('bar', $response->headers()->all());
|
||||
$this->assertEquals('baz', $response->headers()->get('bar'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -38,7 +39,7 @@ public function testErrorMethodSetsContentToErrorView()
|
|||
{
|
||||
$response = Response::error('404', array('name' => 'Taylor'));
|
||||
|
||||
$this->assertEquals(404, $response->status);
|
||||
$this->assertEquals(404, $response->status());
|
||||
$this->assertEquals('error.404', $response->content->view);
|
||||
$this->assertEquals('Taylor', $response->content->data['name']);
|
||||
}
|
||||
|
@ -70,7 +71,7 @@ public function testHeaderMethodSetsValueInHeaderArray()
|
|||
{
|
||||
$response = Response::make('')->header('foo', 'bar');
|
||||
|
||||
$this->assertEquals('bar', $response->headers['foo']);
|
||||
$this->assertEquals('bar', $response->headers()->get('foo'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -82,7 +83,7 @@ public function testStatusMethodSetsStatusCode()
|
|||
{
|
||||
$response = Response::make('')->status(404);
|
||||
|
||||
$this->assertEquals(404, $response->status);
|
||||
$this->assertEquals(404, $response->status());
|
||||
}
|
||||
|
||||
}
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
use Symfony\Component\HttpFoundation\LaravelRequest as RequestFoundation;
|
||||
|
||||
class URITest extends PHPUnit_Framework_TestCase {
|
||||
|
||||
/**
|
||||
|
@ -12,6 +14,21 @@ public function tearDown()
|
|||
URI::$segments = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set this request's URI to the given string
|
||||
*
|
||||
* @param string $uri
|
||||
*/
|
||||
protected function setRequestUri($uri)
|
||||
{
|
||||
// FIXME: Ugly hack, but old contents from previous requests seem to
|
||||
// trip up the Foundation class.
|
||||
$_FILES = array();
|
||||
|
||||
$_SERVER['REQUEST_URI'] = $uri;
|
||||
Request::$foundation = RequestFoundation::createFromGlobals();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the URI::current method.
|
||||
*
|
||||
|
@ -20,7 +37,8 @@ public function tearDown()
|
|||
*/
|
||||
public function testCorrectURIIsReturnedByCurrentMethod($uri, $expectation)
|
||||
{
|
||||
$_SERVER['REQUEST_URI'] = $uri;
|
||||
$this->setRequestUri($uri);
|
||||
|
||||
$this->assertEquals($expectation, URI::current());
|
||||
}
|
||||
|
||||
|
@ -31,7 +49,7 @@ public function testCorrectURIIsReturnedByCurrentMethod($uri, $expectation)
|
|||
*/
|
||||
public function testSegmentMethodReturnsAURISegment()
|
||||
{
|
||||
$_SERVER['REQUEST_URI'] = 'http://localhost/index.php/user/profile';
|
||||
$this->setRequestUri('http://localhost/index.php/user/profile');
|
||||
|
||||
$this->assertEquals('user', URI::segment(1));
|
||||
$this->assertEquals('profile', URI::segment(2));
|
||||
|
|
Loading…
Reference in New Issue