TestCase.php 2.7 KB

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