You've already forked ugly-queue
Adding 2 methods and beginning work on test cases
This commit is contained in:
@@ -308,4 +308,48 @@ HTML;
|
||||
{
|
||||
return $this->queueBaseDir;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int|null
|
||||
* @throws \RuntimeException
|
||||
*/
|
||||
public function getQueueItemCount()
|
||||
{
|
||||
if ($this->init === false)
|
||||
throw new \RuntimeException('UglyQueue::getQueueItemCount - Must first initialize queue');
|
||||
|
||||
return FileHelper::getLineCount($this->queueGroupDirPath.'queue.txt');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
* @return bool
|
||||
* @throws \RuntimeException
|
||||
*/
|
||||
public function keyExistsInQueue($key)
|
||||
{
|
||||
if ($this->init === false)
|
||||
throw new \RuntimeException('UglyQueue::keyExistsInQueue - Must first initialize queue');
|
||||
|
||||
// If we don't have a lock, assume issue and move on.
|
||||
if ($this->haveLock === false)
|
||||
throw new \RuntimeException('UglyQueue::keyExistsInQueue - Must first acquire queue lock');
|
||||
|
||||
$key = (string)$key;
|
||||
|
||||
// Try to open the file for reading / writing.
|
||||
$queue_file_handle = fopen($this->queueGroupDirPath.'queue.txt', 'r');
|
||||
|
||||
while(($line = fscanf($queue_file_handle, "%s\t")) !== false)
|
||||
{
|
||||
if (strpos($line, $key) === 0)
|
||||
{
|
||||
fclose($queue_file_handle);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
fclose($queue_file_handle);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,23 @@
|
||||
*/
|
||||
class UglyQueueTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $tastySandwich = array(
|
||||
'0' => 'unsalted butter',
|
||||
'1' => 'all-purpose flour',
|
||||
'2' => 'hot milk',
|
||||
'3' => 'kosher salt',
|
||||
'4' => 'freshly ground black pepper',
|
||||
'5' => 'nutmeg',
|
||||
'6' => 'grated Gruyere',
|
||||
'7' => 'freshly grated Parmesan',
|
||||
'8' => 'white sandwich bread, crust removed',
|
||||
'9' => 'Dijon mustard',
|
||||
'10' => 'Virginia baked ham, sliced',
|
||||
);
|
||||
|
||||
/**
|
||||
* @covers \DCarbone\UglyQueue::__construct
|
||||
* @uses \DCarbone\UglyQueue
|
||||
@@ -18,6 +35,8 @@ class UglyQueueTest extends PHPUnit_Framework_TestCase
|
||||
|
||||
$uglyQueue = new \DCarbone\UglyQueue($conf);
|
||||
|
||||
$this->assertInstanceOf('\\DCarbone\\UglyQueue', $uglyQueue);
|
||||
|
||||
return $uglyQueue;
|
||||
}
|
||||
|
||||
@@ -45,4 +64,27 @@ class UglyQueueTest extends PHPUnit_Framework_TestCase
|
||||
|
||||
$uglyQueue = new \DCarbone\UglyQueue($conf);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \DCarbone\UglyQueue::initialize
|
||||
* @uses \DCarbone\UglyQueue
|
||||
* @depends testCanConstructUglyQueueWithValidParameter
|
||||
* @param \DCarbone\UglyQueue $uglyQueue
|
||||
*/
|
||||
public function testCanInitializeExistingQueue(\DCarbone\UglyQueue $uglyQueue)
|
||||
{
|
||||
$uglyQueue->initialize('tasty-sandwich');
|
||||
|
||||
$this->assertTrue(
|
||||
is_dir($uglyQueue->getQueueBaseDir().$uglyQueue->getQueueGroup().'/'),
|
||||
'Could not verify existence of queue group dir');
|
||||
|
||||
$this->assertTrue(
|
||||
file_exists($uglyQueue->getQueueBaseDir().$uglyQueue->getQueueGroup().'/'.'index.html'),
|
||||
'Could not verify existence of index.html in queue group dir');
|
||||
|
||||
$this->assertTrue(
|
||||
file_exists($uglyQueue->getQueueBaseDir().$uglyQueue->getQueueGroup().'/'.'queue.txt'),
|
||||
'Could not verify existence of queue.txt in queue group dir');
|
||||
}
|
||||
}
|
||||
8
tests/misc/tasty-sandwich/index.html
Normal file
8
tests/misc/tasty-sandwich/index.html
Normal file
@@ -0,0 +1,8 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>403 Forbidden</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Directory access is forbidden.</p>
|
||||
</body>
|
||||
</html>
|
||||
0
tests/misc/tasty-sandwich/queue.txt
Normal file
0
tests/misc/tasty-sandwich/queue.txt
Normal file
Reference in New Issue
Block a user