13
13
namespace Geocoder \Plugin \Tests \Plugin ;
14
14
15
15
use Cache \Adapter \Void \VoidCachePool ;
16
+ use Generator ;
17
+ use Geocoder \Model \Coordinates ;
16
18
use Geocoder \Plugin \Plugin \CachePlugin ;
17
19
use Geocoder \Query \GeocodeQuery ;
18
20
use Geocoder \Query \Query ;
21
+ use Geocoder \Query \ReverseQuery ;
19
22
use PHPUnit \Framework \TestCase ;
20
23
21
24
class CachePluginTest extends TestCase
@@ -50,18 +53,31 @@ public function testPluginMiss()
50
53
$ this ->assertEquals ('result ' , $ plugin ->handleQuery ($ query , $ next , $ first ));
51
54
}
52
55
53
- public function testPluginHit ()
56
+ public function getQueryProvider (): Generator
54
57
{
55
58
$ query = GeocodeQuery::create ('foo ' );
56
- $ queryString = sha1 ($ query ->__toString ());
59
+ $ key = sha1 ($ query ->__toString ());
60
+ yield [$ query , $ key ];
61
+
62
+ $ query = ReverseQuery::create (new Coordinates (12.123456 , 12.123456 ));
63
+ $ lessPreciseQuery = $ query ->withCoordinates (new Coordinates (12.1235 , 12.1235 ));
64
+ $ key = sha1 ((string ) $ lessPreciseQuery );
65
+ yield [$ query , $ key ];
66
+ }
67
+
68
+ /**
69
+ * @dataProvider getQueryProvider
70
+ */
71
+ public function testPluginHit (Query $ query , string $ key )
72
+ {
57
73
$ cache = $ this ->getMockBuilder (VoidCachePool::class)
58
74
->disableOriginalConstructor ()
59
75
->setMethods (['get ' , 'set ' ])
60
76
->getMock ();
61
77
62
78
$ cache ->expects ($ this ->once ())
63
79
->method ('get ' )
64
- ->with ('v4 ' .$ queryString )
80
+ ->with ('v4 ' .$ key )
65
81
->willReturn ('result ' );
66
82
$ cache ->expects ($ this ->never ())->method ('set ' );
67
83
@@ -72,7 +88,7 @@ public function testPluginHit()
72
88
$ this ->fail ('Plugin not call $next on cache hit ' );
73
89
};
74
90
75
- $ plugin = new CachePlugin ($ cache );
91
+ $ plugin = new CachePlugin ($ cache, 0 , 4 );
76
92
$ this ->assertEquals ('result ' , $ plugin ->handleQuery ($ query , $ next , $ first ));
77
93
}
78
94
}
0 commit comments