Skip to content

Commit 098e2bf

Browse files
committed
Allow to skip the caching layer
See phpunit.xml.dist file
1 parent fcb858e commit 098e2bf

File tree

4 files changed

+27
-5
lines changed

4 files changed

+27
-5
lines changed

phpunit.xml.dist

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@
1111
bootstrap="tests/bootstrap.php"
1212
>
1313
<php>
14+
<!--
15+
Turn this parameter to 'false' or comment it to bypass
16+
the caching layer. See the `CachedResponseAdapter` class.
17+
-->
18+
<server name="USE_CACHED_RESPONSES" value="true" />
19+
20+
<!-- API Keys -->
1421
<!-- <server name="IPINFODB_API_KEY" value="YOUR_API_KEY" /> -->
1522
<!-- <server name="BINGMAPS_API_KEY" value="YOUR_API_KEY" /> -->
1623
<!-- <server name="CLOUDMADE_API_KEY" value="YOUR_API_KEY" /> -->
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
s:387:"<?xml version="1.0"?>
2+
<rdf:RDF
3+
xmlns:dc="http://purl.org/dc/elements/1.1/"
4+
xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"
5+
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
6+
>
7+
<geo:Point rdf:nodeID="aid12215090">
8+
<dc:description>1600 Pennsylvania Ave NW, Washington DC 20502</dc:description>
9+
<geo:long>-77.037684</geo:long>
10+
<geo:lat>38.898748</geo:lat>
11+
</geo:Point>
12+
</rdf:RDF>
13+
";

tests/Geocoder/Tests/CachedResponseAdapter.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ public function __construct(HttpAdapterInterface $adapter, $cacheDir = '.cached_
2121
*/
2222
public function getContent($url)
2323
{
24-
$file = sprintf('%s/%s/%s', realpath(__DIR__ . '/../../'), $this->cacheDir, sha1($url));
24+
$useCache = isset($_SERVER['USE_CACHED_RESPONSES']) && true === $_SERVER['USE_CACHED_RESPONSES'];
25+
$file = sprintf('%s/%s/%s', realpath(__DIR__ . '/../../'), $this->cacheDir, sha1($url));
2526

26-
if (is_file($file) && is_readable($file)) {
27+
if ($useCache && is_file($file) && is_readable($file)) {
2728
$response = unserialize(file_get_contents($file));
2829

2930
if (!empty($response)) {
@@ -32,7 +33,10 @@ public function getContent($url)
3233
}
3334

3435
$response = $this->adapter->getContent($url);
35-
file_put_contents($file, serialize($response));
36+
37+
if ($useCache) {
38+
file_put_contents($file, serialize($response));
39+
}
3640

3741
return $response;
3842
}

tests/Geocoder/Tests/Provider/GeocoderUsProviderTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ public function testGetGeocodedDataWithWrongAddress()
3838

3939
public function testGetGeocodedDataWithRealAddress()
4040
{
41-
$this->markTestIncomplete('Timeout too long');
42-
4341
$provider = new GeocoderUsProvider($this->getAdapter());
4442
$result = $provider->getGeocodedData('1600 Pennsylvania Ave, Washington, DC');
4543

0 commit comments

Comments
 (0)