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

2 years ago
  1. <?php
  2. namespace Tests;
  3. use App\Providers\SettingServiceProvider;
  4. use Illuminate\Contracts\Console\Kernel;
  5. use Illuminate\Support\ServiceProvider;
  6. trait CreatesApplication
  7. {
  8. /**
  9. * Creates the application.
  10. *
  11. * @return \Illuminate\Foundation\Application
  12. */
  13. public function createApplication()
  14. {
  15. $app = require __DIR__.'/../bootstrap/app.php';
  16. $app->make(Kernel::class)->bootstrap();
  17. $app->id = 0;
  18. app()->bind('nextId', fn() => $this->nextId());
  19. app()->instance(SettingServiceProvider::class, null);
  20. app()->register(FakeSettingServiceProvider::class);
  21. return $app;
  22. }
  23. private function nextId(): int
  24. {
  25. $id = $this->app->id;
  26. $id++;
  27. $this->app->id = $id;
  28. return $id;
  29. }
  30. }
  31. class FakeSettingServiceProvider extends ServiceProvider {
  32. function boot() {
  33. $this->app->bind('settings', function() {
  34. return json_decode(file_get_contents(base_path('settings.json')), true);
  35. });
  36. }
  37. }