Skip to content

Commit

Permalink
feat(tests): Install and enable login captcha extension
Browse files Browse the repository at this point in the history
- Install and enable login captcha extension
- Add publish and install commands
- Initialize the login captcha service provider
  • Loading branch information
guanguans committed Oct 13, 2023
1 parent e4195a1 commit 6f160a1
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 21 deletions.
1 change: 0 additions & 1 deletion tests/Facades/CaptchaBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,5 @@
use Guanguans\DcatLoginCaptcha\Facades\CaptchaBuilder;

it('can get captcha content', function (): void {
$this->markTestSkipped('This test is skipped.');
expect(CaptchaBuilder::get())->toBeString();
})->group(__DIR__, __FILE__);
Empty file added tests/Fixtures/.gitkeep
Empty file.
Binary file removed tests/Fixtures/database.sqlite
Binary file not shown.
47 changes: 27 additions & 20 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ protected function setUp(): void
{
parent::setUp();
$this->startMockery();
$this->install();
}

protected function tearDown(): void
Expand All @@ -56,6 +57,26 @@ protected function tearDown(): void
parent::tearDown();
}

/**
* @noinspection ForgottenDebugOutputInspection
* @noinspection DebugFunctionUsageInspection
*/
protected function install(): void
{
try {
// $this->fixDatabaseMigrations();
// $this->loadMigrationsFrom(__DIR__.'/../vendor/dcat/laravel-admin/database/migrations');
Artisan::call('admin:publish', ['--force' => false]);
Artisan::call('admin:install');
// Artisan::call('admin:ext-install', ['name' => 'guanguans.dcat-login-captcha', ['--path' => __DIR__.'/../']]);
// Artisan::call('admin:ext-enable', ['name' => 'guanguans.dcat-login-captcha']);
$loginCaptchaServiceProvider = app(LoginCaptchaServiceProvider::class);
$loginCaptchaServiceProvider->init();
} catch (\Throwable $throwable) {
dump($throwable->getMessage());
}
}

protected function getPackageProviders($app): array
{
return [
Expand All @@ -77,24 +98,16 @@ protected function defineEnvironment($app): void
});
}

protected function defineDatabaseMigrations(): void
protected function defineRoutes($router): void
{
// $this->fixDatabaseMigrations();
Artisan::call('admin:publish', [
// '--force' => true
]);
Artisan::call('admin:install');
// Artisan::call('admin:ext-install', ['name' => 'guanguans.dcat-login-captcha', ['--path' => __DIR__.'/../']]);
// Artisan::call('admin:ext-enable', ['name' => 'guanguans.dcat-login-captcha']);
// $this->loadMigrationsFrom(__DIR__.'/../vendor/dcat/laravel-admin/database/migrations');
$loginCaptchaServiceProvider = app(LoginCaptchaServiceProvider::class);
$loginCaptchaServiceProvider->init();
Route::get('foo/bar', static function (): void {
})->name('dcat.admin.foo.bar');
}

protected function fixDatabaseMigrations(): void
{
$traverser = new NodeTraverser();
$traverser->addVisitor(new class() extends NodeVisitorAbstract {
$nodeTraverser = new NodeTraverser();
$nodeTraverser->addVisitor(new class() extends NodeVisitorAbstract {
public function enterNode(Node $node): void
{
if ($node instanceof \PhpParser\Node\Expr\Closure) {
Expand All @@ -119,13 +132,7 @@ public function enterNode(Node $node): void

$migratedFile = __DIR__.'/../vendor/dcat/laravel-admin/database/migrations/2020_11_01_083237_update_admin_menu_table.php';
$stmts = (new ParserFactory())->create(1)->parse(File::get($migratedFile));
$traverser->traverse($stmts);
$nodeTraverser->traverse($stmts);
File::put($migratedFile, (new Standard())->prettyPrintFile($stmts));
}

protected function defineRoutes($router): void
{
Route::get('foo/bar', static function (): void {
})->name('dcat.admin.foo.bar');
}
}

0 comments on commit 6f160a1

Please sign in to comment.