From 676d2bee6db9309262787bddb212fc256c2f0ba4 Mon Sep 17 00:00:00 2001 From: ErickSkrauch Date: Sat, 30 Apr 2016 12:24:24 +0300 Subject: [PATCH] Removed redundant feature from AntiTempmailRepo class --- src/Loader/AntiTempmailRepo.php | 44 +++++++++++++-------------- tests/Loader/AntiTempmailRepoTest.php | 25 +++++++++++++-- 2 files changed, 45 insertions(+), 24 deletions(-) diff --git a/src/Loader/AntiTempmailRepo.php b/src/Loader/AntiTempmailRepo.php index f868979..33377dc 100644 --- a/src/Loader/AntiTempmailRepo.php +++ b/src/Loader/AntiTempmailRepo.php @@ -10,24 +10,25 @@ use Exception; class AntiTempmailRepo implements LoaderInterface { /** - * @var array with custom paths to find data file + * File path array to data repository. + * + * Default paths are used in following cases: + * 1. if this library and data repository are included in project as composer dependencies; + * 2. if this library is deployed for development (data repository included as composer dependency to this library). + * + * @return array */ - private $customPaths; - - /** - * @param array $customPaths - */ - public function __construct(array $customPaths = []) - { - $this->customPaths = $customPaths; - } + private $searchPaths = [ + __DIR__ . '/../../../anti-tempmail-repo/data.json', + __DIR__ . '/../../vendor/ely/anti-tempmail-repo/data.json', + ]; /** * @inheritdoc */ public function load() { - $paths = $this->getPaths(); + $paths = $this->getSearchPaths(); $dataPath = null; foreach($paths as $path) { if (file_exists($path)) { @@ -49,19 +50,18 @@ class AntiTempmailRepo implements LoaderInterface } /** - * Generates file path array to data repository. - * - * Default paths are used in following cases: - * 1. if this library and data repository are included in project as composer dependencies; - * 2. if this library is deployed for development (data repository included as composer dependency to this library). - * * @return array */ - protected function getPaths() + public function getSearchPaths() { - return array_merge($this->customPaths, [ - __DIR__ . '/../../../anti-tempmail-repo/data.json', - __DIR__ . '/../../vendor/ely/anti-tempmail-repo/data.json', - ]); + return $this->searchPaths; + } + + /** + * @param array|string $path + */ + public function setSearchPaths($path) + { + $this->searchPaths = (array)$path; } } diff --git a/tests/Loader/AntiTempmailRepoTest.php b/tests/Loader/AntiTempmailRepoTest.php index 0818ad7..559c7ad 100644 --- a/tests/Loader/AntiTempmailRepoTest.php +++ b/tests/Loader/AntiTempmailRepoTest.php @@ -22,11 +22,32 @@ class AntiTempmailRepoTest extends \PHPUnit_Framework_TestCase $loader = new AntiTempmailRepoWithInvalidJson(); $loader->load(); } + + public function testGetSearchPaths() + { + $loader = new AntiTempmailRepo(); + $this->assertTrue(is_array($loader->getSearchPaths())); + } + + public function testSetSearchPaths() + { + $path = __DIR__ . '/test.json'; + + $loader = new AntiTempmailRepo(); + $loader->setSearchPaths([$path]); + $this->assertTrue(is_array($loader->getSearchPaths())); + $this->assertEquals([$path], $loader->getSearchPaths()); + + $loader = new AntiTempmailRepo(); + $loader->setSearchPaths($path); + $this->assertTrue(is_array($loader->getSearchPaths())); + $this->assertEquals([$path], $loader->getSearchPaths()); + } } class AntiTempmailRepoWithWrongPaths extends AntiTempmailRepo { - protected function getPaths() + public function getSearchPaths() { return [ __DIR__ . '/virtual_reality.json', @@ -36,7 +57,7 @@ class AntiTempmailRepoWithWrongPaths extends AntiTempmailRepo class AntiTempmailRepoWithInvalidJson extends AntiTempmailRepo { - protected function getPaths() + public function getSearchPaths() { return [ __DIR__ . '/AntiTempmailRepoTest.php',