|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* This file is part of the Geocoder package. |
|
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
8
|
|
|
* file that was distributed with this source code. |
|
9
|
|
|
* |
|
10
|
|
|
* @license MIT License |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
namespace Geocoder\Plugin\Tests\Plugin; |
|
14
|
|
|
|
|
15
|
|
|
use Geocoder\Plugin\Plugin\QueryDataPlugin; |
|
16
|
|
|
use Geocoder\Query\GeocodeQuery; |
|
17
|
|
|
use Geocoder\Query\Query; |
|
18
|
|
|
use PHPUnit\Framework\TestCase; |
|
19
|
|
|
|
|
20
|
|
|
class QueryDataPluginTest extends TestCase |
|
21
|
|
|
{ |
|
22
|
|
|
public function testPlugin() |
|
23
|
|
|
{ |
|
24
|
|
|
$query = GeocodeQuery::create('xxx'); |
|
25
|
|
|
$query = $query->withData('default', 'value'); |
|
26
|
|
|
$first = function (Query $query) { |
|
27
|
|
|
$this->fail('Plugin should not restart the chain'); |
|
28
|
|
|
}; |
|
29
|
|
|
$next = function (Query $query) { |
|
30
|
|
|
$this->assertEquals('bar', $query->getData('foo')); |
|
31
|
|
|
$this->assertEquals('value', $query->getData('default')); |
|
32
|
|
|
}; |
|
33
|
|
|
|
|
34
|
|
|
$plugin = new QueryDataPlugin(['foo' => 'bar', 'default' => 'new value']); |
|
35
|
|
|
$plugin->handleQuery($query, $next, $first); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function testPluginForce() |
|
39
|
|
|
{ |
|
40
|
|
|
$query = GeocodeQuery::create('xxx'); |
|
41
|
|
|
$query = $query->withData('default', 'value'); |
|
42
|
|
|
$first = function (Query $query) { |
|
43
|
|
|
$this->fail('Plugin should not restart the chain'); |
|
44
|
|
|
}; |
|
45
|
|
|
$next = function (Query $query) { |
|
46
|
|
|
$this->assertEquals('bar', $query->getData('foo')); |
|
47
|
|
|
$this->assertEquals('new value', $query->getData('default')); |
|
48
|
|
|
}; |
|
49
|
|
|
|
|
50
|
|
|
$plugin = new QueryDataPlugin(['foo' => 'bar', 'default' => 'new value'], true); |
|
51
|
|
|
$plugin->handleQuery($query, $next, $first); |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
|