-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: added language and unit system trait tests
- Loading branch information
1 parent
b3e5f68
commit 67d5598
Showing
5 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
} |