Skip to content

Commit

Permalink
tests: added language and unit system trait tests
Browse files Browse the repository at this point in the history
  • Loading branch information
andrepimpao committed May 9, 2024
1 parent b3e5f68 commit 67d5598
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Test/Util/TestCollectionResponseTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@ public function testCollectionResponse(
$response = $this->api->$resource()->$method(...$args);
$this->assertContainsOnlyInstancesOf($responseClass, $response);
}

abstract public static function provideCollectionResponseData(): \Generator;
}
2 changes: 2 additions & 0 deletions src/Test/Util/TestItemResponseTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@ public function testItemResponse(
$response = $this->api->$resource()->$method(...$args);
$this->assertInstanceOf($responseClass, $response);
}

abstract public static function provideItemResponseData(): \Generator;
}
2 changes: 2 additions & 0 deletions src/Test/Util/TestValidationExceptionTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ public function testValidationException(string $resource, string $method, ?array
$this->expectException(ValidationException::class);
$this->api->$resource()->$method(...$args);
}

abstract public static function provideValidationExceptionData(): \Generator;
}
39 changes: 39 additions & 0 deletions tests/Integration/LanguageTraitTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace Integration;

use ProgrammatorDev\OpenWeatherMap\Resource\Resource;
use ProgrammatorDev\OpenWeatherMap\Resource\Util\LanguageTrait;
use ProgrammatorDev\OpenWeatherMap\Test\AbstractTest;
use ProgrammatorDev\Validator\Exception\ValidationException;

class LanguageTraitTest extends AbstractTest
{
private Resource $resource;

protected function setUp(): void
{
parent::setUp();

$this->resource = new class($this->api) extends Resource {
use LanguageTrait;

public function getLanguage(): string
{
return $this->api->getQueryDefault('lang');
}
};
}

public function testMethods(): void
{
$this->assertSame('pt', $this->resource->withLanguage('pt')->getLanguage());
$this->assertSame('en', $this->resource->getLanguage()); // back to default value
}

public function testValidationException(): void
{
$this->expectException(ValidationException::class);
$this->resource->withLanguage('invalid');
}
}
39 changes: 39 additions & 0 deletions tests/Integration/UnitSystemTraitTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace Integration;

use ProgrammatorDev\OpenWeatherMap\Resource\Resource;
use ProgrammatorDev\OpenWeatherMap\Resource\Util\UnitSystemTrait;
use ProgrammatorDev\OpenWeatherMap\Test\AbstractTest;
use ProgrammatorDev\Validator\Exception\ValidationException;

class UnitSystemTraitTest extends AbstractTest
{
private Resource $resource;

protected function setUp(): void
{
parent::setUp();

$this->resource = new class($this->api) extends Resource {
use UnitSystemTrait;

public function getUnitSystem(): string
{
return $this->api->getQueryDefault('units');
}
};
}

public function testMethods(): void
{
$this->assertSame('imperial', $this->resource->withUnitSystem('imperial')->getUnitSystem());
$this->assertSame('metric', $this->resource->getUnitSystem()); // back to default value
}

public function testValidationException(): void
{
$this->expectException(ValidationException::class);
$this->resource->withUnitSystem('invalid');
}
}

0 comments on commit 67d5598

Please sign in to comment.