-
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.
- Loading branch information
1 parent
8538f4b
commit 84a5862
Showing
17 changed files
with
453 additions
and
380 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,27 @@ | ||
<?php | ||
|
||
namespace ProgrammatorDev\OpenWeatherMap\Test\Util; | ||
|
||
use Nyholm\Psr7\Response; | ||
use PHPUnit\Framework\Attributes\DataProvider; | ||
|
||
trait TestCollectionResponseTrait | ||
{ | ||
#[DataProvider(methodName: 'provideCollectionResponseData')] | ||
public function testCollectionResponse( | ||
string $responseClass, | ||
string $responseBody, | ||
string $resource, | ||
string $method, | ||
?array $args = null | ||
): void | ||
{ | ||
$this->mockClient->addResponse(new Response( | ||
status: 200, | ||
body: $responseBody | ||
)); | ||
|
||
$response = $this->api->$resource()->$method(...$args); | ||
$this->assertContainsOnlyInstancesOf($responseClass, $response); | ||
} | ||
} |
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,27 @@ | ||
<?php | ||
|
||
namespace ProgrammatorDev\OpenWeatherMap\Test\Util; | ||
|
||
use Nyholm\Psr7\Response; | ||
use PHPUnit\Framework\Attributes\DataProvider; | ||
|
||
trait TestItemResponseTrait | ||
{ | ||
#[DataProvider(methodName: 'provideItemResponseData')] | ||
public function testItemResponse( | ||
string $responseClass, | ||
string $responseBody, | ||
string $resource, | ||
string $method, | ||
?array $args = null | ||
): void | ||
{ | ||
$this->mockClient->addResponse(new Response( | ||
status: 200, | ||
body: $responseBody | ||
)); | ||
|
||
$response = $this->api->$resource()->$method(...$args); | ||
$this->assertInstanceOf($responseClass, $response); | ||
} | ||
} |
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,16 @@ | ||
<?php | ||
|
||
namespace ProgrammatorDev\OpenWeatherMap\Test\Util; | ||
|
||
use PHPUnit\Framework\Attributes\DataProvider; | ||
use ProgrammatorDev\Validator\Exception\ValidationException; | ||
|
||
trait TestValidationExceptionTrait | ||
{ | ||
#[DataProvider(methodName: 'provideValidationExceptionData')] | ||
public function testValidationException(string $resource, string $method, ?array $args = null): void | ||
{ | ||
$this->expectException(ValidationException::class); | ||
$this->api->$resource()->$method(...$args); | ||
} | ||
} |
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,47 @@ | ||
<?php | ||
|
||
namespace Integration; | ||
|
||
use ProgrammatorDev\OpenWeatherMap\Entity\Weather\Weather; | ||
use ProgrammatorDev\OpenWeatherMap\Entity\Weather\WeatherCollection; | ||
use ProgrammatorDev\OpenWeatherMap\Test\AbstractTest; | ||
use ProgrammatorDev\OpenWeatherMap\Test\MockResponse; | ||
use ProgrammatorDev\OpenWeatherMap\Test\Util\TestValidationExceptionTrait; | ||
use ProgrammatorDev\OpenWeatherMap\Test\Util\TestItemResponseTrait; | ||
|
||
class WeatherResourceTest extends AbstractTest | ||
{ | ||
use TestItemResponseTrait; | ||
use TestValidationExceptionTrait; | ||
|
||
public static function provideItemResponseData(): \Generator | ||
{ | ||
yield 'get current' => [ | ||
Weather::class, | ||
MockResponse::WEATHER_CURRENT, | ||
'weather', | ||
'getCurrent', | ||
[50, 50] | ||
]; | ||
yield 'get forecast' => [ | ||
WeatherCollection::class, | ||
MockResponse::WEATHER_FORECAST, | ||
'weather', | ||
'getForecast', | ||
[50, 50] | ||
]; | ||
} | ||
|
||
public static function provideValidationExceptionData(): \Generator | ||
{ | ||
yield 'get current, latitude lower than -90' => ['weather', 'getCurrent', [-91, 50]]; | ||
yield 'get current, latitude greater than 90' => ['weather', 'getCurrent', [91, 50]]; | ||
yield 'get current, longitude lower than -180' => ['weather', 'getCurrent', [50, -181]]; | ||
yield 'get current, longitude greater than 180' => ['weather', 'getCurrent', [50, 181]]; | ||
yield 'get forecast, latitude lower than -90' => ['weather', 'getForecast', [-91, 50]]; | ||
yield 'get forecast, latitude greater than 90' => ['weather', 'getForecast', [91, 50]]; | ||
yield 'get forecast, longitude lower than -180' => ['weather', 'getForecast', [50, -181]]; | ||
yield 'get forecast, longitude greater than 180' => ['weather', 'getForecast', [50, 181]]; | ||
yield 'get forecast, zero num results' => ['weather', 'getForecast', [50, 50, 0]]; | ||
} | ||
} |
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,26 @@ | ||
<?php | ||
|
||
namespace ProgrammatorDev\OpenWeatherMap\Test\Unit; | ||
|
||
use ProgrammatorDev\OpenWeatherMap\Entity\Condition; | ||
use ProgrammatorDev\OpenWeatherMap\Entity\Icon; | ||
use ProgrammatorDev\OpenWeatherMap\Test\AbstractTest; | ||
|
||
class ConditionTest extends AbstractTest | ||
{ | ||
public function testMethods() | ||
{ | ||
$entity = new Condition([ | ||
'id' => 200, | ||
'main' => 'name', | ||
'description' => 'description', | ||
'icon' => '01d' | ||
]); | ||
|
||
$this->assertSame(200, $entity->getId()); | ||
$this->assertSame('name', $entity->getName()); | ||
$this->assertSame('description', $entity->getDescription()); | ||
$this->assertInstanceOf(Icon::class, $entity->getIcon()); | ||
$this->assertSame('THUNDERSTORM', $entity->getSystemName()); | ||
} | ||
} |
Oops, something went wrong.