Skip to content

Commit

Permalink
chore(tests): workaround to fix weird test issues
Browse files Browse the repository at this point in the history
Signed-off-by: Fery Wardiyanto <[email protected]>
  • Loading branch information
feryardiant committed Apr 2, 2024
1 parent 7ba49a3 commit cfbce36
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 22 deletions.
8 changes: 4 additions & 4 deletions tests/Models/RegencyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ public function it_should_belongs_to_province(Collection $regencies): void
#[Depends('it_should_has_many_regencies')]
public function it_should_has_many_districts(Collection $regencies): void
{
$regencies->each(function (Regency $regency) {
$this->assertTrue($regency->districts->every(fn ($dis) => $dis instanceof District));
$regencies->take(5)->each(function (Regency $regency) {
$this->assertTrue($regency->districts->take(5)->every(fn ($dis) => $dis instanceof District));
});
}

Expand All @@ -91,8 +91,8 @@ public function it_should_has_many_districts(Collection $regencies): void
#[Depends('it_should_has_many_regencies')]
public function it_should_has_many_villages(Collection $regencies): void
{
$regencies->each(function (Regency $regency) {
$this->assertTrue($regency->villages->every(fn ($vil) => $vil instanceof Village));
$regencies->take(5)->each(function (Regency $regency) {
$this->assertTrue($regency->villages->take(5)->every(fn ($vil) => $vil instanceof Village));
});
}
}
39 changes: 21 additions & 18 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@
use Creasi\Nusa\ServiceProvider;
use Database\Seeders\DatabaseSeeder;
use Illuminate\Config\Repository;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Orchestra\Testbench\TestCase as Orchestra;

class TestCase extends Orchestra
{
use DatabaseMigrations;

private static $shouldMigrate = true;

protected function getPackageProviders($app)
Expand Down Expand Up @@ -51,28 +54,28 @@ protected function getEnvironmentSetUp($app): void
$config->set('app.locale', 'id');
$config->set('app.faker_locale', 'id_ID');

$conn = env('DB_CONNECTION', 'sqlite');
// $conn = env('DB_CONNECTION', 'sqlite');

$config->set('database.default', $conn);
// $conn = $config->get('database.default');

if ($conn === 'sqlite') {
$database = __DIR__.'/test.sqlite';
// if ($conn === 'sqlite') {
// // $database = __DIR__.'/test.sqlite';

if (self::$shouldMigrate) {
$this->recreateDatabase($database);
}
// // if (self::$shouldMigrate) {
// // $this->recreateDatabase($database);
// // }

$this->mergeConfig($config, 'database.connections.sqlite', [
'database' => $database,
'foreign_key_constraints' => true,
]);
} else {
$this->mergeConfig($config, 'database.connections.'.$conn, [
'database' => env('DB_DATABASE', 'creasi_test'),
'username' => env('DB_USERNAME', 'creasico'),
'password' => env('DB_PASSWORD', 'secret'),
]);
}
// $this->mergeConfig($config, 'database.connections.sqlite', [
// 'database' => ':memory:',
// 'foreign_key_constraints' => true,
// ]);
// } else {
// $this->mergeConfig($config, 'database.connections.'.$conn, [
// 'database' => env('DB_DATABASE', 'creasi_test'),
// 'username' => env('DB_USERNAME', 'creasico'),
// 'password' => env('DB_PASSWORD', 'secret'),
// ]);
// }
});
}

Expand Down

0 comments on commit cfbce36

Please sign in to comment.