From fbe1edf8f05ab306ba6d53667e4f11d74f3309f6 Mon Sep 17 00:00:00 2001
From: Oliver Davies <oliver@oliverdavies.uk>
Date: Mon, 1 Apr 2019 13:19:01 +0100
Subject: [PATCH] Throw Exception if there is no addresses file

Fixes #14
---
 src/Exception/PartialNotFoundException.php | 5 +++++
 src/Service/Addresses.php                  | 9 ++++++---
 tests/Unit/Service/AddressesTest.php       | 7 +++++++
 3 files changed, 18 insertions(+), 3 deletions(-)
 create mode 100644 src/Exception/PartialNotFoundException.php

diff --git a/src/Exception/PartialNotFoundException.php b/src/Exception/PartialNotFoundException.php
new file mode 100644
index 0000000..f434027
--- /dev/null
+++ b/src/Exception/PartialNotFoundException.php
@@ -0,0 +1,5 @@
+<?php
+
+namespace Opdavies\GmailFilterBuilder\Exception;
+
+class PartialNotFoundException extends \RuntimeException {}
diff --git a/src/Service/Addresses.php b/src/Service/Addresses.php
index 6768277..d6e0f23 100644
--- a/src/Service/Addresses.php
+++ b/src/Service/Addresses.php
@@ -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;
     }
 
     /**
diff --git a/tests/Unit/Service/AddressesTest.php b/tests/Unit/Service/AddressesTest.php
index b2159a8..0e5ac49 100644
--- a/tests/Unit/Service/AddressesTest.php
+++ b/tests/Unit/Service/AddressesTest.php
@@ -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