Skip to content

Commit d35ac0c

Browse files
norkunasjbelien
andauthored
Resolve some deprecations and remove igorw/get-in dependency (#1257)
* Remove `igorw/get-in` dependency to simplify code * Fix phpunit deprecation * Simplify phpunit's `->will($this->returnValue())` with `->willReturn()` * Simplify phpunit's `->will($this->returnCallback())` with `->willReturnCallback()` * Fix deprecated mock builder `setMethds` with `createPartialMock` * Remove deprecated phpstan `checkGenericClassInNonGenericObjectType` option * Bump phpunit to 9.6 --------- Co-authored-by: Jonathan Beliën <jbelien@users.noreply.github.com>
1 parent 69dc5bc commit d35ac0c

File tree

3 files changed

+19
-26
lines changed

3 files changed

+19
-26
lines changed

Tests/GeoIP2AdapterTest.php

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,7 @@ public function testIpAddressIsPassedCorrectToReader(string $geoIp2Model): void
8686
->expects($this->once())
8787
->method($geoIp2Model)
8888
->with('127.0.0.1')
89-
->will($this->returnValue(
90-
$this->getGeoIP2ModelMock($geoIp2Model)
91-
));
89+
->willReturn($this->getGeoIP2ModelMock($geoIp2Model));
9290

9391
$adapter = new GeoIP2Adapter($geoIp2Provider, $geoIp2Model);
9492
$adapter->getContent('file://geoip?127.0.0.1');
@@ -110,15 +108,15 @@ public function testReaderResponseIsJsonEncoded(): void
110108
$geoIp2Provider
111109
->expects($this->any())
112110
->method('city')
113-
->will($this->returnValue($cityModel));
111+
->willReturn($cityModel);
114112

115113
$adapter = new GeoIP2Adapter($geoIp2Provider);
116114

117115
$result = $adapter->getContent('file://database?127.0.0.1');
118116
$this->assertJson($result);
119117

120118
$decodedResult = json_decode($result);
121-
$this->assertObjectHasAttribute('city', $decodedResult);
119+
$this->assertObjectHasProperty('city', $decodedResult);
122120
}
123121

124122
/**
@@ -145,23 +143,21 @@ protected function getGeoIP2ModelMock($geoIP2Model)
145143
$mock
146144
->expects($this->any())
147145
->method('jsonSerialize')
148-
->will($this->returnValue(
149-
[
150-
'city' => [
151-
'geoname_id' => 2911298,
152-
'names' => [
153-
'de' => 'Hamburg',
154-
'en' => 'Hamburg',
155-
'es' => 'Hamburgo',
156-
'fr' => 'Hambourg',
157-
'ja' => 'ハンブルク',
158-
'pt-BR' => 'Hamburgo',
159-
'ru' => 'Гамбург',
160-
'zh-CN' => '汉堡市',
161-
],
146+
->willReturn([
147+
'city' => [
148+
'geoname_id' => 2911298,
149+
'names' => [
150+
'de' => 'Hamburg',
151+
'en' => 'Hamburg',
152+
'es' => 'Hamburgo',
153+
'fr' => 'Hambourg',
154+
'ja' => 'ハンブルク',
155+
'pt-BR' => 'Hamburgo',
156+
'ru' => 'Гамбург',
157+
'zh-CN' => '汉堡市',
162158
],
163-
]
164-
));
159+
],
160+
]);
165161

166162
return $mock;
167163
}

Tests/GeoIP2Test.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -264,10 +264,7 @@ public static function provideDataForTestingExceptions(): array
264264
*/
265265
private function getGeoIP2AdapterMock($returnValue = '')
266266
{
267-
$mock = $this->getMockBuilder(GeoIP2Adapter::class)
268-
->disableOriginalConstructor()
269-
->setMethods(['getContent'])
270-
->getMock();
267+
$mock = $this->createPartialMock(GeoIP2Adapter::class, ['getContent']);
271268

272269
if ($returnValue instanceof \Exception) {
273270
$returnValue = $this->throwException($returnValue);

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
},
2222
"require-dev": {
2323
"geocoder-php/provider-integration-tests": "^1.6.3",
24-
"phpunit/phpunit": "^9.5"
24+
"phpunit/phpunit": "^9.6.11"
2525
},
2626
"extra": {
2727
"branch-alias": {

0 commit comments

Comments
 (0)