Skip to content

Commit

Permalink
refactor: fix integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JaZo committed May 31, 2024
1 parent 4caaac5 commit 997fec1
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions tests/Integration/SituationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,34 @@

final class SituationsTest extends TestCase
{
private Client $client;
private static Client $client;

public static function setUpBeforeClass(): void
#[DataProvider('areaIdProvider')]
public function testSituations(int $areaId): void
{
if (!getenv('MELVIN_USERNAME') || !getenv('MELVIN_PASSWORD')) {
self::markTestSkipped('Missing Melvin credentials.');
}
}

#[DataProvider('areaIdProvider')]
public function testSituations(int $areaId): void
{
$params = (new SituationFilterParameters())
->setIncludeDetours(true)
->setAreaIds([$areaId]);

$situations = $this->client()->situations()->export($params);
$situations = self::client()->situations()->export($params);

$this->assertNotEmpty($situations);
}

public static function areaIdProvider(): \Generator
{
if (!getenv('MELVIN_USERNAME') || !getenv('MELVIN_PASSWORD')) {
yield 'skipped' => [0];

return;
}

$areas = array_filter(
$this->client()->areas()->all(),
self::client()->areas()->all(),
static fn (Area $area) => $area->type->equals(AreaType::PROVINCE())
);

Expand All @@ -46,12 +49,10 @@ public static function areaIdProvider(): \Generator
}
}

private function client(): Client
private static function client(): Client
{
if (!isset($this->client)) {
$this->client = Client::create(getenv('MELVIN_USERNAME'), getenv('MELVIN_PASSWORD'));
}
self::$client ??= Client::create(getenv('MELVIN_USERNAME'), getenv('MELVIN_PASSWORD'));

return $this->client;
return self::$client;
}
}

0 comments on commit 997fec1

Please sign in to comment.