You've already forked ugly-queue
More tests and minor updates.
This commit is contained in:
@@ -180,6 +180,7 @@ HTML;
|
||||
/**
|
||||
* @param int $count
|
||||
* @throws \RuntimeException
|
||||
* @throws \InvalidArgumentException
|
||||
* @return bool|array
|
||||
*/
|
||||
public function processQueue($count = 1)
|
||||
@@ -188,8 +189,16 @@ HTML;
|
||||
throw new \RuntimeException('UglyQueue::processQueue - Must first initialize queue!');
|
||||
|
||||
// If we don't have a lock, assume issue and move on.
|
||||
if ($this->haveLock === false || !file_exists($this->queueGroupDirPath.'queue.txt'))
|
||||
return false;
|
||||
if ($this->haveLock === false)
|
||||
throw new \RuntimeException('UglyQueue::processQueue - Cannot process queue locked by another process');
|
||||
|
||||
// If non-int valid is passed
|
||||
if (!is_int($count))
|
||||
throw new \InvalidArgumentException('UglyQueue::processQueue - Argument 1 expected to be integer greater than 0, "'.gettype($count).'" seen');
|
||||
|
||||
// If negative integer passed
|
||||
if ($count <= 0)
|
||||
throw new \InvalidArgumentException('UglyQueue::processQueue - Argument 1 expected to be integer greater than 0, "'.$count.'" seen');
|
||||
|
||||
// Find number of lines in the queue file
|
||||
$lineCount = FileHelper::getLineCount($this->queueGroupDirPath.'queue.txt');
|
||||
@@ -222,7 +231,6 @@ HTML;
|
||||
rewind($queueFileHandle);
|
||||
ftruncate($queueFileHandle, 0);
|
||||
fclose($queueFileHandle);
|
||||
$this->unlock();
|
||||
}
|
||||
// Otherwise, create new queue file minus the processed lines.
|
||||
else
|
||||
@@ -314,12 +322,7 @@ HTML;
|
||||
if ($this->init === false)
|
||||
throw new \RuntimeException('UglyQueue::getQueueItemCount - Must first initialize queue');
|
||||
|
||||
$count = FileHelper::getLineCount($this->queueGroupDirPath.'queue.txt');
|
||||
|
||||
if ($count > 0)
|
||||
return ($count - 1);
|
||||
|
||||
return $count;
|
||||
return FileHelper::getLineCount($this->queueGroupDirPath.'queue.txt');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -170,6 +170,18 @@ class UglyQueueTest extends PHPUnit_Framework_TestCase
|
||||
$keyExists = $uglyQueue->keyExistsInQueue(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \DCarbone\UglyQueue::processQueue
|
||||
* @uses \DCarbone\UglyQueue
|
||||
* @depends testCanConstructUglyQueueWithValidParameter
|
||||
* @expectedException \RuntimeException
|
||||
* @param \DCarbone\UglyQueue $uglyQueue
|
||||
*/
|
||||
public function testExceptionThrownWhenTryingToProcessQueueBeforeInitialization(\DCarbone\UglyQueue $uglyQueue)
|
||||
{
|
||||
$process = $uglyQueue->processQueue();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \DCarbone\UglyQueue::initialize
|
||||
* @covers \DCarbone\UglyQueue::getInit
|
||||
@@ -187,6 +199,18 @@ class UglyQueueTest extends PHPUnit_Framework_TestCase
|
||||
return $uglyQueue;
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \DCarbone\UglyQueue::processQueue
|
||||
* @uses \DCarbone\UglyQueue
|
||||
* @depends testCanInitializeNewUglyQueue
|
||||
* @expectedException \RuntimeException
|
||||
* @param \DCarbone\UglyQueue $uglyQueue
|
||||
*/
|
||||
public function testExceptionThrownWhenTryingToProcessQueueAfterInitializationBeforeLock(\DCarbone\UglyQueue $uglyQueue)
|
||||
{
|
||||
$process = $uglyQueue->processQueue();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \DCarbone\UglyQueue::keyExistsInQueue
|
||||
* @uses \DCarbone\UglyQueue
|
||||
@@ -471,7 +495,7 @@ class UglyQueueTest extends PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testCanPopulateQueueTempFileAfterInitializationAndAcquiringLock(\DCarbone\UglyQueue $uglyQueue)
|
||||
{
|
||||
foreach($this->tastySandwich as $k=>$v)
|
||||
foreach(array_reverse($this->tastySandwich, true) as $k=>$v)
|
||||
{
|
||||
$added = $uglyQueue->addToQueue($k, $v);
|
||||
$this->assertTrue($added);
|
||||
@@ -521,7 +545,7 @@ class UglyQueueTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
$itemCount = $uglyQueue->getQueueItemCount();
|
||||
|
||||
$this->assertEquals(10, $itemCount);
|
||||
$this->assertEquals(11, $itemCount);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -536,4 +560,74 @@ class UglyQueueTest extends PHPUnit_Framework_TestCase
|
||||
|
||||
$this->assertTrue($exists);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \DCarbone\UglyQueue::processQueue
|
||||
* @uses \DCarbone\UglyQueue
|
||||
* @depends testCanPopulateQueueTempFileAfterInitializationAndAcquiringLock
|
||||
* @expectedException \InvalidArgumentException
|
||||
* @param \DCarbone\UglyQueue $uglyQueue
|
||||
*/
|
||||
public function testExceptionThrownWhenTryingToProcessLockedQueueWithNonInteger(\DCarbone\UglyQueue $uglyQueue)
|
||||
{
|
||||
$process = $uglyQueue->processQueue('Eleventy Billion');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \DCarbone\UglyQueue::processQueue
|
||||
* @uses \DCarbone\UglyQueue
|
||||
* @depends testCanPopulateQueueTempFileAfterInitializationAndAcquiringLock
|
||||
* @expectedException \InvalidArgumentException
|
||||
* @param \DCarbone\UglyQueue $uglyQueue
|
||||
*/
|
||||
public function testExceptionThrownWhenTryingToProcessLockedQueueWithIntegerLessThan1(\DCarbone\UglyQueue $uglyQueue)
|
||||
{
|
||||
$process = $uglyQueue->processQueue(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \DCarbone\UglyQueue::processQueue
|
||||
* @covers \DCarbone\UglyQueue::getQueueItemCount
|
||||
* @uses \DCarbone\UglyQueue
|
||||
* @uses \DCarbone\Helpers\FileHelper
|
||||
* @depends testCanPopulateQueueTempFileAfterInitializationAndAcquiringLock
|
||||
* @param \DCarbone\UglyQueue $uglyQueue
|
||||
* @return \DCarbone\UglyQueue
|
||||
*/
|
||||
public function testCanGetPartialQueueContents(\DCarbone\UglyQueue $uglyQueue)
|
||||
{
|
||||
$process = $uglyQueue->processQueue(5);
|
||||
|
||||
$this->assertEquals(5, count($process));
|
||||
|
||||
$this->assertArrayHasKey('0', $process);
|
||||
$this->assertArrayHasKey('4', $process);
|
||||
|
||||
$this->assertEquals(6, $uglyQueue->getQueueItemCount());
|
||||
|
||||
return $uglyQueue;
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \DCarbone\UglyQueue::processQueue
|
||||
* @covers \DCarbone\UglyQueue::getQueueItemCount
|
||||
* @uses \DCarbone\UglyQueue
|
||||
* @uses \DCarbone\Helpers\FileHelper
|
||||
* @depends testCanGetPartialQueueContents
|
||||
* @param \DCarbone\UglyQueue $uglyQueue
|
||||
* @return \DCarbone\UglyQueue
|
||||
*/
|
||||
public function testCanGetFullQueueContents(\DCarbone\UglyQueue $uglyQueue)
|
||||
{
|
||||
$process = $uglyQueue->processQueue(6);
|
||||
|
||||
$this->assertEquals(6, count($process));
|
||||
|
||||
$this->assertArrayHasKey('10', $process);
|
||||
$this->assertArrayHasKey('5', $process);
|
||||
|
||||
$this->assertEquals(0, $uglyQueue->getQueueItemCount());
|
||||
|
||||
return $uglyQueue;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user