Last active
July 19, 2023 03:59
-
-
Save ogaty/63242ad43854ab9931aaf51ec80a28f7 to your computer and use it in GitHub Desktop.
make url check test for laravel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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