Skip to content

Commit

Permalink
Add try block around file_exists() (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-m authored Dec 8, 2023
1 parent 58eba37 commit 3d86660
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 8 deletions.
9 changes: 6 additions & 3 deletions src/Processor/Local.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
13 changes: 12 additions & 1 deletion src/Processor/ProcessorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
23 changes: 19 additions & 4 deletions test/Processor/LocalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
Expand Down

0 comments on commit 3d86660

Please sign in to comment.