diff --git a/src/Processor/Local.php b/src/Processor/Local.php index 691c9a4..43bccce 100644 --- a/src/Processor/Local.php +++ b/src/Processor/Local.php @@ -10,10 +10,13 @@ public function isServerCompatible(array $state): bool { $path = $state['source']; - if (file_exists($path) && !is_dir($path)) { - return true; + try { + if (file_exists($path) && !is_dir($path)) { + return true; + } + } catch (\Throwable $t) { + // If there was an error, then the local file is not available. } - return false; } diff --git a/src/Processor/ProcessorInterface.php b/src/Processor/ProcessorInterface.php index a1bbdc3..24710bc 100644 --- a/src/Processor/ProcessorInterface.php +++ b/src/Processor/ProcessorInterface.php @@ -22,9 +22,20 @@ interface ProcessorInterface { /** - * Whether the server holding the "file" will work with this processor. + * Whether the state for this file transfer will work with this processor. + * + * For instance, a Local processor will check if the source file exists. A + * Remote processor will check if the source URL is valid. + * + * This method is called to determine which configured processor to use to + * perform the fetch. + * + * @param array $state + * The file fetcher object's state array. * * @return bool + * True if the processor can be used with the state/configuration. False + * otherwise. */ public function isServerCompatible(array $state): bool; diff --git a/test/Processor/LocalTest.php b/test/Processor/LocalTest.php index a3524d5..45f0afa 100644 --- a/test/Processor/LocalTest.php +++ b/test/Processor/LocalTest.php @@ -2,17 +2,32 @@ namespace FileFetcherTests\Processor; -use FileFetcher\PhpFunctionsBridge; use FileFetcher\Processor\Local; -use MockChain\Chain; use PHPUnit\Framework\TestCase; +/** + * @covers \FileFetcher\Processor\Local + * @coversDefaultClass \FileFetcher\Processor\Local + */ class LocalTest extends TestCase { - public function test() + + public function provideSource() + { + return [ + 'any-normal-file' => ['blah'], + 'no-such-wrapper' => ['s3://foo.bar'], + ]; + } + + /** + * @covers ::isServerCompatible + * @dataProvider provideSource + */ + public function test($source) { $processor = new Local(); - $state = ['source' => 'blah']; + $state = ['source' => $source]; $this->assertFalse( $processor->isServerCompatible($state) );