refactoring testing setup.
This commit is contained in:
parent
392caeed91
commit
b3c9dc59c0
|
@ -91,6 +91,8 @@
|
|||
|
||||
IoC::$container = $container;
|
||||
|
||||
unset($config, $container);
|
||||
|
||||
/**
|
||||
* Register the application auto-loader. The auto-loader is responsible
|
||||
* for the lazy-loading of all of the Laravel core classes, as well as
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
*/
|
||||
if (Config::$items['session']['driver'] !== '')
|
||||
{
|
||||
$session = $container->core('session.manager');
|
||||
$session = IoC::container()->core('session.manager');
|
||||
|
||||
Session\Manager::$payload = $session->payload(Config::$items['session']);
|
||||
}
|
||||
|
@ -82,11 +82,11 @@
|
|||
*/
|
||||
list($method, $uri) = array(Request::method(), Request::uri());
|
||||
|
||||
$route = $container->core('routing.router')->route($method, $uri);
|
||||
$route = IoC::container()->core('routing.router')->route($method, $uri);
|
||||
|
||||
if ( ! is_null($route))
|
||||
{
|
||||
$response = $container->core('routing.caller')->call($route);
|
||||
$response = IoC::container()->core('routing.caller')->call($route);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
<phpunit colors="true" backupGlobals="false" bootstrap="tests/bootstrap.php">
|
||||
<testsuites>
|
||||
<testsuite name="Laravel Framework Tests">
|
||||
<directory>tests</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
</phpunit>
|
|
@ -1,13 +0,0 @@
|
|||
<?php
|
||||
|
||||
class BenchmarkTest extends PHPUnit_Framework_TestCase {
|
||||
|
||||
public function testStartMethodCreatesMark()
|
||||
{
|
||||
Benchmark::start('test');
|
||||
|
||||
$this->assertTrue(is_float(Benchmark::check('test')));
|
||||
$this->assertGreaterThan(0.0, Benchmark::check('test'));
|
||||
}
|
||||
|
||||
}
|
|
@ -29,11 +29,9 @@ public function testSetMethodSetsItemsInArray($array)
|
|||
Arr::set($array, 'name', 'Taylor');
|
||||
Arr::set($array, 'names.aunt', 'Tammy');
|
||||
Arr::set($array, 'names.friends.best', 'Abigail');
|
||||
|
||||
$this->assertEquals($array['name'], 'Taylor');
|
||||
$this->assertEquals($array['names']['aunt'], 'Tammy');
|
||||
$this->assertEquals($array['names']['friends']['best'], 'Abigail');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -42,7 +40,6 @@ public function testSetMethodSetsItemsInArray($array)
|
|||
public function testFirstMethodReturnsFirstItemPassingTruthTest($array)
|
||||
{
|
||||
$array['email2'] = 'taylor@hotmail.com';
|
||||
|
||||
$this->assertEquals('taylorotwell@gmail.com', Arr::first($array, function($k, $v) {return substr($v, 0, 3) == 'tay';}));
|
||||
}
|
||||
|
|
@ -1,39 +1,37 @@
|
|||
<?php
|
||||
<?php namespace Laravel; use PHPUnit_Framework_TestCase;
|
||||
|
||||
class ConfigTest extends PHPUnit_Framework_TestCase {
|
||||
|
||||
public function testHasMethodReturnsTrueWhenItemExists()
|
||||
public function test_has_method_indicates_if_configuration_item_exists()
|
||||
{
|
||||
Config::set('hasvalue', true);
|
||||
|
||||
$this->assertTrue(Config::has('hasvalue'));
|
||||
}
|
||||
|
||||
public function testHasMethodReturnsFalseWhenItemDoesntExist()
|
||||
public function test_has_method_returns_false_when_item_doesnt_exist()
|
||||
{
|
||||
$this->assertFalse(Config::has('something'));
|
||||
}
|
||||
|
||||
public function testConfigClassCanRetrieveItems()
|
||||
public function test_config_get_can_retrieve_item_from_configuration()
|
||||
{
|
||||
$this->assertTrue(is_array(Config::get('application')));
|
||||
$this->assertEquals(Config::get('application.url'), 'http://localhost');
|
||||
}
|
||||
|
||||
public function testGetMethodReturnsDefaultWhenItemDoesntExist()
|
||||
public function test_get_method_returns_default_when_requested_item_doesnt_exist()
|
||||
{
|
||||
$this->assertNull(Config::get('config.item'));
|
||||
$this->assertEquals(Config::get('config.item', 'test'), 'test');
|
||||
$this->assertEquals(Config::get('config.item', function() {return 'test';}), 'test');
|
||||
}
|
||||
|
||||
public function testConfigClassCanSetItems()
|
||||
public function test_config_set_can_set_configuration_items()
|
||||
{
|
||||
Config::set('application.names.test', 'test');
|
||||
Config::set('application.url', 'test');
|
||||
Config::set('session', array());
|
||||
Config::set('test', array());
|
||||
|
||||
$this->assertEquals(Config::get('application.names.test'), 'test');
|
||||
$this->assertEquals(Config::get('application.url'), 'test');
|
||||
$this->assertEquals(Config::get('session'), array());
|
|
@ -8,40 +8,32 @@ class SessionManagerTest extends PHPUnit_Framework_TestCase {
|
|||
/**
|
||||
* @dataProvider mockProvider
|
||||
*/
|
||||
public function testSessionManagerCallsTransporterGet($driver, $transporter)
|
||||
public function test_session_manager_calls_transporter_get($driver, $transporter)
|
||||
{
|
||||
$transporter->expects($this->once())->method('get');
|
||||
|
||||
$manager = new Manager($driver, $transporter);
|
||||
|
||||
$manager->payload($this->getConfig());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider mockProvider
|
||||
*/
|
||||
public function testSessionManagerCallsDriverLoadWithSessionID($driver, $transporter)
|
||||
public function test_session_manager_calls_driver_load_with_session_id($driver, $transporter)
|
||||
{
|
||||
$transporter->expects($this->any())->method('get')->will($this->returnValue('something'));
|
||||
|
||||
$driver->expects($this->once())->method('load')->with($this->equalTo('something'));
|
||||
|
||||
$manager = new Manager($driver, $transporter);
|
||||
|
||||
$manager->payload($this->getConfig());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider mockProvider
|
||||
*/
|
||||
public function testSessionManagerReturnsPayloadWhenFound($driver, $transporter)
|
||||
public function test_session_manager_returns_payload_when_found($driver, $transporter)
|
||||
{
|
||||
$this->setDriverExpectation($driver, 'load', $this->getDummySession());
|
||||
|
||||
$manager = new Manager($driver, $transporter);
|
||||
|
||||
$payload = $manager->payload($this->getConfig());
|
||||
|
||||
$this->assertInstanceOf('Laravel\\Session\\Payload', $payload);
|
||||
$this->assertEquals($payload->session, $this->getDummySession());
|
||||
}
|
||||
|
@ -49,14 +41,11 @@ public function testSessionManagerReturnsPayloadWhenFound($driver, $transporter)
|
|||
/**
|
||||
* @dataProvider mockProvider
|
||||
*/
|
||||
public function testSessionManagerCreatesNewSessionWhenSessionIsNull($driver, $transporter)
|
||||
public function test_session_manager_creates_new_session_when_session_is_null($driver, $transporter)
|
||||
{
|
||||
$this->setDriverExpectation($driver, 'load', null);
|
||||
|
||||
$manager = new Manager($driver, $transporter);
|
||||
|
||||
$payload = $manager->payload($this->getConfig());
|
||||
|
||||
$this->assertInstanceOf('Laravel\\Session\\Payload', $payload);
|
||||
$this->assertEquals(strlen($payload->session['id']), 40);
|
||||
$this->assertTrue(is_array($payload->session['data']));
|
||||
|
@ -65,16 +54,12 @@ public function testSessionManagerCreatesNewSessionWhenSessionIsNull($driver, $t
|
|||
/**
|
||||
* @dataProvider mockProvider
|
||||
*/
|
||||
public function testSessionManagerCreatesNewSessionWhenSessionIsExpired($driver, $transporter)
|
||||
public function test_session_manager_creates_new_session_when_session_is_expired($driver, $transporter)
|
||||
{
|
||||
$dateTime = new DateTime('1970-01-01');
|
||||
|
||||
$this->setDriverExpectation($driver, 'load', array('last_activity' => $dateTime->getTimestamp()));
|
||||
|
||||
$manager = new Manager($driver, $transporter);
|
||||
|
||||
$payload = $manager->payload($this->getConfig());
|
||||
|
||||
$this->assertInstanceOf('Laravel\\Session\\Payload', $payload);
|
||||
$this->assertEquals(strlen($payload->session['id']), 40);
|
||||
}
|
||||
|
@ -82,18 +67,13 @@ public function testSessionManagerCreatesNewSessionWhenSessionIsExpired($driver,
|
|||
/**
|
||||
* @dataProvider mockProvider
|
||||
*/
|
||||
public function testSessionManagerSetsCSRFTokenIfOneIsNotPresent($driver, $transporter)
|
||||
public function test_session_manager_sets_csrf_token_if_one_is_not_present($driver, $transporter)
|
||||
{
|
||||
$session = $this->getDummySession();
|
||||
|
||||
unset($session['data']['csrf_token']);
|
||||
|
||||
$this->setDriverExpectation($driver, 'load', $session);
|
||||
|
||||
$manager = new Manager($driver, $transporter);
|
||||
|
||||
$payload = $manager->payload($this->getConfig());
|
||||
|
||||
$this->assertTrue(isset($payload->session['data']['csrf_token']));
|
||||
$this->assertEquals(strlen($payload->session['data']['csrf_token']), 16);
|
||||
}
|
||||
|
@ -101,58 +81,40 @@ public function testSessionManagerSetsCSRFTokenIfOneIsNotPresent($driver, $trans
|
|||
/**
|
||||
* @dataProvider mockProvider
|
||||
*/
|
||||
public function testCloseMethodCallsDriverAndTransporter($driver, $transporter)
|
||||
public function test_close_method_calls_driver_and_transporter($driver, $transporter)
|
||||
{
|
||||
$driver->expects($this->any())->method('load')->will($this->returnValue($this->getDummySession()));
|
||||
|
||||
$manager = new Manager($driver, $transporter);
|
||||
|
||||
$payload = $this->getMock('Laravel\\Session\\Payload', array('age'), array(array('id' => 'something')));
|
||||
|
||||
$payload->expects($this->any())->method('age')->will($this->returnValue('something'));
|
||||
|
||||
$driver->expects($this->once())->method('save')->with('something', $this->getConfig());
|
||||
|
||||
$transporter->expects($this->once())->method('put')->with('something', $this->getConfig());
|
||||
|
||||
$manager->close($payload, $this->getConfig());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider mockProvider
|
||||
*/
|
||||
public function testCloseMethodCallsSweepWhenDriverIsSweeper($driver, $transporter)
|
||||
public function test_close_method_calls_sweep_when_driver_is_sweeper($driver, $transporter)
|
||||
{
|
||||
$driver = $this->getMock('SweeperStub', array('sweep'));
|
||||
|
||||
$driver->expects($this->once())->method('sweep');
|
||||
|
||||
$manager = new Manager($driver, $transporter);
|
||||
|
||||
$config = $this->getConfig();
|
||||
|
||||
$config['sweepage'] = array(100, 100);
|
||||
|
||||
$manager->close(new Laravel\Session\Payload($this->getDummySession()), $config);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider mockProvider
|
||||
*/
|
||||
public function testCloseMethodDoesntCallSweepWhenDriverIsNotSweeper($driver, $transporter)
|
||||
public function test_close_method_doesnt_call_sweep_when_driver_isnt_sweeper($driver, $transporter)
|
||||
{
|
||||
$driver = $this->getMock('Laravel\\Session\\Drivers\\Driver', array('sweep', 'load', 'save', 'delete'));
|
||||
|
||||
$driver->expects($this->never())->method('sweep');
|
||||
|
||||
$manager = new Manager($driver, $transporter);
|
||||
|
||||
$manager = new Manager($driver, $transporter);
|
||||
|
||||
$config = $this->getConfig();
|
||||
|
||||
$config['sweepage'] = array(100, 100);
|
||||
|
||||
$manager->close(new Laravel\Session\Payload($this->getDummySession()), $config);
|
||||
}
|
||||
|
||||
|
@ -192,14 +154,14 @@ private function getDummySession()
|
|||
'id' => 'something',
|
||||
'last_activity' => time(),
|
||||
'data' => array(
|
||||
'name' => 'Taylor',
|
||||
'csrf_token' => 'token'
|
||||
'name' => 'Taylor',
|
||||
'csrf_token' => 'token'
|
||||
));
|
||||
}
|
||||
|
||||
private function getConfig()
|
||||
{
|
||||
return IoC::resolve('laravel.config')->get('session');
|
||||
return Laravel\Config::get('session');
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -211,7 +173,7 @@ private function getConfig()
|
|||
class SweeperStub implements Laravel\Session\Drivers\Driver, Laravel\Session\Drivers\Sweeper {
|
||||
|
||||
public function load($id) {}
|
||||
public function save($session, $config) {}
|
||||
public function save($session, $config, $exists) {}
|
||||
public function delete($id) {}
|
||||
public function sweep($expiration) {}
|
||||
|
|
@ -4,137 +4,111 @@
|
|||
|
||||
class SessionPayloadTest extends PHPUnit_Framework_TestCase {
|
||||
|
||||
public function testHasMethodIndicatesIfItemExistsInPayload()
|
||||
public function test_has_method_indicates_if_item_exists_in_payload()
|
||||
{
|
||||
$payload = new Payload($this->getDummyData());
|
||||
|
||||
$this->assertTrue($payload->has('name'));
|
||||
$this->assertTrue($payload->has('age'));
|
||||
$this->assertTrue($payload->has('gender'));
|
||||
|
||||
$this->assertFalse($payload->has('something'));
|
||||
$this->assertFalse($payload->has('id'));
|
||||
$this->assertFalse($payload->has('last_activity'));
|
||||
}
|
||||
|
||||
public function testGetMethodReturnsItemFromPayload()
|
||||
public function test_get_method_returns_item_from_payload()
|
||||
{
|
||||
$payload = new Payload($this->getDummyData());
|
||||
|
||||
$this->assertEquals($payload->get('name'), 'Taylor');
|
||||
$this->assertEquals($payload->get('age'), 25);
|
||||
$this->assertEquals($payload->get('gender'), 'male');
|
||||
}
|
||||
|
||||
public function testGetMethodReturnsDefaultWhenItemDoesntExist()
|
||||
public function test_get_method_returns_default_when_item_doesnt_exist()
|
||||
{
|
||||
$payload = new Payload($this->getDummyData());
|
||||
|
||||
$this->assertNull($payload->get('something'));
|
||||
$this->assertEquals('Taylor', $payload->get('something', 'Taylor'));
|
||||
$this->assertEquals('Taylor', $payload->get('something', function() {return 'Taylor';}));
|
||||
}
|
||||
|
||||
public function testPutMethodAddsToPayload()
|
||||
public function test_put_method_adds_to_payload()
|
||||
{
|
||||
$payload = new Payload($this->getDummyData());
|
||||
|
||||
$payload->put('name', 'Weldon');
|
||||
$payload->put('workmate', 'Joe');
|
||||
|
||||
$this->assertEquals($payload->session['data']['name'], 'Weldon');
|
||||
$this->assertEquals($payload->session['data']['workmate'], 'Joe');
|
||||
$this->assertInstanceOf('Laravel\\Session\\Payload', $payload->put('something', 'test'));
|
||||
}
|
||||
|
||||
public function testFlashMethodPutsItemInFlashData()
|
||||
public function test_flash_method_puts_item_in_flash_data()
|
||||
{
|
||||
$payload = new Payload(array());
|
||||
|
||||
$payload->flash('name', 'Taylor');
|
||||
|
||||
$this->assertEquals($payload->session['data'][':new:name'], 'Taylor');
|
||||
$this->assertInstanceOf('Laravel\\Session\\Payload', $payload->flash('something', 'test'));
|
||||
}
|
||||
|
||||
public function testReflashKeepsAllSessionData()
|
||||
public function test_reflash_keeps_all_session_data()
|
||||
{
|
||||
$payload = new Payload(array('data' => array(':old:name' => 'Taylor', ':old:age' => 25)));
|
||||
|
||||
$payload->reflash();
|
||||
|
||||
$this->assertTrue(isset($payload->session['data'][':new:name']));
|
||||
$this->assertTrue(isset($payload->session['data'][':new:age']));
|
||||
$this->assertFalse(isset($payload->session['data'][':old:name']));
|
||||
$this->assertFalse(isset($payload->session['data'][':old:age']));
|
||||
}
|
||||
|
||||
public function testKeepMethodKeepsSpecificSessionData()
|
||||
public function test_keep_method_keeps_specified_session_data()
|
||||
{
|
||||
$payload = new Payload(array('data' => array(':old:name' => 'Taylor', ':old:age' => 25)));
|
||||
|
||||
$payload->keep('name');
|
||||
|
||||
$this->assertTrue(isset($payload->session['data'][':new:name']));
|
||||
$this->assertFalse(isset($payload->session['data'][':old:name']));
|
||||
|
||||
$payload = new Payload(array('data' => array(':old:name' => 'Taylor', ':old:age' => 25)));
|
||||
|
||||
$payload->keep(array('name', 'age'));
|
||||
|
||||
$this->assertTrue(isset($payload->session['data'][':new:name']));
|
||||
$this->assertTrue(isset($payload->session['data'][':new:age']));
|
||||
$this->assertFalse(isset($payload->session['data'][':old:name']));
|
||||
$this->assertFalse(isset($payload->session['data'][':old:age']));
|
||||
}
|
||||
|
||||
public function testFlushMethodShouldClearPayloadData()
|
||||
public function test_flush_method_clears_payload_data()
|
||||
{
|
||||
$payload = new Payload(array('data' => array('name' => 'Taylor')));
|
||||
|
||||
$payload->flush();
|
||||
|
||||
$this->assertEquals(count($payload->session['data']), 0);
|
||||
}
|
||||
|
||||
public function testRegenerateMethodSetsNewSessionID()
|
||||
public function test_regenerate_session_sets_new_session_id()
|
||||
{
|
||||
$payload = new Payload(array('id' => 'something'));
|
||||
|
||||
$payload->regenerate();
|
||||
|
||||
$this->assertTrue($payload->regenerated);
|
||||
$this->assertEquals(strlen($payload->session['id']), 40);
|
||||
}
|
||||
|
||||
public function testAgeMethodSetsLastActivityTime()
|
||||
public function test_age_method_sets_last_activity_time()
|
||||
{
|
||||
$data = $this->getDummyData();
|
||||
|
||||
unset($data['last_activity']);
|
||||
|
||||
$payload = new Payload($data);
|
||||
|
||||
$payload->age();
|
||||
|
||||
$this->assertTrue(isset($payload->session['last_activity']));
|
||||
}
|
||||
|
||||
public function testAgeMethodAgesAllFlashData()
|
||||
public function test_age_method_ages_all_flash_data()
|
||||
{
|
||||
$payload = new Payload($this->getDummyData());
|
||||
|
||||
$payload->age();
|
||||
|
||||
$this->assertTrue(isset($payload->session['data'][':old:age']));
|
||||
$this->assertFalse(isset($payload->session['data'][':old:gender']));
|
||||
}
|
||||
|
||||
public function testAgeMethodReturnsSessionArray()
|
||||
public function test_age_method_returns_session_array()
|
||||
{
|
||||
$payload = new Payload($this->getDummyData());
|
||||
|
||||
$age = $payload->age();
|
||||
|
||||
$this->assertEquals($age['id'], 'something');
|
||||
}
|
||||
|
|
@ -1,98 +0,0 @@
|
|||
<?php
|
||||
|
||||
use Laravel\Database\Manager;
|
||||
|
||||
class DatabaseManagerTest extends PHPUnit_Framework_TestCase {
|
||||
|
||||
public function testWhenCallingConnectionMethodForNonEstablishedConnectionNewConnectionIsReturned()
|
||||
{
|
||||
$manager = new Manager($this->getConfig());
|
||||
|
||||
$connection = $manager->connection();
|
||||
|
||||
$this->assertInstanceOf('PDOStub', $connection->pdo);
|
||||
$this->assertInstanceOf('Laravel\\Database\\Connection', $connection);
|
||||
}
|
||||
|
||||
public function testConnectionMethodsReturnsSingletonConnections()
|
||||
{
|
||||
$manager = new Manager($this->getConfig());
|
||||
|
||||
$connection = $manager->connection();
|
||||
|
||||
$this->assertTrue($connection === $manager->connection());
|
||||
}
|
||||
|
||||
public function testConnectionMethodOverridesDefaultWhenConnectionNameIsGiven()
|
||||
{
|
||||
$config = $this->getConfig();
|
||||
|
||||
$config['connectors']['something'] = function($config) {return new AnotherPDOStub;};
|
||||
|
||||
$manager = new Manager($config);
|
||||
|
||||
$this->assertInstanceOf('AnotherPDOStub', $manager->connection('something')->pdo);
|
||||
}
|
||||
|
||||
public function testConfigurationArrayIsPassedToConnector()
|
||||
{
|
||||
$manager = new Manager($this->getConfig());
|
||||
|
||||
$this->assertEquals($manager->connection()->pdo->config, $this->getConfig());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Exception
|
||||
*/
|
||||
public function testExceptionIsThrownIfConnectorIsNotDefined()
|
||||
{
|
||||
$manager = new Manager($this->getConfig());
|
||||
|
||||
$manager->connection('something');
|
||||
}
|
||||
|
||||
public function testTableMethodCallsTableMethodOnConnection()
|
||||
{
|
||||
$manager = new Manager($this->getConfig());
|
||||
|
||||
$this->assertEquals($manager->table('users'), 'table');
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// Support Functions
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
private function getConfig()
|
||||
{
|
||||
return array('default' => 'test', 'connectors' => array('test' => function($config) {return new PDOStub($config);}));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// Stubs
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
class PDOStub extends PDO {
|
||||
|
||||
public $config;
|
||||
|
||||
public function __construct($config = array()) { $this->config = $config; }
|
||||
|
||||
public function table()
|
||||
{
|
||||
return 'table';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class AnotherPDOStub extends PDO {
|
||||
|
||||
public function __construct() {}
|
||||
|
||||
public function table()
|
||||
{
|
||||
return 'anotherTable';
|
||||
}
|
||||
|
||||
}
|
|
@ -1,131 +0,0 @@
|
|||
<?php
|
||||
|
||||
define('TEST_BASE_PATH', dirname(realpath(__FILE__)) . '/');
|
||||
|
||||
class RoutesTest extends PHPUnit_Framework_TestCase {
|
||||
public static function setUpBeforeClass() {
|
||||
// changing paths
|
||||
IoC::container()->register('laravel.routing.caller', function($c)
|
||||
{
|
||||
return new \Laravel\Routing\Caller($c, require TEST_BASE_PATH.'filters'.EXT, CONTROLLER_PATH);
|
||||
});
|
||||
|
||||
IoC::container()->register('laravel.routing.loader', function($c)
|
||||
{
|
||||
return new \Laravel\Routing\Loader(TEST_BASE_PATH,TEST_BASE_PATH . 'routes/');
|
||||
}, true);
|
||||
}
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$_POST = array();
|
||||
|
||||
unset($_SERVER['REQUEST_URI'], $_SERVER['REQUEST_METHOD']);
|
||||
}
|
||||
|
||||
/**
|
||||
* tests
|
||||
* GET /test/wildcard/(:num)/(:any)
|
||||
* GET /test/optwildcard/(:any+)
|
||||
*/
|
||||
public function testWildCards()
|
||||
{
|
||||
$response = $this->processRoute('/test/wildcard/123456/joe');
|
||||
$this->assertEquals($response->content, '123456/joe');
|
||||
|
||||
$response = $this->processRoute('/test/wildcard/123456');
|
||||
$this->assertEquals($response->content->view, 'error/404');
|
||||
|
||||
$response = $this->processRoute('/test/wildcard/abc123');
|
||||
$this->assertEquals($response->content, 'abc123');
|
||||
|
||||
$response = $this->processRoute('/test/optwildcard/foo');
|
||||
$this->assertEquals($response->content, 'foo');
|
||||
|
||||
$response = $this->processRoute('/test/optwildcard');
|
||||
$this->assertEquals($response->content, '');
|
||||
}
|
||||
|
||||
/**
|
||||
* tests GET /test/direct
|
||||
*/
|
||||
public function testDirect()
|
||||
{
|
||||
$response = $this->processRoute('/test/direct');
|
||||
$this->assertEquals($response->content, 'direct');
|
||||
|
||||
$response = $this->processRoute('/test/doesnt/exist');
|
||||
$this->assertEquals($response->content->view, 'error/404');
|
||||
}
|
||||
|
||||
/**
|
||||
* tests GET /test/multi and GET /test/altmulti
|
||||
* both routes are the same
|
||||
*/
|
||||
public function testMultiRoutes()
|
||||
{
|
||||
$response = $this->processRoute('/test/multi');
|
||||
$this->assertEquals($response->content, 'multi test');
|
||||
|
||||
$response = $this->processRoute('/test/altmulti');
|
||||
$this->assertEquals($response->content, 'multi test');
|
||||
}
|
||||
|
||||
/**
|
||||
* tests post
|
||||
*/
|
||||
public function testPost()
|
||||
{
|
||||
$response = $this->processRoute('/test/postrequest', 'POST');
|
||||
$this->assertEquals($response->content, 'POST request');
|
||||
}
|
||||
|
||||
/**
|
||||
* tests route spoofing
|
||||
*/
|
||||
public function testSpoofing()
|
||||
{
|
||||
$_POST['__spoofer'] = 'PUT';
|
||||
$response = $this->processRoute('/test/putrequest');
|
||||
$this->assertEquals($response->content, 'PUT request');
|
||||
}
|
||||
|
||||
/**
|
||||
* tests filters
|
||||
*/
|
||||
public function testFilters()
|
||||
{
|
||||
$response = $this->processRoute('/test/filter/before');
|
||||
$this->assertEquals($response->content, 'filtered before');
|
||||
|
||||
$response = $this->processRoute('/test/filter/after');
|
||||
$this->assertEquals($response->content, 'filtered after');
|
||||
|
||||
$response = $this->processRoute('/test/filter/multi');
|
||||
$this->assertEquals($response->content, 'filtered after filtered after2');
|
||||
}
|
||||
|
||||
private function processRoute($uri, $method = 'GET')
|
||||
{
|
||||
$_SERVER['REQUEST_URI'] = $uri;
|
||||
$_SERVER['REQUEST_METHOD'] = $method;
|
||||
|
||||
// not using container resolve because it is a singleton and that makes it so we can't change $_SERVER
|
||||
$request = new \Laravel\Request(new \Laravel\URI($_SERVER), $_SERVER, $_POST);
|
||||
$router = IoC::container()->resolve('laravel.routing.router');
|
||||
|
||||
list($method, $uri) = array($request->method(), $request->uri());
|
||||
$route = $router->route($request, $method, $uri);
|
||||
|
||||
if ( ! is_null($route))
|
||||
{
|
||||
$response = IoC::container()->resolve('laravel.routing.caller')->call($route);
|
||||
}
|
||||
else
|
||||
{
|
||||
$response = Response::error('404');
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
<?php
|
||||
|
||||
return array(
|
||||
'before_filter' => function()
|
||||
{
|
||||
return 'filtered before';
|
||||
},
|
||||
|
||||
'after_filter' => function($response)
|
||||
{
|
||||
$response->content = 'filtered after';
|
||||
|
||||
return $response;
|
||||
},
|
||||
|
||||
'after_filter2' => function($response)
|
||||
{
|
||||
$response->content .= ' filtered after2';
|
||||
|
||||
return $response;
|
||||
},
|
||||
);
|
|
@ -1,87 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* routes for test units
|
||||
*/
|
||||
|
||||
return array(
|
||||
/**
|
||||
* wildcard test
|
||||
*/
|
||||
'GET /test/wildcard/(:num)/(:any)' => function($id, $name)
|
||||
{
|
||||
return $id . '/' . $name;
|
||||
},
|
||||
|
||||
/**
|
||||
* regex wildcard
|
||||
*/
|
||||
'GET /test/wildcard/([a-z]{3}[0-9]{3})' => function($id)
|
||||
{
|
||||
return $id;
|
||||
},
|
||||
|
||||
/**
|
||||
* wildcard with optional parameter
|
||||
*/
|
||||
'GET /test/optwildcard/(:any?)' => function($value = '')
|
||||
{
|
||||
return $value;
|
||||
},
|
||||
|
||||
/**
|
||||
* direct path test
|
||||
*/
|
||||
'GET /test/direct' => function()
|
||||
{
|
||||
return 'direct';
|
||||
},
|
||||
|
||||
/**
|
||||
* multiple routes in one
|
||||
*/
|
||||
'GET /test/multi, GET /test/altmulti' => function()
|
||||
{
|
||||
return 'multi test';
|
||||
},
|
||||
|
||||
/**
|
||||
* post request
|
||||
*/
|
||||
'POST /test/postrequest' => function()
|
||||
{
|
||||
return 'POST request';
|
||||
},
|
||||
|
||||
/**
|
||||
* PUT request
|
||||
*/
|
||||
'PUT /test/putrequest' => function()
|
||||
{
|
||||
return 'PUT request';
|
||||
},
|
||||
|
||||
/**
|
||||
* before filter
|
||||
*/
|
||||
'GET /test/filter/before' => array('before' => 'before_filter', function()
|
||||
{
|
||||
return 'not filtered';
|
||||
}),
|
||||
|
||||
/**
|
||||
* after filter
|
||||
*/
|
||||
'GET /test/filter/after' => array('after' => 'after_filter', function()
|
||||
{
|
||||
return 'not filtered';
|
||||
}),
|
||||
|
||||
/**
|
||||
* multiple filters
|
||||
*/
|
||||
'GET /test/filter/multi' => array('after' => 'after_filter, after_filter2', function()
|
||||
{
|
||||
return 'not filtered';
|
||||
}),
|
||||
);
|
|
@ -13,14 +13,14 @@
|
|||
|
|
||||
*/
|
||||
|
||||
$application = 'application';
|
||||
$application = '../application';
|
||||
|
||||
$laravel = 'laravel';
|
||||
$laravel = '../laravel';
|
||||
|
||||
$packages = 'packages';
|
||||
$packages = '../packages';
|
||||
|
||||
$storage = 'storage';
|
||||
$storage = '../storage';
|
||||
|
||||
$public = 'public';
|
||||
$public = '../public';
|
||||
|
||||
require realpath($laravel).'/bootstrap/core.php';
|
|
@ -0,0 +1,7 @@
|
|||
<phpunit colors="true" bootstrap="bootstrap.php">
|
||||
<testsuites>
|
||||
<testsuite name="Laravel Framework Tests">
|
||||
<directory>Cases</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
</phpunit>
|
Loading…
Reference in New Issue