Reintroduce getRouteKey to handle router with model + tests

This commit is contained in:
Jérémy Munsch 2021-09-16 09:43:04 +02:00
parent 4dfe0eb17c
commit 1e2e9bdecf
No known key found for this signature in database
GPG key ID: 55196BEE445F6049
2 changed files with 8 additions and 9 deletions

View file

@ -23,9 +23,7 @@ abstract class BaseEnumRoutable extends BaseEnum implements UrlRoutable
*/
public function getRouteKey()
{
// @codeCoverageIgnoreStart
throw new NotImplementedException('getRouteKey not implemented, should not be used.');
// @codeCoverageIgnoreEnd
return $this->value;
}
/**

View file

@ -118,7 +118,7 @@ class BaseEnumRoutableTest extends TestCase
{
$router->get('/journals/{journal}', function (Journal $journal) {
return response()->json([$journal->day]);
})->middleware('bindings');
})->middleware('bindings')->name('journal.view');
$router->get('/reports/{report}', function (Report $report) {
return response()->json([$report->day]);
})->middleware('bindings');
@ -203,15 +203,16 @@ class BaseEnumRoutableTest extends TestCase
public function testRoutesWithEnumAsPrimaryKeyWithoutCastEnumsAndCast()
{
$response = $this->json('GET', sprintf('/journals/%s', Days::none()->value));
// This test includes getRouteKey method for coverage
$response = $this->json('GET', \route('journal.view', Days::none()));
$response->assertOk();
$response = $this->json('GET', sprintf('/journals/%s', Days::mon()->value));
$response = $this->json('GET', \route('journal.view', Days::mon()));
$response->assertOk();
$response = $this->json('GET', sprintf('/journals/%s', Days::tue()->value));
$response = $this->json('GET', \route('journal.view', Days::tue()));
$response->assertOk();
$response = $this->json('GET', sprintf('/journals/%s', Days::fri()->value));
$response = $this->json('GET', \route('journal.view', Days::fri()));
$response->assertOk();
$response = $this->json('GET', sprintf('/journals/%s', 9999));
$response = $this->json('GET', \route('journal.view', 9999));
$response->assertNotFound();
}