Ver Fonte

单元测试集成

update
jqh há 5 anos atrás
pai
commit
67ea4f342b
45 ficheiros alterados com 272 adições e 202 exclusões
  1. 3 0
      .gitignore
  2. 22 0
      .travis.yml
  3. 15 10
      composer.json
  4. 1 2
      phpunit.xml.dist
  5. 0 92
      tests/BasicTestCase.php
  6. 1 1
      tests/Controllers/DropdownController.php
  7. 7 10
      tests/Controllers/ReportController.php
  8. 14 21
      tests/Controllers/UserController.php
  9. 2 2
      tests/CreatesApplication.php
  10. 1 1
      tests/DuskTestCase.php
  11. 8 4
      tests/Feature/AuthTest.php
  12. 6 3
      tests/Feature/CombineGridTest.php
  13. 5 2
      tests/Feature/IndexTest.php
  14. 5 4
      tests/Feature/InstallTest.php
  15. 5 2
      tests/Feature/MenuTest.php
  16. 5 2
      tests/Feature/OperationLogTest.php
  17. 5 2
      tests/Feature/PermissionsTest.php
  18. 5 2
      tests/Feature/RolesTest.php
  19. 2 2
      tests/Feature/SectionTest.php
  20. 13 8
      tests/Feature/TranslationTest.php
  21. 5 2
      tests/Feature/UserFormTest.php
  22. 5 2
      tests/Feature/UserGridTest.php
  23. 5 2
      tests/Feature/UserSettingTest.php
  24. 5 2
      tests/Feature/UserShowTest.php
  25. 5 2
      tests/Feature/UsersTest.php
  26. 1 1
      tests/Models/File.php
  27. 1 1
      tests/Models/Image.php
  28. 1 1
      tests/Models/MultipleImage.php
  29. 1 1
      tests/Models/Profile.php
  30. 1 1
      tests/Models/Tag.php
  31. 1 1
      tests/Models/Tree.php
  32. 1 1
      tests/Models/User.php
  33. 1 1
      tests/Repositories/Report.php
  34. 3 2
      tests/Repositories/User.php
  35. 94 3
      tests/TestCase.php
  36. 0 0
      tests/resources/assets/test.jpg
  37. 16 8
      tests/resources/config/admin.php
  38. 0 0
      tests/resources/config/filesystems.php
  39. 0 0
      tests/resources/lang/en/global.php
  40. 0 0
      tests/resources/lang/en/user.php
  41. 0 0
      tests/resources/migrations/2016_11_22_093148_create_test_tables.php
  42. 0 0
      tests/resources/seeds/UserTableSeeder.php
  43. 0 0
      tests/resources/seeds/factory.php
  44. 0 0
      tests/resources/views/test.blade.php
  45. 1 1
      tests/routes.php

+ 3 - 0
.gitignore

@@ -0,0 +1,3 @@
+vendor/
+composer.lock
+.idea

+ 22 - 0
.travis.yml

@@ -0,0 +1,22 @@
+language: php
+
+php:
+  - 7
+
+matrix:
+  fast_finish: true
+  allow_failures:
+    - php: hhvm
+
+sudo: false
+
+services:
+  - mysql
+
+before_script:
+  - mysql -e 'create database if not exists laravel_dcat_admin_test;'
+  - travis_retry composer self-update
+  - travis_retry composer install --no-interaction
+
+script:
+  - composer test

+ 15 - 10
composer.json

@@ -2,7 +2,7 @@
     "name": "dcat/laravel-admin",
     "description": "dcat admin",
     "type": "library",
-    "keywords": ["dcat", "laravel", "admin", "grid", "form"],
+    "keywords": ["dcat", "laravel", "admin", "grid", "form", "laravel admin"],
     "homepage": "https://github.com/jqhph/dcat-admin",
     "license": "MIT",
     "authors": [
@@ -19,7 +19,14 @@
         "spatie/eloquent-sortable": "3.*"
     },
     "require-dev": {
-        "laravel/browser-kit-testing": "~5.1"
+        "laravel/browser-kit-testing": "~5.1",
+        "friendsofphp/php-cs-fixer": "^2.15",
+        "laravel/laravel": "~5.5|~6",
+        "phpstan/phpstan": "^0.12.0",
+        "phpunit/phpunit": "^7.5",
+        "fzaninotto/faker": "^1.4",
+        "mockery/mockery": "^1.0",
+        "dcat/easy-excel": "^1.0"
     },
     "autoload": {
         "psr-4": {
@@ -31,15 +38,13 @@
     },
     "autoload-dev": {
         "psr-4": {
-            "Tests\\Models\\": "tests/models",
-            "Tests\\Controllers\\": "tests/controllers"
-        },
-        "classmap": [
-            "tests/TestCase.php"
-        ]
+            "Dcat\\Admin\\Tests\\": "tests/"
+        }
     },
     "scripts": {
-        "test": "./vendor/bin/phpunit"
+        "phpcs": "vendor/bin/php-cs-fixer fix",
+        "phpstan": "vendor/bin/phpstan analyse",
+        "test": "vendor/bin/phpunit"
     },
     "suggest": {
         "intervention/image": "Required to handling and manipulation upload images (~2.3).",
@@ -52,4 +57,4 @@
             ]
         }
     }
-}
+}

+ 1 - 2
phpunit.xml.dist

@@ -8,9 +8,8 @@
          convertWarningsToExceptions="true"
          processIsolation="false"
          stopOnFailure="true"
-         syntaxCheck="false"
          verbose="true"
-        >
+>
     <testsuites>
         <testsuite name="all">
             <directory>tests/</directory>

+ 0 - 92
tests/BasicTestCase.php

@@ -1,92 +0,0 @@
-<?php
-
-namespace Tests;
-
-use Dcat\Admin\Models\Administrator;
-use Illuminate\Filesystem\Filesystem;
-use Illuminate\Support\Arr;
-use Illuminate\Support\Facades\DB;
-use Illuminate\Support\Facades\Schema;
-
-trait BasicTestCase
-{
-    public function setUp(): void
-    {
-        parent::setUp();
-
-        $adminConfig = require __DIR__.'/config/admin.php';
-
-        $this->app['config']->set('database.default', 'mysql');
-        $this->app['config']->set('database.connections.mysql.host', env('MYSQL_HOST', 'localhost'));
-        $this->app['config']->set('database.connections.mysql.database', 'laravel_dcat_admin_test');
-        $this->app['config']->set('database.connections.mysql.username', 'root');
-        $this->app['config']->set('database.connections.mysql.password', '');
-        $this->app['config']->set('app.key', 'AckfSECXIvnK5r28GVIWUAxmbBSjTsmF');
-        $this->app['config']->set('filesystems', require __DIR__.'/config/filesystems.php');
-        $this->app['config']->set('admin', $adminConfig);
-
-        foreach (Arr::dot(Arr::get($adminConfig, 'auth'), 'auth.') as $key => $value) {
-            $this->app['config']->set($key, $value);
-        }
-
-        $this->artisan('vendor:publish', ['--provider' => 'Dcat\Admin\AdminServiceProvider']);
-
-        Schema::defaultStringLength(191);
-
-        $this->artisan('admin:install');
-
-        $this->migrateTestTables();
-
-        if (file_exists($routes = admin_path('routes.php'))) {
-            require $routes;
-        }
-
-        require __DIR__.'/routes.php';
-
-        require __DIR__.'/seeds/factory.php';
-
-        view()->addNamespace('admin-tests', __DIR__.'/views');
-
-        if ($this->login) {
-            $this->be($this->getUser(), 'admin');
-        }
-    }
-
-    /**
-     * @return Administrator
-     */
-    protected function getUser()
-    {
-        if ($this->user) {
-            return $this->user;
-        }
-
-        return $this->user = Administrator::first();
-    }
-
-    public function tearDown(): void
-    {
-        (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'");
-
-        parent::tearDown();
-    }
-
-    /**
-     * run package database migrations.
-     *
-     * @return void
-     */
-    public function migrateTestTables()
-    {
-        $fileSystem = new Filesystem();
-
-        $fileSystem->requireOnce(__DIR__.'/migrations/2016_11_22_093148_create_test_tables.php');
-
-        (new \CreateTestTables())->up();
-    }
-}

+ 1 - 1
tests/Controllers/DropdownController.php

@@ -1,6 +1,6 @@
 <?php
 
-namespace Tests\Controllers;
+namespace Dcat\Admin\Tests\Controllers;
 
 use Dcat\Admin\Admin;
 use Dcat\Admin\Layout\Content;

+ 7 - 10
tests/Controllers/ReportController.php

@@ -1,18 +1,19 @@
 <?php
 
-namespace Tests\Controllers;
+namespace Dcat\Admin\Tests\Controllers;
 
 use App\Http\Controllers\Controller;
 use Dcat\Admin\Grid;
 use Dcat\Admin\Layout\Content;
-use Illuminate\Contracts\Support\Renderable;
-use Tests\Repositories\Report;
+use Dcat\Admin\Tests\Repositories\Report;
 
 class ReportController extends Controller
 {
     public function index(Content $content)
     {
-        return $content->header('报表')->body($this->grid());
+        return $content
+            ->header('报表')
+            ->body($this->grid());
     }
 
     protected function grid()
@@ -21,16 +22,12 @@ class ReportController extends Controller
 
         // 开启responsive插件
         $grid->responsive();
+
         $grid->disableActions();
         $grid->disableBatchDelete();
         $grid->disableCreateButton();
 
-        $grid->setRowSelectorOptions(['style' => 'success', 'clicktr' => true]);
-
-        // 更改表格外层容器
-        $grid->wrap(function (Renderable $view) {
-            return $view;
-        });
+        $grid->rowSelector()->style('success')->click();
 
         $grid->combine('avgCost', ['avgMonthCost', 'avgQuarterCost', 'avgYearCost'])->responsive()->help('test');
         $grid->combine('avgVist', ['avgMonthVist', 'avgQuarterVist', 'avgYearVist'])->responsive();

+ 14 - 21
tests/Controllers/UserController.php

@@ -1,6 +1,6 @@
 <?php
 
-namespace Tests\Controllers;
+namespace Dcat\Admin\Tests\Controllers;
 
 use App\Http\Controllers\Controller;
 use Dcat\Admin\Controllers\HasResourceActions;
@@ -9,7 +9,7 @@ use Dcat\Admin\Grid;
 use Dcat\Admin\Layout\Content;
 use Dcat\Admin\Show;
 use Tests\Models\Tag;
-use Tests\Repositories\User;
+use Dcat\Admin\Tests\Repositories\User;
 
 class UserController extends Controller
 {
@@ -122,7 +122,7 @@ class UserController extends Controller
         $grid->created_at();
         $grid->updated_at();
 
-        $grid->showExporter();
+        $grid->export();
 
         $grid->filter(function (Grid\Filter $filter) {
             $filter->equal('id');
@@ -134,7 +134,7 @@ class UserController extends Controller
         });
 
         $grid->actions(function (Grid\Displayers\Actions $actions) {
-            if ($actions->getKey() % 2 == 0) {
+            if ($actions->key() % 2 == 0) {
                 $actions->append('<a href="/" class="btn btn-xs btn-danger">detail</a>');
             }
         });
@@ -151,22 +151,18 @@ class UserController extends Controller
      */
     protected function detail($id)
     {
-        $show = new Show(new User());
+        return Show::make($id, new User(), function (Show $show) {
+            $show->id('ID');
+            $show->username();
+            $show->email;
 
-        $show->setId($id);
+            $show->divider();
 
-        $show->id('ID');
-        $show->username();
-        $show->email;
+            $show->full_name();
+            $show->field('profile.postcode');
 
-        $show->divider();
-
-        $show->full_name();
-        $show->field('profile.postcode');
-
-        $show->tags->json();
-
-        return $show;
+            $show->tags->json();
+        });
     }
 
     /**
@@ -203,16 +199,13 @@ class UserController extends Controller
         $form->datetime('profile.start_at');
         $form->datetime('profile.end_at');
 
-//        $tags = Tag::all()->pluck('name', 'id');
-//        print_r($tags);die;
-
         $form->multipleSelect('tags', 'Tags')->options(Tag::all()->pluck('name', 'id'))->customFormat(function ($value) {
             if (! $value) {
                 return [];
             }
 
             return array_column($value, 'id');
-        }); //->rules('max:10|min:3');
+        });
 
         $form->display('created_at', 'Created At');
         $form->display('updated_at', 'Updated At');

+ 2 - 2
tests/CreatesApplication.php

@@ -1,6 +1,6 @@
 <?php
 
-namespace Tests;
+namespace Dcat\Admin\Tests;
 
 use Illuminate\Contracts\Console\Kernel;
 
@@ -13,7 +13,7 @@ trait CreatesApplication
      */
     public function createApplication()
     {
-        $app = require __DIR__.'/../bootstrap/app.php';
+        $app = require __DIR__.'/../vendor/laravel/laravel/bootstrap/app.php';
 
         $app->make(Kernel::class)->bootstrap();
 

+ 1 - 1
tests/DuskTestCase.php

@@ -1,6 +1,6 @@
 <?php
 
-namespace Tests;
+namespace Dcat\Admin\Tests;
 
 use Dcat\Admin\Models\Administrator;
 use Facebook\WebDriver\Chrome\ChromeOptions;

+ 8 - 4
tests/Feature/AuthTest.php

@@ -1,9 +1,12 @@
 <?php
 
-namespace Tests\Feature;
+namespace Dcat\Admin\Tests\Feature;
 
-use Tests\TestCase;
+use Dcat\Admin\Tests\TestCase;
 
+/**
+ * @group auth
+ */
 class AuthTest extends TestCase
 {
     protected $login = false;
@@ -11,7 +14,7 @@ class AuthTest extends TestCase
     public function testLoginPage()
     {
         $this->visit('admin/auth/login')
-            ->see('login');
+            ->see('Login');
     }
 
     public function testVisitWithoutLogin()
@@ -26,7 +29,8 @@ class AuthTest extends TestCase
         $credentials = ['username' => 'admin', 'password' => 'admin'];
 
         $this->visit('admin/auth/login')
-            ->see('login')
+            ->seePageIs('admin/auth/login')
+            ->see('Login')
             ->submitForm('Login', $credentials)
             ->see('dashboard')
             ->seeCredentials($credentials, 'admin')

+ 6 - 3
tests/Feature/CombineGridTest.php

@@ -1,9 +1,12 @@
 <?php
 
-namespace Tests\Feature;
+namespace Dcat\Admin\Tests\Feature;
 
-use Tests\TestCase;
+use Dcat\Admin\Tests\TestCase;
 
+/**
+ * @group combine-grid
+ */
 class CombineGridTest extends TestCase
 {
     public function test()
@@ -17,7 +20,7 @@ class CombineGridTest extends TestCase
             ->see('top');
 
         // Column::help
-        $this->assertCount(1, $this->crawler()->filter('th a i[class*=fa-question-circle]'));
+        $this->assertCount(1, $this->crawler()->filter('th a[class*=fa-question-circle]'));
 
         $this->assertCount(2, $this->crawler()->filter('thead tr'));
 

+ 5 - 2
tests/Feature/IndexTest.php

@@ -1,9 +1,12 @@
 <?php
 
-namespace Tests\Feature;
+namespace Dcat\Admin\Tests\Feature;
 
-use Tests\TestCase;
+use Dcat\Admin\Tests\TestCase;
 
+/**
+ * @group index
+ */
 class IndexTest extends TestCase
 {
     public function testIndex()

+ 5 - 4
tests/Feature/InstallTest.php

@@ -1,9 +1,12 @@
 <?php
 
-namespace Tests\Feature;
+namespace Dcat\Admin\Tests\Feature;
 
-use Tests\TestCase;
+use Dcat\Admin\Tests\TestCase;
 
+/**
+ * @group install
+ */
 class InstallTest extends TestCase
 {
     public function testInstalledDirectories()
@@ -20,8 +23,6 @@ class InstallTest extends TestCase
 
         $this->assertFileExists(admin_path('Controllers/AuthController.php'));
 
-        $this->assertFileExists(admin_path('Controllers/ExampleController.php'));
-
         $this->assertFileExists(config_path('admin.php'));
 
         $this->assertFileExists(public_path('vendor/dcat-admin'));

+ 5 - 2
tests/Feature/MenuTest.php

@@ -1,10 +1,13 @@
 <?php
 
-namespace Tests\Feature;
+namespace Dcat\Admin\Tests\Feature;
 
 use Dcat\Admin\Models\Menu;
-use Tests\TestCase;
+use Dcat\Admin\Tests\TestCase;
 
+/**
+ * @group menu
+ */
 class MenuTest extends TestCase
 {
     public function testMenuIndex()

+ 5 - 2
tests/Feature/OperationLogTest.php

@@ -1,10 +1,13 @@
 <?php
 
-namespace Tests\Feature;
+namespace Dcat\Admin\Tests\Feature;
 
 use Dcat\Admin\Models\OperationLog;
-use Tests\TestCase;
+use Dcat\Admin\Tests\TestCase;
 
+/**
+ * @group log
+ */
 class OperationLogTest extends TestCase
 {
     public function testOperationLogIndex()

+ 5 - 2
tests/Feature/PermissionsTest.php

@@ -1,12 +1,15 @@
 <?php
 
-namespace Tests\Feature;
+namespace Dcat\Admin\Tests\Feature;
 
 use Dcat\Admin\Models\Administrator;
 use Dcat\Admin\Models\Permission;
 use Dcat\Admin\Models\Role;
-use Tests\TestCase;
+use Dcat\Admin\Tests\TestCase;
 
+/**
+ * @group permissions
+ */
 class PermissionsTest extends TestCase
 {
     public function testPermissionsIndex()

+ 5 - 2
tests/Feature/RolesTest.php

@@ -1,11 +1,14 @@
 <?php
 
-namespace Tests\Feature;
+namespace Dcat\Admin\Tests\Feature;
 
 use Dcat\Admin\Models\Administrator;
 use Dcat\Admin\Models\Role;
-use Tests\TestCase;
+use Dcat\Admin\Tests\TestCase;
 
+/**
+ * @group role
+ */
 class RolesTest extends TestCase
 {
     public function testRolesIndex()

+ 2 - 2
tests/Feature/SectionTest.php

@@ -1,8 +1,8 @@
 <?php
 
-namespace Tests\Feature;
+namespace Dcat\Admin\Tests\Feature;
 
-use Tests\TestCase;
+use Dcat\Admin\Tests\TestCase;
 
 class SectionTest extends TestCase
 {

+ 13 - 8
tests/Feature/TranslationTest.php

@@ -1,18 +1,22 @@
 <?php
 
-namespace Tests\Feature;
+namespace Dcat\Admin\Tests\Feature;
 
+use Dcat\Admin\Tests\TestCase;
 use Illuminate\Translation\FileLoader;
 use Illuminate\Translation\Translator;
-use Tests\TestCase;
 
+/**
+ * @group trans
+ */
 class TranslationTest extends TestCase
 {
     public function testTransField()
     {
-        $this->visit('admin/tests/users');
+        $this->visit('admin/tests/users')
+            ->see('Post code');
 
-        $this->load();
+        $this->registerTranslator();
 
         $this->assertEquals('user', admin_controller_slug());
 
@@ -27,7 +31,7 @@ class TranslationTest extends TestCase
     {
         $this->visit('admin/tests/users');
 
-        $this->load();
+        $this->registerTranslator();
 
         $this->assertEquals('user', admin_controller_slug());
 
@@ -38,7 +42,7 @@ class TranslationTest extends TestCase
     {
         $this->visit('admin/tests/users');
 
-        $this->load();
+        $this->registerTranslator();
 
         $this->assertEquals('user', admin_controller_slug());
 
@@ -50,9 +54,10 @@ class TranslationTest extends TestCase
         $this->assertEquals(admin_trans_label('Create'), 'Create');
     }
 
-    protected function load()
+
+    protected function registerTranslator()
     {
-        $loader = new FileLoader(app('files'), __DIR__.'/../lang');
+        $loader = new FileLoader(app('files'), __DIR__ . '/../resources/lang');
 
         $translator = new Translator($loader, 'en');
 

+ 5 - 2
tests/Feature/UserFormTest.php

@@ -1,10 +1,13 @@
 <?php
 
-namespace Tests\Feature;
+namespace Dcat\Admin\Tests\Feature;
 
 use Tests\Models\User as UserModel;
-use Tests\TestCase;
+use Dcat\Admin\Tests\TestCase;
 
+/**
+ * @group user-form
+ */
 class UserFormTest extends TestCase
 {
     public function testCreatePage()

+ 5 - 2
tests/Feature/UserGridTest.php

@@ -1,11 +1,14 @@
 <?php
 
-namespace Tests\Feature;
+namespace Dcat\Admin\Tests\Feature;
 
 use Tests\Models\Profile as ProfileModel;
 use Tests\Models\User as UserModel;
-use Tests\TestCase;
+use Dcat\Admin\Tests\TestCase;
 
+/**
+ * @group user-grid
+ */
 class UserGridTest extends TestCase
 {
     public function testIndexPage()

+ 5 - 2
tests/Feature/UserSettingTest.php

@@ -1,10 +1,13 @@
 <?php
 
-namespace Tests\Feature;
+namespace Dcat\Admin\Tests\Feature;
 
 use Dcat\Admin\Models\Administrator;
-use Tests\TestCase;
+use Dcat\Admin\Tests\TestCase;
 
+/**
+ * @group user-setting
+ */
 class UserSettingTest extends TestCase
 {
     public function testVisitSettingPage()

+ 5 - 2
tests/Feature/UserShowTest.php

@@ -1,9 +1,12 @@
 <?php
 
-namespace Tests\Feature;
+namespace Dcat\Admin\Tests\Feature;
 
-use Tests\TestCase;
+use Dcat\Admin\Tests\TestCase;
 
+/**
+ * @group user-show
+ */
 class UserShowTest extends TestCase
 {
     public function test()

+ 5 - 2
tests/Feature/UsersTest.php

@@ -1,9 +1,12 @@
 <?php
 
-namespace Tests\Feature;
+namespace Dcat\Admin\Tests\Feature;
 
-use Tests\TestCase;
+use Dcat\Admin\Tests\TestCase;
 
+/**
+ * @group user
+ */
 class UsersTest extends TestCase
 {
     public function testUsersIndexPage()

+ 1 - 1
tests/Models/File.php

@@ -1,6 +1,6 @@
 <?php
 
-namespace Tests\Models;
+namespace Dcat\Admin\Tests\Models;
 
 use Illuminate\Database\Eloquent\Model;
 

+ 1 - 1
tests/Models/Image.php

@@ -1,6 +1,6 @@
 <?php
 
-namespace Tests\Models;
+namespace Dcat\Admin\Tests\Models;
 
 use Illuminate\Database\Eloquent\Model;
 

+ 1 - 1
tests/Models/MultipleImage.php

@@ -1,6 +1,6 @@
 <?php
 
-namespace Tests\Models;
+namespace Dcat\Admin\Tests\Models;
 
 use Illuminate\Database\Eloquent\Model;
 

+ 1 - 1
tests/Models/Profile.php

@@ -1,6 +1,6 @@
 <?php
 
-namespace Tests\Models;
+namespace Dcat\Admin\Tests\Models;
 
 use Illuminate\Database\Eloquent\Model;
 

+ 1 - 1
tests/Models/Tag.php

@@ -1,6 +1,6 @@
 <?php
 
-namespace Tests\Models;
+namespace Dcat\Admin\Tests\Models;
 
 use Illuminate\Database\Eloquent\Model;
 

+ 1 - 1
tests/Models/Tree.php

@@ -1,6 +1,6 @@
 <?php
 
-namespace Tests\Models;
+namespace Dcat\Admin\Tests\Models;
 
 use Encore\Admin\Traits\AdminBuilder;
 use Encore\Admin\Traits\ModelTree;

+ 1 - 1
tests/Models/User.php

@@ -1,6 +1,6 @@
 <?php
 
-namespace Tests\Models;
+namespace Dcat\Admin\Tests\Models;
 
 use Illuminate\Database\Eloquent\Model;
 

+ 1 - 1
tests/Repositories/Report.php

@@ -1,6 +1,6 @@
 <?php
 
-namespace Tests\Repositories;
+namespace Dcat\Admin\Tests\Repositories;
 
 use Dcat\Admin\Grid;
 use Dcat\Admin\Repositories\Repository;

+ 3 - 2
tests/Repositories/User.php

@@ -1,10 +1,11 @@
 <?php
 
-namespace Tests\Repositories;
+namespace Dcat\Admin\Tests\Repositories;
 
+use Dcat\Admin\Tests\Models\User as Model;
 use Dcat\Admin\Repositories\EloquentRepository;
 
 class User extends EloquentRepository
 {
-    protected $eloquentClass = \Tests\Models\User::class;
+    protected $eloquentClass = Model::class;
 }

+ 94 - 3
tests/TestCase.php

@@ -1,14 +1,17 @@
 <?php
 
-namespace Tests;
+namespace Dcat\Admin\Tests;
 
 use Dcat\Admin\Models\Administrator;
 use Laravel\BrowserKitTesting\TestCase as BaseTestCase;
+use Illuminate\Filesystem\Filesystem;
+use Illuminate\Support\Arr;
+use Illuminate\Support\Facades\DB;
+use Illuminate\Support\Facades\Schema;
 
 class TestCase extends BaseTestCase
 {
-    use CreatesApplication,
-        BasicTestCase;
+    use CreatesApplication;
 
     protected $baseUrl = 'http://localhost:8000';
 
@@ -18,4 +21,92 @@ class TestCase extends BaseTestCase
     protected $user;
 
     protected $login = true;
+
+    public function setUp(): void
+    {
+        parent::setUp();
+
+        $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__.'/routes.php';
+
+        require __DIR__ . '/resources/seeds/factory.php';
+
+        view()->addNamespace('admin-tests', __DIR__ . '/resources/views');
+
+        if ($this->login) {
+            $this->be($this->getUser(), 'admin');
+        }
+    }
+
+    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('MYSQL_HOST', 'localhost'));
+        $config->set('database.connections.mysql.database', 'laravel_dcat_admin_test');
+        $config->set('database.connections.mysql.username', env('MYSQL_USER', 'root'));
+        $config->set('database.connections.mysql.password', env('MYSQL_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);
+        }
+    }
+
+    /**
+     * @return Administrator
+     */
+    protected function getUser()
+    {
+        if ($this->user) {
+            return $this->user;
+        }
+
+        return $this->user = Administrator::first();
+    }
+
+    public function tearDown(): void
+    {
+        (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'");
+
+        parent::tearDown();
+    }
+
+    /**
+     * run package database migrations.
+     *
+     * @return void
+     */
+    public function migrateTestTables()
+    {
+        $fileSystem = new Filesystem();
+
+        $fileSystem->requireOnce(__DIR__ . '/resources/migrations/2016_11_22_093148_create_test_tables.php');
+
+        (new \CreateTestTables())->up();
+    }
 }

+ 0 - 0
tests/assets/test.jpg → tests/resources/assets/test.jpg


+ 16 - 8
tests/config/admin.php → tests/resources/config/admin.php

@@ -1,9 +1,5 @@
 <?php
 
-use Dcat\Admin\Models\Menu;
-use Dcat\Admin\Models\Permission;
-use Dcat\Admin\Models\Role;
-
 return [
 
     /*
@@ -38,7 +34,7 @@ return [
     | '<img src="http://logo-url" alt="Admin logo">'.
     |
     */
-    'logo-mini' => '<b>Da</b>',
+    'logo-mini' => 'Da',
 
     /*
     |--------------------------------------------------------------------------
@@ -95,7 +91,7 @@ return [
     |--------------------------------------------------------------------------
     |
    */
-    'cdn' => false,
+    'cdn' => env('ADMIN_CDN', false),
 
     /*
     |--------------------------------------------------------------------------
@@ -119,9 +115,12 @@ return [
     |
     */
     'auth' => [
+        'enable' => true,
 
         'controller' => Dcat\Admin\Controllers\AuthController::class,
 
+        'login_view' => 'admin::login',
+
         'guard' => 'admin',
 
         'guards' => [
@@ -160,6 +159,15 @@ return [
         'grid_action_class' => Dcat\Admin\Grid\Displayers\DropdownActions::class,
     ],
 
+    /*
+    |--------------------------------------------------------------------------
+    | dcat-admin helpers setting.
+    |--------------------------------------------------------------------------
+    */
+    'helpers' => [
+        'enable' => true,
+    ],
+
     /*
     |--------------------------------------------------------------------------
     | dcat-admin permission setting
@@ -319,7 +327,7 @@ return [
     | "sidebar-mini".
     |
     */
-    'layout' => ['sidebar-mini', 'sidebar-collapse', 'fixed'],
+    'layout' => ['sidebar-mini', 'fixed'],
 
     /*
     |--------------------------------------------------------------------------
@@ -336,7 +344,7 @@ return [
     | The exception handler class
     |--------------------------------------------------------------------------
     |
-   */
+    */
     'exception_handler' => \Dcat\Admin\Exception\Handler::class,
 
     /*

+ 0 - 0
tests/config/filesystems.php → tests/resources/config/filesystems.php


+ 0 - 0
tests/lang/en/global.php → tests/resources/lang/en/global.php


+ 0 - 0
tests/lang/en/user.php → tests/resources/lang/en/user.php


+ 0 - 0
tests/migrations/2016_11_22_093148_create_test_tables.php → tests/resources/migrations/2016_11_22_093148_create_test_tables.php


+ 0 - 0
tests/seeds/UserTableSeeder.php → tests/resources/seeds/UserTableSeeder.php


+ 0 - 0
tests/seeds/factory.php → tests/resources/seeds/factory.php


+ 0 - 0
tests/views/test.blade.php → tests/resources/views/test.blade.php


+ 1 - 1
tests/routes.php

@@ -2,7 +2,7 @@
 
 Route::group([
     'prefix'     => config('admin.route.prefix'),
-    'namespace'  => 'Tests\Controllers',
+    'namespace'  => 'Dcat\Admin\Tests\Controllers',
     'middleware' => ['web', 'admin'],
 ], function ($router) {
     $router->resource('tests/users', UserController::class);