From ac7ceb0eb262c0486fd8f69f312a812d06096d4c Mon Sep 17 00:00:00 2001 From: fqqdk Date: Fri, 13 Sep 2024 16:58:23 +0200 Subject: [PATCH] remove legacy chunk iterator that uses deprecated endpoints AUT-3246 Co-authored-by: Bence Kadar --- src/Suite/Api/ContactList.php | 2 +- src/Suite/Api/ContactListChunkFetcher.php | 8 -- src/Suite/Api/ContactListChunkIterator.php | 113 ----------------- .../Api/ContactListChunkIteratorTest.php | 115 ------------------ 4 files changed, 1 insertion(+), 237 deletions(-) delete mode 100644 src/Suite/Api/ContactListChunkFetcher.php delete mode 100644 src/Suite/Api/ContactListChunkIterator.php delete mode 100644 test/unit/Suite/Api/ContactListChunkIteratorTest.php diff --git a/src/Suite/Api/ContactList.php b/src/Suite/Api/ContactList.php index 493b350..56175fd 100644 --- a/src/Suite/Api/ContactList.php +++ b/src/Suite/Api/ContactList.php @@ -4,7 +4,7 @@ use Traversable; -class ContactList implements ContactListChunkFetcher +class ContactList { /** * @var Client diff --git a/src/Suite/Api/ContactListChunkFetcher.php b/src/Suite/Api/ContactListChunkFetcher.php deleted file mode 100644 index 9fbae2d..0000000 --- a/src/Suite/Api/ContactListChunkFetcher.php +++ /dev/null @@ -1,8 +0,0 @@ -chunkFetcher = $chunkFetcher; - $this->chunkSize = $chunkSize; - $this->customerId = $customerId; - $this->contactListId = $contactListId; - } - - /** - * Return the current element - * @link http://php.net/manual/en/iterator.current.php - * @return mixed Can return any type. - * @since 5.0.0 - */ - public function current() - { - return $this->currentChunk; - } - - /** - * Move forward to next element - * @link http://php.net/manual/en/iterator.next.php - * @return void Any returned value is ignored. - * @since 5.0.0 - */ - public function next() - { - $this->page++; - $this->loadPage(); - } - - /** - * Return the key of the current element - * @link http://php.net/manual/en/iterator.key.php - * @return mixed scalar on success, or null on failure. - * @since 5.0.0 - */ - public function key() - { - return $this->page; - } - - /** - * Checks if current position is valid - * @link http://php.net/manual/en/iterator.valid.php - * @return boolean The return value will be casted to boolean and then evaluated. - * Returns true on success or false on failure. - * @since 5.0.0 - */ - public function valid() - { - return !empty($this->currentChunk); - } - - /** - * Rewind the Iterator to the first element - * @link http://php.net/manual/en/iterator.rewind.php - * @return void Any returned value is ignored. - * @since 5.0.0 - */ - public function rewind() - { - $this->page = 0; - $this->loadPage(); - } - - private function loadPage() - { - $this->currentChunk = $this->chunkFetcher->getContactsOfList( - $this->customerId, - $this->contactListId, - $this->chunkSize, - $this->page * $this->chunkSize - ); - } -} diff --git a/test/unit/Suite/Api/ContactListChunkIteratorTest.php b/test/unit/Suite/Api/ContactListChunkIteratorTest.php deleted file mode 100644 index 05f506c..0000000 --- a/test/unit/Suite/Api/ContactListChunkIteratorTest.php +++ /dev/null @@ -1,115 +0,0 @@ -customerId, $this->contactListId, $this->chunkSize - ); - $this->assertEquals([], iterator_to_array($iter)); - } - - - /** - * @test - */ - public function iterate_OneChunk_Perfect() - { - $iter = new ContactListChunkIterator( - new class implements ContactListChunkFetcher { - private $counter = 0; - public function getContactsOfList(int $customerId, int $contactListId, int $limit, int $offset) - { - if ($this->counter == 0) { - $this->counter++; - return [1, 2]; - } - $this->counter++; - return []; - } - }, $this->customerId, $this->contactListId, $this->chunkSize - ); - - $this->assertEquals([[1, 2]], iterator_to_array($iter)); - } - - - /** - * @test - */ - public function iterate_SeveralChunks_Perfect() - { - $iter = new ContactListChunkIterator( - new class implements ContactListChunkFetcher { - private $counter = 0; - public function getContactsOfList(int $customerId, int $contactListId, int $limit, int $offset) - { - switch ($this->counter) { - case 0: $result = [1, 2, 3]; break; - case 1: $result = [4, 5, 6]; break; - case 2: $result = [7, 8, 9]; break; - case 3: $result = [10, 11]; break; - default: $result = []; - } - $this->counter++; - return $result; - } - }, $this->customerId, $this->contactListId, $this->chunkSize - ); - $chunks = [ - [1, 2, 3], - [4, 5, 6], - [7, 8, 9], - [10, 11], - ]; - - $this->assertEquals($chunks, iterator_to_array($iter)); - } - - - /** - * @test - */ - public function iterate_ApiRequestFailed_ThrowsException() - { - $iter = new ContactListChunkIterator( - new class implements ContactListChunkFetcher { - public function getContactsOfList(int $customerId, int $contactListId, int $limit, int $offset) - { - throw new RequestFailed(); - } - }, $this->customerId, $this->contactListId, $this->chunkSize - ); - - $this->expectException(RequestFailed::class); - iterator_to_array($iter); - } -}