Reputation: 11
Like the the title suggest how to get list of routes in a test case. I know that it can be done in controllers by using Route::getRoutes()
. But, this will not work in test cases. Can somebody give me an idea on this.
Update:
How can I do this in test cases?
$routeCollection = Route::getRoutes();
$routeArray = [];
$i = 0
foreach($routeCollection as $value) {
$routeArray[$i++] = $value->getPath();
}
Update 2: Like this test case. I want to get a list of route in the test case. But this does not work.
<?php
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Laracasts\Integrated\Extensions\Selenium as IntegrationTest;
class RouteTest extends IntegrationTest
{
/**
* A basic test example.
*
* @return void
*/
public function testExample()
{
$routeCollection = Route::getRoutes();
foreach($routeCollection as $value) {
$this->visit($value->getPath())
->onPage($value->getPath());
}
}
}
Upvotes: 1
Views: 2046
Reputation: 182
In http://laravel.com/docs/4.2/testing#calling-routes-from-tests there is a note that says:
Note: Route filters are disabled when in the testing environment. To enable them, add Route::enableFilters() to your test.
PD:This is for 4.2.
Upvotes: 1