Fixing some issues noticed in test cases.

This commit is contained in:
2014-09-29 17:02:28 -05:00
parent 89c51468eb
commit 1e98b0cf7e
5 changed files with 98 additions and 259 deletions

View File

@@ -51,7 +51,7 @@ class UglyQueue implements \Serializable, \SplSubject
* @throws \InvalidArgumentException
* @return UglyQueue
*/
public static function queueWithGroupDirectoryPathAndObservers($directoryPath, array $observers = array())
public static function queueWithDirectoryPathAndObservers($directoryPath, array $observers = array())
{
if (!is_string($directoryPath))
throw new \InvalidArgumentException('Argument 1 expected to be string, '.gettype($directoryPath).' seen');
@@ -72,7 +72,7 @@ class UglyQueue implements \Serializable, \SplSubject
$uglyQueue = new UglyQueue();
$uglyQueue->observers = $observers;
$split = preg_split('#[/\\]+/#', $directoryPath);
$split = preg_split('#[/\\\]+#', $directoryPath);
$uglyQueue->_name = end($split);
$uglyQueue->_path = rtrim(realpath(implode(DIRECTORY_SEPARATOR, $split)), "/\\").DIRECTORY_SEPARATOR;
@@ -226,9 +226,9 @@ HTML;
{
$lock = json_decode(file_get_contents($this->_path.'queue.lock'), true);
// If we have an invalid lock structure, THIS IS BAD.
// If we have an invalid lock structure.
if (!isset($lock['ttl']) || !isset($lock['born']))
throw new \RuntimeException(get_class($this).'::isLocked - Invalid "queue.lock" file structure seen at "'.$this->_path.'queue.lock'.'"');
throw new \RuntimeException('Invalid "queue.lock" file structure seen at "'.$this->_path.'queue.lock".');
// Otherwise...
$lock_ttl = ((int)$lock['born'] + (int)$lock['ttl']);
@@ -414,7 +414,7 @@ HTML;
// Try to open the file for reading / writing.
$queueFileHandle = fopen($this->_path.'queue.txt', 'r');
while(($line = fscanf($queueFileHandle, "%s\t")) !== false)
while(($line = fscanf($queueFileHandle, "%s\t%s\n")) !== false)
{
list ($lineKey, $lineValue) = $line;

View File

@@ -76,7 +76,7 @@ class UglyQueueManager implements \SplObserver, \SplSubject
if (file_exists($queueDir.DIRECTORY_SEPARATOR.self::UGLY_QUEUE_SERIALIZED_NAME))
$uglyQueue = unserialize(file_get_contents($queueDir.DIRECTORY_SEPARATOR.self::UGLY_QUEUE_SERIALIZED_NAME));
else
$uglyQueue = UglyQueue::queueWithGroupDirectoryPathAndObservers($queueDir, $manager->observers);
$uglyQueue = UglyQueue::queueWithDirectoryPathAndObservers($queueDir, $manager->observers);
$manager->addQueue($uglyQueue);
}
@@ -109,7 +109,7 @@ class UglyQueueManager implements \SplObserver, \SplSubject
*/
public function addQueueAtPath($path)
{
$uglyQueue = UglyQueue::queueWithGroupDirectoryPathAndObservers($path, $this->observers);
$uglyQueue = UglyQueue::queueWithDirectoryPathAndObservers($path, $this->observers);
return $this->addQueue($uglyQueue);
}