Skip to content

Commit 71320be

Browse files
committed
chore: test improvements
1 parent 2a04001 commit 71320be

11 files changed

+60
-62
lines changed

src/Test/AbstractTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ protected function setUp(): void
2121
$this->mockHttpClient = new Client();
2222
}
2323

24-
protected function getApi(): OpenWeatherMap
24+
protected function givenApi(): OpenWeatherMap
2525
{
2626
return new OpenWeatherMap(
2727
new Config([

tests/AirPollutionEndpointTest.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ public function testAirPollutionGetCurrent()
2323
)
2424
);
2525

26-
$response = $this->getApi()->getAirPollution()->getCurrent(38.7077507, -9.1365919);
26+
$response = $this->givenApi()->getAirPollution()->getCurrent(50, 50);
2727
$this->assertCurrentResponse($response);
2828
}
2929

3030
#[DataProviderExternal(InvalidParamDataProvider::class, 'provideInvalidCoordinateData')]
3131
public function testAirPollutionGetCurrentWithInvalidCoordinate(float $latitude, float $longitude, string $expectedException)
3232
{
3333
$this->expectException($expectedException);
34-
$this->getApi()->getAirPollution()->getCurrent($latitude, $longitude);
34+
$this->givenApi()->getAirPollution()->getCurrent($latitude, $longitude);
3535
}
3636

3737
public function testAirPollutionGetForecast()
@@ -43,15 +43,15 @@ public function testAirPollutionGetForecast()
4343
)
4444
);
4545

46-
$response = $this->getApi()->getAirPollution()->getForecast(38.7077507, -9.1365919);
46+
$response = $this->givenApi()->getAirPollution()->getForecast(50, 50);
4747
$this->assertForecastResponse($response);
4848
}
4949

5050
#[DataProviderExternal(InvalidParamDataProvider::class, 'provideInvalidCoordinateData')]
5151
public function testAirPollutionGetForecastWithInvalidCoordinate(float $latitude, float $longitude, string $expectedException)
5252
{
5353
$this->expectException($expectedException);
54-
$this->getApi()->getAirPollution()->getForecast($latitude, $longitude);
54+
$this->givenApi()->getAirPollution()->getForecast($latitude, $longitude);
5555
}
5656

5757
public function testAirPollutionGetHistory()
@@ -65,9 +65,9 @@ public function testAirPollutionGetHistory()
6565

6666
$utcTimezone = new \DateTimeZone('UTC');
6767

68-
$response = $this->getApi()->getAirPollution()->getHistory(
69-
38.7077507,
70-
-9.1365919,
68+
$response = $this->givenApi()->getAirPollution()->getHistory(
69+
50,
70+
50,
7171
new \DateTimeImmutable('-5 days', $utcTimezone),
7272
new \DateTimeImmutable('-4 days', $utcTimezone)
7373
);
@@ -82,7 +82,7 @@ public function testAirPollutionGetHistoryWithInvalidCoordinate(float $latitude,
8282
$startDate = new \DateTimeImmutable('-5 days');
8383
$endDate = new \DateTimeImmutable('-4 days');
8484

85-
$this->getApi()->getAirPollution()->getHistory($latitude, $longitude, $startDate, $endDate);
85+
$this->givenApi()->getAirPollution()->getHistory($latitude, $longitude, $startDate, $endDate);
8686
}
8787

8888
#[DataProviderExternal(InvalidParamDataProvider::class, 'provideInvalidPastDateData')]
@@ -92,9 +92,9 @@ public function testAirPollutionGetHistoryWithInvalidPastStartDate(
9292
)
9393
{
9494
$this->expectException($expectedException);
95-
$this->getApi()->getAirPollution()->getHistory(
96-
38.7077507,
97-
-9.1365919,
95+
$this->givenApi()->getAirPollution()->getHistory(
96+
50,
97+
50,
9898
$startDate,
9999
new \DateTimeImmutable('-5 days', new \DateTimeZone('UTC'))
100100
);
@@ -107,9 +107,9 @@ public function testAirPollutionGetHistoryWithInvalidPastEndDate(
107107
)
108108
{
109109
$this->expectException($expectedException);
110-
$this->getApi()->getAirPollution()->getHistory(
111-
38.7077507,
112-
-9.1365919,
110+
$this->givenApi()->getAirPollution()->getHistory(
111+
50,
112+
50,
113113
new \DateTimeImmutable('-5 days', new \DateTimeZone('UTC')),
114114
$endDate
115115
);
@@ -123,7 +123,7 @@ public function testAirPollutionGetHistoryWithInvalidDateRange(
123123
)
124124
{
125125
$this->expectException($expectedException);
126-
$this->getApi()->getAirPollution()->getHistory(38.7077507, -9.1365919, $startDate, $endDate);
126+
$this->givenApi()->getAirPollution()->getHistory(50, 50, $startDate, $endDate);
127127
}
128128

129129
private function assertCurrentResponse(AirPollutionLocation $response): void

tests/ApiErrorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function testApiError(int $statusCode, string $expectedException)
2424
);
2525

2626
$this->expectException($expectedException);
27-
$this->getApi()->getWeather()->getCurrent(38.7077507, -9.1365919);
27+
$this->givenApi()->getWeather()->getCurrent(38.7077507, -9.1365919);
2828
}
2929

3030
public static function provideApiErrorData(): \Generator

tests/ConfigTest.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace ProgrammatorDev\OpenWeatherMap\Test;
44

5-
use Monolog\Logger;
65
use PHPUnit\Framework\Attributes\DataProvider;
76
use PHPUnit\Framework\Attributes\DataProviderExternal;
87
use ProgrammatorDev\OpenWeatherMap\Config;
@@ -11,7 +10,6 @@
1110
use ProgrammatorDev\YetAnotherPhpValidator\Exception\ValidationException;
1211
use Psr\Cache\CacheItemPoolInterface;
1312
use Psr\Log\LoggerInterface;
14-
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
1513
use Symfony\Component\OptionsResolver\Exception\InvalidOptionsException;
1614
use Symfony\Component\OptionsResolver\Exception\MissingOptionsException;
1715

@@ -45,8 +43,8 @@ public function testConfigWithOptions()
4543
'unitSystem' => 'imperial',
4644
'language' => 'pt',
4745
'httpClientBuilder' => new HttpClientBuilder(),
48-
'cache' => new FilesystemAdapter(),
49-
'logger' => new Logger('test')
46+
'cache' => $this->createMock(CacheItemPoolInterface::class),
47+
'logger' => $this->createMock(LoggerInterface::class)
5048
]);
5149

5250
$this->assertSame('newtestappkey', $config->getApplicationKey());
@@ -139,13 +137,13 @@ public function testConfigSetHttpClientBuilder()
139137

140138
public function testConfigSetCache()
141139
{
142-
$this->config->setCache(new FilesystemAdapter());
140+
$this->config->setCache($this->createMock(CacheItemPoolInterface::class));
143141
$this->assertInstanceOf(CacheItemPoolInterface::class, $this->config->getCache());
144142
}
145143

146144
public function testConfigSetLogger()
147145
{
148-
$this->config->setLogger(new Logger('test'));
146+
$this->config->setLogger($this->createMock(LoggerInterface::class));
149147
$this->assertInstanceOf(LoggerInterface::class, $this->config->getLogger());
150148
}
151149
}

tests/GeocodingEndpointTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ public function testGeocodingGetByLocationName()
2222
)
2323
);
2424

25-
$response = $this->getApi()->getGeocoding()->getByLocationName('lisbon, pt');
25+
$response = $this->givenApi()->getGeocoding()->getByLocationName('lisbon, pt');
2626
$this->assertLocationListResponse($response);
2727
}
2828

2929
public function testGeocodingGetByLocationNameWithBlankValue()
3030
{
3131
$this->expectException(ValidationException::class);
32-
$this->getApi()->getGeocoding()->getByLocationName('');
32+
$this->givenApi()->getGeocoding()->getByLocationName('');
3333
}
3434

3535
public function testGeocodingGetByZipCode()
@@ -41,7 +41,7 @@ public function testGeocodingGetByZipCode()
4141
)
4242
);
4343

44-
$response = $this->getApi()->getGeocoding()->getByZipCode('1000-001', 'pt');
44+
$response = $this->givenApi()->getGeocoding()->getByZipCode('1000-001', 'pt');
4545
$this->assertInstanceOf(ZipCodeLocation::class, $response);
4646

4747
$this->assertSame('1000-001', $response->getZipCode());
@@ -58,7 +58,7 @@ public function testGeocodingGetByZipCode()
5858
public function testGeocodingGetByZipCodeWithInvalidValue(string $zipCode, string $countryCode)
5959
{
6060
$this->expectException(ValidationException::class);
61-
$this->getApi()->getGeocoding()->getByZipCode($zipCode, $countryCode);
61+
$this->givenApi()->getGeocoding()->getByZipCode($zipCode, $countryCode);
6262
}
6363

6464
public static function provideGeocodingGetByZipCodeWithInvalidValueData(): \Generator
@@ -77,7 +77,7 @@ public function testGeocodingGetByCoordinate()
7777
)
7878
);
7979

80-
$response = $this->getApi()->getGeocoding()->getByCoordinate(38.7077507, -9.1365919);
80+
$response = $this->givenApi()->getGeocoding()->getByCoordinate(50, 50);
8181
$this->assertLocationListResponse($response);
8282
}
8383

@@ -89,7 +89,7 @@ public function testGeocodingGetByCoordinateWithInvalidCoordinate(
8989
)
9090
{
9191
$this->expectException($expectedException);
92-
$this->getApi()->getGeocoding()->getByCoordinate($latitude, $longitude);
92+
$this->givenApi()->getGeocoding()->getByCoordinate($latitude, $longitude);
9393
}
9494

9595
#[DataProviderExternal(InvalidParamDataProvider::class, 'provideInvalidNumResultsData')]
@@ -99,7 +99,7 @@ public function testGeocodingGetByCoordinateWithInvalidNumResults(
9999
)
100100
{
101101
$this->expectException($expectedException);
102-
$this->getApi()->getGeocoding()->getByCoordinate(38.7077507, -9.1365919, $numResults);
102+
$this->givenApi()->getGeocoding()->getByCoordinate(50, 50, $numResults);
103103
}
104104

105105
/**

tests/OneCallEndpointTest.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ public function testOneCallGetWeather()
3030
)
3131
);
3232

33-
$response = $this->getApi()->getOneCall()->getWeather(38.7077507, -9.1365919);
33+
$response = $this->givenApi()->getOneCall()->getWeather(50, 50);
3434
$this->assertWeatherResponse($response);
3535
}
3636

3737
#[DataProviderExternal(InvalidParamDataProvider::class, 'provideInvalidCoordinateData')]
3838
public function testOneCallGetWeatherWithInvalidCoordinate(float $latitude, float $longitude, string $expectedException)
3939
{
4040
$this->expectException($expectedException);
41-
$this->getApi()->getOneCall()->getWeather($latitude, $longitude);
41+
$this->givenApi()->getOneCall()->getWeather($latitude, $longitude);
4242
}
4343

4444
public function testOneCallGetHistoryMoment()
@@ -50,9 +50,9 @@ public function testOneCallGetHistoryMoment()
5050
)
5151
);
5252

53-
$response = $this->getApi()->getOneCall()->getHistoryMoment(
54-
38.7077507,
55-
-9.1365919,
53+
$response = $this->givenApi()->getOneCall()->getHistoryMoment(
54+
50,
55+
50,
5656
new \DateTimeImmutable('2023-01-01 00:00:00')
5757
);
5858
$this->assertHistoryMomentResponse($response);
@@ -62,7 +62,7 @@ public function testOneCallGetHistoryMoment()
6262
public function testOneCallGetHistoryMomentWithInvalidCoordinate(float $latitude, float $longitude, string $expectedException)
6363
{
6464
$this->expectException($expectedException);
65-
$this->getApi()->getOneCall()->getHistoryMoment(
65+
$this->givenApi()->getOneCall()->getHistoryMoment(
6666
$latitude,
6767
$longitude,
6868
new \DateTimeImmutable('2023-01-01 00:00:00')
@@ -73,7 +73,7 @@ public function testOneCallGetHistoryMomentWithInvalidCoordinate(float $latitude
7373
public function testOneCallGetHistoryMomentWithInvalidPastDate(\DateTimeImmutable $date, string $expectedException)
7474
{
7575
$this->expectException($expectedException);
76-
$this->getApi()->getOneCall()->getHistoryMoment(38.7077507, -9.1365919, $date);
76+
$this->givenApi()->getOneCall()->getHistoryMoment(50, 50, $date);
7777
}
7878

7979
public function testOneCallGetHistoryAggregate()
@@ -85,9 +85,9 @@ public function testOneCallGetHistoryAggregate()
8585
)
8686
);
8787

88-
$response = $this->getApi()->getOneCall()->getHistoryAggregate(
89-
38.7077507,
90-
-9.1365919,
88+
$response = $this->givenApi()->getOneCall()->getHistoryAggregate(
89+
50,
90+
50,
9191
new \DateTimeImmutable('2023-01-01')
9292
);
9393
$this->assertHistoryAggregateResponse($response);
@@ -97,7 +97,7 @@ public function testOneCallGetHistoryAggregate()
9797
public function testOneCallGetHistoryAggregateWithInvalidCoordinate(float $latitude, float $longitude, string $expectedException)
9898
{
9999
$this->expectException($expectedException);
100-
$this->getApi()->getOneCall()->getHistoryAggregate(
100+
$this->givenApi()->getOneCall()->getHistoryAggregate(
101101
$latitude,
102102
$longitude,
103103
new \DateTimeImmutable('2023-01-01')
@@ -108,12 +108,12 @@ public function testOneCallGetHistoryAggregateWithInvalidCoordinate(float $latit
108108
public function testOneCallGetHistoryAggregateWithInvalidPastDate(\DateTimeImmutable $date, string $expectedException)
109109
{
110110
$this->expectException($expectedException);
111-
$this->getApi()->getOneCall()->getHistoryAggregate(38.7077507, -9.1365919, $date);
111+
$this->givenApi()->getOneCall()->getHistoryAggregate(50, 50, $date);
112112
}
113113

114114
public function testOneCallMethodsWithExist()
115115
{
116-
$weatherEndpoint = $this->getApi()->getWeather();
116+
$weatherEndpoint = $this->givenApi()->getWeather();
117117

118118
$this->assertSame(true, method_exists($weatherEndpoint, 'withLanguage'));
119119
$this->assertSame(true, method_exists($weatherEndpoint, 'withUnitSystem'));

tests/OpenWeatherMapTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,26 @@ class OpenWeatherMapTest extends AbstractTest
1212
{
1313
public function testOpenWeatherMapGetConfig()
1414
{
15-
$this->assertInstanceOf(Config::class, $this->getApi()->getConfig());
15+
$this->assertInstanceOf(Config::class, $this->givenApi()->getConfig());
1616
}
1717

1818
public function testOpenWeatherMapGetOneCall()
1919
{
20-
$this->assertInstanceOf(OneCallEndpoint::class, $this->getApi()->getOneCall());
20+
$this->assertInstanceOf(OneCallEndpoint::class, $this->givenApi()->getOneCall());
2121
}
2222

2323
public function testOpenWeatherMapGetWeather()
2424
{
25-
$this->assertInstanceOf(WeatherEndpoint::class, $this->getApi()->getWeather());
25+
$this->assertInstanceOf(WeatherEndpoint::class, $this->givenApi()->getWeather());
2626
}
2727

2828
public function testOpenWeatherMapGetAirPollution()
2929
{
30-
$this->assertInstanceOf(AirPollutionEndpoint::class, $this->getApi()->getAirPollution());
30+
$this->assertInstanceOf(AirPollutionEndpoint::class, $this->givenApi()->getAirPollution());
3131
}
3232

3333
public function testOpenWeatherMapGetGeocoding()
3434
{
35-
$this->assertInstanceOf(GeocodingEndpoint::class, $this->getApi()->getGeocoding());
35+
$this->assertInstanceOf(GeocodingEndpoint::class, $this->givenApi()->getGeocoding());
3636
}
3737
}

tests/WeatherEndpointTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@ public function testWeatherGetCurrent()
2929
)
3030
);
3131

32-
$response = $this->getApi()->getWeather()->getCurrent(38.7077507, -9.1365919);
32+
$response = $this->givenApi()->getWeather()->getCurrent(50, 50);
3333
$this->assertCurrentResponse($response);
3434
}
3535

3636
#[DataProviderExternal(InvalidParamDataProvider::class, 'provideInvalidCoordinateData')]
3737
public function testWeatherGetCurrentWithInvalidCoordinate(float $latitude, float $longitude, string $expectedException)
3838
{
3939
$this->expectException($expectedException);
40-
$this->getApi()->getWeather()->getCurrent($latitude, $longitude);
40+
$this->givenApi()->getWeather()->getCurrent($latitude, $longitude);
4141
}
4242

4343
public function testWeatherGetForecast()
@@ -49,27 +49,27 @@ public function testWeatherGetForecast()
4949
)
5050
);
5151

52-
$response = $this->getApi()->getWeather()->getForecast(38.7077507, -9.1365919, 1);
52+
$response = $this->givenApi()->getWeather()->getForecast(50, 50, 1);
5353
$this->assertForecastResponse($response);
5454
}
5555

5656
#[DataProviderExternal(InvalidParamDataProvider::class, 'provideInvalidCoordinateData')]
5757
public function testWeatherGetForecastWithInvalidCoordinate(float $latitude, float $longitude, string $expectedException)
5858
{
5959
$this->expectException($expectedException);
60-
$this->getApi()->getWeather()->getForecast($latitude, $longitude, 10);
60+
$this->givenApi()->getWeather()->getForecast($latitude, $longitude, 10);
6161
}
6262

6363
#[DataProviderExternal(InvalidParamDataProvider::class, 'provideInvalidNumResultsData')]
6464
public function testWeatherGetForecastWithInvalidNumResults(int $numResults, string $expectedException)
6565
{
6666
$this->expectException($expectedException);
67-
$this->getApi()->getWeather()->getForecast(38.7077507, -9.1365919, $numResults);
67+
$this->givenApi()->getWeather()->getForecast(50, 50, $numResults);
6868
}
6969

7070
public function testWeatherMethodsWithExist()
7171
{
72-
$weatherEndpoint = $this->getApi()->getWeather();
72+
$weatherEndpoint = $this->givenApi()->getWeather();
7373

7474
$this->assertSame(true, method_exists($weatherEndpoint, 'withLanguage'));
7575
$this->assertSame(true, method_exists($weatherEndpoint, 'withUnitSystem'));

0 commit comments

Comments
 (0)