You've already forked ugly-queue
Devil is in the details.
This commit is contained in:
@@ -46,23 +46,23 @@ class UglyQueue implements \Serializable, \SplSubject, \Countable
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $baseDir
|
* @param string $baseDir
|
||||||
* @param string $queueName
|
* @param string $name
|
||||||
* @param \SplObserver[] $observers
|
* @param \SplObserver[] $observers
|
||||||
*/
|
*/
|
||||||
public function __construct($baseDir, $queueName, array $observers = array())
|
public function __construct($baseDir, $name, array $observers = array())
|
||||||
{
|
{
|
||||||
$this->baseDir = trim($baseDir, "/\\");
|
$this->baseDir = trim($baseDir, "/\\");
|
||||||
$this->name = $queueName;
|
$this->name = $name;
|
||||||
$this->_observers = $observers;
|
$this->_observers = $observers;
|
||||||
|
|
||||||
$path = sprintf('%s/%s', $baseDir, $queueName);
|
$path = sprintf('%s/%s', $baseDir, $name);
|
||||||
if (!file_exists($path) && !@mkdir($path))
|
if (!file_exists($path) && !@mkdir($path))
|
||||||
throw new \RuntimeException('Unable to initialize queue directory "'.$path.'". Please check permissions.');
|
throw new \RuntimeException('Unable to initialize queue directory "'.$path.'". Please check permissions.');
|
||||||
|
|
||||||
$this->path = $path;
|
$this->path = $path;
|
||||||
$this->lockFile = sprintf('%s/queue.lock', $this->path);
|
$this->lockFile = sprintf('%s/queue.lock', $path);
|
||||||
$this->queueFile = sprintf('%s/queue.txt', $this->path);
|
$this->queueFile = sprintf('%s/queue.txt', $path);
|
||||||
$this->queueTmpFile = sprintf('%s/queue.tmp', $this->path);
|
$this->queueTmpFile = sprintf('%s/queue.tmp', $path);
|
||||||
|
|
||||||
$this->_initialize();
|
$this->_initialize();
|
||||||
}
|
}
|
||||||
@@ -77,7 +77,7 @@ class UglyQueue implements \Serializable, \SplSubject, \Countable
|
|||||||
else if (is_readable($this->path))
|
else if (is_readable($this->path))
|
||||||
$this->mode = self::QUEUE_READONLY;
|
$this->mode = self::QUEUE_READONLY;
|
||||||
|
|
||||||
if (!file_exists($this->path.'index.html'))
|
if (!file_exists($this->path.'/index.html'))
|
||||||
{
|
{
|
||||||
if ($this->mode === self::QUEUE_READONLY)
|
if ($this->mode === self::QUEUE_READONLY)
|
||||||
throw new \RuntimeException('Cannot initialize queue with name "'.$this->name.'", the user lacks permission to create files.');
|
throw new \RuntimeException('Cannot initialize queue with name "'.$this->name.'", the user lacks permission to create files.');
|
||||||
@@ -92,7 +92,7 @@ class UglyQueue implements \Serializable, \SplSubject, \Countable
|
|||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
HTML;
|
HTML;
|
||||||
file_put_contents($this->path.'index.html', $html);
|
file_put_contents($this->path.'/index.html', $html);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!file_exists($this->queueFile))
|
if (!file_exists($this->queueFile))
|
||||||
@@ -301,7 +301,7 @@ HTML;
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Find number of lines in the queue file
|
// Find number of lines in the queue file
|
||||||
$lineCount = FileHelper::getLineCount($this->queueFile);
|
$lineCount = count($this);
|
||||||
|
|
||||||
// If queue line count is 0, assume empty
|
// If queue line count is 0, assume empty
|
||||||
if ($lineCount === 0)
|
if ($lineCount === 0)
|
||||||
@@ -450,6 +450,7 @@ HTML;
|
|||||||
*/
|
*/
|
||||||
public function count()
|
public function count()
|
||||||
{
|
{
|
||||||
|
var_dump($this->queueFile);
|
||||||
return (int)FileHelper::getLineCount($this->queueFile);
|
return (int)FileHelper::getLineCount($this->queueFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ class UglyQueueTest extends PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
protected function setUp()
|
protected function setUp()
|
||||||
{
|
{
|
||||||
$this->baseDir = __DIR__.'/../misc/queues';
|
$this->baseDir = realpath(__DIR__.'/../misc/queues');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -40,6 +40,7 @@ class UglyQueueTest extends PHPUnit_Framework_TestCase
|
|||||||
*/
|
*/
|
||||||
public function testCanInitializeObjectWithValidParameters()
|
public function testCanInitializeObjectWithValidParameters()
|
||||||
{
|
{
|
||||||
|
echo __FUNCTION__."\n";
|
||||||
$uglyQueue = new \DCarbone\UglyQueue($this->baseDir, 'tasty-sandwich');
|
$uglyQueue = new \DCarbone\UglyQueue($this->baseDir, 'tasty-sandwich');
|
||||||
|
|
||||||
$this->assertInstanceOf('\\DCarbone\\UglyQueue', $uglyQueue);
|
$this->assertInstanceOf('\\DCarbone\\UglyQueue', $uglyQueue);
|
||||||
@@ -56,6 +57,7 @@ class UglyQueueTest extends PHPUnit_Framework_TestCase
|
|||||||
*/
|
*/
|
||||||
public function testExceptionThrownWhenTryingToProcessQueueAfterInitializationBeforeLock(\DCarbone\UglyQueue $uglyQueue)
|
public function testExceptionThrownWhenTryingToProcessQueueAfterInitializationBeforeLock(\DCarbone\UglyQueue $uglyQueue)
|
||||||
{
|
{
|
||||||
|
echo __FUNCTION__."\n";
|
||||||
$uglyQueue->retrieveItems();
|
$uglyQueue->retrieveItems();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,6 +69,7 @@ class UglyQueueTest extends PHPUnit_Framework_TestCase
|
|||||||
*/
|
*/
|
||||||
public function testKeyExistsInQueueReturnsFalseWithEmptyQueueAfterInitialization(\DCarbone\UglyQueue $uglyQueue)
|
public function testKeyExistsInQueueReturnsFalseWithEmptyQueueAfterInitialization(\DCarbone\UglyQueue $uglyQueue)
|
||||||
{
|
{
|
||||||
|
echo __FUNCTION__."\n";
|
||||||
$exists = $uglyQueue->keyExistsInQueue(0);
|
$exists = $uglyQueue->keyExistsInQueue(0);
|
||||||
|
|
||||||
$this->assertFalse($exists);
|
$this->assertFalse($exists);
|
||||||
@@ -92,6 +95,7 @@ class UglyQueueTest extends PHPUnit_Framework_TestCase
|
|||||||
*/
|
*/
|
||||||
public function testCanGetQueueDirectory(\DCarbone\UglyQueue $uglyQueue)
|
public function testCanGetQueueDirectory(\DCarbone\UglyQueue $uglyQueue)
|
||||||
{
|
{
|
||||||
|
echo __FUNCTION__."\n";
|
||||||
$queuePath = $uglyQueue->getPath();
|
$queuePath = $uglyQueue->getPath();
|
||||||
|
|
||||||
$this->assertFileExists($queuePath);
|
$this->assertFileExists($queuePath);
|
||||||
@@ -105,6 +109,7 @@ class UglyQueueTest extends PHPUnit_Framework_TestCase
|
|||||||
*/
|
*/
|
||||||
public function testCanGetQueueName(\DCarbone\UglyQueue $uglyQueue)
|
public function testCanGetQueueName(\DCarbone\UglyQueue $uglyQueue)
|
||||||
{
|
{
|
||||||
|
echo __FUNCTION__."\n";
|
||||||
$queueName = $uglyQueue->getName();
|
$queueName = $uglyQueue->getName();
|
||||||
|
|
||||||
$this->assertEquals('tasty-sandwich', $queueName);
|
$this->assertEquals('tasty-sandwich', $queueName);
|
||||||
@@ -118,6 +123,7 @@ class UglyQueueTest extends PHPUnit_Framework_TestCase
|
|||||||
*/
|
*/
|
||||||
public function testCanGetQueueLockedStatus(\DCarbone\UglyQueue $uglyQueue)
|
public function testCanGetQueueLockedStatus(\DCarbone\UglyQueue $uglyQueue)
|
||||||
{
|
{
|
||||||
|
echo __FUNCTION__."\n";
|
||||||
$locked = $uglyQueue->isLocked();
|
$locked = $uglyQueue->isLocked();
|
||||||
|
|
||||||
$this->assertFalse($locked);
|
$this->assertFalse($locked);
|
||||||
@@ -131,6 +137,7 @@ class UglyQueueTest extends PHPUnit_Framework_TestCase
|
|||||||
*/
|
*/
|
||||||
public function testGetQueueItemCountReturnsZeroWithEmptyQueue(\DCarbone\UglyQueue $uglyQueue)
|
public function testGetQueueItemCountReturnsZeroWithEmptyQueue(\DCarbone\UglyQueue $uglyQueue)
|
||||||
{
|
{
|
||||||
|
echo __FUNCTION__."\n";
|
||||||
$itemCount = count($uglyQueue);
|
$itemCount = count($uglyQueue);
|
||||||
$this->assertEquals(0, $itemCount);
|
$this->assertEquals(0, $itemCount);
|
||||||
}
|
}
|
||||||
@@ -142,6 +149,7 @@ class UglyQueueTest extends PHPUnit_Framework_TestCase
|
|||||||
*/
|
*/
|
||||||
public function testCanInitializeExistingQueue()
|
public function testCanInitializeExistingQueue()
|
||||||
{
|
{
|
||||||
|
echo __FUNCTION__."\n";
|
||||||
$uglyQueue = new \DCarbone\UglyQueue($this->baseDir, 'tasty-sandwich');
|
$uglyQueue = new \DCarbone\UglyQueue($this->baseDir, 'tasty-sandwich');
|
||||||
|
|
||||||
$this->assertInstanceOf('\\DCarbone\\UglyQueue', $uglyQueue);
|
$this->assertInstanceOf('\\DCarbone\\UglyQueue', $uglyQueue);
|
||||||
@@ -158,6 +166,7 @@ class UglyQueueTest extends PHPUnit_Framework_TestCase
|
|||||||
*/
|
*/
|
||||||
public function testExceptionThrownWhenPassingNonIntegerValueToLock(\DCarbone\UglyQueue $uglyQueue)
|
public function testExceptionThrownWhenPassingNonIntegerValueToLock(\DCarbone\UglyQueue $uglyQueue)
|
||||||
{
|
{
|
||||||
|
echo __FUNCTION__."\n";
|
||||||
$uglyQueue->lock('7 billion');
|
$uglyQueue->lock('7 billion');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -170,6 +179,7 @@ class UglyQueueTest extends PHPUnit_Framework_TestCase
|
|||||||
*/
|
*/
|
||||||
public function testExceptionThrownWhenPassingNegativeIntegerValueToLock(\DCarbone\UglyQueue $uglyQueue)
|
public function testExceptionThrownWhenPassingNegativeIntegerValueToLock(\DCarbone\UglyQueue $uglyQueue)
|
||||||
{
|
{
|
||||||
|
echo __FUNCTION__."\n";
|
||||||
$uglyQueue->lock(-73);
|
$uglyQueue->lock(-73);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -184,6 +194,7 @@ class UglyQueueTest extends PHPUnit_Framework_TestCase
|
|||||||
*/
|
*/
|
||||||
public function testCanLockUglyQueueWithDefaultTTL(\DCarbone\UglyQueue $uglyQueue)
|
public function testCanLockUglyQueueWithDefaultTTL(\DCarbone\UglyQueue $uglyQueue)
|
||||||
{
|
{
|
||||||
|
echo __FUNCTION__."\n";
|
||||||
$locked = $uglyQueue->lock();
|
$locked = $uglyQueue->lock();
|
||||||
|
|
||||||
$this->assertTrue($locked);
|
$this->assertTrue($locked);
|
||||||
@@ -209,6 +220,7 @@ class UglyQueueTest extends PHPUnit_Framework_TestCase
|
|||||||
*/
|
*/
|
||||||
public function testCannotLockQueueThatIsAlreadyLocked(\DCarbone\UglyQueue $uglyQueue)
|
public function testCannotLockQueueThatIsAlreadyLocked(\DCarbone\UglyQueue $uglyQueue)
|
||||||
{
|
{
|
||||||
|
echo __FUNCTION__."\n";
|
||||||
$lock = $uglyQueue->lock();
|
$lock = $uglyQueue->lock();
|
||||||
|
|
||||||
$this->assertFalse($lock);
|
$this->assertFalse($lock);
|
||||||
@@ -222,6 +234,7 @@ class UglyQueueTest extends PHPUnit_Framework_TestCase
|
|||||||
*/
|
*/
|
||||||
public function testIsLockedReturnsTrueAfterLocking(\DCarbone\UglyQueue $uglyQueue)
|
public function testIsLockedReturnsTrueAfterLocking(\DCarbone\UglyQueue $uglyQueue)
|
||||||
{
|
{
|
||||||
|
echo __FUNCTION__."\n";
|
||||||
$isLocked = $uglyQueue->isLocked();
|
$isLocked = $uglyQueue->isLocked();
|
||||||
$this->assertTrue($isLocked);
|
$this->assertTrue($isLocked);
|
||||||
}
|
}
|
||||||
@@ -236,6 +249,7 @@ class UglyQueueTest extends PHPUnit_Framework_TestCase
|
|||||||
*/
|
*/
|
||||||
public function testCanUnlockLockedQueue(\DCarbone\UglyQueue $uglyQueue)
|
public function testCanUnlockLockedQueue(\DCarbone\UglyQueue $uglyQueue)
|
||||||
{
|
{
|
||||||
|
echo __FUNCTION__."\n";
|
||||||
$uglyQueue->unlock();
|
$uglyQueue->unlock();
|
||||||
|
|
||||||
$this->assertFileNotExists($uglyQueue->getLockFile());
|
$this->assertFileNotExists($uglyQueue->getLockFile());
|
||||||
@@ -251,6 +265,7 @@ class UglyQueueTest extends PHPUnit_Framework_TestCase
|
|||||||
*/
|
*/
|
||||||
public function testIsLockedReturnsFalseAfterUnlockingQueue(\DCarbone\UglyQueue $uglyQueue)
|
public function testIsLockedReturnsFalseAfterUnlockingQueue(\DCarbone\UglyQueue $uglyQueue)
|
||||||
{
|
{
|
||||||
|
echo __FUNCTION__."\n";
|
||||||
$isLocked = $uglyQueue->isLocked();
|
$isLocked = $uglyQueue->isLocked();
|
||||||
|
|
||||||
$this->assertFalse($isLocked);
|
$this->assertFalse($isLocked);
|
||||||
@@ -266,6 +281,7 @@ class UglyQueueTest extends PHPUnit_Framework_TestCase
|
|||||||
*/
|
*/
|
||||||
public function testIsLockedReturnsFalseWithStaleQueueLockFile(\DCarbone\UglyQueue $uglyQueue)
|
public function testIsLockedReturnsFalseWithStaleQueueLockFile(\DCarbone\UglyQueue $uglyQueue)
|
||||||
{
|
{
|
||||||
|
echo __FUNCTION__."\n";
|
||||||
$uglyQueue->lock(2);
|
$uglyQueue->lock(2);
|
||||||
$isLocked = $uglyQueue->isLocked();
|
$isLocked = $uglyQueue->isLocked();
|
||||||
$this->assertTrue($isLocked);
|
$this->assertTrue($isLocked);
|
||||||
@@ -279,7 +295,6 @@ class UglyQueueTest extends PHPUnit_Framework_TestCase
|
|||||||
/**
|
/**
|
||||||
* @covers \DCarbone\UglyQueue::lock
|
* @covers \DCarbone\UglyQueue::lock
|
||||||
* @covers \DCarbone\UglyQueue::isLocked
|
* @covers \DCarbone\UglyQueue::isLocked
|
||||||
* @covers \DCarbone\UglyQueue::__get
|
|
||||||
* @uses \DCarbone\UglyQueue
|
* @uses \DCarbone\UglyQueue
|
||||||
* @depends testCanUnlockLockedQueue
|
* @depends testCanUnlockLockedQueue
|
||||||
* @param \DCarbone\UglyQueue $uglyQueue
|
* @param \DCarbone\UglyQueue $uglyQueue
|
||||||
@@ -287,6 +302,7 @@ class UglyQueueTest extends PHPUnit_Framework_TestCase
|
|||||||
*/
|
*/
|
||||||
public function testCanLockQueueWithValidIntegerValue(\DCarbone\UglyQueue $uglyQueue)
|
public function testCanLockQueueWithValidIntegerValue(\DCarbone\UglyQueue $uglyQueue)
|
||||||
{
|
{
|
||||||
|
echo __FUNCTION__."\n";
|
||||||
$locked = $uglyQueue->lock(200);
|
$locked = $uglyQueue->lock(200);
|
||||||
|
|
||||||
$this->assertTrue($locked);
|
$this->assertTrue($locked);
|
||||||
@@ -313,6 +329,7 @@ class UglyQueueTest extends PHPUnit_Framework_TestCase
|
|||||||
*/
|
*/
|
||||||
public function testCanPopulateQueueTempFileAfterInitializationAndAcquiringLock(\DCarbone\UglyQueue $uglyQueue)
|
public function testCanPopulateQueueTempFileAfterInitializationAndAcquiringLock(\DCarbone\UglyQueue $uglyQueue)
|
||||||
{
|
{
|
||||||
|
echo __FUNCTION__."\n";
|
||||||
foreach(array_reverse($this->tastySandwich, true) as $k=>$v)
|
foreach(array_reverse($this->tastySandwich, true) as $k=>$v)
|
||||||
{
|
{
|
||||||
$added = $uglyQueue->addItem($k, $v);
|
$added = $uglyQueue->addItem($k, $v);
|
||||||
@@ -339,6 +356,7 @@ class UglyQueueTest extends PHPUnit_Framework_TestCase
|
|||||||
*/
|
*/
|
||||||
public function testCanForciblyUpdateQueueFileFromTempFile(\DCarbone\UglyQueue $uglyQueue)
|
public function testCanForciblyUpdateQueueFileFromTempFile(\DCarbone\UglyQueue $uglyQueue)
|
||||||
{
|
{
|
||||||
|
echo __FUNCTION__."\n";
|
||||||
$uglyQueue->_populateQueue();
|
$uglyQueue->_populateQueue();
|
||||||
|
|
||||||
$this->assertFileNotExists($uglyQueue->getQueueTmpFile());
|
$this->assertFileNotExists($uglyQueue->getQueueTmpFile());
|
||||||
@@ -370,6 +388,7 @@ class UglyQueueTest extends PHPUnit_Framework_TestCase
|
|||||||
*/
|
*/
|
||||||
public function testKeyExistsReturnsTrueWithPopulatedQueue(\DCarbone\UglyQueue $uglyQueue)
|
public function testKeyExistsReturnsTrueWithPopulatedQueue(\DCarbone\UglyQueue $uglyQueue)
|
||||||
{
|
{
|
||||||
|
echo __FUNCTION__."\n";
|
||||||
$exists = $uglyQueue->keyExistsInQueue(5);
|
$exists = $uglyQueue->keyExistsInQueue(5);
|
||||||
|
|
||||||
$this->assertTrue($exists);
|
$this->assertTrue($exists);
|
||||||
@@ -384,6 +403,7 @@ class UglyQueueTest extends PHPUnit_Framework_TestCase
|
|||||||
*/
|
*/
|
||||||
public function testExceptionThrownWhenTryingToProcessLockedQueueWithNonInteger(\DCarbone\UglyQueue $uglyQueue)
|
public function testExceptionThrownWhenTryingToProcessLockedQueueWithNonInteger(\DCarbone\UglyQueue $uglyQueue)
|
||||||
{
|
{
|
||||||
|
echo __FUNCTION__."\n";
|
||||||
$uglyQueue->retrieveItems('Eleventy Billion');
|
$uglyQueue->retrieveItems('Eleventy Billion');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -396,6 +416,7 @@ class UglyQueueTest extends PHPUnit_Framework_TestCase
|
|||||||
*/
|
*/
|
||||||
public function testExceptionThrownWhenTryingToProcessLockedQueueWithIntegerLessThan1(\DCarbone\UglyQueue $uglyQueue)
|
public function testExceptionThrownWhenTryingToProcessLockedQueueWithIntegerLessThan1(\DCarbone\UglyQueue $uglyQueue)
|
||||||
{
|
{
|
||||||
|
echo __FUNCTION__."\n";
|
||||||
$uglyQueue->retrieveItems(0);
|
$uglyQueue->retrieveItems(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -410,6 +431,7 @@ class UglyQueueTest extends PHPUnit_Framework_TestCase
|
|||||||
*/
|
*/
|
||||||
public function testCanGetPartialQueueContents(\DCarbone\UglyQueue $uglyQueue)
|
public function testCanGetPartialQueueContents(\DCarbone\UglyQueue $uglyQueue)
|
||||||
{
|
{
|
||||||
|
echo __FUNCTION__."\n";
|
||||||
$process = $uglyQueue->retrieveItems(5);
|
$process = $uglyQueue->retrieveItems(5);
|
||||||
|
|
||||||
$this->assertEquals(5, count($process));
|
$this->assertEquals(5, count($process));
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ class UglyQueueManagerTest extends PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
protected function setUp()
|
protected function setUp()
|
||||||
{
|
{
|
||||||
$this->baseDir = __DIR__.'/../misc/queues';
|
$this->baseDir = realpath(__DIR__.'/../misc/queues');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -142,7 +142,7 @@ class UglyQueueManagerTest extends PHPUnit_Framework_TestCase
|
|||||||
*/
|
*/
|
||||||
public function testCanInitializeNewQueueAndAddToManager(\DCarbone\UglyQueueManager $manager)
|
public function testCanInitializeNewQueueAndAddToManager(\DCarbone\UglyQueueManager $manager)
|
||||||
{
|
{
|
||||||
$manager->addQueueAtPath(__DIR__.'/../misc/queues/really-tasty-sandwich');
|
$manager->addQueueAtPath($this->baseDir.'/really-tasty-sandwich');
|
||||||
|
|
||||||
$uglyQueue = $manager->getQueueWithName('really-tasty-sandwich');
|
$uglyQueue = $manager->getQueueWithName('really-tasty-sandwich');
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user