You've already forked ugly-queue
More test methods and slight modifications to UglyQueue
This commit is contained in:
@@ -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'];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -130,14 +132,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))
|
||||||
@@ -293,22 +293,6 @@ HTML;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getQueueGroup()
|
|
||||||
{
|
|
||||||
return $this->queueGroup;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getQueueBaseDir()
|
|
||||||
{
|
|
||||||
return $this->queueBaseDir;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return int|null
|
* @return int|null
|
||||||
* @throws \RuntimeException
|
* @throws \RuntimeException
|
||||||
@@ -352,4 +336,36 @@ HTML;
|
|||||||
fclose($queue_file_handle);
|
fclose($queue_file_handle);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public function getInit()
|
||||||
|
{
|
||||||
|
return $this->init;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getQueueBaseDir()
|
||||||
|
{
|
||||||
|
return $this->queueBaseDir;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getQueueGroupDirPath()
|
||||||
|
{
|
||||||
|
return $this->queueGroupDirPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getQueueGroup()
|
||||||
|
{
|
||||||
|
return $this->queueGroup;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
date_default_timezone_set('UTC');
|
||||||
|
|
||||||
|
require_once __DIR__.'/../misc/cleanup.php';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class UglyQueueTest
|
* Class UglyQueueTest
|
||||||
*/
|
*/
|
||||||
@@ -66,25 +70,162 @@ class UglyQueueTest extends PHPUnit_Framework_TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers \DCarbone\UglyQueue::initialize
|
* @covers \DCarbone\UglyQueue::getQueueBaseDir
|
||||||
* @uses \DCarbone\UglyQueue
|
* @uses \DCarbone\UglyQueue
|
||||||
* @depends testCanConstructUglyQueueWithValidParameter
|
* @depends testCanConstructUglyQueueWithValidParameter
|
||||||
* @param \DCarbone\UglyQueue $uglyQueue
|
* @param \DCarbone\UglyQueue $uglyQueue
|
||||||
*/
|
*/
|
||||||
public function testCanInitializeExistingQueue(\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::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');
|
$uglyQueue->initialize('tasty-sandwich');
|
||||||
|
|
||||||
$this->assertTrue(
|
$this->assertTrue($uglyQueue->getInit());
|
||||||
is_dir($uglyQueue->getQueueBaseDir().$uglyQueue->getQueueGroup().'/'),
|
|
||||||
'Could not verify existence of queue group dir');
|
|
||||||
|
|
||||||
$this->assertTrue(
|
return $uglyQueue;
|
||||||
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');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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::initialize
|
||||||
|
* @covers \DCarbone\UglyQueue::__construct
|
||||||
|
* @covers \DCarbone\UglyQueue::getInit
|
||||||
|
* @uses \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());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \DCarbone\UglyQueue::lock
|
||||||
|
* @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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
4
tests/misc/cleanup.php
Normal file
4
tests/misc/cleanup.php
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
if (is_dir(__DIR__.'/tasty-sandwich'))
|
||||||
|
\DCarbone\Helpers\FileHelper::superUnlink(__DIR__.'/tasty-sandwich');
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title>403 Forbidden</title>
|
<title>403 Forbidden</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<p>Directory access is forbidden.</p>
|
<p>Directory access is forbidden.</p>
|
||||||
|
|||||||
Reference in New Issue
Block a user