Skip to content

Commit

Permalink
Merge pull request #2686 from samsonasik/fix-2676
Browse files Browse the repository at this point in the history
Fix #2676 : add ability to test redirect()->route() via ControllerTester
  • Loading branch information
MGatner authored Mar 18, 2020
2 parents 28dfa26 + 527bdcc commit 84b9cc7
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 13 deletions.
19 changes: 11 additions & 8 deletions system/Test/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
$paths = new Config\Paths();

// Define necessary framework path constants
defined('APPPATH') || define('APPPATH', realpath($paths->appDirectory) . DIRECTORY_SEPARATOR);
defined('WRITEPATH') || define('WRITEPATH', realpath($paths->writableDirectory) . DIRECTORY_SEPARATOR);
defined('SYSTEMPATH') || define('SYSTEMPATH', realpath($paths->systemDirectory) . DIRECTORY_SEPARATOR);
defined('ROOTPATH') || define('ROOTPATH', realpath(APPPATH . '../') . DIRECTORY_SEPARATOR);
defined('CIPATH') || define('CIPATH', realpath(SYSTEMPATH . '../') . DIRECTORY_SEPARATOR);
defined('FCPATH') || define('FCPATH', realpath(PUBLICPATH) . DIRECTORY_SEPARATOR);
defined('TESTPATH') || define('TESTPATH', realpath(HOMEPATH . 'tests/') . DIRECTORY_SEPARATOR);
defined('SUPPORTPATH') || define('SUPPORTPATH', realpath(TESTPATH . '_support/') . DIRECTORY_SEPARATOR);
defined('APPPATH') || define('APPPATH', realpath($paths->appDirectory) . DIRECTORY_SEPARATOR);
defined('WRITEPATH') || define('WRITEPATH', realpath($paths->writableDirectory) . DIRECTORY_SEPARATOR);
defined('SYSTEMPATH') || define('SYSTEMPATH', realpath($paths->systemDirectory) . DIRECTORY_SEPARATOR);
defined('ROOTPATH') || define('ROOTPATH', realpath(APPPATH . '../') . DIRECTORY_SEPARATOR);
defined('CIPATH') || define('CIPATH', realpath(SYSTEMPATH . '../') . DIRECTORY_SEPARATOR);
defined('FCPATH') || define('FCPATH', realpath(PUBLICPATH) . DIRECTORY_SEPARATOR);
defined('TESTPATH') || define('TESTPATH', realpath(HOMEPATH . 'tests/') . DIRECTORY_SEPARATOR);
defined('SUPPORTPATH') || define('SUPPORTPATH', realpath(TESTPATH . '_support/') . DIRECTORY_SEPARATOR);
defined('COMPOSER_PATH') || define('COMPOSER_PATH', realpath(HOMEPATH . 'vendor/autoload.php'));

// Load Common.php from App then System
Expand Down Expand Up @@ -58,3 +58,6 @@ class_alias('Config\Services', 'CodeIgniter\Services');

// Register the loader with the SPL autoloader stack.
$loader->register();

require_once APPPATH . 'Config/Routes.php';
$routes->getRoutes('*');
2 changes: 1 addition & 1 deletion tests/_support/Config/Routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
* This is a simple file to include for testing the RouteCollection class.
*/

$routes->add('testing', 'TestController::index');
$routes->add('testing', 'TestController::index', ['as' => 'testing-index']);
5 changes: 5 additions & 0 deletions tests/_support/Controllers/Popcorn.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,9 @@ public function xml()
$this->respond('<my><pet>cat</pet></my>');
}

public function toindex()
{
return redirect()->route('testing-index');
}

}
2 changes: 1 addition & 1 deletion tests/system/Router/RouteCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1118,7 +1118,7 @@ public function testDiscoverLocalAllowsConfigToOverridePackages()

$routes = $this->getCollector($config, [], $moduleConfig);

$routes->add('testing', 'MainRoutes::index');
$routes->add('testing', 'MainRoutes::index', ['as' => 'testing-index']);

$match = $routes->getRoutes();

Expand Down
7 changes: 7 additions & 0 deletions tests/system/Test/ControllerTesterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,4 +228,11 @@ public function testControllerNoURI()
$this->assertTrue($result->isOK());
}

public function testRedirectRoute()
{
$result = $this->controller(\Tests\Support\Controllers\Popcorn::class)
->execute('toindex');
$this->assertTrue($result->isRedirect());
}

}
6 changes: 3 additions & 3 deletions tests/system/Test/FeatureTestCaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public function testReturns()
[
'get',
'home',
'Tests\Support\Controllers\Popcorn::index',
'\Tests\Support\Controllers\Popcorn::index',
],
]);
$response = $this->get('home');
Expand All @@ -174,7 +174,7 @@ public function testIgnores()
[
'get',
'home',
'Tests\Support\Controllers\Popcorn::cat',
'\Tests\Support\Controllers\Popcorn::cat',
],
]);
$response = $this->get('home');
Expand All @@ -187,7 +187,7 @@ public function testEchoes()
[
'get',
'home',
'Tests\Support\Controllers\Popcorn::canyon',
'\Tests\Support\Controllers\Popcorn::canyon',
],
]);
ob_start();
Expand Down

0 comments on commit 84b9cc7

Please sign in to comment.