Skip to content

Commit 3041e56

Browse files
committed
Cleanup dev dependencies
1 parent 1071c96 commit 3041e56

File tree

4 files changed

+35
-122
lines changed

4 files changed

+35
-122
lines changed

composer.json

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,11 @@
2121
"require-dev": {
2222
"friendsofphp/php-cs-fixer": "^3.50",
2323
"geoip2/geoip2": "^3.0",
24-
"mockery/mockery": "^1.6",
24+
"orchestra/testbench": "^8.8 || ^9.0",
2525
"phpstan/phpstan": "^1.10",
2626
"phpunit/phpunit": "^10.5 || ^11.0",
2727
"squizlabs/php_codesniffer": "^3.9",
28-
"vimeo/psalm": "^5.22",
29-
"vlucas/phpdotenv": "^5.4"
28+
"vimeo/psalm": "^5.22"
3029
},
3130
"suggest": {
3231
"geoip2/geoip2": "Required to use the MaxMind database or web service with GeoIP (~2.1).",
@@ -43,10 +42,7 @@
4342
"autoload-dev": {
4443
"psr-4": {
4544
"InteractionDesignFoundation\\GeoIP\\Tests\\": "tests/"
46-
},
47-
"files": [
48-
"tests/TestFunctions.php"
49-
]
45+
}
5046
},
5147
"config": {
5248
"sort-packages": true

tests/CacheTest.php

Lines changed: 25 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -5,95 +5,51 @@
55
namespace InteractionDesignFoundation\GeoIP\Tests;
66

77
use Illuminate\Cache\CacheManager;
8-
use Mockery;
8+
use InteractionDesignFoundation\GeoIP\Cache;
9+
use InteractionDesignFoundation\GeoIP\Location;
10+
use PHPUnit\Framework\Attributes\CoversClass;
11+
use PHPUnit\Framework\Attributes\Test;
912

10-
/**
11-
* @covers \InteractionDesignFoundation\GeoIP\Cache
12-
*/
13+
#[CoversClass(Cache::class)]
1314
class CacheTest extends TestCase
1415
{
15-
/** @test */
16+
#[Test]
1617
public function should_return_valid_location(): void
1718
{
18-
$data = [
19+
$cache = new Cache(app(CacheManager::class), [], 30);
20+
$originalLocation = new Location([
1921
'ip' => '81.2.69.142',
2022
'iso_code' => 'US',
2123
'lat' => 41.31,
2224
'lon' => -72.92,
23-
];
24-
25-
$cacheMock = Mockery::mock(CacheManager::class)
26-
->shouldAllowMockingProtectedMethods();
27-
28-
$cacheMock->shouldReceive('supportsTags')->andReturn(false);
29-
$cacheMock->shouldReceive('get')->with($data['ip'])->andReturn($data);
30-
31-
$geo_ip = $this->makeGeoIP([], $cacheMock);
32-
$geo_ip->getCache()->setPrefix('');
33-
34-
$location = $geo_ip->getCache()->get($data['ip']);
35-
36-
$this->assertInstanceOf(\InteractionDesignFoundation\GeoIP\Location::class, $location);
37-
$this->assertSame($location->ip, $data['ip']);
38-
$this->assertSame($location->default, false);
39-
}
40-
41-
/** @test */
42-
public function should_return_invalid_location(): void
43-
{
44-
$cacheMock = Mockery::mock(CacheManager::class)
45-
->shouldAllowMockingProtectedMethods();
46-
47-
$cacheMock->shouldReceive('supportsTags')->andReturn(false);
48-
49-
$geo_ip = $this->makeGeoIP([], $cacheMock);
50-
$geo_ip->getCache()->setPrefix('');
25+
]);
5126

52-
$cacheMock->shouldReceive('get')->with('81.2.69.142')->andReturn(null);
27+
$cache->set($originalLocation['ip'], $originalLocation);
28+
$uncachedLocation = $cache->get($originalLocation['ip']);
5329

54-
$this->assertSame($geo_ip->getCache()->get('81.2.69.142'), null);
30+
$this->assertInstanceOf(Location::class, $uncachedLocation);
31+
$this->assertSame($uncachedLocation->ip, $originalLocation->ip);
32+
$this->assertSame($uncachedLocation->default, false);
5533
}
5634

57-
/** @test */
58-
public function should_set_location(): void
35+
#[Test]
36+
public function it_flushes_empty_cache(): void
5937
{
60-
$location = new \InteractionDesignFoundation\GeoIP\Location([
61-
'ip' => '81.2.69.142',
62-
'iso_code' => 'US',
63-
'lat' => 41.31,
64-
'lon' => -72.92,
65-
]);
66-
67-
$cacheMock = Mockery::mock(CacheManager::class)
68-
->shouldAllowMockingProtectedMethods();
38+
$cache = new Cache(app(CacheManager::class), [], 30);
6939

70-
$cacheMock->shouldReceive('supportsTags')->andReturn(false);
40+
$flushResult = $cache->flush();
7141

72-
$geo_ip = $this->makeGeoIP([], $cacheMock);
73-
$geo_ip->getCache()->setPrefix('');
74-
75-
$cacheMock->shouldReceive('put')->withArgs(['81.2.69.142', $location->toArray(), $geo_ip->config('cache_expires')])->andReturn(null);
76-
77-
$cacheMock->shouldReceive('tags')
78-
->with($geo_ip->config('cache_tags'))
79-
->andReturnSelf();
80-
81-
$this->assertSame($geo_ip->getCache()->set('81.2.69.142', $location), null);
42+
$this->assertTrue($flushResult);
8243
}
8344

84-
/** @test */
85-
public function should_flush_locations(): void
45+
#[Test]
46+
public function it_flushes_non_empty_cache(): void
8647
{
87-
$cacheMock = Mockery::mock(CacheManager::class)
88-
->shouldAllowMockingProtectedMethods();
89-
$cacheMock->shouldReceive('supportsTags')->andReturn(false);
90-
91-
$geo_ip = $this->makeGeoIP([], $cacheMock);
92-
93-
$cacheMock->shouldReceive('flush')->andReturn(true);
48+
$cache = new Cache(app(CacheManager::class), [], 30);
49+
$cache->set('42', new Location());
9450

95-
$cacheMock->shouldReceive('tags')->with($geo_ip->config('cache_tags'))->andReturnSelf();
51+
$flushResult = $cache->flush();
9652

97-
$this->assertSame($geo_ip->getCache()->flush(), true);
53+
$this->assertTrue($flushResult);
9854
}
9955
}

tests/TestCase.php

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,23 @@
44

55
namespace InteractionDesignFoundation\GeoIP\Tests;
66

7-
use Illuminate\Cache\CacheManager;
87
use InteractionDesignFoundation\GeoIP\GeoIP;
9-
use Mockery;
10-
use PHPUnit\Framework\TestCase as PHPUnitTestCase;
8+
use PHPUnit\Framework\Attributes\CoversNothing;
119

12-
/**
13-
* @coversNothing
14-
*/
15-
class TestCase extends PHPUnitTestCase
10+
#[CoversNothing]
11+
class TestCase extends \Orchestra\Testbench\TestCase
1612
{
17-
public static $functions;
18-
13+
/** @inheritDoc */
1914
protected function setUp(): void
2015
{
21-
self::$functions = Mockery::mock();
22-
}
23-
24-
protected function tearDown(): void
25-
{
26-
Mockery::close();
16+
parent::setUp();
2717
}
2818

29-
protected function makeGeoIP(array $config = [], $cacheMock = null): GeoIP
19+
protected function makeGeoIP(array $config = []): GeoIP
3020
{
31-
$cacheMock = $cacheMock ?: Mockery::mock(CacheManager::class);
32-
$cacheMock->shouldReceive('supportsTags')->andReturn(false);
33-
3421
$config = array_merge($this->getConfig(), $config);
3522

36-
$cacheMock->shouldReceive('tags')->with(['laravel-geoip-location'])->andReturnSelf();
37-
38-
return new GeoIP($config, $cacheMock);
23+
return new GeoIP($config, $this->app['cache']);
3924
}
4025

4126
protected function getConfig(): array

tests/TestFunctions.php

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)