Throw Exception if there is no addresses file

Fixes #14
This commit is contained in:
Oliver Davies 2019-04-01 13:19:01 +01:00
parent db97fb8d60
commit fbe1edf8f0
3 changed files with 18 additions and 3 deletions

View file

@ -0,0 +1,5 @@
<?php
namespace Opdavies\GmailFilterBuilder\Exception;
class PartialNotFoundException extends \RuntimeException {}

View file

@ -2,6 +2,7 @@
namespace Opdavies\GmailFilterBuilder\Service;
use Opdavies\GmailFilterBuilder\Exception\PartialNotFoundException;
use Tightenco\Collect\Support\Collection;
/**
@ -26,11 +27,13 @@ class Addresses
return file_exists($file);
});
if ($file) {
return include $file;
if (!$file) {
throw new PartialNotFoundException(vsprintf('%s does not exist.', [
$filename,
]));
}
return [];
return include $file;
}
/**

View file

@ -23,6 +23,13 @@ class AddressesTest extends TestCase
'bar@example.com'
], FakeAddresses::load());
}
/** @test */
public function throw_an_exception_an_address_file_does_not_exist() {
$this->expectException(\RuntimeException::class);
Addresses::load('does-not-exist');
}
}
class FakeAddresses extends Addresses