Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
143 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,9 @@ | ||
language: php | ||
|
||
php: | ||
- 5.3 | ||
- 5.4 | ||
- 5.6 | ||
- 7 | ||
- 7.1 | ||
- hhvm | ||
|
||
before_script: travis_retry composer install | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
namespace FileFetcher; | ||
|
||
/** | ||
* Decorator for FileFetcher objects that records file fetching calls. | ||
* | ||
* @since 3.2 | ||
* | ||
* @licence GNU GPL v2+ | ||
* @author Jeroen De Dauw < jeroendedauw@gmail.com > | ||
*/ | ||
class SpyingFileFetcher implements FileFetcher { | ||
|
||
private $fileFetcher; | ||
|
||
private $fetchedUrls = []; | ||
|
||
public function __construct( FileFetcher $fileFetcher ) { | ||
$this->fileFetcher = $fileFetcher; | ||
} | ||
|
||
/** | ||
* @see FileFetcher::fetchFile | ||
* | ||
* @param string $fileUrl | ||
* | ||
* @return string | ||
* @throws FileFetchingException | ||
*/ | ||
public function fetchFile( $fileUrl ) { | ||
$this->fetchedUrls[] = $fileUrl; | ||
return $this->fileFetcher->fetchFile( $fileUrl ); | ||
} | ||
|
||
/** | ||
* Returns an ordered list of fetched URLs. Duplicates are preserved. | ||
* | ||
* @return string[] | ||
*/ | ||
public function getFetchedUrls() { | ||
return $this->fetchedUrls; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?php | ||
|
||
namespace FileFetcher\Tests\Phpunit; | ||
|
||
use FileFetcher\FileFetchingException; | ||
use FileFetcher\InMemoryFileFetcher; | ||
use FileFetcher\SpyingFileFetcher; | ||
|
||
/** | ||
* @covers FileFetcher\SpyingFileFetcher | ||
* | ||
* @licence GNU GPL v2+ | ||
* @author Jeroen De Dauw < jeroendedauw@gmail.com > | ||
*/ | ||
class SpyingFileFetcherTest extends \PHPUnit_Framework_TestCase { | ||
|
||
public function testReturnsResultOfDecoratedFetcher() { | ||
$innerFetcher = new InMemoryFileFetcher( [ | ||
'url' => 'content' | ||
] ); | ||
|
||
$spyingFetcher = new SpyingFileFetcher( $innerFetcher ); | ||
|
||
$this->assertSame( 'content', $spyingFetcher->fetchFile( 'url' ) ); | ||
|
||
$this->expectException( FileFetchingException::class ); | ||
$spyingFetcher->fetchFile( 'foo' ); | ||
} | ||
|
||
public function testWhenNoCalls_getFetchedUrlsReturnsEmptyArray() { | ||
$innerFetcher = new InMemoryFileFetcher( [ | ||
'url' => 'content' | ||
] ); | ||
|
||
$spyingFetcher = new SpyingFileFetcher( $innerFetcher ); | ||
|
||
$this->assertSame( [], $spyingFetcher->getFetchedUrls() ); | ||
} | ||
|
||
public function testWhenSomeCalls_getFetchedUrlsReturnsTheArguments() { | ||
$innerFetcher = new InMemoryFileFetcher( [ | ||
'url' => 'content', | ||
'foo' => 'bar' | ||
] ); | ||
|
||
$spyingFetcher = new SpyingFileFetcher( $innerFetcher ); | ||
$spyingFetcher->fetchFile( 'url' ); | ||
$spyingFetcher->fetchFile( 'foo' ); | ||
$spyingFetcher->fetchFile( 'url' ); | ||
|
||
$this->assertSame( [ 'url', 'foo', 'url' ], $spyingFetcher->getFetchedUrls() ); | ||
} | ||
|
||
public function testCallsCausingExceptionsGetRecorded() { | ||
$innerFetcher = new InMemoryFileFetcher( [] ); | ||
|
||
$spyingFetcher = new SpyingFileFetcher( $innerFetcher ); | ||
|
||
try { | ||
$spyingFetcher->fetchFile( 'url' ); | ||
} | ||
catch ( FileFetchingException $ex ) { | ||
} | ||
|
||
try { | ||
$spyingFetcher->fetchFile( 'foo' ); | ||
} | ||
catch ( FileFetchingException $ex ) { | ||
} | ||
|
||
$this->assertSame( [ 'url', 'foo' ], $spyingFetcher->getFetchedUrls() ); | ||
} | ||
|
||
} |