Skip to content

Instantly share code, notes, and snippets.

@ogaty
Last active July 19, 2023 03:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ogaty/63242ad43854ab9931aaf51ec80a28f7 to your computer and use it in GitHub Desktop.
Save ogaty/63242ad43854ab9931aaf51ec80a28f7 to your computer and use it in GitHub Desktop.
make url check test for laravel
admin method url controller name title
admin get /admin/news NewsController admin.news.index admin news
front get /news NewsController admin.news.index front news
<?php
require_once '../vendor/autoload.php';
use League\Csv\Reader;
$csv = Reader::createFromPath('./route.csv', 'r');
$csv->setHeaderOffset(0);
$records = $csv->getRecords();
echo "public function test_routing()\n";
echo "{\n";
foreach($records as $record) {
printf(" \$this->assertEquals(route(\"%s\", [], false), \"%s\");\n", $record['name'], $record['url']);
if ($record['admin'] == 'admin') {
printf(" \$response = \$this->actingAs(\$admin)->\$this->%s(route(\"%s\"));\n", $record['method'], $record['name']);
} else {
printf(" \$response = \$this->%s(route(\"%s\"));\n", $record['method'], $record['name']);
}
echo " \$response->assertOk();" . "\n";
printf(" \$response->assertSee(<title>%s</title>);\n", $record['title']);
echo "\n";
}
echo "}\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment