Skip to content

Commit 186cc1a

Browse files
authored
Allow fake IP works for all IPs (#311)
Allow fake IP works for all IPs
1 parent 2bf9328 commit 186cc1a

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

Plugin/FakeIpPlugin.php

+3
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ public function handleQuery(Query $query, callable $next, callable $first)
7676
if ($count > 0) {
7777
$query = $query->withText($text);
7878
}
79+
if (null === $this->needle || '' === $this->needle) {
80+
$query = $query->withText($replacement);
81+
}
7982

8083
return $next($query);
8184
}

Tests/Plugin/FakeIpPluginTest.php

+15
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,21 @@ public function testSimpleHandleQuery()
3333
$this->assertSame($query->getText(), '123.123.123.123');
3434
}
3535

36+
/**
37+
* @testWith [null]
38+
* ['']
39+
*/
40+
public function testEmptyLocalIpQuery(?string $localIp)
41+
{
42+
$fakeIpPlugin = new FakeIpPlugin($localIp, '123.123.123.123');
43+
$query = GeocodeQuery::create('124.124.124.124');
44+
45+
/** @var Query $query */
46+
$query = $fakeIpPlugin->handleQuery($query, function (Query $query) { return $query; }, function () {});
47+
48+
$this->assertSame($query->getText(), '123.123.123.123');
49+
}
50+
3651
public function testHandleQueryUsingFaker()
3752
{
3853
$fakeIpPlugin = new FakeIpPlugin('127.0.0.1', '192.168.1.1', true);

0 commit comments

Comments
 (0)