Skip to content

Commit

Permalink
fix: resolve database migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
owenvoke committed Feb 27, 2024
1 parent b258e6b commit 7f060ee
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 27 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[![GitHub Code Style Action Status](https://img.shields.io/github/workflow/status/worksome/laravel-mfa/Static%20Analysis?style=flat-square&label=code%20style)](https://github.com/worksome/laravel-mfa/actions?query=workflow%3A"Static+Analysis"+branch%3Amain)
[![Total Downloads](https://img.shields.io/packagist/dt/worksome/laravel-mfa.svg?style=flat-square)](https://packagist.org/packages/worksome/laravel-mfa)

A driver-based multifactor authentication package for Laravel
A driver-based multi-factor authentication package for Laravel

## Installation

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "worksome/laravel-mfa",
"description": "A driver-based multifactor authentication package for Laravel",
"description": "A driver-based multi-factor authentication package for Laravel",
"keywords": [
"worksome",
"laravel",
Expand Down
2 changes: 2 additions & 0 deletions database/migrations/create_mfa_multi_factors_table.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
Expand Down
13 changes: 9 additions & 4 deletions src/MultiFactorAuthServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

namespace Worksome\MultiFactorAuth;

use Illuminate\Contracts\Config\Repository;
use Illuminate\Foundation\Console\AboutCommand;
use Illuminate\Support\Collection;
use Spatie\LaravelPackageTools\Package;
use Spatie\LaravelPackageTools\PackageServiceProvider;
use Worksome\MultiFactorAuth\Enums\Channel;
Expand All @@ -21,7 +23,8 @@ public function configurePackage(Package $package): void
$package
->name('laravel-mfa')
->hasConfigFile()
->hasMigration('create_mfa_multi_factors_table');
->hasMigration('create_mfa_multi_factors_table')
->runsMigrations();
}

public function bootingPackage(): void
Expand All @@ -31,20 +34,22 @@ public function bootingPackage(): void

private function extendAboutCommand(): void
{
if (! config('mfa.features.about_command', true)) {
$config = $this->app->make(Repository::class);

if (! $config->get('mfa.features.about_command', true)) {
return;
}

/** @var array<class-string<Channel>, array{driver: string|null}> $channels */
$channels = config('mfa.channels', []);
$channels = $config->get('mfa.channels', []);

if (empty($channels)) {
return;
}

AboutCommand::add(
'Multi-Factor Authentication (MFA)',
fn () => collect($channels)->mapWithKeys(fn (array $config, string $channel) => [
fn () => Collection::make($channels)->mapWithKeys(fn (array $config, string $channel) => [
Channel::driverDescription($channel) => $config['driver'] ?? 'null'
])
);
Expand Down
4 changes: 3 additions & 1 deletion tests/Pest.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?php

declare(strict_types=1);

use Worksome\MultiFactorAuth\Tests\TestCase;

uses(TestCase::class)->in(__DIR__ . '/Feature');
uses(TestCase::class)->in('Feature');

// Test functions

Expand Down
27 changes: 7 additions & 20 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
@@ -1,41 +1,28 @@
<?php

declare(strict_types=1);

namespace Worksome\MultiFactorAuth\Tests;

use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Contracts\Config\Repository as ConfigRepository;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Orchestra\Testbench\TestCase as Orchestra;
use Worksome\MultiFactorAuth\MultiFactorAuthServiceProvider;

class TestCase extends Orchestra
abstract class TestCase extends Orchestra
{
use RefreshDatabase;

protected function setUp(): void
{
parent::setUp();

Factory::guessFactoryNamesUsing(
fn(
string $modelName,
) => 'Worksome\\TwoFactorAuth\\Database\\Factories\\' . class_basename($modelName) . 'Factory'
);
}

protected function getPackageProviders($app): array
{
return [
MultiFactorAuthServiceProvider::class,
];
}

public function defineEnvironment($app)
{
config()->set('database.default', 'testing');
}

protected function defineDatabaseMigrations()
/** {@inheritdoc} */
public function defineEnvironment($app): void
{
$this->loadMigrationsFrom(__DIR__ . '/../database/migrations/create_mfa_multi_factors_table.php');
$app->make(ConfigRepository::class)->set('database.default', 'testing');
}
}

0 comments on commit 7f060ee

Please sign in to comment.