Skip to content

Commit

Permalink
test: add integration testsuite
Browse files Browse the repository at this point in the history
  • Loading branch information
JaZo committed Mar 12, 2024
1 parent 0f667a6 commit f000175
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
run: composer update --${{ matrix.stability }} --prefer-dist --no-interaction

- name: Execute tests
run: XDEBUG_MODE=coverage vendor/bin/phpunit --coverage-text --coverage-clover=coverage.clover
run: XDEBUG_MODE=coverage vendor/bin/phpunit --testsuite=default --coverage-text --coverage-clover=coverage.clover

- name: Upload Scrutinizer coverage
uses: sudo-bot/action-scrutinizer@latest
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
}
},
"scripts": {
"test": "phpunit",
"test": "phpunit --testsuite=default",
"check-style": "php-cs-fixer fix --dry-run -v",
"fix-style": "php-cs-fixer fix"
},
Expand Down
6 changes: 5 additions & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,12 @@
</report>
</coverage>
<testsuites>
<testsuite name="Melvin Test Suite">
<testsuite name="default">
<directory>tests</directory>
<exclude>tests/Integration</exclude>
</testsuite>
<testsuite name="integration">
<directory>tests/Integration</directory>
</testsuite>
</testsuites>
<logging>
Expand Down
60 changes: 60 additions & 0 deletions tests/Integration/SituationsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

declare(strict_types=1);

namespace Swis\Melvin\Tests\Integration;

use PHPUnit\Framework\TestCase;
use Swis\Melvin\Client;
use Swis\Melvin\Enums\AreaType;
use Swis\Melvin\Models\Area;
use Swis\Melvin\SituationFilterParameters;

class SituationsTest extends TestCase
{
private Client $client;

public static function setUpBeforeClass(): void
{
if (!getenv('MELVIN_USERNAME') || !getenv('MELVIN_PASSWORD')) {
self::markTestSkipped('Missing Melvin credentials.');
}
}

/**
* @dataProvider areaIdProvider
*
* @param int $areaId
*/
public function testSituations(int $areaId): void
{
$params = (new SituationFilterParameters())
->setIncludeDetours(true)
->setAreaIds([$areaId]);

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

$this->assertNotEmpty($situations);
}

public function areaIdProvider(): \Generator
{
$areas = array_filter(
$this->client()->areas()->all(),
static fn (Area $area) => $area->type->equals(AreaType::PROVINCE())
);

foreach ($areas as $area) {
yield $area->name => [$area->id];
}
}

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

return $this->client;
}
}

0 comments on commit f000175

Please sign in to comment.