123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- <?php
- namespace Tests;
- use Dcat\Admin\Models\Administrator;
- use Illuminate\Contracts\Console\Kernel;
- use Illuminate\Filesystem\Filesystem;
- use Illuminate\Support\Arr;
- use Illuminate\Support\Facades\Artisan;
- use Illuminate\Support\Facades\DB;
- use Illuminate\Support\Facades\Schema;
- trait CreatesApplication
- {
- public function createApplication()
- {
- $app = require $this->getAppPath();
- $app->make(Kernel::class)->bootstrap();
- return $app;
- }
- protected function boot()
- {
- $this->config();
- $this->artisan('admin:publish');
- Schema::defaultStringLength(191);
- $this->artisan('admin:install');
- $this->migrateTestTables();
- if (file_exists($routes = admin_path('routes.php'))) {
- require $routes;
- }
- require __DIR__.'/helpers.php';
- require __DIR__.'/routes.php';
- require __DIR__.'/resources/seeds/factory.php';
- view()->addNamespace('admin-tests', __DIR__.'/resources/views');
- }
- protected function config()
- {
- $adminConfig = require __DIR__.'/resources/config/admin.php';
- $config = $this->app['config'];
- $config->set('database.default', 'mysql');
- $config->set('database.connections.mysql.host', env('DB_HOST', 'localhost'));
- $config->set('database.connections.mysql.database', env('DB_DATABASE', 'laravel_dcat_admin_test'));
- $config->set('database.connections.mysql.username', env('DB_USERNAME', 'root'));
- $config->set('database.connections.mysql.password', env('DB_PASSWORD', ''));
- $config->set('app.key', 'AckfSECXIvnK5r28GVIWUAxmbBSjTsmF');
- $config->set('filesystems', require __DIR__.'/resources/config/filesystems.php');
- $config->set('admin', $adminConfig);
- $config->set('app.debug', true);
- foreach (Arr::dot(Arr::get($adminConfig, 'auth'), 'auth.') as $key => $value) {
- $this->app['config']->set($key, $value);
- }
- }
- protected function getAppPath()
- {
- $path = __DIR__.'/../bootstrap/app.php';
- if (! is_file($path)) {
- $path = __DIR__.'/../../bootstrap/app.php';
- }
- return $path;
- }
- protected function destory()
- {
- (new \CreateAdminTables())->down();
- (new \CreateTestTables())->down();
- DB::select("delete from `migrations` where `migration` = '2016_01_04_173148_create_admin_tables'");
- DB::select("delete from `migrations` where `migration` = '2016_11_22_093148_create_test_tables'");
- Artisan::call('migrate:rollback');
- }
- public function migrateTestTables()
- {
- $fileSystem = new Filesystem();
- $fileSystem->requireOnce(__DIR__.'/resources/migrations/2016_11_22_093148_create_test_tables.php');
- (new \CreateTestTables())->up();
- }
- /**
- * @return Administrator
- */
- protected function getUser()
- {
- if ($this->user) {
- return $this->user;
- }
- return $this->user = Administrator::first();
- }
- }
|