diff --git a/tests/PoolTest.php b/tests/PoolTest.php index cb7c8fc..426b377 100644 --- a/tests/PoolTest.php +++ b/tests/PoolTest.php @@ -70,55 +70,56 @@ public function testAddItem() $this->assertKeys(['test']); } - public function testAddItemEmpty() + /** + * @dataProvider providerAddItemsEmpty + */ + public function testAddItemEmpty($emptyItem = null) { $pool = new Pool($this->redis, 'test'); + $pool->addItem(1); try { - $pool->addItem(''); - $this->fail('Expected InvalidArgumentException to be thrown'); - } catch (Exception\InvalidArgument $e) {} - - try { - $pool->addItem(''); - $this->fail('Expected InvalidArgumentException to be thrown'); - } catch (Exception\InvalidArgument $e) {} - - try { - $pool->addItem(null); - $this->fail('Expected InvalidArgumentException to be thrown'); - } catch (Exception\InvalidArgument $e) {} - - try { - $pool->addItem(0); - $this->fail('Expected InvalidArgumentException to be thrown'); + $pool->addItem($emptyItem); + $this->fail('Expected \PhpRQ\Exception\InvalidArgument to be thrown'); } catch (Exception\InvalidArgument $e) {} - $this->assertKeys([]); + $this->assertSame(['1'], $this->redis->zrange('test', 0, 5)); + $this->assertKeys(['test']); } - public function testAddItemsEmpty() + public function testAddItems() { + $time = time(); $pool = new Pool($this->redis, 'test'); + $pool->addItems([1, 3, 5, 3]); + $pool->addItems([3, 6]); - try { - $pool->addItems([1, '', 5]); - $this->fail('Expected InvalidArgumentException to be thrown'); - } catch (Exception\InvalidArgument $e) {} - - try { - $pool->addItems([1, null, 5]); - $this->fail('Expected InvalidArgumentException to be thrown'); - } catch (Exception\InvalidArgument $e) {} + $this->assertSame( + array_fill_keys(['1', '3', '5', '6'], (string)$time), + $this->redis->zrange('test', 0, 5, 'WITHSCORES') + ); + $this->assertKeys(['test']); + } + /** + * @dataProvider providerAddItemsEmpty + */ + public function testAddItemsEmpty($emptyItem = null) + { + $pool = new Pool($this->redis, 'test'); try { - $pool->addItems([1, 0, 5]); - $this->fail('Expected InvalidArgumentException to be thrown'); + $pool->addItems([1, $emptyItem, 5]); + $this->fail('Expected \PhpRQ\Exception\InvalidArgument to be thrown'); } catch (Exception\InvalidArgument $e) {} $this->assertKeys([]); } + public function providerAddItemsEmpty() + { + return ['', null, 0, false]; + } + public function testGetItems() { $time = time(); @@ -143,29 +144,21 @@ public function testGetItems() $this->assertKeys(['test']); } - public function testGetItemsInvalid() + /** + * @dataProvider providerGetItemsInvalid + */ + public function testGetItemsInvalid($count = null) { $pool = new Pool($this->redis, 'test'); - try { - $pool->getItems(0); - $this->fail('Expected InvalidArgumentException to be thrown'); - } catch (Exception\InvalidArgument $e) {} - - try { - $pool->getItems(-5); - $this->fail('Expected InvalidArgumentException to be thrown'); - } catch (Exception\InvalidArgument $e) {} - - try { - $pool->getItems(''); - $this->fail('Expected InvalidArgumentException to be thrown'); + $pool->getItems($count); + $this->fail('Expected \PhpRQ\Exception\InvalidArgument to be thrown'); } catch (Exception\InvalidArgument $e) {} + } - try { - $pool->getItems(null); - $this->fail('Expected InvalidArgumentException to be thrown'); - } catch (Exception\InvalidArgument $e) {} + public function providerGetItemsInvalid() + { + return [0, -5, '', null, false]; } public function testGetAllItems() diff --git a/tests/QueueTest.php b/tests/QueueTest.php index 9e9e958..f0275e1 100755 --- a/tests/QueueTest.php +++ b/tests/QueueTest.php @@ -36,29 +36,17 @@ public function testAddItem() $this->assertKeys(['test']); } - public function testAddItemEmpty() + /** + * @dataProvider providerAddItemsEmpty + */ + public function testAddItemEmpty($invalidItem = null) { $queue = new Queue($this->redis, 'test'); $queue->addItem(1); try { - $queue->addItem(''); - $this->fail('Expected InvalidArgumentException to be thrown'); - } catch (Exception\InvalidArgument $e) {} - - try { - $queue->addItem(''); - $this->fail('Expected InvalidArgumentException to be thrown'); - } catch (Exception\InvalidArgument $e) {} - - try { - $queue->addItem(null); - $this->fail('Expected InvalidArgumentException to be thrown'); - } catch (Exception\InvalidArgument $e) {} - - try { - $queue->addItem(0); - $this->fail('Expected InvalidArgumentException to be thrown'); + $queue->addItem($invalidItem); + $this->fail('Expected \PhpRQ\Exception\InvalidArgument to be thrown'); } catch (Exception\InvalidArgument $e) {} $this->assertSame(['1'], $this->redis->lrange('test', 0, 5)); @@ -75,28 +63,26 @@ public function testAddItems() $this->assertKeys(['test']); } - public function testAddItemsEmpty() + /** + * @dataProvider providerAddItemsEmpty + */ + public function testAddItemsEmpty($emptyItem = null) { $queue = new Queue($this->redis, 'test'); try { - $queue->addItems([1, '', 5]); - $this->fail('Expected InvalidArgumentException to be thrown'); - } catch (Exception\InvalidArgument $e) {} - - try { - $queue->addItems([1, null, 5]); - $this->fail('Expected InvalidArgumentException to be thrown'); - } catch (Exception\InvalidArgument $e) {} - - try { - $queue->addItems([1, 0, 5]); - $this->fail('Expected InvalidArgumentException to be thrown'); + $queue->addItems([1, $emptyItem, 5]); + $this->fail('Expected \PhpRQ\Exception\InvalidArgument to be thrown'); } catch (Exception\InvalidArgument $e) {} $this->assertKeys([]); } + public function providerAddItemsEmpty() + { + return ['', null, 0, false]; + } + public function testGetItems() { $this->redis->lpush('test', [1, 5, 5, 3]); @@ -118,29 +104,21 @@ public function testGetItems() ]); } - public function testGetItemsInvalid() + /** + * @dataProvider providerGetItemsInvalid + */ + public function testGetItemsInvalid($count = null) { $queue = new Queue($this->redis, 'test'); - - try { - $queue->getItems(0); - $this->fail('Expected InvalidArgumentException to be thrown'); - } catch (Exception\InvalidArgument $e) {} - try { - $queue->getItems(-5); - $this->fail('Expected InvalidArgumentException to be thrown'); - } catch (Exception\InvalidArgument $e) {} - - try { - $queue->getItems(''); - $this->fail('Expected InvalidArgumentException to be thrown'); + $queue->getItems($count); + $this->fail('Expected \PhpRQ\Exception\InvalidArgument to be thrown'); } catch (Exception\InvalidArgument $e) {} + } - try { - $queue->getItems(null); - $this->fail('Expected InvalidArgumentException to be thrown'); - } catch (Exception\InvalidArgument $e) {} + public function providerGetItemsInvalid() + { + return [0, -5, '', null, false]; } public function testGetAllItems() diff --git a/tests/UniqueQueueTest.php b/tests/UniqueQueueTest.php index 41931c2..8c5ac75 100755 --- a/tests/UniqueQueueTest.php +++ b/tests/UniqueQueueTest.php @@ -42,26 +42,21 @@ public function testAddItem() $this->assertKeys(['test', 'test-unique']); } - public function testAddItemEmpty() + /** + * @dataProvider providerAddItemsEmpty + */ + public function testAddItemEmpty($invalidItem = null) { - $queue = new UniqueQueue($this->redis, 'test'); - - try { - $queue->addItem(''); - $this->fail('Expected InvalidArgumentException to be thrown'); - } catch (Exception\InvalidArgument $e) {} - - try { - $queue->addItem(null); - $this->fail('Expected InvalidArgumentException to be thrown'); - } catch (Exception\InvalidArgument $e) {} + $queue = new Queue($this->redis, 'test'); + $queue->addItem(1); try { - $queue->addItem(0); - $this->fail('Expected InvalidArgumentException to be thrown'); + $queue->addItem($invalidItem); + $this->fail('Expected \PhpRQ\Exception\InvalidArgument to be thrown'); } catch (Exception\InvalidArgument $e) {} - $this->assertKeys([]); + $this->assertSame(['1'], $this->redis->lrange('test', 0, 5)); + $this->assertKeys(['test']); } public function testAddItems() @@ -81,28 +76,26 @@ public function testAddItems() $this->assertKeys(['test', 'test-unique']); } - public function testAddItemsEmpty() + /** + * @dataProvider providerAddItemsEmpty + */ + public function testAddItemsEmpty($emptyItem = null) { $queue = new UniqueQueue($this->redis, 'test'); try { - $queue->addItems([1, '', 5]); - $this->fail('Expected InvalidArgumentException to be thrown'); - } catch (Exception\InvalidArgument $e) {} - - try { - $queue->addItems([1, null, 5]); - $this->fail('Expected InvalidArgumentException to be thrown'); - } catch (Exception\InvalidArgument $e) {} - - try { - $queue->addItems([1, 0, 5]); - $this->fail('Expected InvalidArgumentException to be thrown'); + $queue->addItems([1, $emptyItem, 5]); + $this->fail('Expected \PhpRQ\Exception\InvalidArgument to be thrown'); } catch (Exception\InvalidArgument $e) {} $this->assertKeys([]); } + public function providerAddItemsEmpty() + { + return ['', null, 0, false]; + } + public function testGetItems() { $this->redis->lpush('test', [1, 5, 3]); @@ -125,29 +118,22 @@ public function testGetItems() ]); } - public function testGetItemsInvalid() + /** + * @dataProvider providerGetItemsInvalid + */ + public function testGetItemsInvalid($count = null) { $queue = new UniqueQueue($this->redis, 'test'); try { - $queue->getItems(0); - $this->fail('Expected InvalidArgumentException to be thrown'); - } catch (Exception\InvalidArgument $e) {} - - try { - $queue->getItems(-5); - $this->fail('Expected InvalidArgumentException to be thrown'); - } catch (Exception\InvalidArgument $e) {} - - try { - $queue->getItems(''); - $this->fail('Expected InvalidArgumentException to be thrown'); + $queue->getItems($count); + $this->fail('Expected \PhpRQ\Exception\InvalidArgument to be thrown'); } catch (Exception\InvalidArgument $e) {} + } - try { - $queue->getItems(null); - $this->fail('Expected InvalidArgumentException to be thrown'); - } catch (Exception\InvalidArgument $e) {} + public function providerGetItemsInvalid() + { + return [0, -5, '', null, false]; } public function testGetAllItems()