You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

50 lines
1.0 KiB

<?php
namespace Tests;
use App\Providers\SettingServiceProvider;
use Illuminate\Contracts\Console\Kernel;
use Illuminate\Support\ServiceProvider;
trait CreatesApplication
{
/**
* Creates the application.
*
* @return \Illuminate\Foundation\Application
*/
public function createApplication()
{
$app = require __DIR__.'/../bootstrap/app.php';
$app->make(Kernel::class)->bootstrap();
$app->id = 0;
app()->bind('nextId', fn() => $this->nextId());
app()->instance(SettingServiceProvider::class, null);
app()->register(FakeSettingServiceProvider::class);
return $app;
}
private function nextId(): int
{
$id = $this->app->id;
$id++;
$this->app->id = $id;
return $id;
}
}
class FakeSettingServiceProvider extends ServiceProvider {
function boot() {
$this->app->bind('settings', function() {
return json_decode(file_get_contents(base_path('settings.json')), true);
});
}
}