Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bootstrap/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
return Application::configure(basePath: dirname(__DIR__))
->withRouting(
web: __DIR__.'/../routes/web.php',
api: __DIR__.'/../routes/api.php',
api: file_exists(__DIR__.'/../routes/api.php') ? __DIR__.'/../routes/api.php' : null,
commands: __DIR__.'/../routes/console.php',
health: '/up',
)
Expand Down
28 changes: 28 additions & 0 deletions tests/Feature/ApiRoutingTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

use Illuminate\Contracts\Console\Kernel;
use Illuminate\Foundation\Application;

test('application boots when routes api file is missing', function () {
$apiFile = base_path('routes/api.php');
$backupFile = base_path('routes/api.php.test_backup');

if (file_exists($apiFile)) {
rename($apiFile, $backupFile);
}

try {
$app = require base_path('bootstrap/app.php');
$app->make(Kernel::class)->bootstrap();

expect($app)->toBeInstanceOf(Application::class);
} finally {
if (file_exists($backupFile)) {
rename($backupFile, $apiFile);
}
}
});

test('api routes are registered when routes api file is present', function () {
$this->getJson('/api/user')->assertStatus(401);
});