You've already forked ugly-queue
Some more tests and such.
This commit is contained in:
@@ -84,12 +84,12 @@ class UglyQueueManager implements \SplObserver, \SplSubject
|
|||||||
/**
|
/**
|
||||||
* @param UglyQueue $uglyQueue
|
* @param UglyQueue $uglyQueue
|
||||||
* @return \DCarbone\UglyQueueManager
|
* @return \DCarbone\UglyQueueManager
|
||||||
* @throws \InvalidArgumentException
|
* @throws \RuntimeException
|
||||||
*/
|
*/
|
||||||
public function addQueue(UglyQueue $uglyQueue)
|
public function addQueue(UglyQueue $uglyQueue)
|
||||||
{
|
{
|
||||||
if ($this->containsQueueWithName($uglyQueue->name))
|
if ($this->containsQueueWithName($uglyQueue->name))
|
||||||
throw new \InvalidArgumentException('Queue named "'.$uglyQueue->name.'" already exists in this manager.');
|
throw new \RuntimeException('Queue named "'.$uglyQueue->name.'" already exists in this manager.');
|
||||||
|
|
||||||
$this->queues[$uglyQueue->name] = $uglyQueue;
|
$this->queues[$uglyQueue->name] = $uglyQueue;
|
||||||
|
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ class UglyQueueTest extends PHPUnit_Framework_TestCase
|
|||||||
*/
|
*/
|
||||||
public function testCanInitializeUglyQueueWithValidConfigArrayAndNoObservers()
|
public function testCanInitializeUglyQueueWithValidConfigArrayAndNoObservers()
|
||||||
{
|
{
|
||||||
$uglyQueue = \DCarbone\UglyQueue::queueWithDirectoryPathAndObservers(dirname(__DIR__).'/misc/tasty-sandwich');
|
$uglyQueue = \DCarbone\UglyQueue::queueWithDirectoryPathAndObservers(dirname(__DIR__).'/misc/queues/tasty-sandwich');
|
||||||
|
|
||||||
$this->assertInstanceOf('\\DCarbone\\UglyQueue', $uglyQueue);
|
$this->assertInstanceOf('\\DCarbone\\UglyQueue', $uglyQueue);
|
||||||
|
|
||||||
@@ -170,7 +170,7 @@ class UglyQueueTest extends PHPUnit_Framework_TestCase
|
|||||||
*/
|
*/
|
||||||
public function testCanInitializeExistingQueue()
|
public function testCanInitializeExistingQueue()
|
||||||
{
|
{
|
||||||
$uglyQueue = \DCarbone\UglyQueue::queueWithDirectoryPathAndObservers(dirname(__DIR__).'/misc/tasty-sandwich');
|
$uglyQueue = \DCarbone\UglyQueue::queueWithDirectoryPathAndObservers(dirname(__DIR__).'/misc/queues/tasty-sandwich');
|
||||||
|
|
||||||
$this->assertInstanceOf('\\DCarbone\\UglyQueue', $uglyQueue);
|
$this->assertInstanceOf('\\DCarbone\\UglyQueue', $uglyQueue);
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,12 @@
|
|||||||
*/
|
*/
|
||||||
class UglyQueueManagerTest extends PHPUnit_Framework_TestCase
|
class UglyQueueManagerTest extends PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
|
protected $reallyTastySandwich = array(
|
||||||
|
'0' => 'beef broth',
|
||||||
|
'1' => 'barbeque sauce',
|
||||||
|
'2' => 'boneless pork ribs',
|
||||||
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers \DCarbone\UglyQueueManager::__construct
|
* @covers \DCarbone\UglyQueueManager::__construct
|
||||||
* @covers \DCarbone\UglyQueueManager::init
|
* @covers \DCarbone\UglyQueueManager::init
|
||||||
@@ -19,7 +25,7 @@ class UglyQueueManagerTest extends PHPUnit_Framework_TestCase
|
|||||||
public function testCanInitializeManagerWithConfigAndNoObservers()
|
public function testCanInitializeManagerWithConfigAndNoObservers()
|
||||||
{
|
{
|
||||||
$config = array(
|
$config = array(
|
||||||
'queue-base-dir' => __DIR__.'/../misc/'
|
'queue-base-dir' => __DIR__.'/../misc/queues'
|
||||||
);
|
);
|
||||||
|
|
||||||
$manager = \DCarbone\UglyQueueManager::init($config);
|
$manager = \DCarbone\UglyQueueManager::init($config);
|
||||||
@@ -85,6 +91,106 @@ class UglyQueueManagerTest extends PHPUnit_Framework_TestCase
|
|||||||
$this->assertFalse($shouldBeFalse);
|
$this->assertFalse($shouldBeFalse);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \DCarbone\UglyQueueManager::getQueueWithName
|
||||||
|
* @covers \DCarbone\UglyQueue::__get
|
||||||
|
* @uses \DCarbone\UglyQueueManager
|
||||||
|
* @uses \DCarbone\UglyQueue
|
||||||
|
* @depends testCanInitializeManagerWithConfigAndNoObservers
|
||||||
|
* @param \DCarbone\UglyQueueManager $manager
|
||||||
|
*/
|
||||||
|
public function testCanGetUglyQueueObjectFromManager(\DCarbone\UglyQueueManager $manager)
|
||||||
|
{
|
||||||
|
$uglyQueue = $manager->getQueueWithName('tasty-sandwich');
|
||||||
|
|
||||||
|
$this->assertInstanceOf('\\DCarbone\\UglyQueue', $uglyQueue);
|
||||||
|
$this->assertEquals('tasty-sandwich', $uglyQueue->name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \DCarbone\UglyQueueManager::getQueueWithName
|
||||||
|
* @uses \DCarbone\UglyQueueManager
|
||||||
|
* @expectedException \InvalidArgumentException
|
||||||
|
* @depends testCanInitializeManagerWithConfigAndNoObservers
|
||||||
|
* @param \DCarbone\UglyQueueManager $manager
|
||||||
|
*/
|
||||||
|
public function testExceptionThrownWhenTryingToGetNonExistentQueueFromManager(\DCarbone\UglyQueueManager $manager)
|
||||||
|
{
|
||||||
|
$shouldNotExist = $manager->getQueueWithName('sandwiches');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \DCarbone\UglyQueueManager::getQueueList
|
||||||
|
* @uses \DCarbone\UglyQueueManager
|
||||||
|
* @depends testCanInitializeManagerWithConfigAndNoObservers
|
||||||
|
* @param \DCarbone\UglyQueueManager $manager
|
||||||
|
*/
|
||||||
|
public function testCanGetListOfQueuesInManager(\DCarbone\UglyQueueManager $manager)
|
||||||
|
{
|
||||||
|
$queueList = $manager->getQueueList();
|
||||||
|
|
||||||
|
$this->assertInternalType('array', $queueList);
|
||||||
|
$this->assertCount(1, $queueList);
|
||||||
|
$this->assertContains('tasty-sandwich', $queueList);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \DCarbone\UglyQueueManager::getQueueWithName
|
||||||
|
* @covers \DCarbone\UglyQueueManager::addQueue
|
||||||
|
* @uses \DCarbone\UglyQueueManager
|
||||||
|
* @uses \DCarbone\UglyQueue
|
||||||
|
* @expectedException \RuntimeException
|
||||||
|
* @depends testCanInitializeManagerWithConfigAndNoObservers
|
||||||
|
* @param \DCarbone\UglyQueueManager $manager
|
||||||
|
*/
|
||||||
|
public function testExceptionThrownWhenReAddingQueueToManager(\DCarbone\UglyQueueManager $manager)
|
||||||
|
{
|
||||||
|
$uglyQueue = $manager->getQueueWithName('tasty-sandwich');
|
||||||
|
|
||||||
|
$manager->addQueue($uglyQueue);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \DCarbone\UglyQueueManager::addQueueAtPath
|
||||||
|
* @covers \DCarbone\UglyQueueManager::addQueue
|
||||||
|
* @covers \DCarbone\UglyQueueManager::getQueueWithName
|
||||||
|
* @uses \DCarbone\UglyQueueManager
|
||||||
|
* @uses \DCarbone\UglyQueue
|
||||||
|
* @depends testCanInitializeManagerWithConfigAndNoObservers
|
||||||
|
* @param \DCarbone\UglyQueueManager $manager
|
||||||
|
*/
|
||||||
|
public function testCanInitializeNewQueueAndAddToManager(\DCarbone\UglyQueueManager $manager)
|
||||||
|
{
|
||||||
|
$manager->addQueueAtPath(__DIR__.'/../misc/queues/really-tasty-sandwich');
|
||||||
|
|
||||||
|
$uglyQueue = $manager->getQueueWithName('really-tasty-sandwich');
|
||||||
|
|
||||||
|
$this->assertInstanceOf('\\DCarbone\\UglyQueue', $uglyQueue);
|
||||||
|
$this->assertEquals('really-tasty-sandwich', $uglyQueue->name);
|
||||||
|
|
||||||
|
$queueList = $manager->getQueueList();
|
||||||
|
|
||||||
|
$this->assertInternalType('array', $queueList);
|
||||||
|
$this->assertCount(2, $queueList);
|
||||||
|
$this->assertContains('really-tasty-sandwich', $queueList);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \DCarbone\UglyQueueManager::removeQueueByName
|
||||||
|
* @uses \DCarbone\UglyQueueManager
|
||||||
|
* @depends testCanInitializeManagerWithConfigAndNoObservers
|
||||||
|
* @param \DCarbone\UglyQueueManager $manager
|
||||||
|
*/
|
||||||
|
public function testCanRemoveQueueFromManagerByName(\DCarbone\UglyQueueManager $manager)
|
||||||
|
{
|
||||||
|
$manager->removeQueueByName('really-tasty-sandwich');
|
||||||
|
|
||||||
|
$queueList = $manager->getQueueList();
|
||||||
|
|
||||||
|
$this->assertCount(1, $queueList);
|
||||||
|
$this->assertNotContains('really-tasty-sandwich', $queueList);
|
||||||
|
}
|
||||||
|
|
||||||
// /**
|
// /**
|
||||||
// * @covers \DCarbone\UglyQueue::queueExists
|
// * @covers \DCarbone\UglyQueue::queueExists
|
||||||
// * @uses \DCarbone\UglyQueue
|
// * @uses \DCarbone\UglyQueue
|
||||||
|
|||||||
@@ -1,13 +1,22 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
if (is_dir(__DIR__.'/tasty-sandwich'))
|
if (is_dir(__DIR__.'/queues/'))
|
||||||
{
|
{
|
||||||
foreach(glob(__DIR__.'/tasty-sandwich/*') as $file)
|
foreach(glob(__DIR__.'/queues/*', GLOB_ONLYDIR) as $queueDir)
|
||||||
{
|
{
|
||||||
if (substr($file, -1) === '.')
|
foreach(glob($queueDir.'/*') as $file)
|
||||||
continue;
|
{
|
||||||
|
$split = preg_split('#[/\\\]+#', $file);
|
||||||
|
if (strpos(end($split), '.') === 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
unlink($file);
|
unlink($file);
|
||||||
|
}
|
||||||
|
|
||||||
|
rmdir($queueDir);
|
||||||
}
|
}
|
||||||
rmdir(__DIR__.'/tasty-sandwich');
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mkdir(__DIR__.'/queues');
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user