TestCase.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. use Illuminate\Filesystem\Filesystem;
  3. use Illuminate\Support\Facades\DB;
  4. use Illuminate\Support\Facades\Schema;
  5. use Laravel\BrowserKitTesting\TestCase as BaseTestCase;
  6. class TestCase extends BaseTestCase
  7. {
  8. protected $baseUrl = 'http://localhost:8000';
  9. /**
  10. * Boots the application.
  11. *
  12. * @return \Illuminate\Foundation\Application
  13. */
  14. public function createApplication()
  15. {
  16. $app = require __DIR__.'/../vendor/laravel/laravel/bootstrap/app.php';
  17. $app->booting(function () {
  18. $loader = \Illuminate\Foundation\AliasLoader::getInstance();
  19. $loader->alias('Admin', \Encore\Admin\Facades\Admin::class);
  20. });
  21. $app->make('Illuminate\Contracts\Console\Kernel')->bootstrap();
  22. $app->register('Encore\Admin\AdminServiceProvider');
  23. return $app;
  24. }
  25. public function setUp()
  26. {
  27. parent::setUp();
  28. $adminConfig = require __DIR__.'/config/admin.php';
  29. $this->app['config']->set('database.default', 'mysql');
  30. $this->app['config']->set('database.connections.mysql.host', env('MYSQL_HOST', 'localhost'));
  31. $this->app['config']->set('database.connections.mysql.database', 'laravel_admin');
  32. $this->app['config']->set('database.connections.mysql.username', 'root');
  33. $this->app['config']->set('database.connections.mysql.password', '');
  34. $this->app['config']->set('app.key', 'AckfSECXIvnK5r28GVIWUAxmbBSjTsmF');
  35. $this->app['config']->set('filesystems', require __DIR__.'/config/filesystems.php');
  36. $this->app['config']->set('admin', $adminConfig);
  37. foreach (array_dot(array_get($adminConfig, 'auth'), 'auth.') as $key => $value) {
  38. $this->app['config']->set($key, $value);
  39. }
  40. $this->artisan('vendor:publish', ['--provider' => 'Encore\Admin\AdminServiceProvider']);
  41. Schema::defaultStringLength(191);
  42. $this->artisan('admin:install');
  43. $this->migrateTestTables();
  44. if (file_exists($routes = admin_path('routes.php'))) {
  45. require $routes;
  46. }
  47. require __DIR__.'/routes.php';
  48. require __DIR__.'/seeds/factory.php';
  49. }
  50. public function tearDown()
  51. {
  52. (new CreateAdminTables())->down();
  53. (new CreateTestTables())->down();
  54. DB::select("delete from `migrations` where `migration` = '2016_01_04_173148_create_admin_tables'");
  55. parent::tearDown();
  56. }
  57. /**
  58. * run package database migrations.
  59. *
  60. * @return void
  61. */
  62. public function migrateTestTables()
  63. {
  64. $fileSystem = new Filesystem();
  65. $fileSystem->requireOnce(__DIR__.'/migrations/2016_11_22_093148_create_test_tables.php');
  66. (new CreateTestTables())->up();
  67. }
  68. }