Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alies-dev committed Aug 27, 2024
1 parent ea6d6ad commit 909bc44
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 21 deletions.
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
],
"require": {
"php": "^8.1",
"doctrine/dbal": "^3.7 || ^4.0",
"doctrine/dbal": "^3.7",
"laravel/framework": "^10.2"
},
"require-dev": {
"interaction-design-foundation/coding-standard": "^0.3",
"interaction-design-foundation/coding-standard": "0.*",
"orchestra/testbench": "^8.0",
"phpunit/phpunit": "^10.1 || ^11.0"
},
"minimum-stability": "dev",
Expand All @@ -26,7 +27,7 @@
},
"autoload-dev": {
"psr-4": {
"InteractionDesignFoundation\\LaravelDatabaseToolkit\\Tests\\": "tests/"
"Tests\\": "tests/"
}
},
"config": {
Expand Down
24 changes: 6 additions & 18 deletions tests/Console/Commands/FindRiskyDatabaseColumnsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@

namespace Tests\Console\Commands;

use App\Modules\Publication\Models\Quote;
use Illuminate\Foundation\Testing\Concerns\InteractsWithConsole;
use Illuminate\Testing\PendingCommand;
use InteractionDesignFoundation\LaravelDatabaseToolkit\Console\Commands\FindRiskyDatabaseColumns;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Test;
use Tests\ApplicationTestCase;
use Tests\Factories\Publication\QuoteFactory;
use Tests\TestCase;

#[CoversClass(\App\Modules\Infrastructure\Console\Commands\FindRiskyDatabaseColumns::class)]
final class FindRiskyDatabaseColumnsTest extends ApplicationTestCase
#[CoversClass(FindRiskyDatabaseColumns::class)]
final class FindRiskyDatabaseColumnsTest extends TestCase
{
use InteractsWithConsole;

#[Test]
public function it_works_with_default_threshold(): void
{
Expand All @@ -21,17 +22,4 @@ public function it_works_with_default_threshold(): void
assert($pendingCommand instanceof PendingCommand);
$pendingCommand->assertExitCode(0);
}

#[Test]
public function it_fails_on_very_low_threshold(): void
{
/** We can create {@see \App\Modules\Logging\Models\VisitorActivity} instances, but they are slow to create (too many indexes) */
QuoteFactory::new()->createOne(['id' => 42_000]);

$pendingCommand = $this->artisan(FindRiskyDatabaseColumns::class, ['--threshold' => 0.001]);

assert($pendingCommand instanceof PendingCommand);
$pendingCommand->assertExitCode(1);
$pendingCommand->expectsOutputToContain(get_table_name(Quote::class).'.id is full for '); // check line like "ixdf.quote.id is 0.0148% full (threshold for allowed usage is 0.0000001%)\n"
}
}
20 changes: 20 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php declare(strict_types=1);

namespace Tests;

use InteractionDesignFoundation\LaravelDatabaseToolkit\DatabaseToolkitServiceProvider;

abstract class TestCase extends \Orchestra\Testbench\TestCase
{
/**
* Load package service provider.
* @param \Illuminate\Foundation\Application $app
* @return list<string>
*/
protected function getPackageProviders($app): array
{
return [
DatabaseToolkitServiceProvider::class,
];
}
}

0 comments on commit 909bc44

Please sign in to comment.