|
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\Http\Provider\Tests; |
|
14
|
|
|
|
|
15
|
|
|
use Geocoder\Collection; |
|
16
|
|
|
use Geocoder\Http\Provider\AbstractHttpProvider; |
|
17
|
|
|
use Geocoder\Model\AddressCollection; |
|
18
|
|
|
use Geocoder\Query\GeocodeQuery; |
|
19
|
|
|
use Geocoder\Query\ReverseQuery; |
|
20
|
|
|
use Http\Client\HttpClient; |
|
21
|
|
|
use Http\Discovery\ClassDiscovery; |
|
22
|
|
|
use Http\Mock\Client; |
|
23
|
|
|
use PHPUnit\Framework\TestCase; |
|
24
|
|
|
|
|
25
|
|
|
class AbstractHttpProviderTest extends TestCase |
|
26
|
|
|
{ |
|
27
|
|
|
public static function setUpBeforeClass() |
|
28
|
|
|
{ |
|
29
|
|
|
ClassDiscovery::prependStrategy('\Nyholm\Psr7\Httplug\DiscoveryStrategy'); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function testHttpClientGetter() |
|
33
|
|
|
{ |
|
34
|
|
|
$client = $this->getMockBuilder(Client::class)->disableOriginalConstructor()->getMock(); |
|
35
|
|
|
$provider = new DummyProvider($client); |
|
36
|
|
|
$this->assertSame($client, $provider->getHttpClient()); |
|
37
|
|
|
} |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
class DummyProvider extends AbstractHttpProvider |
|
|
|
|
|
|
41
|
|
|
{ |
|
42
|
|
|
public function getHttpClient(): HttpClient |
|
43
|
|
|
{ |
|
44
|
|
|
return parent::getHttpClient(); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function geocodeQuery(GeocodeQuery $query): Collection |
|
48
|
|
|
{ |
|
49
|
|
|
return new AddressCollection([]); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function reverseQuery(ReverseQuery $query): Collection |
|
53
|
|
|
{ |
|
54
|
|
|
return new AddressCollection([]); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
public function getName(): string |
|
58
|
|
|
{ |
|
59
|
|
|
return 'dummy'; |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
|
Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.