CreatesApplication.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. namespace Tests;
  3. use Dcat\Admin\Models\Administrator;
  4. use Illuminate\Contracts\Console\Kernel;
  5. use Illuminate\Filesystem\Filesystem;
  6. use Illuminate\Support\Facades\Artisan;
  7. use Illuminate\Support\Facades\DB;
  8. use Illuminate\Support\Facades\Schema;
  9. trait CreatesApplication
  10. {
  11. public function createApplication()
  12. {
  13. $app = require $this->getAppPath();
  14. $app->make(Kernel::class)->bootstrap();
  15. return $app;
  16. }
  17. protected function boot()
  18. {
  19. $this->artisan('admin:publish');
  20. Schema::defaultStringLength(191);
  21. $this->artisan('admin:install');
  22. $this->migrateTestTables();
  23. require __DIR__.'/helpers.php';
  24. require __DIR__.'/resources/seeds/factory.php';
  25. view()->addNamespace('admin-tests', __DIR__.'/resources/views');
  26. }
  27. protected function getAppPath()
  28. {
  29. $path = __DIR__.'/../bootstrap/app.php';
  30. if (! is_file($path)) {
  31. $path = __DIR__.'/../../bootstrap/app.php';
  32. }
  33. if (! is_file($path)) {
  34. $path = __DIR__.'/../../../bootstrap/app.php';
  35. }
  36. return $path;
  37. }
  38. protected function destory()
  39. {
  40. //(new \CreateAdminTables())->down();
  41. //(new \CreateAdminSettingsTable())->down();
  42. //(new \CreateAdminExtensionsTable())->down();
  43. //(new \UpdateAdminMenuTable())->down();
  44. //
  45. (new \CreateTestTables())->down();
  46. //DB::select("delete from `migrations` where `migration` = '2016_01_04_173148_create_admin_tables'");
  47. //DB::select("delete from `migrations` where `migration` = '2020_09_07_090635_create_admin_settings_table'");
  48. //DB::select("delete from `migrations` where `migration` = '2020_09_22_015815_create_admin_extensions_table'");
  49. //DB::select("delete from `migrations` where `migration` = '2020_11_01_083237_update_admin_menu_table'");
  50. DB::select("delete from `migrations` where `migration` = '2016_11_22_093148_create_test_tables'");
  51. Artisan::call('migrate:rollback');
  52. }
  53. public function migrateTestTables()
  54. {
  55. $fileSystem = new Filesystem();
  56. $fileSystem->requireOnce(__DIR__.'/resources/migrations/2016_11_22_093148_create_test_tables.php');
  57. (new \CreateTestTables())->up();
  58. }
  59. /**
  60. * @return Administrator
  61. */
  62. protected function getUser()
  63. {
  64. if ($this->user) {
  65. return $this->user;
  66. }
  67. return $this->user = Administrator::first();
  68. }
  69. }