Skip to content

Commit 97cdc68

Browse files
committed
tests: add assistant resource related tests
1 parent fcb9c51 commit 97cdc68

File tree

6 files changed

+132
-3
lines changed

6 files changed

+132
-3
lines changed

src/Entity/Assistant/WeatherData.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ class WeatherData extends BaseWeather
1818

1919
private \DateTimeImmutable $sunsetAt;
2020

21-
public function __construct(string $location, array $data)
21+
public function __construct(string $locationName, array $data)
2222
{
2323
parent::__construct($data);
2424

25-
$this->locationName = $location;
25+
$this->locationName = $locationName;
2626
$this->temperature = $data['temp'];
2727
$this->temperatureFeelsLike = $data['feels_like'];
2828
$this->visibility = $data['visibility'];

src/Resource/AssistantResource.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
class AssistantResource extends Resource
1111
{
1212
/**
13-
* Start a new session with the Weather AI Assistant and enter a prompt
13+
* Start a new session with the Weather AI Assistant
1414
*
1515
* @throws ClientExceptionInterface
1616
*/

src/Test/MockResponse.php

Lines changed: 3 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace ProgrammatorDev\OpenWeatherMap\Test\Integration;
4+
5+
use ProgrammatorDev\OpenWeatherMap\Entity\Assistant\Answer;
6+
use ProgrammatorDev\OpenWeatherMap\Test\AbstractTest;
7+
use ProgrammatorDev\OpenWeatherMap\Test\MockResponse;
8+
use ProgrammatorDev\OpenWeatherMap\Test\Util\TestItemResponseTrait;
9+
10+
class AssistantResourceTest extends AbstractTest
11+
{
12+
use TestItemResponseTrait;
13+
14+
public static function provideItemResponseData(): \Generator
15+
{
16+
yield 'start session' => [
17+
Answer::class,
18+
MockResponse::ASSISTANT_START_SESSION,
19+
'assistant',
20+
'startSession',
21+
['prompt']
22+
];
23+
}
24+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
namespace ProgrammatorDev\OpenWeatherMap\Test\Unit\Assistant;
4+
5+
use ProgrammatorDev\OpenWeatherMap\Entity\Assistant\Answer;
6+
use ProgrammatorDev\OpenWeatherMap\Entity\Assistant\WeatherData;
7+
use ProgrammatorDev\OpenWeatherMap\Test\AbstractTest;
8+
9+
class AnswerTest extends AbstractTest
10+
{
11+
public function testMethods()
12+
{
13+
$entity = new Answer([
14+
'answer' => 'Answer text',
15+
'data' => [
16+
'location' => [
17+
'clouds' => 100,
18+
'dew_point' => 10,
19+
'dt' => 1762622549,
20+
'feels_like' => 10,
21+
'humidity' => 10,
22+
'pressure' => 1000,
23+
'sunrise' => 1762602543,
24+
'sunset' => 1762638067,
25+
'temp' => 10,
26+
'uvi' => 1,
27+
'visibility' => 10000,
28+
'weather' => [
29+
[
30+
'description' => 'description',
31+
'icon' => '01d',
32+
'id' => 200,
33+
'main' => 'name'
34+
]
35+
],
36+
'wind_deg' => 10,
37+
'wind_speed' => 10,
38+
'wind_gust' => 10,
39+
]
40+
],
41+
'session_id' => '777f049a-c96b-423f-baef-ca34ff725fe9'
42+
]);
43+
44+
$this->assertSame('Answer text', $entity->getAnswer());
45+
$this->assertSame('777f049a-c96b-423f-baef-ca34ff725fe9', $entity->getSessionId());
46+
$this->assertContainsOnlyInstancesOf(WeatherData::class, $entity->getData());
47+
}
48+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
namespace ProgrammatorDev\OpenWeatherMap\Test\Unit\Assistant;
4+
5+
use ProgrammatorDev\OpenWeatherMap\Entity\Assistant\WeatherData;
6+
use ProgrammatorDev\OpenWeatherMap\Entity\Condition;
7+
use ProgrammatorDev\OpenWeatherMap\Entity\Wind;
8+
use ProgrammatorDev\OpenWeatherMap\Test\AbstractTest;
9+
10+
class WeatherDataTest extends AbstractTest
11+
{
12+
public function testMethods()
13+
{
14+
$entity = new WeatherData('locationName', [
15+
'clouds' => 100,
16+
'dew_point' => 10,
17+
'dt' => 1762622549,
18+
'feels_like' => 10,
19+
'humidity' => 10,
20+
'pressure' => 1000,
21+
'sunrise' => 1762602543,
22+
'sunset' => 1762638067,
23+
'temp' => 10,
24+
'uvi' => 1,
25+
'visibility' => 10000,
26+
'weather' => [
27+
[
28+
'description' => 'description',
29+
'icon' => '01d',
30+
'id' => 200,
31+
'main' => 'name'
32+
]
33+
],
34+
'wind_deg' => 10,
35+
'wind_speed' => 10,
36+
'wind_gust' => 10,
37+
]);
38+
39+
$this->assertSame('locationName', $entity->getLocationName());
40+
$this->assertInstanceOf(\DateTimeImmutable::class, $entity->getDateTime());
41+
$this->assertSame(1000, $entity->getAtmosphericPressure());
42+
$this->assertSame(10, $entity->getHumidity());
43+
$this->assertSame(10.0, $entity->getDewPoint());
44+
$this->assertSame(1.0, $entity->getUltraVioletIndex());
45+
$this->assertSame(100, $entity->getCloudiness());
46+
$this->assertInstanceOf(Wind::class, $entity->getWind());
47+
$this->assertContainsOnlyInstancesOf(Condition::class, $entity->getConditions());
48+
$this->assertSame(10.0, $entity->getTemperature());
49+
$this->assertSame(10.0, $entity->getTemperatureFeelsLike());
50+
$this->assertSame(10000, $entity->getVisibility());
51+
$this->assertInstanceOf(\DateTimeImmutable::class, $entity->getSunriseAt());
52+
$this->assertInstanceOf(\DateTimeImmutable::class, $entity->getSunsetAt());
53+
}
54+
}

0 commit comments

Comments
 (0)