You've already forked ugly-queue
Adding some test cases for UglyQueueManager
This commit is contained in:
@@ -256,8 +256,7 @@ HTML;
|
||||
public function processQueue($count = 1)
|
||||
{
|
||||
if ($this->mode === self::QUEUE_READONLY)
|
||||
throw new \RuntimeException('Queue "'.$this->_name.'" cannot be processed.'.
|
||||
' It was started in Read-Only mode (the user running this process does not have permission to write to the queue directory).');
|
||||
throw new \RuntimeException('Queue "'.$this->_name.'" cannot be processed. It was started in Read-Only mode (the user running this process does not have permission to write to the queue directory).');
|
||||
|
||||
// If we don't have a lock, assume issue and move on.
|
||||
if ($this->_locked === false)
|
||||
|
||||
@@ -43,8 +43,6 @@ class UglyQueueManager implements \SplObserver, \SplSubject
|
||||
if (!is_dir($config['queue-base-dir']))
|
||||
throw new \RuntimeException('"queue-base-dir" points to a directory that does not exist.');
|
||||
|
||||
$this->notifyStatus = self::NOTIFY_MANAGER_INITIALIZED;
|
||||
|
||||
$this->config = $config;
|
||||
$this->queueBaseDir = rtrim(realpath($this->config['queue-base-dir']), "/\\").DIRECTORY_SEPARATOR;
|
||||
$this->observers = $observers;
|
||||
@@ -58,18 +56,14 @@ class UglyQueueManager implements \SplObserver, \SplSubject
|
||||
public static function init(array $config, array $observers = array())
|
||||
{
|
||||
/** @var \DCarbone\UglyQueueManager $manager */
|
||||
$manager = new static($config, array());
|
||||
|
||||
$manager->observers = $observers;
|
||||
|
||||
$manager->notify();
|
||||
$manager = new static($config, $observers);
|
||||
|
||||
/** @var \DCarbone\UglyQueue $uglyQueue */
|
||||
|
||||
foreach(glob($manager->queueBaseDir.DIRECTORY_SEPARATOR.'*', GLOB_ONLYDIR) as $queueDir)
|
||||
{
|
||||
// Try to avoid looking at hidden directories or magic dirs such as '.' and '..'
|
||||
$split = preg_split('#[/\\]+#', $queueDir);
|
||||
$split = preg_split('#[/\\\]+#', $queueDir);
|
||||
if (strpos(end($split), '.') === 0)
|
||||
continue;
|
||||
|
||||
@@ -81,6 +75,9 @@ class UglyQueueManager implements \SplObserver, \SplSubject
|
||||
$manager->addQueue($uglyQueue);
|
||||
}
|
||||
|
||||
$manager->notifyStatus = self::NOTIFY_MANAGER_INITIALIZED;
|
||||
$manager->notify();
|
||||
|
||||
return $manager;
|
||||
}
|
||||
|
||||
@@ -91,10 +88,9 @@ class UglyQueueManager implements \SplObserver, \SplSubject
|
||||
*/
|
||||
public function addQueue(UglyQueue $uglyQueue)
|
||||
{
|
||||
if ($this->queueExistsByName($uglyQueue->name))
|
||||
if ($this->containsQueueWithName($uglyQueue->name))
|
||||
throw new \InvalidArgumentException('Queue named "'.$uglyQueue->name.'" already exists in this manager.');
|
||||
|
||||
|
||||
$this->queues[$uglyQueue->name] = $uglyQueue;
|
||||
|
||||
$this->notifyStatus = self::NOTIFY_QUEUE_ADDED;
|
||||
@@ -120,7 +116,7 @@ class UglyQueueManager implements \SplObserver, \SplSubject
|
||||
*/
|
||||
public function removeQueue(UglyQueue $uglyQueue)
|
||||
{
|
||||
if ($this->queueExistsByName($uglyQueue->name))
|
||||
if ($this->containsQueueWithName($uglyQueue->name))
|
||||
unset($this->queues[$uglyQueue->name]);
|
||||
|
||||
return $this;
|
||||
@@ -132,7 +128,7 @@ class UglyQueueManager implements \SplObserver, \SplSubject
|
||||
*/
|
||||
public function removeQueueByName($name)
|
||||
{
|
||||
if ($this->queueExistsByName($name))
|
||||
if ($this->containsQueueWithName($name))
|
||||
{
|
||||
unset($this->queues[$name]);
|
||||
$this->notifyStatus = self::NOTIFY_QUEUE_REMOVED;
|
||||
@@ -159,7 +155,7 @@ class UglyQueueManager implements \SplObserver, \SplSubject
|
||||
* @param string $name
|
||||
* @return bool
|
||||
*/
|
||||
public function queueExistsByName($name)
|
||||
public function containsQueueWithName($name)
|
||||
{
|
||||
return isset($this->queues[$name]);
|
||||
}
|
||||
|
||||
@@ -113,6 +113,31 @@ class UglyQueueTest extends PHPUnit_Framework_TestCase
|
||||
$this->assertEquals('tasty-sandwich', $queueName);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \DCarbone\UglyQueue::__get
|
||||
* @uses \DCarbone\UglyQueue
|
||||
* @depends testCanInitializeUglyQueueWithValidConfigArrayAndNoObservers
|
||||
* @param \DCarbone\UglyQueue $uglyQueue
|
||||
*/
|
||||
public function testCanGetQueueLockedStatus(\DCarbone\UglyQueue $uglyQueue)
|
||||
{
|
||||
$locked = $uglyQueue->locked;
|
||||
|
||||
$this->assertFalse($locked);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \DCarbone\UglyQueue::__get
|
||||
* @uses \DCarbone\UglyQueue
|
||||
* @expectedException \OutOfBoundsException
|
||||
* @depends testCanInitializeUglyQueueWithValidConfigArrayAndNoObservers
|
||||
* @param \DCarbone\UglyQueue $uglyQueue
|
||||
*/
|
||||
public function testExceptionThrownWhenAttemptingToGetInvalidProperty(\DCarbone\UglyQueue $uglyQueue)
|
||||
{
|
||||
$sandwich = $uglyQueue->sandwich;
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \DCarbone\UglyQueue::isLocked
|
||||
* @uses \DCarbone\UglyQueue
|
||||
|
||||
@@ -5,6 +5,59 @@
|
||||
*/
|
||||
class UglyQueueManagerTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \DCarbone\UglyQueueManager::__construct
|
||||
* @covers \DCarbone\UglyQueueManager::init
|
||||
* @covers \DCarbone\UglyQueue::unserialize
|
||||
* @covers \DCarbone\UglyQueueManager::addQueue
|
||||
* @covers \DCarbone\UglyQueueManager::containsQueueWithName
|
||||
* @uses \DCarbone\UglyQueueManager
|
||||
* @uses \DCarbone\UglyQueue
|
||||
* @return \DCarbone\UglyQueueManager
|
||||
*/
|
||||
public function testCanInitializeManagerWithConfigAndNoObservers()
|
||||
{
|
||||
$config = array(
|
||||
'queue-base-dir' => __DIR__.'/../misc/'
|
||||
);
|
||||
|
||||
$manager = \DCarbone\UglyQueueManager::init($config);
|
||||
|
||||
$this->assertInstanceOf('\\DCarbone\\UglyQueueManager', $manager);
|
||||
|
||||
return $manager;
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \DCarbone\UglyQueueManager::init
|
||||
* @covers \DCarbone\UglyQueueManager::__construct
|
||||
* @uses \DCarbone\UglyQueueManager
|
||||
* @expectedException \RuntimeException
|
||||
*/
|
||||
public function testExceptionThrownDuringConstructionWithInvalidBasePathValue()
|
||||
{
|
||||
$config = array(
|
||||
'queue-base-dir' => 'i do not exist!'
|
||||
);
|
||||
|
||||
$manager = \DCarbone\UglyQueueManager::init($config);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \DCarbone\UglyQueueManager::init
|
||||
* @covers \DCarbone\UglyQueueManager::__construct
|
||||
* @uses \DCarbone\UglyQueueManager
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testExceptionThrownDuringConstructionWithInvalidConfArray()
|
||||
{
|
||||
$config = array(
|
||||
'wrong-key' => 'wrong value'
|
||||
);
|
||||
|
||||
$manager = \DCarbone\UglyQueueManager::init($config);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * @covers \DCarbone\UglyQueue::queueExists
|
||||
// * @uses \DCarbone\UglyQueue
|
||||
|
||||
Reference in New Issue
Block a user