From b2b8a0438fba4ce6e1aac0082ecbbf0f5f179356 Mon Sep 17 00:00:00 2001 From: ErickSkrauch Date: Fri, 29 Apr 2016 00:14:34 +0300 Subject: [PATCH] Implemented Storage interface --- src/Storage.php | 16 +++++++--------- src/StorageInterface.php | 22 ++++++++++++++++++++++ src/TempMailBuster.php | 21 +++++++++++---------- tests/StorageTest.php | 22 +++++++++++----------- 4 files changed, 51 insertions(+), 30 deletions(-) create mode 100644 src/StorageInterface.php diff --git a/src/Storage.php b/src/Storage.php index 3028fdd..675d7a4 100644 --- a/src/Storage.php +++ b/src/Storage.php @@ -1,7 +1,7 @@ items = $items; + $this->items = (array)$items; return $this; } /** - * @param string|array $items item or items, that will be merged to items - * @return static + * @inheritdoc */ - public function append($items) + public function appendItems($items) { $items = (array)$items; $this->items = array_merge($this->items, $items); diff --git a/src/StorageInterface.php b/src/StorageInterface.php new file mode 100644 index 0000000..54052f2 --- /dev/null +++ b/src/StorageInterface.php @@ -0,0 +1,22 @@ +primaryStorage = $primaryStorage; $this->secondaryStorage = $secondaryStorage; @@ -62,7 +63,7 @@ class TempMailBuster } /** - * @return Storage + * @return StorageInterface */ public function getPrimaryStorage() { @@ -70,17 +71,17 @@ class TempMailBuster } /** - * @param Storage $primaryStorage + * @param StorageInterface $primaryStorage * @return static */ - public function setPrimaryStorage(Storage $primaryStorage) + public function setPrimaryStorage(StorageInterface $primaryStorage) { $this->primaryStorage = $primaryStorage; return $this; } /** - * @return Storage|null + * @return StorageInterface|null */ public function getSecondaryStorage() { @@ -88,10 +89,10 @@ class TempMailBuster } /** - * @param Storage|null $secondaryStorage + * @param StorageInterface|null $secondaryStorage * @return static */ - public function setSecondaryStorage(Storage $secondaryStorage = null) + public function setSecondaryStorage(StorageInterface $secondaryStorage = null) { $this->secondaryStorage = $secondaryStorage; return $this; diff --git a/tests/StorageTest.php b/tests/StorageTest.php index eea4466..9f7bf12 100644 --- a/tests/StorageTest.php +++ b/tests/StorageTest.php @@ -9,21 +9,21 @@ class StorageTest extends \PHPUnit_Framework_TestCase $this->assertEquals(['item'], $storage->getItems()); } - public function testAppend() - { - $storage = new Storage(['item1']); - $this->assertEquals($storage, $storage->append(['item2'])); - $this->assertEquals(['item1', 'item2'], $storage->getItems()); - - $storage = new Storage(['item1']); - $this->assertEquals($storage, $storage->append('item2')); - $this->assertEquals(['item1', 'item2'], $storage->getItems()); - } - public function testSetItems() { $storage = new Storage(['item1']); $this->assertEquals($storage, $storage->setItems(['item2'])); $this->assertEquals(['item2'], $storage->getItems()); } + + public function testAppendItems() + { + $storage = new Storage(['item1']); + $this->assertEquals($storage, $storage->appendItems(['item2'])); + $this->assertEquals(['item1', 'item2'], $storage->getItems()); + + $storage = new Storage(['item1']); + $this->assertEquals($storage, $storage->appendItems('item2')); + $this->assertEquals(['item1', 'item2'], $storage->getItems()); + } }