You've already forked ugly-queue
Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 12f6edf269 | |||
| 0b3b876b64 | |||
| e07cb21821 | |||
| 9387bb8843 | |||
| 1825c09123 | |||
| 728c6a5a7d | |||
| d63950b5f5 | |||
| 6dcb89742e | |||
| b166fd3497 | |||
| 734ec3d5c4 |
16
.travis.yml
Normal file
16
.travis.yml
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
language: php
|
||||||
|
|
||||||
|
php:
|
||||||
|
- 5.3.3
|
||||||
|
- 5.3
|
||||||
|
- 5.4
|
||||||
|
- 5.5
|
||||||
|
- 5.6
|
||||||
|
|
||||||
|
before_script:
|
||||||
|
- composer self-update
|
||||||
|
- composer update --prefer-source
|
||||||
|
- composer install --no-interaction --dev --prefer-source
|
||||||
|
|
||||||
|
script:
|
||||||
|
- ./vendor/bin/phpunit
|
||||||
@@ -3,4 +3,6 @@ ugly-queue
|
|||||||
|
|
||||||
A simple file-based queue system for PHP 5.3.3+
|
A simple file-based queue system for PHP 5.3.3+
|
||||||
|
|
||||||
|
Build status: [](https://travis-ci.org/dcarbone/ugly-queue)
|
||||||
|
|
||||||
Documentation and Test suites forthcoming.
|
Documentation and Test suites forthcoming.
|
||||||
@@ -43,6 +43,8 @@ class UglyQueue
|
|||||||
throw new \RuntimeException('UglyQueue::__construct - "$config[\'queue-base-dir\']" points to a directory that either doesn\'t exist or is not writable');
|
throw new \RuntimeException('UglyQueue::__construct - "$config[\'queue-base-dir\']" points to a directory that either doesn\'t exist or is not writable');
|
||||||
|
|
||||||
$this->config = $config;
|
$this->config = $config;
|
||||||
|
|
||||||
|
$this->queueBaseDir = $this->config['queue-base-dir'];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -56,10 +58,17 @@ class UglyQueue
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param int $ttl Time to live in seconds
|
* @param int $ttl Time to live in seconds
|
||||||
|
* @throws \InvalidArgumentException
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function lock($ttl = 250)
|
public function lock($ttl = 250)
|
||||||
{
|
{
|
||||||
|
if (!is_int($ttl))
|
||||||
|
throw new \InvalidArgumentException('UglyQueue::lock - Argument 1 expected to be positive integer, "'.gettype($ttl).'" seen');
|
||||||
|
|
||||||
|
if ($ttl < 0)
|
||||||
|
throw new \InvalidArgumentException('UglyQueue::lock - Argument 1 expected to be positive integer, "'.$ttl.'" seen');
|
||||||
|
|
||||||
$already_locked = $this->isLocked();
|
$already_locked = $this->isLocked();
|
||||||
|
|
||||||
// If there is no lock, currently
|
// If there is no lock, currently
|
||||||
@@ -88,22 +97,26 @@ class UglyQueue
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Close file_queue, writing out contents to file.
|
* Close this ugly queue, writing out contents to file.
|
||||||
*/
|
*/
|
||||||
public function unlock()
|
public function unlock()
|
||||||
{
|
{
|
||||||
if ($this->haveLock === true)
|
if ($this->haveLock === true)
|
||||||
{
|
{
|
||||||
@FileHelper::superUnlink($this->queueGroupDirPath.'queue.lock');
|
unlink($this->queueGroupDirPath.'queue.lock');
|
||||||
$this->haveLock = false;
|
$this->haveLock = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @throws \RuntimeException
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function isLocked()
|
public function isLocked()
|
||||||
{
|
{
|
||||||
|
if ($this->init === false)
|
||||||
|
throw new \RuntimeException('UglyQueue::isLocked - Must first initialize queue');
|
||||||
|
|
||||||
// First check for lock file
|
// First check for lock file
|
||||||
if (is_file($this->queueGroupDirPath.'queue.lock'))
|
if (is_file($this->queueGroupDirPath.'queue.lock'))
|
||||||
{
|
{
|
||||||
@@ -111,8 +124,9 @@ class UglyQueue
|
|||||||
|
|
||||||
// If we have an invalid lock structure, THIS IS BAD.
|
// If we have an invalid lock structure, THIS IS BAD.
|
||||||
if (!isset($lock['ttl']) || !isset($lock['born']))
|
if (!isset($lock['ttl']) || !isset($lock['born']))
|
||||||
return true;
|
throw new \RuntimeException('UglyQueue::isLocked - Invalid "queue.lock" file structure seen at "'.$this->queueGroupDirPath.'queue.lock'.'"');
|
||||||
|
|
||||||
|
// Otherwise...
|
||||||
$lock_ttl = ((int)$lock['born'] + (int)$lock['ttl']);
|
$lock_ttl = ((int)$lock['born'] + (int)$lock['ttl']);
|
||||||
|
|
||||||
// If we're within the TTL of the lock, assume another thread is already processing.
|
// If we're within the TTL of the lock, assume another thread is already processing.
|
||||||
@@ -121,7 +135,7 @@ class UglyQueue
|
|||||||
return true;
|
return true;
|
||||||
|
|
||||||
// Else, remove lock file and assume we're good to go!
|
// Else, remove lock file and assume we're good to go!
|
||||||
@FileHelper::superUnlink($this->queueGroupDirPath.'queue.lock');
|
unlink($this->queueGroupDirPath.'queue.lock');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -130,14 +144,12 @@ class UglyQueue
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $queue_group
|
* @param string $queueGroup
|
||||||
*/
|
*/
|
||||||
public function initialize($queue_group)
|
public function initialize($queueGroup)
|
||||||
{
|
{
|
||||||
$this->queueBaseDir = $this->config['queue-base-dir'];
|
$this->queueGroup = $queueGroup;
|
||||||
|
$this->queueGroupDirPath = $this->queueBaseDir.$queueGroup.DIRECTORY_SEPARATOR;
|
||||||
$this->queueGroup = $queue_group;
|
|
||||||
$this->queueGroupDirPath = $this->queueBaseDir.$queue_group.DIRECTORY_SEPARATOR;
|
|
||||||
|
|
||||||
// Create directory for this queue group
|
// Create directory for this queue group
|
||||||
if (!is_dir($this->queueGroupDirPath))
|
if (!is_dir($this->queueGroupDirPath))
|
||||||
@@ -168,34 +180,43 @@ HTML;
|
|||||||
/**
|
/**
|
||||||
* @param int $count
|
* @param int $count
|
||||||
* @throws \RuntimeException
|
* @throws \RuntimeException
|
||||||
|
* @throws \InvalidArgumentException
|
||||||
* @return bool|array
|
* @return bool|array
|
||||||
*/
|
*/
|
||||||
public function processQueue($count = 1)
|
public function processQueue($count = 1)
|
||||||
{
|
{
|
||||||
if ($this->init === false)
|
if ($this->init === false)
|
||||||
throw new \RuntimeException('file_queue::load_queue_data - Must first initialize queue!');
|
throw new \RuntimeException('UglyQueue::processQueue - Must first initialize queue!');
|
||||||
|
|
||||||
// If we don't have a lock, assume issue and move on.
|
// If we don't have a lock, assume issue and move on.
|
||||||
if ($this->haveLock === false || !file_exists($this->queueGroupDirPath.'queue.txt'))
|
if ($this->haveLock === false)
|
||||||
return 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
|
// Find number of lines in the queue file
|
||||||
$line_count = FileHelper::getLineCount($this->queueGroupDirPath.'queue.txt');
|
$lineCount = FileHelper::getLineCount($this->queueGroupDirPath.'queue.txt');
|
||||||
|
|
||||||
// If queue line count is 0, assume empty
|
// If queue line count is 0, assume empty
|
||||||
if ($line_count === 0)
|
if ($lineCount === 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Try to open the file for reading / writing.
|
// Try to open the file for reading / writing.
|
||||||
$queue_file_handle = fopen($this->queueGroupDirPath.'queue.txt', 'r+');
|
$queueFileHandle = fopen($this->queueGroupDirPath.'queue.txt', 'r+');
|
||||||
if ($queue_file_handle === false)
|
if ($queueFileHandle === false)
|
||||||
$this->unlock();
|
$this->unlock();
|
||||||
|
|
||||||
// Get an array of the oldest $count data in the queue
|
// Get an array of the oldest $count data in the queue
|
||||||
$data = array();
|
$data = array();
|
||||||
$start_line = $line_count - $count;
|
$start_line = $lineCount - $count;
|
||||||
$i = 0;
|
$i = 0;
|
||||||
while (($line = fscanf($queue_file_handle, "%s\t%s\n")) !== false && $i < $line_count)
|
while (($line = fscanf($queueFileHandle, "%s\t%s\n")) !== false && $i < $lineCount)
|
||||||
{
|
{
|
||||||
if ($i++ >= $start_line)
|
if ($i++ >= $start_line)
|
||||||
{
|
{
|
||||||
@@ -205,20 +226,19 @@ HTML;
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If we have consumed the rest of the file
|
// If we have consumed the rest of the file
|
||||||
if ($count >= $line_count)
|
if ($count >= $lineCount)
|
||||||
{
|
{
|
||||||
rewind($queue_file_handle);
|
rewind($queueFileHandle);
|
||||||
ftruncate($queue_file_handle, 0);
|
ftruncate($queueFileHandle, 0);
|
||||||
fclose($queue_file_handle);
|
fclose($queueFileHandle);
|
||||||
$this->unlock();
|
|
||||||
}
|
}
|
||||||
// Otherwise, create new queue file minus the processed lines.
|
// Otherwise, create new queue file minus the processed lines.
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$tmp = fopen($this->queueGroupDirPath.'queue.tmp', 'w+');
|
$tmp = fopen($this->queueGroupDirPath.'queue.tmp', 'w+');
|
||||||
rewind($queue_file_handle);
|
rewind($queueFileHandle);
|
||||||
$i = 0;
|
$i = 0;
|
||||||
while (($line = fgets($queue_file_handle)) !== false && $i < $start_line)
|
while (($line = fgets($queueFileHandle)) !== false && $i < $start_line)
|
||||||
{
|
{
|
||||||
if ($line !== "\n" || $line !== "")
|
if ($line !== "\n" || $line !== "")
|
||||||
fwrite($tmp, $line);
|
fwrite($tmp, $line);
|
||||||
@@ -226,9 +246,9 @@ HTML;
|
|||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose($queue_file_handle);
|
fclose($queueFileHandle);
|
||||||
fclose($tmp);
|
fclose($tmp);
|
||||||
FileHelper::superUnlink($this->queueGroupDirPath.'queue.txt');
|
unlink($this->queueGroupDirPath.'queue.txt');
|
||||||
rename($this->queueGroupDirPath.'queue.tmp', $this->queueGroupDirPath.'queue.txt');
|
rename($this->queueGroupDirPath.'queue.tmp', $this->queueGroupDirPath.'queue.txt');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -244,17 +264,17 @@ HTML;
|
|||||||
public function addToQueue($key, $value)
|
public function addToQueue($key, $value)
|
||||||
{
|
{
|
||||||
if ($this->init === false)
|
if ($this->init === false)
|
||||||
throw new \RuntimeException('file_queue::add_to_queue - Must first initialize queue!');
|
throw new \RuntimeException('UglyQueue::addToQueue - Must first initialize queue!');
|
||||||
|
|
||||||
// If we don't have a lock, assume issue and move on.
|
// If we don't have a lock, assume issue and move on.
|
||||||
if ($this->haveLock === false)
|
if ($this->haveLock === false)
|
||||||
return false;
|
throw new \RuntimeException('UglyQueue::addToQueue - You do not have a lock on this queue');
|
||||||
|
|
||||||
if (!is_resource($this->_tmpHandle))
|
if (!is_resource($this->_tmpHandle))
|
||||||
{
|
{
|
||||||
$this->_tmpHandle = fopen($this->queueGroupDirPath.'queue.tmp', 'w+');
|
$this->_tmpHandle = fopen($this->queueGroupDirPath.'queue.tmp', 'w+');
|
||||||
if ($this->_tmpHandle === false)
|
if ($this->_tmpHandle === false)
|
||||||
return false;
|
throw new \RuntimeException('UglyQueue::addToQueue - Unable to create "queue.tmp" file');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_array($value) || $value instanceof \stdClass)
|
if (is_array($value) || $value instanceof \stdClass)
|
||||||
@@ -271,21 +291,21 @@ HTML;
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
protected function _populateQueue()
|
public function _populateQueue()
|
||||||
{
|
{
|
||||||
if (is_resource($this->_tmpHandle))
|
if (is_resource($this->_tmpHandle))
|
||||||
{
|
{
|
||||||
if (file_exists($this->queueGroupDirPath.'queue.txt'))
|
if (file_exists($this->queueGroupDirPath.'queue.txt'))
|
||||||
{
|
{
|
||||||
$queue_file_handle = fopen($this->queueGroupDirPath.'queue.txt', 'r+');
|
$queueFileHandle = fopen($this->queueGroupDirPath.'queue.txt', 'r+');
|
||||||
while (($line = fgets($queue_file_handle)) !== false)
|
while (($line = fgets($queueFileHandle)) !== false)
|
||||||
{
|
{
|
||||||
if ($line !== "\n" && $line !== "")
|
if ($line !== "\n" && $line !== "")
|
||||||
fwrite($this->_tmpHandle, $line);
|
fwrite($this->_tmpHandle, $line);
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose($queue_file_handle);
|
fclose($queueFileHandle);
|
||||||
FileHelper::superUnlink($this->queueGroupDirPath.'queue.txt');
|
unlink($this->queueGroupDirPath.'queue.txt');
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose($this->_tmpHandle);
|
fclose($this->_tmpHandle);
|
||||||
@@ -294,11 +314,53 @@ HTML;
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @return int
|
||||||
|
* @throws \RuntimeException
|
||||||
*/
|
*/
|
||||||
public function getQueueGroup()
|
public function getQueueItemCount()
|
||||||
{
|
{
|
||||||
return $this->queueGroup;
|
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');
|
||||||
|
|
||||||
|
$key = (string)$key;
|
||||||
|
|
||||||
|
// Try to open the file for reading / writing.
|
||||||
|
$queueFileHandle = fopen($this->queueGroupDirPath.'queue.txt', 'r');
|
||||||
|
|
||||||
|
while(($line = fscanf($queueFileHandle, "%s\t")) !== false)
|
||||||
|
{
|
||||||
|
list($queueKey) = $line;
|
||||||
|
|
||||||
|
if ($key === $queueKey)
|
||||||
|
{
|
||||||
|
fclose($queueFileHandle);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose($queueFileHandle);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public function getInit()
|
||||||
|
{
|
||||||
|
return $this->init;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -308,4 +370,20 @@ HTML;
|
|||||||
{
|
{
|
||||||
return $this->queueBaseDir;
|
return $this->queueBaseDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getQueueGroupDirPath()
|
||||||
|
{
|
||||||
|
return $this->queueGroupDirPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getQueueGroup()
|
||||||
|
{
|
||||||
|
return $this->queueGroup;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,10 +1,31 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
date_default_timezone_set('UTC');
|
||||||
|
|
||||||
|
require_once __DIR__.'/../misc/cleanup.php';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class UglyQueueTest
|
* Class UglyQueueTest
|
||||||
*/
|
*/
|
||||||
class UglyQueueTest extends PHPUnit_Framework_TestCase
|
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
|
* @covers \DCarbone\UglyQueue::__construct
|
||||||
* @uses \DCarbone\UglyQueue
|
* @uses \DCarbone\UglyQueue
|
||||||
@@ -18,6 +39,8 @@ class UglyQueueTest extends PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
$uglyQueue = new \DCarbone\UglyQueue($conf);
|
$uglyQueue = new \DCarbone\UglyQueue($conf);
|
||||||
|
|
||||||
|
$this->assertInstanceOf('\\DCarbone\\UglyQueue', $uglyQueue);
|
||||||
|
|
||||||
return $uglyQueue;
|
return $uglyQueue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,4 +68,566 @@ class UglyQueueTest extends PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
$uglyQueue = new \DCarbone\UglyQueue($conf);
|
$uglyQueue = new \DCarbone\UglyQueue($conf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \DCarbone\UglyQueue::getQueueBaseDir
|
||||||
|
* @uses \DCarbone\UglyQueue
|
||||||
|
* @depends testCanConstructUglyQueueWithValidParameter
|
||||||
|
* @param \DCarbone\UglyQueue $uglyQueue
|
||||||
|
*/
|
||||||
|
public function testCanGetQueueBaseDir(\DCarbone\UglyQueue $uglyQueue)
|
||||||
|
{
|
||||||
|
$queueBaseDir = $uglyQueue->getQueueBaseDir();
|
||||||
|
|
||||||
|
$this->assertFileExists(
|
||||||
|
$queueBaseDir,
|
||||||
|
'Could not verify that Queue Base Dir exists');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \DCarbone\UglyQueue::getQueueGroup
|
||||||
|
* @uses \DCarbone\UglyQueue
|
||||||
|
* @depends testCanConstructUglyQueueWithValidParameter
|
||||||
|
* @param \DCarbone\UglyQueue $uglyQueue
|
||||||
|
*/
|
||||||
|
public function testGetQueueGroupReturnsNullBeforeInitialization(\DCarbone\UglyQueue $uglyQueue)
|
||||||
|
{
|
||||||
|
$queueGroup = $uglyQueue->getQueueGroup();
|
||||||
|
|
||||||
|
$this->assertNull($queueGroup);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \DCarbone\UglyQueue::getInit
|
||||||
|
* @uses \DCarbone\UglyQueue
|
||||||
|
* @depends testCanConstructUglyQueueWithValidParameter
|
||||||
|
* @param \DCarbone\UglyQueue $uglyQueue
|
||||||
|
*/
|
||||||
|
public function testGetInitReturnsFalseBeforeInitialization(\DCarbone\UglyQueue $uglyQueue)
|
||||||
|
{
|
||||||
|
$init = $uglyQueue->getInit();
|
||||||
|
$this->assertFalse($init);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \DCarbone\UglyQueue::getQueueGroupDirPath
|
||||||
|
* @uses \DCarbone\UglyQueue
|
||||||
|
* @depends testCanConstructUglyQueueWithValidParameter
|
||||||
|
* @param \DCarbone\UglyQueue $uglyQueue
|
||||||
|
*/
|
||||||
|
public function testGetQueueGroupDirPathReturnsNullBeforeInitialization(\DCarbone\UglyQueue $uglyQueue)
|
||||||
|
{
|
||||||
|
$queueGroupDir = $uglyQueue->getQueueGroupDirPath();
|
||||||
|
|
||||||
|
$this->assertNull($queueGroupDir);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \DCarbone\UglyQueue::isLocked
|
||||||
|
* @uses \DCarbone\UglyQueue
|
||||||
|
* @depends testCanConstructUglyQueueWithValidParameter
|
||||||
|
* @expectedException \RuntimeException
|
||||||
|
* @param \DCarbone\UglyQueue $uglyQueue
|
||||||
|
*/
|
||||||
|
public function testExceptionThrownWhenCallingIsLockedOnUninitializedQueue(\DCarbone\UglyQueue $uglyQueue)
|
||||||
|
{
|
||||||
|
$isLocked = $uglyQueue->isLocked();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \DCarbone\UglyQueue::addToQueue
|
||||||
|
* @uses \DCarbone\UglyQueue
|
||||||
|
* @depends testCanConstructUglyQueueWithValidParameter
|
||||||
|
* @expectedException \RuntimeException
|
||||||
|
* @param \DCarbone\UglyQueue $uglyQueue
|
||||||
|
*/
|
||||||
|
public function testExceptionThrownWhenTryingToAddItemsToUninitializedQueue(\DCarbone\UglyQueue $uglyQueue)
|
||||||
|
{
|
||||||
|
$addToQueue = $uglyQueue->addToQueue('test', 'value');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \DCarbone\UglyQueue::getQueueItemCount
|
||||||
|
* @uses \DCarbone\UglyQueue
|
||||||
|
* @depends testCanConstructUglyQueueWithValidParameter
|
||||||
|
* @expectedException \RuntimeException
|
||||||
|
* @param \DCarbone\UglyQueue $uglyQueue
|
||||||
|
*/
|
||||||
|
public function testExceptionThrownWhenTryingToGetCountOfItemsInQueueBeforeInitialization(\DCarbone\UglyQueue $uglyQueue)
|
||||||
|
{
|
||||||
|
$itemCount = $uglyQueue->getQueueItemCount();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \DCarbone\UglyQueue::keyExistsInQueue
|
||||||
|
* @uses \DCarbone\UglyQueue
|
||||||
|
* @depends testCanConstructUglyQueueWithValidParameter
|
||||||
|
* @expectedException \RuntimeException
|
||||||
|
* @param \DCarbone\UglyQueue $uglyQueue
|
||||||
|
*/
|
||||||
|
public function testExceptionThrownWhenTryingToFindKeyBeforeInitialization(\DCarbone\UglyQueue $uglyQueue)
|
||||||
|
{
|
||||||
|
$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
|
||||||
|
* @uses \DCarbone\UglyQueue
|
||||||
|
* @depends testCanConstructUglyQueueWithValidParameter
|
||||||
|
* @param \DCarbone\UglyQueue $uglyQueue
|
||||||
|
* @return \DCarbone\UglyQueue
|
||||||
|
*/
|
||||||
|
public function testCanInitializeNewUglyQueue(\DCarbone\UglyQueue $uglyQueue)
|
||||||
|
{
|
||||||
|
$uglyQueue->initialize('tasty-sandwich');
|
||||||
|
|
||||||
|
$this->assertTrue($uglyQueue->getInit());
|
||||||
|
|
||||||
|
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
|
||||||
|
* @depends testCanInitializeNewUglyQueue
|
||||||
|
* @param \DCarbone\UglyQueue $uglyQueue
|
||||||
|
*/
|
||||||
|
public function testKeyExistsInQueueReturnsFalseWithEmptyQueueAfterInitialization(\DCarbone\UglyQueue $uglyQueue)
|
||||||
|
{
|
||||||
|
$exists = $uglyQueue->keyExistsInQueue(0);
|
||||||
|
|
||||||
|
$this->assertFalse($exists);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \DCarbone\UglyQueue::addToQueue
|
||||||
|
* @uses \DCarbone\UglyQueue
|
||||||
|
* @depends testCanInitializeNewUglyQueue
|
||||||
|
* @expectedException \RuntimeException
|
||||||
|
* @param \DCarbone\UglyQueue $uglyQueue
|
||||||
|
*/
|
||||||
|
public function testExceptionThrownWhenTryingToAddItemsToQueueWithoutLockAfterInitialization(\DCarbone\UglyQueue $uglyQueue)
|
||||||
|
{
|
||||||
|
$addToQueue = $uglyQueue->addToQueue('test', 'value');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \DCarbone\UglyQueue::getInit
|
||||||
|
* @uses \DCarbone\UglyQueue
|
||||||
|
* @depends testCanInitializeNewUglyQueue
|
||||||
|
* @param \DCarbone\UglyQueue $uglyQueue
|
||||||
|
*/
|
||||||
|
public function testGetInitReturnsTrueAfterInitialization(\DCarbone\UglyQueue $uglyQueue)
|
||||||
|
{
|
||||||
|
$init = $uglyQueue->getInit();
|
||||||
|
$this->assertTrue($init);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \DCarbone\UglyQueue::getQueueGroupDirPath
|
||||||
|
* @uses \DCarbone\UglyQueue
|
||||||
|
* @depends testCanInitializeNewUglyQueue
|
||||||
|
* @param \DCarbone\UglyQueue $uglyQueue
|
||||||
|
*/
|
||||||
|
public function testCanGetQueueGroupDirectoryAfterInitialization(\DCarbone\UglyQueue $uglyQueue)
|
||||||
|
{
|
||||||
|
$queueGroupDir = $uglyQueue->getQueueGroupDirPath();
|
||||||
|
|
||||||
|
$this->assertFileExists($queueGroupDir);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \DCarbone\UglyQueue::getQueueGroup
|
||||||
|
* @uses \DCarbone\UglyQueue
|
||||||
|
* @depends testCanInitializeNewUglyQueue
|
||||||
|
* @param \DCarbone\UglyQueue $uglyQueue
|
||||||
|
*/
|
||||||
|
public function testCanGetQueueGroupAfterInitialization(\DCarbone\UglyQueue $uglyQueue)
|
||||||
|
{
|
||||||
|
$queueGroup = $uglyQueue->getQueueGroup();
|
||||||
|
|
||||||
|
$this->assertEquals('tasty-sandwich', $queueGroup);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \DCarbone\UglyQueue::isLocked
|
||||||
|
* @uses \DCarbone\UglyQueue
|
||||||
|
* @depends testCanInitializeNewUglyQueue
|
||||||
|
* @param \DCarbone\UglyQueue $uglyQueue
|
||||||
|
*/
|
||||||
|
public function testIsLockedReturnsFalseBeforeLockingAfterInitialization(\DCarbone\UglyQueue $uglyQueue)
|
||||||
|
{
|
||||||
|
$isLocked = $uglyQueue->isLocked();
|
||||||
|
|
||||||
|
$this->assertFalse($isLocked);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \DCarbone\UglyQueue::getQueueItemCount
|
||||||
|
* @uses \DCarbone\UglyQueue
|
||||||
|
* @depends testCanInitializeNewUglyQueue
|
||||||
|
* @param \DCarbone\UglyQueue $uglyQueue
|
||||||
|
*/
|
||||||
|
public function testGetQueueItemCountReturnsZeroAfterInitializingEmptyQueue(\DCarbone\UglyQueue $uglyQueue)
|
||||||
|
{
|
||||||
|
$itemCount = $uglyQueue->getQueueItemCount();
|
||||||
|
$this->assertEquals(0, $itemCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \DCarbone\UglyQueue::initialize
|
||||||
|
* @covers \DCarbone\UglyQueue::__construct
|
||||||
|
* @covers \DCarbone\UglyQueue::getInit
|
||||||
|
* @uses \DCarbone\UglyQueue
|
||||||
|
* @return \DCarbone\UglyQueue
|
||||||
|
*/
|
||||||
|
public function testCanInitializeExistingQueue()
|
||||||
|
{
|
||||||
|
$conf = array(
|
||||||
|
'queue-base-dir' => dirname(__DIR__).'/misc/',
|
||||||
|
);
|
||||||
|
|
||||||
|
$uglyQueue = new \DCarbone\UglyQueue($conf);
|
||||||
|
|
||||||
|
$this->assertInstanceOf('\\DCarbone\\UglyQueue', $uglyQueue);
|
||||||
|
|
||||||
|
$this->assertFalse($uglyQueue->getInit());
|
||||||
|
|
||||||
|
$uglyQueue->initialize('tasty-sandwich');
|
||||||
|
|
||||||
|
$this->assertTrue($uglyQueue->getInit());
|
||||||
|
|
||||||
|
return $uglyQueue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \DCarbone\UglyQueue::lock
|
||||||
|
* @uses \DCarbone\UglyQueue
|
||||||
|
* @depends testCanConstructUglyQueueWithValidParameter
|
||||||
|
* @expectedException \InvalidArgumentException
|
||||||
|
* @param \DCarbone\UglyQueue $uglyQueue
|
||||||
|
*/
|
||||||
|
public function testExceptionThrownWhenPassingNonIntegerValueToLock(\DCarbone\UglyQueue $uglyQueue)
|
||||||
|
{
|
||||||
|
$uglyQueue->lock('7 billion');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \DCarbone\UglyQueue::lock
|
||||||
|
* @uses \DCarbone\UglyQueue
|
||||||
|
* @depends testCanConstructUglyQueueWithValidParameter
|
||||||
|
* @expectedException \InvalidArgumentException
|
||||||
|
* @param \DCarbone\UglyQueue $uglyQueue
|
||||||
|
*/
|
||||||
|
public function testExceptionThrownWhenPassingNegativeIntegerValueToLock(\DCarbone\UglyQueue $uglyQueue)
|
||||||
|
{
|
||||||
|
$uglyQueue->lock(-73);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \DCarbone\UglyQueue::lock
|
||||||
|
* @covers \DCarbone\UglyQueue::isLocked
|
||||||
|
* @covers \DCarbone\UglyQueue::createQueueLock
|
||||||
|
* @uses \DCarbone\UglyQueue
|
||||||
|
* @depends testCanInitializeNewUglyQueue
|
||||||
|
* @param \DCarbone\UglyQueue $uglyQueue
|
||||||
|
* @return \DCarbone\UglyQueue
|
||||||
|
*/
|
||||||
|
public function testCanLockUglyQueueWithDefaultTTL(\DCarbone\UglyQueue $uglyQueue)
|
||||||
|
{
|
||||||
|
$locked = $uglyQueue->lock();
|
||||||
|
|
||||||
|
$this->assertTrue($locked);
|
||||||
|
|
||||||
|
$queueDir = $uglyQueue->getQueueBaseDir().$uglyQueue->getQueueGroup().'/';
|
||||||
|
|
||||||
|
$this->assertFileExists($queueDir.'queue.lock');
|
||||||
|
|
||||||
|
$decode = @json_decode(file_get_contents($queueDir.'queue.lock'));
|
||||||
|
|
||||||
|
$this->assertTrue((json_last_error() === JSON_ERROR_NONE));
|
||||||
|
$this->assertObjectHasAttribute('ttl', $decode);
|
||||||
|
$this->assertObjectHasAttribute('born', $decode);
|
||||||
|
$this->assertEquals(250, $decode->ttl);
|
||||||
|
|
||||||
|
return $uglyQueue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \DCarbone\UglyQueue::lock
|
||||||
|
* @covers \DCarbone\UglyQueue::isLocked
|
||||||
|
* @uses \DCarbone\UglyQueue
|
||||||
|
* @depends testCanInitializeExistingQueue
|
||||||
|
* @param \DCarbone\UglyQueue $uglyQueue
|
||||||
|
*/
|
||||||
|
public function testCannotLockInitializedQueueThatIsAlreadyLocked(\DCarbone\UglyQueue $uglyQueue)
|
||||||
|
{
|
||||||
|
$lock = $uglyQueue->lock();
|
||||||
|
|
||||||
|
$this->assertFalse($lock);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \DCarbone\UglyQueue::isLocked
|
||||||
|
* @uses \DCarbone\UglyQueue
|
||||||
|
* @depends testCanLockUglyQueueWithDefaultTTL
|
||||||
|
* @param \DCarbone\UglyQueue $uglyQueue
|
||||||
|
*/
|
||||||
|
public function testIsLockedReturnsTrueAfterLockingInitializedQueue(\DCarbone\UglyQueue $uglyQueue)
|
||||||
|
{
|
||||||
|
$isLocked = $uglyQueue->isLocked();
|
||||||
|
$this->assertTrue($isLocked);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \DCarbone\UglyQueue::unlock
|
||||||
|
* @uses \DCarbone\UglyQueue
|
||||||
|
* @uses \DCarbone\Helpers\FileHelper
|
||||||
|
* @depends testCanLockUglyQueueWithDefaultTTL
|
||||||
|
* @param \DCarbone\UglyQueue $uglyQueue
|
||||||
|
* @return \DCarbone\UglyQueue
|
||||||
|
*/
|
||||||
|
public function testCanUnlockLockedQueue(\DCarbone\UglyQueue $uglyQueue)
|
||||||
|
{
|
||||||
|
$uglyQueue->unlock();
|
||||||
|
|
||||||
|
$queueGroupDir = $uglyQueue->getQueueGroupDirPath();
|
||||||
|
|
||||||
|
$this->assertFileNotExists($queueGroupDir.'queue.lock');
|
||||||
|
|
||||||
|
return $uglyQueue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \DCarbone\UglyQueue::isLocked
|
||||||
|
* @uses \DCarbone\UglyQueue
|
||||||
|
* @depends testCanUnlockLockedQueue
|
||||||
|
* @param \DCarbone\UglyQueue $uglyQueue
|
||||||
|
*/
|
||||||
|
public function testIsLockedReturnsFalseAfterUnlockingQueue(\DCarbone\UglyQueue $uglyQueue)
|
||||||
|
{
|
||||||
|
$isLocked = $uglyQueue->isLocked();
|
||||||
|
|
||||||
|
$this->assertFalse($isLocked);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \DCarbone\UglyQueue::lock
|
||||||
|
* @covers \DCarbone\UglyQueue::isLocked
|
||||||
|
* @uses \DCarbone\UglyQueue
|
||||||
|
* @uses \DCarbone\Helpers\FileHelper
|
||||||
|
* @depends testCanUnlockLockedQueue
|
||||||
|
* @param \DCarbone\UglyQueue $uglyQueue
|
||||||
|
*/
|
||||||
|
public function testIsLockedReturnsFalseWithStaleQueueLockFile(\DCarbone\UglyQueue $uglyQueue)
|
||||||
|
{
|
||||||
|
$uglyQueue->lock(2);
|
||||||
|
$isLocked = $uglyQueue->isLocked();
|
||||||
|
$this->assertTrue($isLocked);
|
||||||
|
|
||||||
|
sleep(3);
|
||||||
|
|
||||||
|
$isLocked = $uglyQueue->isLocked();
|
||||||
|
$this->assertFalse($isLocked);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \DCarbone\UglyQueue::lock
|
||||||
|
* @covers \DCarbone\UglyQueue::isLocked
|
||||||
|
* @covers \DCarbone\UglyQueue::getQueueGroupDirPath
|
||||||
|
* @uses \DCarbone\UglyQueue
|
||||||
|
* @depends testCanUnlockLockedQueue
|
||||||
|
* @param \DCarbone\UglyQueue $uglyQueue
|
||||||
|
* @return \DCarbone\UglyQueue
|
||||||
|
*/
|
||||||
|
public function testCanLockQueueWithValidIntegerValue(\DCarbone\UglyQueue $uglyQueue)
|
||||||
|
{
|
||||||
|
$locked = $uglyQueue->lock(200);
|
||||||
|
|
||||||
|
$this->assertTrue($locked);
|
||||||
|
|
||||||
|
$queueDir = $uglyQueue->getQueueGroupDirPath();
|
||||||
|
|
||||||
|
$this->assertFileExists($queueDir.'queue.lock');
|
||||||
|
|
||||||
|
$decode = @json_decode(file_get_contents($queueDir.'queue.lock'));
|
||||||
|
|
||||||
|
$this->assertTrue((json_last_error() === JSON_ERROR_NONE));
|
||||||
|
$this->assertObjectHasAttribute('ttl', $decode);
|
||||||
|
$this->assertObjectHasAttribute('born', $decode);
|
||||||
|
$this->assertEquals(200, $decode->ttl);
|
||||||
|
|
||||||
|
return $uglyQueue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \DCarbone\UglyQueue::addToQueue
|
||||||
|
* @uses \DCarbone\UglyQueue
|
||||||
|
* @uses \DCarbone\Helpers\FileHelper
|
||||||
|
* @depends testCanLockQueueWithValidIntegerValue
|
||||||
|
* @param \DCarbone\UglyQueue $uglyQueue
|
||||||
|
* @return \DCarbone\UglyQueue
|
||||||
|
*/
|
||||||
|
public function testCanPopulateQueueTempFileAfterInitializationAndAcquiringLock(\DCarbone\UglyQueue $uglyQueue)
|
||||||
|
{
|
||||||
|
foreach(array_reverse($this->tastySandwich, true) as $k=>$v)
|
||||||
|
{
|
||||||
|
$added = $uglyQueue->addToQueue($k, $v);
|
||||||
|
$this->assertTrue($added);
|
||||||
|
}
|
||||||
|
|
||||||
|
$groupDir = $uglyQueue->getQueueGroupDirPath();
|
||||||
|
|
||||||
|
$this->assertFileExists(
|
||||||
|
$groupDir.'queue.tmp',
|
||||||
|
'queue.tmp file was not created!');
|
||||||
|
|
||||||
|
$lineCount = \DCarbone\Helpers\FileHelper::getLineCount($groupDir.'queue.tmp');
|
||||||
|
|
||||||
|
$this->assertEquals(11, $lineCount);
|
||||||
|
|
||||||
|
return $uglyQueue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \DCarbone\UglyQueue::_populateQueue
|
||||||
|
* @uses \DCarbone\UglyQueue
|
||||||
|
* @depends testCanPopulateQueueTempFileAfterInitializationAndAcquiringLock
|
||||||
|
* @param \DCarbone\UglyQueue $uglyQueue
|
||||||
|
* @return \DCarbone\UglyQueue
|
||||||
|
*/
|
||||||
|
public function testCanForciblyUpdateQueueFileFromTempFile(\DCarbone\UglyQueue $uglyQueue)
|
||||||
|
{
|
||||||
|
$uglyQueue->_populateQueue();
|
||||||
|
|
||||||
|
$groupDir = $uglyQueue->getQueueGroupDirPath();
|
||||||
|
|
||||||
|
$this->assertFileNotExists($groupDir.'queue.tmp');
|
||||||
|
|
||||||
|
$uglyQueue->_populateQueue();
|
||||||
|
|
||||||
|
return $uglyQueue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \DCarbone\UglyQueue::getQueueItemCount
|
||||||
|
* @uses \DCarbone\UglyQueue
|
||||||
|
* @uses \DCarbone\Helpers\FileHelper
|
||||||
|
* @depends testCanPopulateQueueTempFileAfterInitializationAndAcquiringLock
|
||||||
|
* @param \DCarbone\UglyQueue $uglyQueue
|
||||||
|
*/
|
||||||
|
public function testCanGetCountOfItemsInPopulatedQueue(\DCarbone\UglyQueue $uglyQueue)
|
||||||
|
{
|
||||||
|
$itemCount = $uglyQueue->getQueueItemCount();
|
||||||
|
|
||||||
|
$this->assertEquals(11, $itemCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \DCarbone\UglyQueue::keyExistsInQueue
|
||||||
|
* @uses \DCarbone\UglyQueue
|
||||||
|
* @depends testCanPopulateQueueTempFileAfterInitializationAndAcquiringLock
|
||||||
|
* @param \DCarbone\UglyQueue $uglyQueue
|
||||||
|
*/
|
||||||
|
public function testKeyExistsReturnsTrueWithPopulatedQueue(\DCarbone\UglyQueue $uglyQueue)
|
||||||
|
{
|
||||||
|
$exists = $uglyQueue->keyExistsInQueue(5);
|
||||||
|
|
||||||
|
$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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
13
tests/misc/cleanup.php
Normal file
13
tests/misc/cleanup.php
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
if (is_dir(__DIR__.'/tasty-sandwich'))
|
||||||
|
{
|
||||||
|
foreach(glob(__DIR__.'/tasty-sandwich/*') as $file)
|
||||||
|
{
|
||||||
|
if (substr($file, -1) === '.')
|
||||||
|
continue;
|
||||||
|
|
||||||
|
unlink($file);
|
||||||
|
}
|
||||||
|
rmdir(__DIR__.'/tasty-sandwich');
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user