@@ -10,14 +10,19 @@ class TestCase extends BaseTestCase
1010{
1111 protected $ baseUrl = 'http://localhost:8000 ' ;
1212
13+ /**
14+ * Cache heavy one-time bootstrapping across tests.
15+ */
16+ protected static bool $ publishedAssets = false ;
17+
1318 /**
1419 * Boots the application.
1520 *
1621 * @return \Illuminate\Foundation\Application
1722 */
1823 public function createApplication ()
1924 {
20- $ app = require __DIR__ . '/../vendor/laravel/laravel/bootstrap/app.php ' ;
25+ $ app = require __DIR__ . '/../vendor/laravel/laravel/bootstrap/app.php ' ;
2126
2227 $ app ->booting (function () {
2328 $ loader = \Illuminate \Foundation \AliasLoader::getInstance ();
@@ -35,22 +40,29 @@ protected function setUp(): void
3540 {
3641 parent ::setUp ();
3742
38- $ adminConfig = require __DIR__ .'/config/admin.php ' ;
43+ $ adminConfig = require __DIR__ . '/config/admin.php ' ;
44+
45+ // Use sqlite in-memory for tests to avoid external MySQL dependency
46+ $ this ->app ['config ' ]->set ('database.default ' , 'sqlite ' );
47+ $ this ->app ['config ' ]->set ('database.connections.sqlite ' , [
48+ 'driver ' => 'sqlite ' ,
49+ 'database ' => ':memory: ' ,
50+ 'prefix ' => '' ,
51+ ]);
3952
40- $ this ->app ['config ' ]->set ('database.default ' , env ('DB_CONNECTION ' , 'mysql ' ));
41- $ this ->app ['config ' ]->set ('database.connections.mysql.host ' , env ('MYSQL_HOST ' , 'localhost ' ));
42- $ this ->app ['config ' ]->set ('database.connections.mysql.database ' , env ('MYSQL_DATABASE ' , 'laravel_admin_test ' ));
43- $ this ->app ['config ' ]->set ('database.connections.mysql.username ' , env ('MYSQL_USER ' , 'root ' ));
44- $ this ->app ['config ' ]->set ('database.connections.mysql.password ' , env ('MYSQL_PASSWORD ' , '' ));
4553 $ this ->app ['config ' ]->set ('app.key ' , 'AckfSECXIvnK5r28GVIWUAxmbBSjTsmF ' );
46- $ this ->app ['config ' ]->set ('filesystems ' , require __DIR__ . '/config/filesystems.php ' );
54+ $ this ->app ['config ' ]->set ('filesystems ' , require __DIR__ . '/config/filesystems.php ' );
4755 $ this ->app ['config ' ]->set ('admin ' , $ adminConfig );
4856
4957 foreach (Arr::dot (Arr::get ($ adminConfig , 'auth ' ), 'auth. ' ) as $ key => $ value ) {
5058 $ this ->app ['config ' ]->set ($ key , $ value );
5159 }
5260
53- $ this ->artisan ('vendor:publish ' , ['--provider ' => 'Casbin\Admin\AdminServiceProvider ' ]);
61+ // Publish assets only once across the entire test run to avoid repeated heavy I/O
62+ if (!self ::$ publishedAssets ) {
63+ $ this ->artisan ('vendor:publish ' , ['--provider ' => 'Casbin\Admin\AdminServiceProvider ' ]);
64+ self ::$ publishedAssets = true ;
65+ }
5466
5567 Schema::defaultStringLength (191 );
5668
@@ -62,13 +74,13 @@ protected function setUp(): void
6274 require $ routes ;
6375 }
6476
65- require __DIR__ . '/routes.php ' ;
77+ require __DIR__ . '/routes.php ' ;
6678
67- require __DIR__ . '/seeds/factory.php ' ;
79+ require_once __DIR__ . '/seeds/factory.php ' ;
6880
69- // \Casbin\Admin\Admin::$css = [];
70- // \Casbin\Admin\Admin::$js = [];
71- // \Casbin\Admin\Admin::$script = [];
81+ // \Casbin\Admin\Admin::$css = [];
82+ // \Casbin\Admin\Admin::$js = [];
83+ // \Casbin\Admin\Admin::$script = [];
7284 }
7385
7486 protected function tearDown (): void
@@ -91,7 +103,7 @@ public function migrateTestTables()
91103 {
92104 $ fileSystem = new Filesystem ();
93105
94- $ fileSystem ->requireOnce (__DIR__ . '/migrations/2016_11_22_093148_create_test_tables.php ' );
106+ $ fileSystem ->requireOnce (__DIR__ . '/migrations/2016_11_22_093148_create_test_tables.php ' );
95107
96108 (new CreateTestTables ())->up ();
97109 }
0 commit comments