Skip to content

Commit 44cd1f3

Browse files
committed
Add types to tests
1 parent b5eccd3 commit 44cd1f3

File tree

5 files changed

+28
-32
lines changed

5 files changed

+28
-32
lines changed

tests/CacheTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
class CacheTest extends TestCase
1414
{
1515
/** @test */
16-
public function should_return_valid_location()
16+
public function should_return_valid_location(): void
1717
{
1818
$data = [
1919
'ip' => '81.2.69.142',
@@ -39,7 +39,7 @@ public function should_return_valid_location()
3939
}
4040

4141
/** @test */
42-
public function should_return_invalid_location()
42+
public function should_return_invalid_location(): void
4343
{
4444
$cacheMock = Mockery::mock(CacheManager::class)
4545
->shouldAllowMockingProtectedMethods();
@@ -55,7 +55,7 @@ public function should_return_invalid_location()
5555
}
5656

5757
/** @test */
58-
public function should_set_location()
58+
public function should_set_location(): void
5959
{
6060
$location = new \InteractionDesignFoundation\GeoIP\Location([
6161
'ip' => '81.2.69.142',
@@ -82,16 +82,16 @@ public function should_set_location()
8282
}
8383

8484
/** @test */
85-
public function should_flush_locations()
85+
public function should_flush_locations(): void
8686
{
8787
$cacheMock = Mockery::mock(CacheManager::class)
8888
->shouldAllowMockingProtectedMethods();
89+
$cacheMock->shouldReceive('supportsTags')->andReturn(false);
8990

9091
$geo_ip = $this->makeGeoIP([], $cacheMock);
9192

9293
$cacheMock->shouldReceive('flush')->andReturn(true);
9394

94-
$cacheMock->shouldReceive('tags')->with($geo_ip->config('cache_tags'))->andReturnSelf();
9595
$cacheMock->shouldReceive('tags')->with($geo_ip->config('cache_tags'))->andReturnSelf();
9696

9797
$this->assertSame($geo_ip->getCache()->flush(), true);

tests/GeoIPTest.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,32 +10,32 @@
1010
class GeoIPTest extends TestCase
1111
{
1212
/** @test */
13-
public function should_get_usd_currency()
13+
public function should_get_usd_currency(): void
1414
{
15-
$geo_ip = $this->makeGeoIP();
15+
$geoIp = $this->makeGeoIP();
1616

17-
$this->assertSame($geo_ip->getCurrency('US'), 'USD');
17+
$this->assertSame($geoIp->getCurrency('US'), 'USD');
1818
}
1919

2020
/** @test */
21-
public function test_get_service()
21+
public function get_service_returns_service_instance(): void
2222
{
23-
$geo_ip = $this->makeGeoIP([
23+
$geoIp = $this->makeGeoIP([
2424
'service' => 'maxmind_database',
2525
]);
2626

2727
// Get config values
2828
$config = $this->getConfig()['services']['maxmind_database'];
2929
unset($config['class']);
3030

31-
$this->assertInstanceOf(\InteractionDesignFoundation\GeoIP\Contracts\ServiceInterface::class, $geo_ip->getService());
31+
$this->assertInstanceOf(\InteractionDesignFoundation\GeoIP\Contracts\ServiceInterface::class, $geoIp->getService());
3232
}
3333

3434
/** @test */
35-
public function test_get_cache()
35+
public function get_cache_returns_cache_instance(): void
3636
{
37-
$geo_ip = $this->makeGeoIP();
37+
$geoIp = $this->makeGeoIP();
3838

39-
$this->assertInstanceOf(\InteractionDesignFoundation\GeoIP\Cache::class, $geo_ip->getCache());
39+
$this->assertInstanceOf(\InteractionDesignFoundation\GeoIP\Cache::class, $geoIp->getCache());
4040
}
4141
}

tests/Services/MaxMindDatabaseTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@
1212
class MaxMindDatabaseTest extends TestCase
1313
{
1414
/** @test */
15-
public function should_return_config_value()
15+
public function should_return_config_value(): void
1616
{
1717
list($service, $config) = $this->getService();
1818

1919
$this->assertSame($service->config('database_path'), $config['database_path']);
2020
}
2121

2222
/** @test */
23-
public function should_return_valid_location()
23+
public function should_return_valid_location(): void
2424
{
2525
[$service] = $this->getService();
2626

@@ -32,7 +32,7 @@ public function should_return_valid_location()
3232
}
3333

3434
/** @test */
35-
public function should_return_invalid_location_for_special_addresses()
35+
public function should_return_invalid_location_for_special_addresses(): void
3636
{
3737
[$service] = $this->getService();
3838

tests/TestCase.php

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace InteractionDesignFoundation\GeoIP\Tests;
66

77
use Illuminate\Cache\CacheManager;
8+
use InteractionDesignFoundation\GeoIP\GeoIP;
89
use Mockery;
910
use PHPUnit\Framework\TestCase as PHPUnitTestCase;
1011

@@ -25,7 +26,7 @@ protected function tearDown(): void
2526
Mockery::close();
2627
}
2728

28-
protected function makeGeoIP(array $config = [], $cacheMock = null)
29+
protected function makeGeoIP(array $config = [], $cacheMock = null): GeoIP
2930
{
3031
$cacheMock = $cacheMock ?: Mockery::mock(CacheManager::class);
3132
$cacheMock->shouldReceive('supportsTags')->andReturn(false);
@@ -34,10 +35,10 @@ protected function makeGeoIP(array $config = [], $cacheMock = null)
3435

3536
$cacheMock->shouldReceive('tags')->with(['laravel-geoip-location'])->andReturnSelf();
3637

37-
return new \InteractionDesignFoundation\GeoIP\GeoIP($config, $cacheMock);
38+
return new GeoIP($config, $cacheMock);
3839
}
3940

40-
protected function getConfig()
41+
protected function getConfig(): array
4142
{
4243
$config = include(__DIR__ . '/../config/geoip.php');
4344

@@ -46,17 +47,12 @@ protected function getConfig()
4647
return $config;
4748
}
4849

49-
/**
50-
* Check for test database and make a copy of it
51-
* if it does not exist.
52-
*
53-
* @param string $database
54-
*/
55-
protected function databaseCheck($database)
50+
/** Check for a test database and make a copy of it if it does not exist.*/
51+
protected function databaseCheck(string $databaseFilepath): void
5652
{
57-
if (file_exists($database) === false) {
58-
@mkdir(dirname($database), 0755, true);
59-
copy(__DIR__ . '/../resources/geoip.mmdb', $database);
53+
if (file_exists($databaseFilepath) === false) {
54+
@mkdir(dirname($databaseFilepath), 0755, true);
55+
copy(__DIR__ . '/../resources/geoip.mmdb', $databaseFilepath);
6056
}
6157
}
6258
}

tests/TestFunctions.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
declare(strict_types=1);
44

55
if (!function_exists('storage_path')) {
6-
function storage_path($path = '')
6+
function storage_path($path = ''): string
77
{
88
return __DIR__ . DIRECTORY_SEPARATOR . 'tmp' . ($path ? DIRECTORY_SEPARATOR . $path : $path);
99
}
1010
}
1111

1212
if (!function_exists('env')) {
13-
function env($key, $default = null)
13+
function env($key, $default = null): mixed
1414
{
1515
return $key;
1616
}

0 commit comments

Comments
 (0)