Skip to content

Commit

Permalink
Merge pull request #1 from grongor/test_changes
Browse files Browse the repository at this point in the history
Added dataProvider for some tests
  • Loading branch information
grongor committed Mar 28, 2015
2 parents 05a322e + a9a1bb9 commit 4578f09
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 143 deletions.
91 changes: 42 additions & 49 deletions tests/PoolTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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()
Expand Down
76 changes: 27 additions & 49 deletions tests/QueueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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]);
Expand All @@ -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()
Expand Down
76 changes: 31 additions & 45 deletions tests/UniqueQueueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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]);
Expand All @@ -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()
Expand Down

0 comments on commit 4578f09

Please sign in to comment.