[5.3] Demo mode is not compatible with `artisan route:cache`
Closed this issue · 5 comments
[LogicException]
Unable to prepare route [demo] for serialization. Uses Closure.
We'd accept a PR that replaces the closure with a controller.
I'm working on it but I meet some difficulties when updating tests...
App can't write in bootstrap\cache
.
This is my WIP code:
Spatie\DemoMode\DemoModeController
namespace Spatie\DemoMode;
use Illuminate\Http\RedirectResponse;
class DemoModeController extends \Illuminate\Routing\Controller
{
/**
* Handle demo mode
*
* @param void
* @return RedirectResponse
*/
public function handle()
{
session()->put('demo_access_granted', true);
return new RedirectResponse(config('laravel-demo-mode.redirect_authorized_users_to_url'));
}
}
tests/DemoModeTest.php
/** @test */
public function it_allows_cached_routes_file()
{
try {
\Artisan::call('route:cache');
} catch (\Exception $e) {
$this->assertTrue(false);
}
$this->assertTrue(true);
}
DemoModeServiceProvider.php
$router->macro('demoAccess', function ($url) use ($router) {
if (!config('laravel-demo-mode.enabled')) {
return;
}
$router->get($url, 'Spatie\DemoMode\DemoModeController@handle');
});
Not sure if it's completely necessary to test this. Feel free to send the PR with the broken test and I'll look into it (or drop the test if it's too much of a hassle).
Done :)
Test is broken.
I'm not comfortable with your way of making tests. When I build packages, I always use a real laravel (require-dev laravel/laravel) so I have a real laravel, not just laravel/framework so it's much easier for me to write tests...
Thanks for your contribution!
New release tagged as 1.1.1
https://github.com/spatie/laravel-demo-mode/releases/tag/1.1.1