Skip to content

Commit

Permalink
feat: Added support for dropAnalyzers, dropGraphs and dropAll to Test…
Browse files Browse the repository at this point in the history
…Case
  • Loading branch information
LaravelFreelancerNL committed Dec 1, 2024
1 parent 863750e commit f7932ef
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 42 deletions.
59 changes: 59 additions & 0 deletions src/Testing/Concerns/CanConfigureMigrationCommands.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

declare(strict_types=1);

namespace LaravelFreelancerNL\Aranguent\Testing\Concerns;

trait CanConfigureMigrationCommands
{
/**
* Determine if types should be dropped when refreshing the database.
*
* @return array<string, array<string>|string>
*/
protected function setMigrationPaths()
{
$migrationSettings = [];

if (property_exists($this, 'realPath')) {
$migrationSettings['--realpath'] = $this->realPath ?? false;
}

if (property_exists($this, 'migrationPaths')) {
$migrationSettings['--path'] = $this->migrationPaths;
}

return $migrationSettings;
}

/**
* Determine if custom analyzers should be dropped when refreshing the database.
*
* @return bool
*/
protected function shouldDropAnalyzers()
{
return property_exists($this, 'dropAnalyzers') ? $this->dropAnalyzers : false;
}

/**
* Determine if graphs should be dropped when refreshing the database.
*
* @return bool
*/
protected function shouldDropGraphs()
{
return property_exists($this, 'dropGraphs') ? $this->dropGraphs : false;
}


/**
* Determine if all analyzers, graphs and views should be dropped when refreshing the database.
*
* @return bool
*/
protected function shouldDropAll()
{
return property_exists($this, 'dropAll') ? $this->dropAll : false;
}
}
28 changes: 8 additions & 20 deletions src/Testing/DatabaseMigrations.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,19 @@
namespace LaravelFreelancerNL\Aranguent\Testing;

use Illuminate\Foundation\Testing\DatabaseMigrations as IlluminateDatabaseMigrations;
use LaravelFreelancerNL\Aranguent\Testing\Concerns\CanConfigureMigrationCommands;

trait DatabaseMigrations
{
use IlluminateDatabaseMigrations;
use CanConfigureMigrationCommands;


/**
* The parameters that should be used when running "migrate:fresh".
*
* Duplicate code because CanConfigureMigrationCommands has a conflict otherwise.
*
* @return array
*/
protected function migrateFreshUsing()
Expand All @@ -21,33 +26,16 @@ protected function migrateFreshUsing()

$results = array_merge(
[
'--drop-analyzers' => $this->shouldDropAnalyzers(),
'--drop-graphs' => $this->shouldDropGraphs(),
'--drop-views' => $this->shouldDropViews(),
'--drop-types' => $this->shouldDropTypes(),
'--drop-all' => $this->shouldDropAll(),
],
$seeder ? ['--seeder' => $seeder] : ['--seed' => $this->shouldSeed()],
$this->setMigrationPaths(),
);

return $results;
}

/**
* Determine if types should be dropped when refreshing the database.
*
* @return array<string, array<string>|string>
*/
protected function setMigrationPaths()
{
$migrationSettings = [];

if (property_exists($this, 'realPath')) {
$migrationSettings['--realpath'] = $this->realPath ?? false;
}

if (property_exists($this, 'migrationPaths')) {
$migrationSettings['--path'] = $this->migrationPaths;
}

return $migrationSettings;
}
}
27 changes: 7 additions & 20 deletions src/Testing/DatabaseTruncation.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@
namespace LaravelFreelancerNL\Aranguent\Testing;

use Illuminate\Foundation\Testing\DatabaseTruncation as IlluminateDatabaseTruncation;
use LaravelFreelancerNL\Aranguent\Testing\Concerns\CanConfigureMigrationCommands;

trait DatabaseTruncation
{
use IlluminateDatabaseTruncation;
use CanConfigureMigrationCommands;

/**
* The parameters that should be used when running "migrate:fresh".
*
* Duplicate code because CanConfigureMigrationCommands has a conflict otherwise.
*
* @return array
*/
protected function migrateFreshUsing()
Expand All @@ -21,33 +25,16 @@ protected function migrateFreshUsing()

$results = array_merge(
[
'--drop-analyzers' => $this->shouldDropAnalyzers(),
'--drop-graphs' => $this->shouldDropGraphs(),
'--drop-views' => $this->shouldDropViews(),
'--drop-types' => $this->shouldDropTypes(),
'--drop-all' => $this->shouldDropAll(),
],
$seeder ? ['--seeder' => $seeder] : ['--seed' => $this->shouldSeed()],
$this->setMigrationPaths(),
);

return $results;
}

/**
* Determine if types should be dropped when refreshing the database.
*
* @return array<string, array<string>|string>
*/
protected function setMigrationPaths()
{
$migrationSettings = [];

if (property_exists($this, 'realPath')) {
$migrationSettings['--realpath'] = $this->realPath ?? false;
}

if (property_exists($this, 'migrationPaths')) {
$migrationSettings['--path'] = $this->migrationPaths;
}

return $migrationSettings;
}
}
8 changes: 8 additions & 0 deletions src/Testing/RefreshDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@

use Illuminate\Foundation\Testing\DatabaseTransactionsManager;
use Illuminate\Foundation\Testing\RefreshDatabase as IlluminateRefreshDatabase;
use LaravelFreelancerNL\Aranguent\Testing\Concerns\CanConfigureMigrationCommands;
use LaravelFreelancerNL\Aranguent\Testing\Concerns\PreparesTestingTransactions;

trait RefreshDatabase
{
use PreparesTestingTransactions;
use CanConfigureMigrationCommands;
use IlluminateRefreshDatabase;

/**
Expand Down Expand Up @@ -51,9 +53,12 @@ public function beginDatabaseTransaction()
});
}


/**
* The parameters that should be used when running "migrate:fresh".
*
* Duplicate code because CanConfigureMigrationCommands has a conflict otherwise.
*
* @return array
*/
protected function migrateFreshUsing()
Expand All @@ -62,8 +67,11 @@ protected function migrateFreshUsing()

$results = array_merge(
[
'--drop-analyzers' => $this->shouldDropAnalyzers(),
'--drop-graphs' => $this->shouldDropGraphs(),
'--drop-views' => $this->shouldDropViews(),
'--drop-types' => $this->shouldDropTypes(),
'--drop-all' => $this->shouldDropAll(),
],
$seeder ? ['--seeder' => $seeder] : ['--seed' => $this->shouldSeed()],
$this->setMigrationPaths(),
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class TestCase extends \Orchestra\Testbench\TestCase

protected ?ConnectionInterface $connection;

protected bool $dropViews = true;
protected bool $dropAll = true;

protected bool $realPath = true;

Expand Down
1 change: 0 additions & 1 deletion tests/Testing/DatabaseTruncationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
expect(count($tables))->toEqual($this->tableCount);
});


test('Ensure all characters are present', function () {
$characters = Character::all();

Expand Down

0 comments on commit f7932ef

Please sign in to comment.