You've already forked ugly-queue
Compare commits
26 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a6ecf19932 | |||
| 942c4e8699 | |||
| d9d01fcbb3 | |||
| de1973025f | |||
| dede25ec32 | |||
| 607d3a9004 | |||
| 032be45f9f | |||
| afbddabea2 | |||
| 2ec085419f | |||
| 7657af0a55 | |||
| 8b87324850 | |||
| 25c80c4baf | |||
| afc24185d3 | |||
| e1cac1e31d | |||
| 0c05079327 | |||
| 7526e04e08 | |||
| b84bde262e | |||
| a2b204fa47 | |||
| f03508bf3e | |||
| 49677e8bf2 | |||
| 50601bc3c8 | |||
| d935032ec3 | |||
| 232e228475 | |||
| d40357df73 | |||
| 4020de5223 | |||
| 13df907166 |
23
.github/workflows/build.yml
vendored
Normal file
23
.github/workflows/build.yml
vendored
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
name: CI
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- "**"
|
||||||
|
tags:
|
||||||
|
- "!**"
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
release:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- name: Create Release Archive
|
||||||
|
id: semrelease
|
||||||
|
uses: go-semantic-release/action@v1
|
||||||
|
with:
|
||||||
|
# custom-arguments: --provider=gitea
|
||||||
|
hooks: exec
|
||||||
|
env:
|
||||||
|
GITEA_TOKEN: ${{ secrets.G_TOKEN }}
|
||||||
|
GITEA_HOST: ${{ secrets.G_SERVER_URL}}
|
||||||
|
|
||||||
24
.github/workflows/dist.yml
vendored
Normal file
24
.github/workflows/dist.yml
vendored
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
name: Create Distribution
|
||||||
|
run-name: Distribute composer package with Gitea Actions 🚀
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- 'v*'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
dist:
|
||||||
|
name: Create Archive
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4 # Checkout Sourcecode
|
||||||
|
- uses: https://hub.cybercinch.nz/cybercinch/composer-build-action@v1
|
||||||
|
- run: |
|
||||||
|
ls -lah
|
||||||
|
- uses: https://hub.cybercinch.nz/guisea/gitea-composer-upload-action@v1
|
||||||
|
with:
|
||||||
|
base_url: "${{ secrets.G_SERVER_URL}}"
|
||||||
|
access_token: "${{ secrets.G_TOKEN }}"
|
||||||
|
username: "${{ secrets.G_USERNAME }}"
|
||||||
|
owner: "cybercinch" # Override owner name for repository (Optional)
|
||||||
|
package_version: "${{ env.GITHUB_REF_NAME }}"
|
||||||
|
|
||||||
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
**/vendor
|
||||||
|
tests/misc/*
|
||||||
|
!tests/misc/cleanup.php
|
||||||
|
!tests/misc/index.html
|
||||||
21
.semrelrc
Normal file
21
.semrelrc
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
{
|
||||||
|
"plugins": {
|
||||||
|
"provider": {
|
||||||
|
"name": "gitea"
|
||||||
|
},
|
||||||
|
"changelog-generator": {
|
||||||
|
"name": "default",
|
||||||
|
"options": {
|
||||||
|
"emojis": "true"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"hooks": {
|
||||||
|
"names": [
|
||||||
|
"exec"
|
||||||
|
],
|
||||||
|
"options": {
|
||||||
|
"exec_on_no_release": "echo {{.Reason}}: {{.Message}}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
language: php
|
language: php
|
||||||
|
|
||||||
|
sudo: false
|
||||||
|
|
||||||
php:
|
php:
|
||||||
- 5.3.3
|
- 5.3.3
|
||||||
- 5.3
|
- 5.3
|
||||||
@@ -8,9 +10,8 @@ php:
|
|||||||
- 5.6
|
- 5.6
|
||||||
|
|
||||||
before_script:
|
before_script:
|
||||||
- composer self-update
|
- composer self-update 1.0.0-alpha10
|
||||||
- composer update --prefer-source
|
- composer install --no-interaction --prefer-source
|
||||||
- composer install --no-interaction --dev --prefer-source
|
|
||||||
|
|
||||||
script:
|
script:
|
||||||
- ./vendor/bin/phpunit
|
- ./vendor/bin/phpunit
|
||||||
|
|||||||
2
LICENSE
2
LICENSE
@@ -652,7 +652,7 @@ Also add information on how to contact you by electronic and paper mail.
|
|||||||
If the program does terminal interaction, make it output a short
|
If the program does terminal interaction, make it output a short
|
||||||
notice like this when it starts in an interactive mode:
|
notice like this when it starts in an interactive mode:
|
||||||
|
|
||||||
{project} Copyright (C) {year} {fullname}
|
dcarbone/ugly-queue Copyright (C) 2015 Daniel Paul Carbone
|
||||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||||
This is free software, and you are welcome to redistribute it
|
This is free software, and you are welcome to redistribute it
|
||||||
under certain conditions; type `show c' for details.
|
under certain conditions; type `show c' for details.
|
||||||
|
|||||||
91
README.md
91
README.md
@@ -1,10 +1,91 @@
|
|||||||
ugly-queue
|
ugly-queue
|
||||||
==========
|
==========
|
||||||
|
|
||||||
A simple file-based queue system for PHP 5.3.3+
|
A simple file-based FIFO queue system for PHP 5.3.3+
|
||||||
|
|
||||||
Build statuses:
|
Build status: [](https://travis-ci.org/Cybercinch/ugly-queue)
|
||||||
- master: [](https://travis-ci.org/dcarbone/ugly-queue)
|
|
||||||
- 0.3.0: [](https://travis-ci.org/dcarbone/ugly-queue)
|
|
||||||
|
|
||||||
Documentation and Test suites forthcoming.
|
## Installation
|
||||||
|
This library is designed to be installed into your app using [https://getcomposer.org/](Composer).
|
||||||
|
Simply copy-paste the following line into your `"requires:"` hash:
|
||||||
|
|
||||||
|
```json
|
||||||
|
"dcarbone/ugly-queue": "0.4.*"
|
||||||
|
```
|
||||||
|
|
||||||
|
## Basic Usage
|
||||||
|
Once installed, you must first initialize an instance of [src/UglyQueueManager.php](UglyQueueManager).
|
||||||
|
This is done as such:
|
||||||
|
|
||||||
|
```php
|
||||||
|
$queueBaseDir = 'path to where you would like queue files and directories to be stored';
|
||||||
|
|
||||||
|
$manager = new UglyQueueManager($queueBaseDir);
|
||||||
|
```
|
||||||
|
|
||||||
|
Once initialized, you can start adding queues!
|
||||||
|
|
||||||
|
```php
|
||||||
|
$sandwichQueue = $manager->createQueue('sandwiches');
|
||||||
|
|
||||||
|
$sandwichQueue->lock();
|
||||||
|
|
||||||
|
$sandwichQueue->addItems(array(
|
||||||
|
'bread',
|
||||||
|
'meat',
|
||||||
|
'cheese',
|
||||||
|
'lettuce',
|
||||||
|
'bread'
|
||||||
|
));
|
||||||
|
|
||||||
|
$sandwichQueue->unlock();
|
||||||
|
```
|
||||||
|
|
||||||
|
Once you have items added to the queue, you can either pull items out ad-hoc or set up some sort of cron
|
||||||
|
or schedule task to process items regularly.
|
||||||
|
|
||||||
|
If the base directory for all of your queues remains the same, each initialization
|
||||||
|
of `UglyQueueManager` will automatically find and initialize instances of pre-existing
|
||||||
|
UglyQueues.
|
||||||
|
|
||||||
|
In a subsequent request, simply do the following:
|
||||||
|
|
||||||
|
```php
|
||||||
|
$queueBaseDir = 'path to where you would like queue files and directories to be stored';
|
||||||
|
|
||||||
|
$manager = new UglyQueueManager($queueBaseDir);
|
||||||
|
|
||||||
|
$tastySandwich = $manager->getQueue('sandwiches');
|
||||||
|
|
||||||
|
// 'sandwiches' queue will exist now
|
||||||
|
|
||||||
|
$tastySandwich->lock();
|
||||||
|
|
||||||
|
// Specify the number of items you wish to retrieve from the queue
|
||||||
|
|
||||||
|
$items = $tastySandwich->retrieveItems(4);
|
||||||
|
|
||||||
|
// $items is now an array...
|
||||||
|
|
||||||
|
var_export($items);
|
||||||
|
|
||||||
|
/*
|
||||||
|
array (
|
||||||
|
4 => 'bread',
|
||||||
|
3 => 'lettuce',
|
||||||
|
2 => 'cheese',
|
||||||
|
1 => 'meat',
|
||||||
|
)
|
||||||
|
*/
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
The queue will then retain a single item, `0 => 'bread'` as the 5th item left in the queue.
|
||||||
|
|
||||||
|
At any time you can determine how many items remain in a queue by executing `count($queueObj);`
|
||||||
|
|
||||||
|
There are a few limitations currently:
|
||||||
|
|
||||||
|
1. This lib is designed for small values without much in the way of formatting or line breaks
|
||||||
|
2. It is designed to be atomic, meaning that only one process can be adding / retrieving items from
|
||||||
|
a queue at a time. Reading actions (count, searching, etc) are NOT atomic, however.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"name" : "dcarbone/ugly-queue",
|
"name" : "cybercinch/ugly-queue",
|
||||||
"type" : "library",
|
"type" : "library",
|
||||||
"description" : "A simple file-based queue system for PHP 5.3.3+",
|
"description" : "A simple file-based queue system for PHP 5.3.3+",
|
||||||
|
|
||||||
@@ -9,28 +9,32 @@
|
|||||||
"file queue",
|
"file queue",
|
||||||
"ugly queue"
|
"ugly queue"
|
||||||
],
|
],
|
||||||
"homepage": "https://github.com/dcarbone/ugly-queue",
|
"homepage": "https://hub.cybercinch.nz/cybercinch/ugly-queue",
|
||||||
"license": "GPLv3",
|
"license": "GPLv3",
|
||||||
|
|
||||||
"authors" : [
|
"authors" : [
|
||||||
{
|
{
|
||||||
"name" : "Daniel Carbone",
|
"name" : "Daniel Carbone",
|
||||||
"email" : "daniel.p.carbone@gmail.com"
|
"email" : "daniel.p.carbone@gmail.com"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name" : "Aaron Guise",
|
||||||
|
"email" : "aaron-composer@guise.net.nz"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|
||||||
"require" : {
|
"require" : {
|
||||||
"php" : ">=5.3.3",
|
"php" : ">=7.1",
|
||||||
"dcarbone/helpers" : "~6.1"
|
"dcarbone/helpers" : "~6.1"
|
||||||
},
|
},
|
||||||
|
|
||||||
"require-dev" : {
|
"require-dev" : {
|
||||||
"phpunit/phpunit": "~4.1"
|
"phpunit/phpunit": "~9.6.21"
|
||||||
},
|
},
|
||||||
|
|
||||||
"autoload" : {
|
"autoload" : {
|
||||||
"psr-4" : {
|
"psr-4" : {
|
||||||
"DCarbone\\" : "src/"
|
"Cybercinch\\" : "src/"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
32
scripts/build.sh
Executable file
32
scripts/build.sh
Executable file
@@ -0,0 +1,32 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
mkdir -p ./build/
|
||||||
|
echo "Made temporary directory"
|
||||||
|
|
||||||
|
# Package up the release (Needs to be .zip for upload to gitea)
|
||||||
|
|
||||||
|
zip -r "./build/Package.zip" \
|
||||||
|
. \
|
||||||
|
-x '.semrel/*' \
|
||||||
|
-x '.generated-go-semantic-release-changelog.md' \
|
||||||
|
-x './vendor/*' \
|
||||||
|
-x './tests/*' \
|
||||||
|
-x './build/*' \
|
||||||
|
-x './.git/*' \
|
||||||
|
-x './.idea/*' \
|
||||||
|
-x './.github/*' \
|
||||||
|
-x './scripts/*'
|
||||||
|
|
||||||
|
#RELEASE_ID=$(curl --silent -X 'GET' "${GITEA_HOST}/api/v1/repos/cybercinch/ugly-queue/releases/latest" \
|
||||||
|
#-H "accept: application/json" \
|
||||||
|
#-H "Authorization: token ${GITEA_TOKEN}" | jq -r .id)
|
||||||
|
#
|
||||||
|
## Attach to release
|
||||||
|
#curl --silent -X 'POST' "${GITEA_HOST}/api/v1/repos/cybercinch/ugly-queue/releases/${RELEASE_ID}/assets?name=ugly-queue-${1}.tar.gz" \
|
||||||
|
#-H "Authorization: token ${GITEA_TOKEN}" \
|
||||||
|
#--form attachment="@build/ugly-queue-${1}.tar.gz"
|
||||||
|
|
||||||
|
# Upload the artifact to composer registry
|
||||||
|
curl --user "cibot:${GITEA_TOKEN}" \
|
||||||
|
--upload-file "build/ugly-queue.zip" \
|
||||||
|
"${GITEA_HOST}/api/packages/cybercinch/composer?version=${1}"
|
||||||
@@ -1,133 +1,74 @@
|
|||||||
<?php namespace DCarbone;
|
<?php namespace Cybercinch;
|
||||||
|
|
||||||
use DCarbone\Helpers\FileHelper;
|
use DCarbone\Helpers\FileHelper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class UglyQueue
|
* Class UglyQueue
|
||||||
* @package DCarbone
|
* @package Cybercinch
|
||||||
*
|
|
||||||
* @property string name
|
|
||||||
* @property string path
|
|
||||||
* @property bool locked
|
|
||||||
*/
|
*/
|
||||||
class UglyQueue implements \Serializable, \SplSubject, \Countable
|
class UglyQueue implements \Serializable, \SplSubject, \Countable
|
||||||
{
|
{
|
||||||
/** @var int */
|
|
||||||
public $notifyStatus;
|
|
||||||
|
|
||||||
const QUEUE_READONLY = 0;
|
const QUEUE_READONLY = 0;
|
||||||
const QUEUE_READWRITE = 1;
|
const QUEUE_READWRITE = 1;
|
||||||
|
|
||||||
/** @var array */
|
/** @var int */
|
||||||
private $observers = array();
|
private $_notifyStatus;
|
||||||
|
|
||||||
|
/** @var \SplObserver[] */
|
||||||
|
private $_observers = array();
|
||||||
|
|
||||||
/** @var int */
|
/** @var int */
|
||||||
protected $mode = null;
|
protected $mode = null;
|
||||||
|
|
||||||
/** @var string */
|
/** @var string */
|
||||||
protected $_name;
|
protected $baseDir;
|
||||||
|
|
||||||
/** @var string */
|
/** @var string */
|
||||||
protected $_path;
|
protected $name;
|
||||||
|
|
||||||
|
/** @var string */
|
||||||
|
protected $path;
|
||||||
|
|
||||||
/** @var bool */
|
/** @var bool */
|
||||||
protected $_locked = false;
|
protected $locked = false;
|
||||||
|
|
||||||
/** @var resource */
|
/** @var resource */
|
||||||
protected $_tmpHandle;
|
protected $tmpHandle;
|
||||||
|
|
||||||
|
/** @var string */
|
||||||
|
protected $queueFile;
|
||||||
|
|
||||||
|
/** @var string */
|
||||||
|
protected $queueTmpFile;
|
||||||
|
|
||||||
|
/** @var string */
|
||||||
|
protected $lockFile;
|
||||||
|
|
||||||
|
/** @var string */
|
||||||
|
protected $serializeFile;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $directoryPath
|
* @param string $baseDir
|
||||||
* @param array $observers
|
* @param string $name
|
||||||
* @throws \RuntimeException
|
* @param \SplObserver[] $observers
|
||||||
* @throws \InvalidArgumentException
|
|
||||||
* @return UglyQueue
|
|
||||||
*/
|
*/
|
||||||
public static function queueWithDirectoryPathAndObservers($directoryPath, array $observers = array())
|
public function __construct($baseDir, $name, array $observers = array())
|
||||||
{
|
{
|
||||||
if (!is_string($directoryPath))
|
$this->baseDir = realpath($baseDir);
|
||||||
throw new \InvalidArgumentException('Argument 1 expected to be string, '.gettype($directoryPath).' seen');
|
$this->name = $name;
|
||||||
|
$this->_observers = $observers;
|
||||||
|
|
||||||
if (($directoryPath = trim($directoryPath)) === '')
|
$path = sprintf('%s%s%s', $baseDir, DIRECTORY_SEPARATOR, $name);
|
||||||
throw new \InvalidArgumentException('Empty string passed for argument 1');
|
if (!file_exists($path) && !@mkdir($path))
|
||||||
|
throw new \RuntimeException('Unable to initialize queue directory "'.$path.'". Please check permissions.');
|
||||||
|
|
||||||
if (file_exists($directoryPath))
|
$this->path = $path;
|
||||||
{
|
$this->lockFile = sprintf('%s%squeue.lock', $path, DIRECTORY_SEPARATOR);
|
||||||
if (!is_dir($directoryPath))
|
$this->queueFile = sprintf('%s%squeue.txt', $path, DIRECTORY_SEPARATOR);
|
||||||
throw new \RuntimeException('Argument 1 expected to be path to directory, path to non-directory seen');
|
$this->queueTmpFile = sprintf('%s%squeue.tmp', $path, DIRECTORY_SEPARATOR);
|
||||||
}
|
$this->serializeFile = sprintf('%s%sugly-queue.obj', $path, DIRECTORY_SEPARATOR);
|
||||||
else if (!@mkdir($directoryPath))
|
|
||||||
{
|
|
||||||
throw new \RuntimeException('Unable to create queue directory at path: "'.$directoryPath.'".');
|
|
||||||
}
|
|
||||||
|
|
||||||
$uglyQueue = new UglyQueue();
|
$this->initialize();
|
||||||
$uglyQueue->observers = $observers;
|
|
||||||
|
|
||||||
$split = preg_split('#[/\\\]+#', $directoryPath);
|
|
||||||
|
|
||||||
$uglyQueue->_name = end($split);
|
|
||||||
$uglyQueue->_path = rtrim(realpath(implode(DIRECTORY_SEPARATOR, $split)), "/\\").DIRECTORY_SEPARATOR;
|
|
||||||
|
|
||||||
if (is_writable($uglyQueue->_path))
|
|
||||||
$uglyQueue->mode = self::QUEUE_READWRITE;
|
|
||||||
else if (is_readable($uglyQueue->_path))
|
|
||||||
$uglyQueue->mode = self::QUEUE_READONLY;
|
|
||||||
|
|
||||||
// Insert "don't look here" index.html file
|
|
||||||
if (!file_exists($uglyQueue->_path.'index.html'))
|
|
||||||
{
|
|
||||||
if ($uglyQueue->mode === self::QUEUE_READONLY)
|
|
||||||
throw new \RuntimeException('Cannot initialize queue with name "'.$uglyQueue->_name.'", the user lacks permission to create files.');
|
|
||||||
|
|
||||||
$html = <<<HTML
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>403 Forbidden</title>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<p>Directory access is forbidden.</p>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
HTML;
|
|
||||||
file_put_contents($uglyQueue->_path.'index.html', $html);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!file_exists($uglyQueue->_path.'queue.txt'))
|
|
||||||
{
|
|
||||||
if ($uglyQueue->mode === self::QUEUE_READONLY)
|
|
||||||
throw new \RuntimeException('Cannot initialize queue with name "'.$uglyQueue->_name.'", the user lacks permission to create files.');
|
|
||||||
|
|
||||||
file_put_contents($uglyQueue->_path.'queue.txt', '');
|
|
||||||
}
|
|
||||||
|
|
||||||
$uglyQueue->notifyStatus = UglyQueueEnum::QUEUE_INITIALIZED;
|
|
||||||
$uglyQueue->notify();
|
|
||||||
|
|
||||||
return $uglyQueue;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $param
|
|
||||||
* @return string
|
|
||||||
* @throws \OutOfBoundsException
|
|
||||||
*/
|
|
||||||
public function __get($param)
|
|
||||||
{
|
|
||||||
switch($param)
|
|
||||||
{
|
|
||||||
case 'name' :
|
|
||||||
return $this->_name;
|
|
||||||
|
|
||||||
case 'path':
|
|
||||||
return $this->_path;
|
|
||||||
|
|
||||||
case 'locked':
|
|
||||||
return $this->_locked;
|
|
||||||
|
|
||||||
default:
|
|
||||||
throw new \OutOfBoundsException(get_class($this).' does not have a property named "'.$param.'".');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -137,7 +78,79 @@ HTML;
|
|||||||
{
|
{
|
||||||
$this->_populateQueue();
|
$this->_populateQueue();
|
||||||
$this->unlock();
|
$this->unlock();
|
||||||
file_put_contents($this->_path.UglyQueueManager::UGLY_QUEUE_SERIALIZED_NAME, serialize($this));
|
file_put_contents($this->path.'/ugly-queue.obj', serialize($this));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getName()
|
||||||
|
{
|
||||||
|
return $this->name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getMode()
|
||||||
|
{
|
||||||
|
return $this->mode;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getPath()
|
||||||
|
{
|
||||||
|
return $this->path;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getBaseDir()
|
||||||
|
{
|
||||||
|
return $this->baseDir;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getQueueFile()
|
||||||
|
{
|
||||||
|
return $this->queueFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getQueueTmpFile()
|
||||||
|
{
|
||||||
|
return $this->queueTmpFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getLockFile()
|
||||||
|
{
|
||||||
|
return $this->lockFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getSerializeFile()
|
||||||
|
{
|
||||||
|
return $this->serializeFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public function isLocked()
|
||||||
|
{
|
||||||
|
return $this->locked;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -150,59 +163,32 @@ HTML;
|
|||||||
if (!is_int($ttl))
|
if (!is_int($ttl))
|
||||||
throw new \InvalidArgumentException('Argument 1 expected to be integer, "'.gettype($ttl).'" seen');
|
throw new \InvalidArgumentException('Argument 1 expected to be integer, "'.gettype($ttl).'" seen');
|
||||||
|
|
||||||
if ($ttl < 0)
|
if ($ttl < 1)
|
||||||
throw new \InvalidArgumentException('Argument 1 expected to be positive integer, "'.$ttl.'" seen');
|
throw new \InvalidArgumentException('Argument 1 expected to be greater than 0 "'.$ttl.'" seen');
|
||||||
|
|
||||||
$alreadyLocked = $this->isLocked();
|
|
||||||
|
|
||||||
// If there is currently no lock
|
// If there is currently no lock
|
||||||
if ($alreadyLocked === false)
|
if ($this->isAlreadyLocked() === false)
|
||||||
return $this->createLockFile($ttl);
|
return $this->createLockFile($ttl);
|
||||||
|
|
||||||
// If we make it this far, there is already a lock in place.
|
// If we make it this far, there is already a lock in place.
|
||||||
$this->_locked = false;
|
$this->locked = false;
|
||||||
$this->notifyStatus = UglyQueueEnum::QUEUE_LOCKED_BY_OTHER_PROCESS;
|
$this->_notifyStatus = UglyQueueEnum::QUEUE_LOCKED_BY_OTHER_PROCESS;
|
||||||
$this->notify();
|
$this->notify();
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param int $ttl seconds to live
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
protected function createLockFile($ttl)
|
|
||||||
{
|
|
||||||
$ok = (bool)@file_put_contents(
|
|
||||||
$this->_path.'queue.lock',
|
|
||||||
json_encode(array('ttl' => $ttl, 'born' => time())));
|
|
||||||
|
|
||||||
if ($ok !== true)
|
|
||||||
{
|
|
||||||
$this->notifyStatus = UglyQueueEnum::QUEUE_FAILED_TO_LOCK;
|
|
||||||
$this->notify();
|
|
||||||
return $this->_locked = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->_locked = true;
|
|
||||||
|
|
||||||
$this->notifyStatus = UglyQueueEnum::QUEUE_LOCKED;
|
|
||||||
$this->notify();
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Close this ugly queue, writing out contents to file.
|
* Close this ugly queue, writing out contents to file.
|
||||||
*/
|
*/
|
||||||
public function unlock()
|
public function unlock()
|
||||||
{
|
{
|
||||||
if ($this->_locked === true)
|
if ($this->isLocked() === true)
|
||||||
{
|
{
|
||||||
unlink($this->_path.'queue.lock');
|
unlink($this->lockFile);
|
||||||
$this->_locked = false;
|
$this->locked = false;
|
||||||
|
|
||||||
$this->notifyStatus = UglyQueueEnum::QUEUE_UNLOCKED;
|
$this->_notifyStatus = UglyQueueEnum::QUEUE_UNLOCKED;
|
||||||
$this->notify();
|
$this->notify();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -211,27 +197,26 @@ HTML;
|
|||||||
* @throws \RuntimeException
|
* @throws \RuntimeException
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function isLocked()
|
public function isAlreadyLocked()
|
||||||
{
|
{
|
||||||
// First check for lock file
|
// First check for lock file
|
||||||
if (is_file($this->_path.'queue.lock'))
|
if (is_file($this->lockFile))
|
||||||
{
|
{
|
||||||
$lock = json_decode(file_get_contents($this->_path.'queue.lock'), true);
|
$lock = json_decode(file_get_contents($this->lockFile), true);
|
||||||
|
|
||||||
// If we have an invalid lock structure.
|
// If the decoded lock file contains a ttl and born value...
|
||||||
if (!isset($lock['ttl']) || !isset($lock['born']))
|
if (isset($lock['ttl']) && isset($lock['born']))
|
||||||
throw new \RuntimeException('Invalid "queue.lock" file structure seen at "'.$this->_path.'queue.lock".');
|
{
|
||||||
|
$lock_ttl = ((int)$lock['born'] + (int)$lock['ttl']);
|
||||||
|
|
||||||
// Otherwise...
|
// If we're within the TTL of the lock, assume another thread is already processing.
|
||||||
$lock_ttl = ((int)$lock['born'] + (int)$lock['ttl']);
|
// We'll pick it up on the next go around.
|
||||||
|
if ($lock_ttl > time())
|
||||||
// If we're within the TTL of the lock, assume another thread is already processing.
|
return true;
|
||||||
// We'll pick it up on the next go around.
|
}
|
||||||
if ($lock_ttl > time())
|
|
||||||
return true;
|
|
||||||
|
|
||||||
// Else, remove lock file and assume we're good to go!
|
// Else, remove lock file and assume we're good to go!
|
||||||
unlink($this->_path.'queue.lock');
|
unlink($this->lockFile);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -245,14 +230,14 @@ HTML;
|
|||||||
* @throws \InvalidArgumentException
|
* @throws \InvalidArgumentException
|
||||||
* @return bool|array
|
* @return bool|array
|
||||||
*/
|
*/
|
||||||
public function processQueue($count = 1)
|
public function retrieveItems($count = 1)
|
||||||
{
|
{
|
||||||
if ($this->mode === self::QUEUE_READONLY)
|
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 we don't have a lock, assume issue and move on.
|
||||||
if ($this->_locked === false)
|
if ($this->isLocked() === false)
|
||||||
throw new \RuntimeException('Cannot process queue named "'.$this->_name.'". It is locked by another process.');
|
throw new \RuntimeException('Cannot process queue named "'.$this->name.'". It is locked by another process.');
|
||||||
|
|
||||||
// If non-int valid is passed
|
// If non-int valid is passed
|
||||||
if (!is_int($count))
|
if (!is_int($count))
|
||||||
@@ -262,21 +247,21 @@ HTML;
|
|||||||
if ($count <= 0)
|
if ($count <= 0)
|
||||||
throw new \InvalidArgumentException('Argument 1 expected to be integer greater than 0, "'.$count.'" seen');
|
throw new \InvalidArgumentException('Argument 1 expected to be integer greater than 0, "'.$count.'" seen');
|
||||||
|
|
||||||
if ($this->notifyStatus !== UglyQueueEnum::QUEUE_PROCESSING)
|
if ($this->_notifyStatus !== UglyQueueEnum::QUEUE_PROCESSING)
|
||||||
{
|
{
|
||||||
$this->notifyStatus = UglyQueueEnum::QUEUE_PROCESSING;
|
$this->_notifyStatus = UglyQueueEnum::QUEUE_PROCESSING;
|
||||||
$this->notify();
|
$this->notify();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find number of lines in the queue file
|
// Find number of lines in the queue file
|
||||||
$lineCount = FileHelper::getLineCount($this->_path.'queue.txt');
|
$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)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Try to open the file for reading / writing.
|
// Try to open the file for reading / writing.
|
||||||
$queueFileHandle = fopen($this->_path.'queue.txt', 'r+');
|
$queueFileHandle = fopen($this->queueFile, 'r+');
|
||||||
if ($queueFileHandle === false)
|
if ($queueFileHandle === false)
|
||||||
$this->unlock();
|
$this->unlock();
|
||||||
|
|
||||||
@@ -284,12 +269,12 @@ HTML;
|
|||||||
$data = array();
|
$data = array();
|
||||||
$start_line = $lineCount - $count;
|
$start_line = $lineCount - $count;
|
||||||
$i = 0;
|
$i = 0;
|
||||||
while (($line = fscanf($queueFileHandle, "%s\t%s\n")) !== false && $i < $lineCount)
|
while (($line = fscanf($queueFileHandle, "%s\t%[^\n]")) !== false && $i < $lineCount)
|
||||||
{
|
{
|
||||||
if ($i++ >= $start_line)
|
if ($i++ >= $start_line)
|
||||||
{
|
{
|
||||||
list ($key, $value) = $line;
|
list ($key, $value) = $line;
|
||||||
$data[$key] = $value;
|
$data = array($key => $value) + $data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -300,13 +285,13 @@ HTML;
|
|||||||
ftruncate($queueFileHandle, 0);
|
ftruncate($queueFileHandle, 0);
|
||||||
fclose($queueFileHandle);
|
fclose($queueFileHandle);
|
||||||
|
|
||||||
$this->notifyStatus = UglyQueueEnum::QUEUE_REACHED_END;
|
$this->_notifyStatus = UglyQueueEnum::QUEUE_REACHED_END;
|
||||||
$this->notify();
|
$this->notify();
|
||||||
}
|
}
|
||||||
// Otherwise, create new queue file minus the processed lines.
|
// Otherwise, create new queue file minus the processed lines.
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$tmp = fopen($this->_path.'queue.tmp', 'w+');
|
$tmp = fopen($this->queueTmpFile, 'w+');
|
||||||
rewind($queueFileHandle);
|
rewind($queueFileHandle);
|
||||||
$i = 0;
|
$i = 0;
|
||||||
while (($line = fgets($queueFileHandle)) !== false && $i < $start_line)
|
while (($line = fgets($queueFileHandle)) !== false && $i < $start_line)
|
||||||
@@ -319,8 +304,8 @@ HTML;
|
|||||||
|
|
||||||
fclose($queueFileHandle);
|
fclose($queueFileHandle);
|
||||||
fclose($tmp);
|
fclose($tmp);
|
||||||
unlink($this->_path.'queue.txt');
|
unlink($this->queueFile);
|
||||||
rename($this->_path.'queue.tmp', $this->_path.'queue.txt');
|
rename($this->queueTmpFile, $this->queueFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
@@ -332,19 +317,19 @@ HTML;
|
|||||||
* @return bool
|
* @return bool
|
||||||
* @throws \RuntimeException
|
* @throws \RuntimeException
|
||||||
*/
|
*/
|
||||||
public function addToQueue($key, $value)
|
public function addItem($key, $value)
|
||||||
{
|
{
|
||||||
if ($this->mode === self::QUEUE_READONLY)
|
if ($this->mode === self::QUEUE_READONLY)
|
||||||
throw new \RuntimeException('Cannot add items to queue "'.$this->_name.'" as it is in read-only mode');
|
throw new \RuntimeException('Cannot add item to queue "'.$this->name.'" as it is in read-only mode');
|
||||||
|
|
||||||
// If we don't have a lock, assume issue and move on.
|
// If we don't have a lock, assume issue and move on.
|
||||||
if ($this->_locked === false)
|
if ($this->isLocked() === false)
|
||||||
throw new \RuntimeException('Cannot add items to queue "'.$this->_name.'". Queue is already locked by another process');
|
throw new \RuntimeException('Cannot add item to queue "'.$this->name.'". Queue is already locked by another process');
|
||||||
|
|
||||||
if (!is_resource($this->_tmpHandle))
|
if (!is_resource($this->tmpHandle))
|
||||||
{
|
{
|
||||||
$this->_tmpHandle = fopen($this->_path.'queue.tmp', 'w+');
|
$this->tmpHandle = fopen($this->queueTmpFile, 'w+');
|
||||||
if ($this->_tmpHandle === false)
|
if ($this->tmpHandle === false)
|
||||||
throw new \RuntimeException('Unable to create "queue.tmp" file.');
|
throw new \RuntimeException('Unable to create "queue.tmp" file.');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -352,11 +337,22 @@ HTML;
|
|||||||
$value = json_encode($value);
|
$value = json_encode($value);
|
||||||
|
|
||||||
return (bool)fwrite(
|
return (bool)fwrite(
|
||||||
$this->_tmpHandle,
|
$this->tmpHandle,
|
||||||
$key."\t".str_replace(array("\r\n", "\n"), ' ', $value)
|
$key."\t".str_replace(array("\r\n", "\n"), ' ', $value)
|
||||||
."\n");
|
."\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $items
|
||||||
|
*/
|
||||||
|
public function addItems(array $items)
|
||||||
|
{
|
||||||
|
foreach($items as $k=>$v)
|
||||||
|
{
|
||||||
|
$this->addItem($k, $v);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If there is a tmp queue file, add it's contents to the beginning of a new queue file
|
* If there is a tmp queue file, add it's contents to the beginning of a new queue file
|
||||||
*
|
*
|
||||||
@@ -364,35 +360,26 @@ HTML;
|
|||||||
*/
|
*/
|
||||||
public function _populateQueue()
|
public function _populateQueue()
|
||||||
{
|
{
|
||||||
if (is_resource($this->_tmpHandle))
|
if (is_resource($this->tmpHandle))
|
||||||
{
|
{
|
||||||
if (file_exists($this->_path.'queue.txt'))
|
if (file_exists($this->queueFile))
|
||||||
{
|
{
|
||||||
$queueFileHandle = fopen($this->_path.'queue.txt', 'r+');
|
$queueFileHandle = fopen($this->queueFile, 'r+');
|
||||||
while (($line = fgets($queueFileHandle)) !== false)
|
while (($line = fgets($queueFileHandle)) !== false)
|
||||||
{
|
{
|
||||||
if ($line !== "\n" && $line !== "")
|
if ($line !== "\n" && $line !== "")
|
||||||
fwrite($this->_tmpHandle, $line);
|
fwrite($this->tmpHandle, $line);
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose($queueFileHandle);
|
fclose($queueFileHandle);
|
||||||
unlink($this->_path.'queue.txt');
|
unlink($this->queueFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose($this->_tmpHandle);
|
fclose($this->tmpHandle);
|
||||||
rename($this->_path.'queue.tmp', $this->_path.'queue.txt');
|
rename($this->queueTmpFile, $this->queueFile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return int
|
|
||||||
* @throws \RuntimeException
|
|
||||||
*/
|
|
||||||
public function getQueueItemCount()
|
|
||||||
{
|
|
||||||
return FileHelper::getLineCount($this->_path.'queue.txt');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $key
|
* @param string $key
|
||||||
* @return bool
|
* @return bool
|
||||||
@@ -403,13 +390,11 @@ HTML;
|
|||||||
$key = (string)$key;
|
$key = (string)$key;
|
||||||
|
|
||||||
// Try to open the file for reading / writing.
|
// Try to open the file for reading / writing.
|
||||||
$queueFileHandle = fopen($this->_path.'queue.txt', 'r');
|
$queueFileHandle = fopen($this->queueFile, 'r');
|
||||||
|
|
||||||
while(($line = fscanf($queueFileHandle, "%s\t%s\n")) !== false)
|
while(($line = fscanf($queueFileHandle, "%s\t%s\n")) !== false)
|
||||||
{
|
{
|
||||||
list ($lineKey, $lineValue) = $line;
|
if ($key === $line[0])
|
||||||
|
|
||||||
if ($key === $lineKey)
|
|
||||||
{
|
{
|
||||||
fclose($queueFileHandle);
|
fclose($queueFileHandle);
|
||||||
return true;
|
return true;
|
||||||
@@ -429,7 +414,7 @@ HTML;
|
|||||||
*/
|
*/
|
||||||
public function count()
|
public function count()
|
||||||
{
|
{
|
||||||
return $this->getQueueItemCount();
|
return (int)FileHelper::getLineCount($this->queueFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -441,7 +426,17 @@ HTML;
|
|||||||
*/
|
*/
|
||||||
public function serialize()
|
public function serialize()
|
||||||
{
|
{
|
||||||
return serialize(array($this->_name, $this->_path));
|
return serialize(
|
||||||
|
array(
|
||||||
|
$this->baseDir,
|
||||||
|
$this->name,
|
||||||
|
$this->path,
|
||||||
|
$this->queueFile,
|
||||||
|
$this->queueTmpFile,
|
||||||
|
$this->lockFile,
|
||||||
|
$this->serializeFile,
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -454,10 +449,15 @@ HTML;
|
|||||||
*/
|
*/
|
||||||
public function unserialize($serialized)
|
public function unserialize($serialized)
|
||||||
{
|
{
|
||||||
/** @var \DCarbone\UglyQueue $uglyQueue */
|
|
||||||
$data = unserialize($serialized);
|
$data = unserialize($serialized);
|
||||||
$this->_name = $data[0];
|
$this->baseDir = $data[0];
|
||||||
$this->_path = $data[1];
|
$this->name = $data[1];
|
||||||
|
$this->path = $data[2];
|
||||||
|
$this->queueFile = $data[3];
|
||||||
|
$this->queueTmpFile = $data[4];
|
||||||
|
$this->lockFile = $data[5];
|
||||||
|
$this->serializeFile = $data[6];
|
||||||
|
$this->initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -470,8 +470,8 @@ HTML;
|
|||||||
*/
|
*/
|
||||||
public function attach(\SplObserver $observer)
|
public function attach(\SplObserver $observer)
|
||||||
{
|
{
|
||||||
if (!in_array($observer, $this->observers))
|
if (!in_array($observer, $this->_observers))
|
||||||
$this->observers[] = $observer;
|
$this->_observers[] = $observer;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -484,9 +484,9 @@ HTML;
|
|||||||
*/
|
*/
|
||||||
public function detach(\SplObserver $observer)
|
public function detach(\SplObserver $observer)
|
||||||
{
|
{
|
||||||
$idx = array_search($observer, $this->observers, true);
|
$idx = array_search($observer, $this->_observers, true);
|
||||||
if ($idx !== false)
|
if ($idx !== false)
|
||||||
unset($this->observers[$idx]);
|
unset($this->_observers[$idx]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -498,9 +498,97 @@ HTML;
|
|||||||
*/
|
*/
|
||||||
public function notify()
|
public function notify()
|
||||||
{
|
{
|
||||||
for ($i = 0, $count = count($this->observers); $i < $count; $i++)
|
foreach($this->_observers as $observer)
|
||||||
{
|
{
|
||||||
$this->observers[$i]->notify($this);
|
$observer->update($this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method is mostly intended to check the "validity" of a re-initialized queue
|
||||||
|
*
|
||||||
|
* Could probably stand to be improved.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function _valid()
|
||||||
|
{
|
||||||
|
return (
|
||||||
|
$this->baseDir !== null &&
|
||||||
|
$this->name !== null &&
|
||||||
|
$this->path !== null &&
|
||||||
|
$this->queueFile !== null &&
|
||||||
|
$this->queueTmpFile !== null &&
|
||||||
|
$this->lockFile !== null &&
|
||||||
|
$this->serializeFile !== null
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// --------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $ttl seconds to live
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
protected function createLockFile($ttl)
|
||||||
|
{
|
||||||
|
$ok = (bool)@file_put_contents(
|
||||||
|
$this->lockFile,
|
||||||
|
json_encode(array('ttl' => $ttl, 'born' => time())));
|
||||||
|
|
||||||
|
if ($ok !== true)
|
||||||
|
{
|
||||||
|
$this->_notifyStatus = UglyQueueEnum::QUEUE_FAILED_TO_LOCK;
|
||||||
|
$this->notify();
|
||||||
|
return $this->locked = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->locked = true;
|
||||||
|
$this->_notifyStatus = UglyQueueEnum::QUEUE_LOCKED;
|
||||||
|
$this->notify();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Post-construct initialization method.
|
||||||
|
*
|
||||||
|
* Also used post-un-serialization
|
||||||
|
*/
|
||||||
|
protected function initialize()
|
||||||
|
{
|
||||||
|
if (is_readable($this->path) && is_writable($this->path))
|
||||||
|
$this->mode = self::QUEUE_READWRITE;
|
||||||
|
else if (is_readable($this->path))
|
||||||
|
$this->mode = self::QUEUE_READONLY;
|
||||||
|
|
||||||
|
if (!file_exists($this->path.'/index.html'))
|
||||||
|
{
|
||||||
|
if ($this->mode === self::QUEUE_READONLY)
|
||||||
|
throw new \RuntimeException('Cannot initialize queue with name "'.$this->name.'", the user lacks permission to create files.');
|
||||||
|
|
||||||
|
$html = <<<HTML
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>403 Forbidden</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<p>Directory access is forbidden.</p>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
HTML;
|
||||||
|
file_put_contents($this->path.'/index.html', $html);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!file_exists($this->queueFile))
|
||||||
|
{
|
||||||
|
if ($this->mode === self::QUEUE_READONLY)
|
||||||
|
throw new \RuntimeException('Cannot initialize queue with name "'.$this->name.'", the user lacks permission to create files.');
|
||||||
|
|
||||||
|
file_put_contents($this->queueFile, '');
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->_notifyStatus = UglyQueueEnum::QUEUE_INITIALIZED;
|
||||||
|
$this->notify();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
<?php namespace DCarbone;
|
<?php namespace Cybercinch;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class UglyQueueEnum
|
* Class UglyQueueEnum
|
||||||
* @package DCarbone
|
* @package Cybercinch
|
||||||
*
|
*
|
||||||
* Pseudo-enum thing.
|
* Pseudo-enum thing.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1,150 +1,152 @@
|
|||||||
<?php namespace DCarbone;
|
<?php namespace Cybercinch;
|
||||||
|
|
||||||
|
use InvalidArgumentException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class UglyQueueManager
|
* Class UglyQueueManager
|
||||||
* @package DCarbone
|
* @package Cybercinch
|
||||||
*/
|
*/
|
||||||
class UglyQueueManager implements \SplObserver, \SplSubject, \Countable
|
class UglyQueueManager implements \SplObserver, \Countable
|
||||||
{
|
{
|
||||||
/** @var int */
|
/** @var UglyQueue[] */
|
||||||
public $notifyStatus;
|
|
||||||
|
|
||||||
const UGLY_QUEUE_SERIALIZED_NAME = 'ugly-queue.obj';
|
|
||||||
|
|
||||||
/** @var array */
|
|
||||||
private $observers = array();
|
|
||||||
|
|
||||||
/** @var array */
|
|
||||||
protected $queues = array();
|
protected $queues = array();
|
||||||
|
|
||||||
/** @var array */
|
|
||||||
protected $config = array();
|
|
||||||
|
|
||||||
/** @var string */
|
/** @var string */
|
||||||
protected $queueBaseDir;
|
protected $baseDir;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
* @param array $config
|
* @param string $baseDir
|
||||||
* @param array $observers
|
|
||||||
* @throws \RuntimeException
|
* @throws \RuntimeException
|
||||||
* @throws \InvalidArgumentException
|
* @throws InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
protected function __construct(array $config, array $observers = array())
|
public function __construct($baseDir)
|
||||||
{
|
{
|
||||||
if (!isset($config['queue-base-dir']))
|
if (false === is_string($baseDir))
|
||||||
throw new \InvalidArgumentException('"$config" parameter "queue-base-dir" not seen.');
|
throw new InvalidArgumentException('Argument 1 expected to be string, "'.gettype($baseDir).'" seen.');
|
||||||
|
|
||||||
if (!is_dir($config['queue-base-dir']))
|
if (false === is_dir($baseDir))
|
||||||
throw new \RuntimeException('"queue-base-dir" points to a directory that does not exist.');
|
throw new \RuntimeException('"'.$baseDir.'" points to a directory that does not exist.');
|
||||||
|
|
||||||
$this->config = $config;
|
if (false === is_readable($baseDir))
|
||||||
$this->queueBaseDir = rtrim(realpath($this->config['queue-base-dir']), "/\\").DIRECTORY_SEPARATOR;
|
throw new \RuntimeException('"'.$baseDir.'" is not readable and/or writable .');
|
||||||
$this->observers = $observers;
|
|
||||||
|
$this->baseDir = rtrim($baseDir, "/\\");
|
||||||
|
|
||||||
|
foreach(glob(sprintf('%s/*', $this->baseDir), GLOB_ONLYDIR) as $queueDir)
|
||||||
|
{
|
||||||
|
$this->addQueueAtPath($queueDir);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $config
|
* @param string $name
|
||||||
* @param array $observers
|
* @return UglyQueue
|
||||||
* @return UglyQueueManager
|
|
||||||
*/
|
*/
|
||||||
public static function init(array $config, array $observers = array())
|
public function getQueue($name)
|
||||||
{
|
{
|
||||||
/** @var \DCarbone\UglyQueueManager $manager */
|
if (isset($this->queues[$name]))
|
||||||
$manager = new static($config, $observers);
|
return $this->queues[$name];
|
||||||
|
|
||||||
/** @var \DCarbone\UglyQueue $uglyQueue */
|
$path = sprintf('%s/%s', $this->baseDir, $name);
|
||||||
|
if (file_exists($path))
|
||||||
|
return $this->addQueueAtPath($path);
|
||||||
|
|
||||||
foreach(glob($manager->queueBaseDir.DIRECTORY_SEPARATOR.'*', GLOB_ONLYDIR) as $queueDir)
|
return $this->createQueue($name);
|
||||||
{
|
|
||||||
// Try to avoid looking at hidden directories or magic dirs such as '.' and '..'
|
|
||||||
$split = preg_split('#[/\\\]+#', $queueDir);
|
|
||||||
if (strpos(end($split), '.') === 0)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
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::queueWithDirectoryPathAndObservers($queueDir, $manager->observers);
|
|
||||||
|
|
||||||
$manager->addQueue($uglyQueue);
|
|
||||||
}
|
|
||||||
|
|
||||||
$manager->notifyStatus = UglyQueueEnum::MANAGER_INITIALIZED;
|
|
||||||
$manager->notify();
|
|
||||||
|
|
||||||
return $manager;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param UglyQueue $uglyQueue
|
* @param UglyQueue $uglyQueue
|
||||||
* @return \DCarbone\UglyQueueManager
|
* @return UglyQueueManager
|
||||||
* @throws \RuntimeException
|
* @throws \RuntimeException
|
||||||
*/
|
*/
|
||||||
public function addQueue(UglyQueue $uglyQueue)
|
public function addQueue(UglyQueue $uglyQueue)
|
||||||
{
|
{
|
||||||
if ($this->containsQueueWithName($uglyQueue->name))
|
$name = $uglyQueue->getName();
|
||||||
throw new \RuntimeException('Queue named "'.$uglyQueue->name.'" already exists in this manager.');
|
|
||||||
|
|
||||||
$this->queues[$uglyQueue->name] = $uglyQueue;
|
if ($this->containsQueueWithName($name))
|
||||||
|
throw new \RuntimeException('Queue named "'.$name.'" already exists in this manager.');
|
||||||
|
|
||||||
$this->notifyStatus = UglyQueueEnum::QUEUE_ADDED;
|
$this->queues[$name] = $uglyQueue;
|
||||||
$this->notify();
|
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $path
|
* @param string $name
|
||||||
|
* @return UglyQueue
|
||||||
|
*/
|
||||||
|
public function createQueue($name)
|
||||||
|
{
|
||||||
|
$queue = new UglyQueue($this->baseDir, $name, array($this));
|
||||||
|
$this->addQueue($queue);
|
||||||
|
return end($this->queues);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $path
|
||||||
* @return \DCarbone\UglyQueueManager
|
* @return \DCarbone\UglyQueueManager
|
||||||
*/
|
*/
|
||||||
public function addQueueAtPath($path)
|
public function addQueueAtPath($path)
|
||||||
{
|
{
|
||||||
$uglyQueue = UglyQueue::queueWithDirectoryPathAndObservers($path, $this->observers);
|
// Try to avoid looking at hidden directories or magic dirs such as '.' and '..'
|
||||||
|
$split = preg_split('#[/\\\]+#', $path);
|
||||||
|
|
||||||
|
$queueName = end($split);
|
||||||
|
|
||||||
|
if (0 === strpos($queueName, '.'))
|
||||||
|
return null;
|
||||||
|
|
||||||
|
$serializedFile = sprintf('%s/%s/ugly-queue.obj', $this->baseDir, $queueName);
|
||||||
|
/** @var \DCarbone\UglyQueue $uglyQueue */
|
||||||
|
if (file_exists($serializedFile))
|
||||||
|
$uglyQueue = unserialize(file_get_contents($serializedFile));
|
||||||
|
|
||||||
|
if (!isset($uglyQueue) || $uglyQueue->_valid() === false)
|
||||||
|
$uglyQueue = new UglyQueue($this->baseDir, $queueName, array($this));
|
||||||
|
|
||||||
|
$uglyQueue->attach($this);
|
||||||
|
|
||||||
return $this->addQueue($uglyQueue);
|
return $this->addQueue($uglyQueue);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param UglyQueue $uglyQueue
|
* @param UglyQueue $uglyQueue
|
||||||
* @return \DCarbone\UglyQueueManager
|
* @return UglyQueueManager
|
||||||
*/
|
*/
|
||||||
public function removeQueue(UglyQueue $uglyQueue)
|
public function removeQueue(UglyQueue $uglyQueue)
|
||||||
{
|
{
|
||||||
if ($this->containsQueueWithName($uglyQueue->name))
|
$name = $uglyQueue->getName();
|
||||||
unset($this->queues[$uglyQueue->name]);
|
if ($this->containsQueueWithName($name))
|
||||||
|
unset($this->queues[$name]);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @return \DCarbone\UglyQueueManager
|
* @return UglyQueueManager
|
||||||
*/
|
*/
|
||||||
public function removeQueueByName($name)
|
public function removeQueueByName($name)
|
||||||
{
|
{
|
||||||
if ($this->containsQueueWithName($name))
|
if ($this->containsQueueWithName($name))
|
||||||
{
|
|
||||||
unset($this->queues[$name]);
|
unset($this->queues[$name]);
|
||||||
$this->notifyStatus = UglyQueueEnum::QUEUE_REMOVED;
|
|
||||||
$this->notify();
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @return \DCarbone\UglyQueue
|
* @return UglyQueue
|
||||||
* @throws \InvalidArgumentException
|
* @throws InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
public function &getQueueWithName($name)
|
public function getQueueWithName($name)
|
||||||
{
|
{
|
||||||
if (isset($this->queues[$name]))
|
if (isset($this->queues[$name]))
|
||||||
return $this->queues[$name];
|
return $this->queues[$name];
|
||||||
|
|
||||||
throw new \InvalidArgumentException('Argument 1 expected to be valid queue name.');
|
throw new InvalidArgumentException('Argument 1 expected to be valid queue name.');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -186,53 +188,6 @@ class UglyQueueManager implements \SplObserver, \SplSubject, \Countable
|
|||||||
*/
|
*/
|
||||||
public function update(\SplSubject $subject)
|
public function update(\SplSubject $subject)
|
||||||
{
|
{
|
||||||
for ($i = 0, $count = count($this->observers); $i < $count; $i++)
|
// Nothing for now...
|
||||||
{
|
|
||||||
$this->observers[$i]->notify($subject);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* (PHP 5 >= 5.1.0)
|
|
||||||
* Attach an SplObserver
|
|
||||||
* @link http://php.net/manual/en/splsubject.attach.php
|
|
||||||
*
|
|
||||||
* @param \SplObserver $observer The SplObserver to attach.
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function attach(\SplObserver $observer)
|
|
||||||
{
|
|
||||||
if (!in_array($observer, $this->observers, true))
|
|
||||||
$this->observers[] = $observer;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* (PHP 5 >= 5.1.0)
|
|
||||||
* Detach an observer
|
|
||||||
* @link http://php.net/manual/en/splsubject.detach.php
|
|
||||||
*
|
|
||||||
* @param \SplObserver $observer The SplObserver to detach.
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function detach(\SplObserver $observer)
|
|
||||||
{
|
|
||||||
$idx = array_search($observer, $this->observers, true);
|
|
||||||
if ($idx !== false)
|
|
||||||
unset($this->observers[$idx]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* (PHP 5 >= 5.1.0)
|
|
||||||
* Notify an observer
|
|
||||||
* @link http://php.net/manual/en/splsubject.notify.php
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function notify()
|
|
||||||
{
|
|
||||||
for ($i = 0, $count = count($this->observers); $i < $count; $i++)
|
|
||||||
{
|
|
||||||
$this->observers[$i]->notify($this);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -7,8 +7,10 @@ require_once __DIR__.'/../misc/cleanup.php';
|
|||||||
/**
|
/**
|
||||||
* Class UglyQueueTest
|
* Class UglyQueueTest
|
||||||
*/
|
*/
|
||||||
class UglyQueueTest extends PHPUnit_Framework_TestCase
|
class UglyQueueTest extends PHPUnit\Framework\TestCase
|
||||||
{
|
{
|
||||||
|
protected $baseDir;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
@@ -26,201 +28,265 @@ class UglyQueueTest extends PHPUnit_Framework_TestCase
|
|||||||
'10' => 'Virginia baked ham, sliced',
|
'10' => 'Virginia baked ham, sliced',
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
protected function setUp(): void
|
||||||
* @covers \DCarbone\UglyQueue::queueWithDirectoryPathAndObservers
|
|
||||||
* @uses \DCarbone\UglyQueue
|
|
||||||
* @return \DCarbone\UglyQueue
|
|
||||||
*/
|
|
||||||
public function testCanInitializeUglyQueueWithValidConfigArrayAndNoObservers()
|
|
||||||
{
|
{
|
||||||
$uglyQueue = \DCarbone\UglyQueue::queueWithDirectoryPathAndObservers(dirname(__DIR__).'/misc/queues/tasty-sandwich');
|
$this->baseDir = realpath(__DIR__.'/../misc/queues');
|
||||||
|
}
|
||||||
|
|
||||||
$this->assertInstanceOf('\\DCarbone\\UglyQueue', $uglyQueue);
|
/**
|
||||||
|
* @covers \Cybercinch\UglyQueue::__construct
|
||||||
|
* @uses \Cybercinch\UglyQueue
|
||||||
|
* @return \Cybercinch\UglyQueue
|
||||||
|
*/
|
||||||
|
public function testCanInitializeObjectWithValidParameters()
|
||||||
|
{
|
||||||
|
$uglyQueue = new \Cybercinch\UglyQueue($this->baseDir, 'tasty-sandwich');
|
||||||
|
|
||||||
|
$this->assertInstanceOf('\\Cybercinch\\UglyQueue', $uglyQueue);
|
||||||
|
|
||||||
return $uglyQueue;
|
return $uglyQueue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers \DCarbone\UglyQueue::queueWithDirectoryPathAndObservers
|
* @covers \Cybercinch\UglyQueue::retrieveItems
|
||||||
* @uses \DCarbone\UglyQueue
|
* @uses \Cybercinch\UglyQueue
|
||||||
* @expectedException \InvalidArgumentException
|
* @depends testCanInitializeObjectWithValidParameters
|
||||||
|
* @param \Cybercinch\UglyQueue $uglyQueue
|
||||||
*/
|
*/
|
||||||
public function testExceptionThrownWhenInitializingUglyQueueWithEmptyOrInvalidConf()
|
public function testExceptionThrownWhenTryingToProcessQueueAfterInitializationBeforeLock(\Cybercinch\UglyQueue $uglyQueue)
|
||||||
{
|
{
|
||||||
$uglyQueue = \DCarbone\UglyQueue::queueWithDirectoryPathAndObservers(array());
|
$this->expectException(\RuntimeException::class);
|
||||||
|
$uglyQueue->retrieveItems();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers \DCarbone\UglyQueue::processQueue
|
* @covers \Cybercinch\UglyQueue::keyExistsInQueue
|
||||||
* @uses \DCarbone\UglyQueue
|
* @uses \Cybercinch\UglyQueue
|
||||||
* @depends testCanInitializeUglyQueueWithValidConfigArrayAndNoObservers
|
* @depends testCanInitializeObjectWithValidParameters
|
||||||
* @expectedException \RuntimeException
|
* @param \Cybercinch\UglyQueue $uglyQueue
|
||||||
* @param \DCarbone\UglyQueue $uglyQueue
|
|
||||||
*/
|
*/
|
||||||
public function testExceptionThrownWhenTryingToProcessQueueAfterInitializationBeforeLock(\DCarbone\UglyQueue $uglyQueue)
|
public function testKeyExistsInQueueReturnsFalseWithEmptyQueueAfterInitialization(\Cybercinch\UglyQueue $uglyQueue)
|
||||||
{
|
|
||||||
$process = $uglyQueue->processQueue();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @covers \DCarbone\UglyQueue::keyExistsInQueue
|
|
||||||
* @uses \DCarbone\UglyQueue
|
|
||||||
* @depends testCanInitializeUglyQueueWithValidConfigArrayAndNoObservers
|
|
||||||
* @param \DCarbone\UglyQueue $uglyQueue
|
|
||||||
*/
|
|
||||||
public function testKeyExistsInQueueReturnsFalseWithEmptyQueueAfterInitialization(\DCarbone\UglyQueue $uglyQueue)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
$exists = $uglyQueue->keyExistsInQueue(0);
|
$exists = $uglyQueue->keyExistsInQueue(0);
|
||||||
|
|
||||||
$this->assertFalse($exists);
|
$this->assertFalse($exists);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers \DCarbone\UglyQueue::addToQueue
|
* @covers \Cybercinch\UglyQueue::addItem
|
||||||
* @uses \DCarbone\UglyQueue
|
* @uses \Cybercinch\UglyQueue
|
||||||
* @depends testCanInitializeUglyQueueWithValidConfigArrayAndNoObservers
|
* @depends testCanInitializeObjectWithValidParameters
|
||||||
* @expectedException \RuntimeException
|
* @param \Cybercinch\UglyQueue $uglyQueue
|
||||||
* @param \DCarbone\UglyQueue $uglyQueue
|
|
||||||
*/
|
*/
|
||||||
public function testExceptionThrownWhenTryingToAddItemsToQueueWithoutLock(\DCarbone\UglyQueue $uglyQueue)
|
public function testExceptionThrownWhenTryingToAddItemsToQueueWithoutLock(\Cybercinch\UglyQueue $uglyQueue)
|
||||||
{
|
{
|
||||||
$addToQueue = $uglyQueue->addToQueue('test', 'value');
|
$this->expectException(\RuntimeException::class);
|
||||||
|
$uglyQueue->addItem('test', 'value');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers \DCarbone\UglyQueue::__get
|
* @covers \Cybercinch\UglyQueue::getPath
|
||||||
* @uses \DCarbone\UglyQueue
|
* @uses \Cybercinch\UglyQueue
|
||||||
* @depends testCanInitializeUglyQueueWithValidConfigArrayAndNoObservers
|
* @depends testCanInitializeObjectWithValidParameters
|
||||||
* @param \DCarbone\UglyQueue $uglyQueue
|
* @param \Cybercinch\UglyQueue $uglyQueue
|
||||||
*/
|
*/
|
||||||
public function testCanGetQueueDirectory(\DCarbone\UglyQueue $uglyQueue)
|
public function testCanGetQueueDirectory(\Cybercinch\UglyQueue $uglyQueue)
|
||||||
{
|
{
|
||||||
$queuePath = $uglyQueue->path;
|
$queuePath = $uglyQueue->getPath();
|
||||||
|
|
||||||
$this->assertFileExists($queuePath);
|
$this->assertFileExists($queuePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers \DCarbone\UglyQueue::__get
|
* @covers \Cybercinch\UglyQueue::getName
|
||||||
* @uses \DCarbone\UglyQueue
|
* @uses \Cybercinch\UglyQueue
|
||||||
* @depends testCanInitializeUglyQueueWithValidConfigArrayAndNoObservers
|
* @depends testCanInitializeObjectWithValidParameters
|
||||||
* @param \DCarbone\UglyQueue $uglyQueue
|
* @param \Cybercinch\UglyQueue $uglyQueue
|
||||||
*/
|
*/
|
||||||
public function testCanGetQueueName(\DCarbone\UglyQueue $uglyQueue)
|
public function testCanGetQueueName(\Cybercinch\UglyQueue $uglyQueue)
|
||||||
{
|
{
|
||||||
$queueName = $uglyQueue->name;
|
$queueName = $uglyQueue->getName();
|
||||||
|
|
||||||
$this->assertEquals('tasty-sandwich', $queueName);
|
$this->assertEquals('tasty-sandwich', $queueName);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers \DCarbone\UglyQueue::__get
|
* @covers \Cybercinch\UglyQueue::getMode
|
||||||
* @uses \DCarbone\UglyQueue
|
* @depends testCanInitializeObjectWithValidParameters
|
||||||
* @depends testCanInitializeUglyQueueWithValidConfigArrayAndNoObservers
|
* @param \Cybercinch\UglyQueue $uglyQueue
|
||||||
* @param \DCarbone\UglyQueue $uglyQueue
|
|
||||||
*/
|
*/
|
||||||
public function testCanGetQueueLockedStatus(\DCarbone\UglyQueue $uglyQueue)
|
public function testCanGetQueueMode(\Cybercinch\UglyQueue $uglyQueue)
|
||||||
{
|
{
|
||||||
$locked = $uglyQueue->locked;
|
$mode = $uglyQueue->getMode();
|
||||||
|
$this->assertEquals(\Cybercinch\UglyQueue::QUEUE_READWRITE, $mode);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \Cybercinch\UglyQueue::getBaseDir
|
||||||
|
* @depends testCanInitializeObjectWithValidParameters
|
||||||
|
* @param \Cybercinch\UglyQueue $uglyQueue
|
||||||
|
*/
|
||||||
|
public function testCanGetBaseDirectory(\Cybercinch\UglyQueue $uglyQueue)
|
||||||
|
{
|
||||||
|
$baseDir = $uglyQueue->getBaseDir();
|
||||||
|
$this->assertEquals($this->baseDir, $baseDir);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \Cybercinch\UglyQueue::getLockFile
|
||||||
|
* @depends testCanInitializeObjectWithValidParameters
|
||||||
|
* @param \Cybercinch\UglyQueue $uglyQueue
|
||||||
|
*/
|
||||||
|
public function testCanGetLockFilePath(\Cybercinch\UglyQueue $uglyQueue)
|
||||||
|
{
|
||||||
|
$lockFile = $uglyQueue->getLockFile();
|
||||||
|
$this->assertEquals(
|
||||||
|
sprintf('%s%s%s%squeue.lock',
|
||||||
|
$this->baseDir,
|
||||||
|
DIRECTORY_SEPARATOR,
|
||||||
|
$uglyQueue->getName(),
|
||||||
|
DIRECTORY_SEPARATOR),
|
||||||
|
$lockFile
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \Cybercinch\UglyQueue::getQueueFile
|
||||||
|
* @depends testCanInitializeObjectWithValidParameters
|
||||||
|
* @param \Cybercinch\UglyQueue $uglyQueue
|
||||||
|
*/
|
||||||
|
public function testCanGetQueueFilePath(\Cybercinch\UglyQueue $uglyQueue)
|
||||||
|
{
|
||||||
|
$queueFile = $uglyQueue->getQueueFile();
|
||||||
|
$this->assertEquals(
|
||||||
|
sprintf('%s%s%s%squeue.txt',
|
||||||
|
$this->baseDir,
|
||||||
|
DIRECTORY_SEPARATOR,
|
||||||
|
$uglyQueue->getName(),
|
||||||
|
DIRECTORY_SEPARATOR),
|
||||||
|
$queueFile
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \Cybercinch\UglyQueue::getQueueTmpFile
|
||||||
|
* @depends testCanInitializeObjectWithValidParameters
|
||||||
|
* @param \Cybercinch\UglyQueue $uglyQueue
|
||||||
|
*/
|
||||||
|
public function testCanGetQueueTmpFilePath(\Cybercinch\UglyQueue $uglyQueue)
|
||||||
|
{
|
||||||
|
$queueTmpFile = $uglyQueue->getQueueTmpFile();
|
||||||
|
$this->assertEquals(
|
||||||
|
sprintf(
|
||||||
|
'%s%s%s%squeue.tmp',
|
||||||
|
$this->baseDir,
|
||||||
|
DIRECTORY_SEPARATOR,
|
||||||
|
$uglyQueue->getName(),
|
||||||
|
DIRECTORY_SEPARATOR),
|
||||||
|
$queueTmpFile
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \Cybercinch\UglyQueue::getSerializeFile
|
||||||
|
* @depends testCanInitializeObjectWithValidParameters
|
||||||
|
* @param \Cybercinch\UglyQueue $uglyQueue
|
||||||
|
*/
|
||||||
|
public function testCanGetSerializeFilePath(\Cybercinch\UglyQueue $uglyQueue)
|
||||||
|
{
|
||||||
|
$serializeFile = $uglyQueue->getSerializeFile();
|
||||||
|
$this->assertEquals(
|
||||||
|
sprintf(
|
||||||
|
'%s%s%s%sugly-queue.obj',
|
||||||
|
$this->baseDir,
|
||||||
|
DIRECTORY_SEPARATOR,
|
||||||
|
$uglyQueue->getName(),
|
||||||
|
DIRECTORY_SEPARATOR),
|
||||||
|
$serializeFile
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \Cybercinch\isAlreadyLocked::isAlreadyLocked
|
||||||
|
* @uses \Cybercinch\UglyQueue
|
||||||
|
* @depends testCanInitializeObjectWithValidParameters
|
||||||
|
* @param \Cybercinch\UglyQueue $uglyQueue
|
||||||
|
*/
|
||||||
|
public function testCanGetQueueLockedStatus(\Cybercinch\UglyQueue $uglyQueue)
|
||||||
|
{
|
||||||
|
$locked = $uglyQueue->isAlreadyLocked();
|
||||||
$this->assertFalse($locked);
|
$this->assertFalse($locked);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers \DCarbone\UglyQueue::__get
|
* @covers \Cybercinch\UglyQueue::count
|
||||||
* @uses \DCarbone\UglyQueue
|
* @uses \Cybercinch\UglyQueue
|
||||||
* @expectedException \OutOfBoundsException
|
* @depends testCanInitializeObjectWithValidParameters
|
||||||
* @depends testCanInitializeUglyQueueWithValidConfigArrayAndNoObservers
|
* @param \Cybercinch\UglyQueue $uglyQueue
|
||||||
* @param \DCarbone\UglyQueue $uglyQueue
|
|
||||||
*/
|
*/
|
||||||
public function testExceptionThrownWhenAttemptingToGetInvalidProperty(\DCarbone\UglyQueue $uglyQueue)
|
public function testGetQueueItemCountReturnsZeroWithEmptyQueue(\Cybercinch\UglyQueue $uglyQueue)
|
||||||
{
|
{
|
||||||
$sandwich = $uglyQueue->sandwich;
|
$itemCount = count($uglyQueue);
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @covers \DCarbone\UglyQueue::isLocked
|
|
||||||
* @uses \DCarbone\UglyQueue
|
|
||||||
* @depends testCanInitializeUglyQueueWithValidConfigArrayAndNoObservers
|
|
||||||
* @param \DCarbone\UglyQueue $uglyQueue
|
|
||||||
*/
|
|
||||||
public function testIsLockedReturnsFalseBeforeLocking(\DCarbone\UglyQueue $uglyQueue)
|
|
||||||
{
|
|
||||||
$isLocked = $uglyQueue->isLocked();
|
|
||||||
|
|
||||||
$this->assertFalse($isLocked);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @covers \DCarbone\UglyQueue::getQueueItemCount
|
|
||||||
* @uses \DCarbone\UglyQueue
|
|
||||||
* @depends testCanInitializeUglyQueueWithValidConfigArrayAndNoObservers
|
|
||||||
* @param \DCarbone\UglyQueue $uglyQueue
|
|
||||||
*/
|
|
||||||
public function testGetQueueItemCountReturnsZeroWithEmptyQueue(\DCarbone\UglyQueue $uglyQueue)
|
|
||||||
{
|
|
||||||
$itemCount = $uglyQueue->getQueueItemCount();
|
|
||||||
$this->assertEquals(0, $itemCount);
|
$this->assertEquals(0, $itemCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers \DCarbone\UglyQueue::queueWithDirectoryPathAndObservers
|
* @covers \Cybercinch\UglyQueue::__construct
|
||||||
* @uses \DCarbone\UglyQueue
|
* @uses \Cybercinch\UglyQueue
|
||||||
* @return \DCarbone\UglyQueue
|
* @return \Cybercinch\UglyQueue
|
||||||
*/
|
*/
|
||||||
public function testCanInitializeExistingQueue()
|
public function testCanInitializeExistingQueue()
|
||||||
{
|
{
|
||||||
$uglyQueue = \DCarbone\UglyQueue::queueWithDirectoryPathAndObservers(dirname(__DIR__).'/misc/queues/tasty-sandwich');
|
$uglyQueue = new \Cybercinch\UglyQueue($this->baseDir, 'tasty-sandwich');
|
||||||
|
|
||||||
$this->assertInstanceOf('\\DCarbone\\UglyQueue', $uglyQueue);
|
$this->assertInstanceOf('\\Cybercinch\\UglyQueue', $uglyQueue);
|
||||||
|
|
||||||
return $uglyQueue;
|
return $uglyQueue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers \DCarbone\UglyQueue::lock
|
* @covers \Cybercinch\UglyQueue::lock
|
||||||
* @uses \DCarbone\UglyQueue
|
* @uses \Cybercinch\UglyQueue
|
||||||
* @depends testCanInitializeUglyQueueWithValidConfigArrayAndNoObservers
|
* @depends testCanInitializeObjectWithValidParameters
|
||||||
* @expectedException \InvalidArgumentException
|
* @param \Cybercinch\UglyQueue $uglyQueue
|
||||||
* @param \DCarbone\UglyQueue $uglyQueue
|
|
||||||
*/
|
*/
|
||||||
public function testExceptionThrownWhenPassingNonIntegerValueToLock(\DCarbone\UglyQueue $uglyQueue)
|
public function testExceptionThrownWhenPassingNonIntegerValueToLock(\Cybercinch\UglyQueue $uglyQueue)
|
||||||
{
|
{
|
||||||
|
$this->expectException(\InvalidArgumentException::class);
|
||||||
$uglyQueue->lock('7 billion');
|
$uglyQueue->lock('7 billion');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers \DCarbone\UglyQueue::lock
|
* @covers \Cybercinch\UglyQueue::lock
|
||||||
* @uses \DCarbone\UglyQueue
|
* @uses \Cybercinch\UglyQueue
|
||||||
* @depends testCanInitializeUglyQueueWithValidConfigArrayAndNoObservers
|
* @depends testCanInitializeObjectWithValidParameters
|
||||||
* @expectedException \InvalidArgumentException
|
* @param \Cybercinch\UglyQueue $uglyQueue
|
||||||
* @param \DCarbone\UglyQueue $uglyQueue
|
|
||||||
*/
|
*/
|
||||||
public function testExceptionThrownWhenPassingNegativeIntegerValueToLock(\DCarbone\UglyQueue $uglyQueue)
|
public function testExceptionThrownWhenPassingNegativeIntegerValueToLock(\Cybercinch\UglyQueue $uglyQueue)
|
||||||
{
|
{
|
||||||
|
$this->expectException(\InvalidArgumentException::class);
|
||||||
$uglyQueue->lock(-73);
|
$uglyQueue->lock(-73);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers \DCarbone\UglyQueue::lock
|
* @covers \Cybercinch\UglyQueue::lock
|
||||||
* @covers \DCarbone\UglyQueue::isLocked
|
* @covers \Cybercinch\isAlreadyLocked::isAlreadyLocked
|
||||||
* @covers \DCarbone\UglyQueue::createLockFile
|
* @covers \Cybercinch\UglyQueue::createLockFile
|
||||||
* @uses \DCarbone\UglyQueue
|
* @uses \Cybercinch\UglyQueue
|
||||||
* @depends testCanInitializeUglyQueueWithValidConfigArrayAndNoObservers
|
* @depends testCanInitializeObjectWithValidParameters
|
||||||
* @param \DCarbone\UglyQueue $uglyQueue
|
* @param \Cybercinch\UglyQueue $uglyQueue
|
||||||
* @return \DCarbone\UglyQueue
|
* @return \Cybercinch\UglyQueue
|
||||||
*/
|
*/
|
||||||
public function testCanLockUglyQueueWithDefaultTTL(\DCarbone\UglyQueue $uglyQueue)
|
public function testCanLockUglyQueueWithDefaultTTL(\Cybercinch\UglyQueue $uglyQueue)
|
||||||
{
|
{
|
||||||
$locked = $uglyQueue->lock();
|
$locked = $uglyQueue->lock();
|
||||||
|
|
||||||
$this->assertTrue($locked);
|
$this->assertTrue($locked);
|
||||||
|
|
||||||
$queueDir = $uglyQueue->path;
|
$this->assertFileExists($uglyQueue->getLockFile());
|
||||||
|
|
||||||
$this->assertFileExists($queueDir.'queue.lock');
|
$decode = @json_decode(file_get_contents($uglyQueue->getLockFile()));
|
||||||
|
|
||||||
$decode = @json_decode(file_get_contents($queueDir.'queue.lock'));
|
|
||||||
|
|
||||||
$this->assertTrue((json_last_error() === JSON_ERROR_NONE));
|
$this->assertTrue((json_last_error() === JSON_ERROR_NONE));
|
||||||
$this->assertObjectHasAttribute('ttl', $decode);
|
$this->assertObjectHasAttribute('ttl', $decode);
|
||||||
@@ -231,103 +297,104 @@ class UglyQueueTest extends PHPUnit_Framework_TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers \DCarbone\UglyQueue::lock
|
* @covers \Cybercinch\UglyQueue::lock
|
||||||
* @covers \DCarbone\UglyQueue::isLocked
|
* @covers \Cybercinch\isAlreadyLocked::isAlreadyLocked
|
||||||
* @uses \DCarbone\UglyQueue
|
* @uses \Cybercinch\UglyQueue
|
||||||
* @depends testCanInitializeExistingQueue
|
* @depends testCanInitializeExistingQueue
|
||||||
* @param \DCarbone\UglyQueue $uglyQueue
|
* @param \Cybercinch\UglyQueue $uglyQueue
|
||||||
*/
|
*/
|
||||||
public function testCannotLockQueueThatIsAlreadyLocked(\DCarbone\UglyQueue $uglyQueue)
|
public function testCannotLockQueueThatIsAlreadyLocked(\Cybercinch\UglyQueue $uglyQueue)
|
||||||
{
|
{
|
||||||
|
|
||||||
$lock = $uglyQueue->lock();
|
$lock = $uglyQueue->lock();
|
||||||
|
|
||||||
$this->assertFalse($lock);
|
$this->assertFalse($lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers \DCarbone\UglyQueue::isLocked
|
* @covers \Cybercinch\isAlreadyLocked::isAlreadyLocked
|
||||||
* @uses \DCarbone\UglyQueue
|
* @uses \Cybercinch\UglyQueue
|
||||||
* @depends testCanLockUglyQueueWithDefaultTTL
|
* @depends testCanLockUglyQueueWithDefaultTTL
|
||||||
* @param \DCarbone\UglyQueue $uglyQueue
|
* @param \Cybercinch\UglyQueue $uglyQueue
|
||||||
*/
|
*/
|
||||||
public function testIsLockedReturnsTrueAfterLocking(\DCarbone\UglyQueue $uglyQueue)
|
public function testIsLockedReturnsTrueAfterLocking(\Cybercinch\UglyQueue $uglyQueue)
|
||||||
{
|
{
|
||||||
$isLocked = $uglyQueue->isLocked();
|
|
||||||
|
$isLocked = $uglyQueue->isAlreadyLocked();
|
||||||
$this->assertTrue($isLocked);
|
$this->assertTrue($isLocked);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers \DCarbone\UglyQueue::unlock
|
* @covers \Cybercinch\UglyQueue::unlock
|
||||||
* @uses \DCarbone\UglyQueue
|
* @uses \Cybercinch\UglyQueue
|
||||||
* @uses \DCarbone\Helpers\FileHelper
|
* @uses \Cybercinch\Helpers\FileHelper
|
||||||
* @depends testCanLockUglyQueueWithDefaultTTL
|
* @depends testCanLockUglyQueueWithDefaultTTL
|
||||||
* @param \DCarbone\UglyQueue $uglyQueue
|
* @param \Cybercinch\UglyQueue $uglyQueue
|
||||||
* @return \DCarbone\UglyQueue
|
* @return \Cybercinch\UglyQueue
|
||||||
*/
|
*/
|
||||||
public function testCanUnlockLockedQueue(\DCarbone\UglyQueue $uglyQueue)
|
public function testCanUnlockLockedQueue(\Cybercinch\UglyQueue $uglyQueue)
|
||||||
{
|
{
|
||||||
|
|
||||||
$uglyQueue->unlock();
|
$uglyQueue->unlock();
|
||||||
|
|
||||||
$queueGroupDir = $uglyQueue->path;
|
$this->assertFileNotExists($uglyQueue->getLockFile());
|
||||||
|
|
||||||
$this->assertFileNotExists($queueGroupDir.'queue.lock');
|
|
||||||
|
|
||||||
return $uglyQueue;
|
return $uglyQueue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers \DCarbone\UglyQueue::isLocked
|
* @covers \Cybercinch\isAlreadyLocked::isAlreadyLocked
|
||||||
* @uses \DCarbone\UglyQueue
|
* @uses \Cybercinch\UglyQueue
|
||||||
* @depends testCanUnlockLockedQueue
|
* @depends testCanUnlockLockedQueue
|
||||||
* @param \DCarbone\UglyQueue $uglyQueue
|
* @param \Cybercinch\UglyQueue $uglyQueue
|
||||||
*/
|
*/
|
||||||
public function testIsLockedReturnsFalseAfterUnlockingQueue(\DCarbone\UglyQueue $uglyQueue)
|
public function testIsLockedReturnsFalseAfterUnlockingQueue(\Cybercinch\UglyQueue $uglyQueue)
|
||||||
{
|
{
|
||||||
$isLocked = $uglyQueue->isLocked();
|
|
||||||
|
$isLocked = $uglyQueue->isAlreadyLocked();
|
||||||
|
|
||||||
$this->assertFalse($isLocked);
|
$this->assertFalse($isLocked);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers \DCarbone\UglyQueue::lock
|
* @covers \Cybercinch\UglyQueue::lock
|
||||||
* @covers \DCarbone\UglyQueue::isLocked
|
* @covers \Cybercinch\isAlreadyLocked::isAlreadyLocked
|
||||||
* @uses \DCarbone\UglyQueue
|
* @uses \Cybercinch\UglyQueue
|
||||||
* @uses \DCarbone\Helpers\FileHelper
|
* @uses \Cybercinch\Helpers\FileHelper
|
||||||
* @depends testCanUnlockLockedQueue
|
* @depends testCanUnlockLockedQueue
|
||||||
* @param \DCarbone\UglyQueue $uglyQueue
|
* @param \Cybercinch\UglyQueue $uglyQueue
|
||||||
*/
|
*/
|
||||||
public function testIsLockedReturnsFalseWithStaleQueueLockFile(\DCarbone\UglyQueue $uglyQueue)
|
public function testIsLockedReturnsFalseWithStaleQueueLockFile(\Cybercinch\UglyQueue $uglyQueue)
|
||||||
{
|
{
|
||||||
|
|
||||||
$uglyQueue->lock(2);
|
$uglyQueue->lock(2);
|
||||||
$isLocked = $uglyQueue->isLocked();
|
$isLocked = $uglyQueue->isAlreadyLocked();
|
||||||
$this->assertTrue($isLocked);
|
$this->assertTrue($isLocked);
|
||||||
|
|
||||||
sleep(3);
|
sleep(3);
|
||||||
|
|
||||||
$isLocked = $uglyQueue->isLocked();
|
$isLocked = $uglyQueue->isAlreadyLocked();
|
||||||
$this->assertFalse($isLocked);
|
$this->assertFalse($isLocked);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers \DCarbone\UglyQueue::lock
|
* @covers \Cybercinch\UglyQueue::lock
|
||||||
* @covers \DCarbone\UglyQueue::isLocked
|
* @covers \Cybercinch\isAlreadyLocked::isAlreadyLocked
|
||||||
* @covers \DCarbone\UglyQueue::__get
|
* @uses \Cybercinch\UglyQueue
|
||||||
* @uses \DCarbone\UglyQueue
|
|
||||||
* @depends testCanUnlockLockedQueue
|
* @depends testCanUnlockLockedQueue
|
||||||
* @param \DCarbone\UglyQueue $uglyQueue
|
* @param \Cybercinch\UglyQueue $uglyQueue
|
||||||
* @return \DCarbone\UglyQueue
|
* @return \Cybercinch\UglyQueue
|
||||||
*/
|
*/
|
||||||
public function testCanLockQueueWithValidIntegerValue(\DCarbone\UglyQueue $uglyQueue)
|
public function testCanLockQueueWithValidIntegerValue(\Cybercinch\UglyQueue $uglyQueue)
|
||||||
{
|
{
|
||||||
|
|
||||||
$locked = $uglyQueue->lock(200);
|
$locked = $uglyQueue->lock(200);
|
||||||
|
|
||||||
$this->assertTrue($locked);
|
$this->assertTrue($locked);
|
||||||
|
|
||||||
$queueDir = $uglyQueue->path;
|
$this->assertFileExists($uglyQueue->getLockFile());
|
||||||
|
|
||||||
$this->assertFileExists($queueDir.'queue.lock');
|
$decode = @json_decode(file_get_contents($uglyQueue->getLockFile()));
|
||||||
|
|
||||||
$decode = @json_decode(file_get_contents($queueDir.'queue.lock'));
|
|
||||||
|
|
||||||
$this->assertTrue((json_last_error() === JSON_ERROR_NONE));
|
$this->assertTrue((json_last_error() === JSON_ERROR_NONE));
|
||||||
$this->assertObjectHasAttribute('ttl', $decode);
|
$this->assertObjectHasAttribute('ttl', $decode);
|
||||||
@@ -338,28 +405,27 @@ class UglyQueueTest extends PHPUnit_Framework_TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers \DCarbone\UglyQueue::addToQueue
|
* @covers \Cybercinch\UglyQueue::addItem
|
||||||
* @uses \DCarbone\UglyQueue
|
* @uses \Cybercinch\UglyQueue
|
||||||
* @uses \DCarbone\Helpers\FileHelper
|
* @uses \Cybercinch\Helpers\FileHelper
|
||||||
* @depends testCanLockQueueWithValidIntegerValue
|
* @depends testCanLockQueueWithValidIntegerValue
|
||||||
* @param \DCarbone\UglyQueue $uglyQueue
|
* @param \Cybercinch\UglyQueue $uglyQueue
|
||||||
* @return \DCarbone\UglyQueue
|
* @return \Cybercinch\UglyQueue
|
||||||
*/
|
*/
|
||||||
public function testCanPopulateQueueTempFileAfterInitializationAndAcquiringLock(\DCarbone\UglyQueue $uglyQueue)
|
public function testCanPopulateQueueTempFileAfterInitializationAndAcquiringLock(\Cybercinch\UglyQueue $uglyQueue)
|
||||||
{
|
{
|
||||||
|
|
||||||
foreach(array_reverse($this->tastySandwich, true) as $k=>$v)
|
foreach(array_reverse($this->tastySandwich, true) as $k=>$v)
|
||||||
{
|
{
|
||||||
$added = $uglyQueue->addToQueue($k, $v);
|
$added = $uglyQueue->addItem($k, $v);
|
||||||
$this->assertTrue($added);
|
$this->assertTrue($added);
|
||||||
}
|
}
|
||||||
|
|
||||||
$groupDir = $uglyQueue->path;
|
|
||||||
|
|
||||||
$this->assertFileExists(
|
$this->assertFileExists(
|
||||||
$groupDir.'queue.tmp',
|
$uglyQueue->getQueueTmpFile(),
|
||||||
'queue.tmp file was not created!');
|
'queue.tmp file was not created!');
|
||||||
|
|
||||||
$lineCount = \DCarbone\Helpers\FileHelper::getLineCount($groupDir.'queue.tmp');
|
$lineCount = \Dcarbone\Helpers\FileHelper::getLineCount($uglyQueue->getQueueTmpFile());
|
||||||
|
|
||||||
$this->assertEquals(11, $lineCount);
|
$this->assertEquals(11, $lineCount);
|
||||||
|
|
||||||
@@ -367,19 +433,18 @@ class UglyQueueTest extends PHPUnit_Framework_TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers \DCarbone\UglyQueue::_populateQueue
|
* @covers \Cybercinch\UglyQueue::_populateQueue
|
||||||
* @uses \DCarbone\UglyQueue
|
* @uses \Cybercinch\UglyQueue
|
||||||
* @depends testCanPopulateQueueTempFileAfterInitializationAndAcquiringLock
|
* @depends testCanPopulateQueueTempFileAfterInitializationAndAcquiringLock
|
||||||
* @param \DCarbone\UglyQueue $uglyQueue
|
* @param \Cybercinch\UglyQueue $uglyQueue
|
||||||
* @return \DCarbone\UglyQueue
|
* @return \Cybercinch\UglyQueue
|
||||||
*/
|
*/
|
||||||
public function testCanForciblyUpdateQueueFileFromTempFile(\DCarbone\UglyQueue $uglyQueue)
|
public function testCanForciblyUpdateQueueFileFromTempFile(\Cybercinch\UglyQueue $uglyQueue)
|
||||||
{
|
{
|
||||||
|
|
||||||
$uglyQueue->_populateQueue();
|
$uglyQueue->_populateQueue();
|
||||||
|
|
||||||
$groupDir = $uglyQueue->path;
|
$this->assertFileNotExists($uglyQueue->getQueueTmpFile());
|
||||||
|
|
||||||
$this->assertFileNotExists($groupDir.'queue.tmp');
|
|
||||||
|
|
||||||
$uglyQueue->_populateQueue();
|
$uglyQueue->_populateQueue();
|
||||||
|
|
||||||
@@ -387,98 +452,101 @@ class UglyQueueTest extends PHPUnit_Framework_TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers \DCarbone\UglyQueue::getQueueItemCount
|
* @covers \Cybercinch\UglyQueue::count
|
||||||
* @uses \DCarbone\UglyQueue
|
* @uses \Cybercinch\UglyQueue
|
||||||
* @uses \DCarbone\Helpers\FileHelper
|
* @uses \Cybercinch\Helpers\FileHelper
|
||||||
* @depends testCanPopulateQueueTempFileAfterInitializationAndAcquiringLock
|
* @depends testCanPopulateQueueTempFileAfterInitializationAndAcquiringLock
|
||||||
* @param \DCarbone\UglyQueue $uglyQueue
|
* @param \Cybercinch\UglyQueue $uglyQueue
|
||||||
*/
|
*/
|
||||||
public function testCanGetCountOfItemsInPopulatedQueue(\DCarbone\UglyQueue $uglyQueue)
|
public function testCanGetCountOfItemsInPopulatedQueue(\Cybercinch\UglyQueue $uglyQueue)
|
||||||
{
|
{
|
||||||
$itemCount = $uglyQueue->getQueueItemCount();
|
$itemCount = count($uglyQueue);
|
||||||
|
|
||||||
$this->assertEquals(11, $itemCount);
|
$this->assertEquals(11, $itemCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers \DCarbone\UglyQueue::keyExistsInQueue
|
* @covers \Cybercinch\UglyQueue::keyExistsInQueue
|
||||||
* @uses \DCarbone\UglyQueue
|
* @uses \Cybercinch\UglyQueue
|
||||||
* @depends testCanPopulateQueueTempFileAfterInitializationAndAcquiringLock
|
* @depends testCanPopulateQueueTempFileAfterInitializationAndAcquiringLock
|
||||||
* @param \DCarbone\UglyQueue $uglyQueue
|
* @param \Cybercinch\UglyQueue $uglyQueue
|
||||||
*/
|
*/
|
||||||
public function testKeyExistsReturnsTrueWithPopulatedQueue(\DCarbone\UglyQueue $uglyQueue)
|
public function testKeyExistsReturnsTrueWithPopulatedQueue(\Cybercinch\UglyQueue $uglyQueue)
|
||||||
{
|
{
|
||||||
|
|
||||||
$exists = $uglyQueue->keyExistsInQueue(5);
|
$exists = $uglyQueue->keyExistsInQueue(5);
|
||||||
|
|
||||||
$this->assertTrue($exists);
|
$this->assertTrue($exists);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers \DCarbone\UglyQueue::processQueue
|
* @covers \Cybercinch\UglyQueue::retrieveItems
|
||||||
* @uses \DCarbone\UglyQueue
|
* @uses \Cybercinch\UglyQueue
|
||||||
* @depends testCanPopulateQueueTempFileAfterInitializationAndAcquiringLock
|
* @depends testCanPopulateQueueTempFileAfterInitializationAndAcquiringLock
|
||||||
* @expectedException \InvalidArgumentException
|
* @param \Cybercinch\UglyQueue $uglyQueue
|
||||||
* @param \DCarbone\UglyQueue $uglyQueue
|
|
||||||
*/
|
*/
|
||||||
public function testExceptionThrownWhenTryingToProcessLockedQueueWithNonInteger(\DCarbone\UglyQueue $uglyQueue)
|
public function testExceptionThrownWhenTryingToProcessLockedQueueWithNonInteger(\Cybercinch\UglyQueue $uglyQueue)
|
||||||
{
|
{
|
||||||
$process = $uglyQueue->processQueue('Eleventy Billion');
|
$this->expectException(\InvalidArgumentException::class);
|
||||||
|
$uglyQueue->retrieveItems('Eleventy Billion');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers \DCarbone\UglyQueue::processQueue
|
* @covers \Cybercinch\UglyQueue::retrieveItems
|
||||||
* @uses \DCarbone\UglyQueue
|
* @uses \Cybercinch\UglyQueue
|
||||||
* @depends testCanPopulateQueueTempFileAfterInitializationAndAcquiringLock
|
* @depends testCanPopulateQueueTempFileAfterInitializationAndAcquiringLock
|
||||||
* @expectedException \InvalidArgumentException
|
* @expectedException
|
||||||
* @param \DCarbone\UglyQueue $uglyQueue
|
* @param \Cybercinch\UglyQueue $uglyQueue
|
||||||
*/
|
*/
|
||||||
public function testExceptionThrownWhenTryingToProcessLockedQueueWithIntegerLessThan1(\DCarbone\UglyQueue $uglyQueue)
|
public function testExceptionThrownWhenTryingToProcessLockedQueueWithIntegerLessThan1(\Cybercinch\UglyQueue $uglyQueue)
|
||||||
{
|
{
|
||||||
$process = $uglyQueue->processQueue(0);
|
$this->expectException(\InvalidArgumentException::class);
|
||||||
|
$uglyQueue->retrieveItems(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers \DCarbone\UglyQueue::processQueue
|
* @covers \Cybercinch\UglyQueue::retrieveItems
|
||||||
* @covers \DCarbone\UglyQueue::getQueueItemCount
|
* @covers \Cybercinch\UglyQueue::count
|
||||||
* @uses \DCarbone\UglyQueue
|
* @uses \Cybercinch\UglyQueue
|
||||||
* @uses \DCarbone\Helpers\FileHelper
|
* @uses \Cybercinch\Helpers\FileHelper
|
||||||
* @depends testCanPopulateQueueTempFileAfterInitializationAndAcquiringLock
|
* @depends testCanPopulateQueueTempFileAfterInitializationAndAcquiringLock
|
||||||
* @param \DCarbone\UglyQueue $uglyQueue
|
* @param \Cybercinch\UglyQueue $uglyQueue
|
||||||
* @return \DCarbone\UglyQueue
|
* @return \Cybercinch\UglyQueue
|
||||||
*/
|
*/
|
||||||
public function testCanGetPartialQueueContents(\DCarbone\UglyQueue $uglyQueue)
|
public function testCanGetPartialQueueContents(\Cybercinch\UglyQueue $uglyQueue)
|
||||||
{
|
{
|
||||||
$process = $uglyQueue->processQueue(5);
|
|
||||||
|
$process = $uglyQueue->retrieveItems(5);
|
||||||
|
|
||||||
$this->assertEquals(5, count($process));
|
$this->assertEquals(5, count($process));
|
||||||
|
|
||||||
$this->assertArrayHasKey('0', $process);
|
$this->assertArrayHasKey('0', $process);
|
||||||
$this->assertArrayHasKey('4', $process);
|
$this->assertArrayHasKey('4', $process);
|
||||||
|
|
||||||
$this->assertEquals(6, $uglyQueue->getQueueItemCount());
|
$this->assertEquals(6, count($uglyQueue));
|
||||||
|
|
||||||
return $uglyQueue;
|
return $uglyQueue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers \DCarbone\UglyQueue::processQueue
|
* @covers \Cybercinch\UglyQueue::retrieveItems
|
||||||
* @covers \DCarbone\UglyQueue::getQueueItemCount
|
* @covers \Cybercinch\UglyQueue::count
|
||||||
* @uses \DCarbone\UglyQueue
|
* @uses \Cybercinch\UglyQueue
|
||||||
* @uses \DCarbone\Helpers\FileHelper
|
* @uses \Cybercinch\Helpers\FileHelper
|
||||||
* @depends testCanGetPartialQueueContents
|
* @depends testCanGetPartialQueueContents
|
||||||
* @param \DCarbone\UglyQueue $uglyQueue
|
* @param \Cybercinch\UglyQueue $uglyQueue
|
||||||
* @return \DCarbone\UglyQueue
|
* @return \Cybercinch\UglyQueue
|
||||||
*/
|
*/
|
||||||
public function testCanGetFullQueueContents(\DCarbone\UglyQueue $uglyQueue)
|
public function testCanGetFullQueueContents(\Cybercinch\UglyQueue $uglyQueue)
|
||||||
{
|
{
|
||||||
$process = $uglyQueue->processQueue(6);
|
$process = $uglyQueue->retrieveItems(6);
|
||||||
|
|
||||||
$this->assertEquals(6, count($process));
|
$this->assertEquals(6, count($process));
|
||||||
|
|
||||||
$this->assertArrayHasKey('10', $process);
|
$this->assertArrayHasKey('10', $process);
|
||||||
$this->assertArrayHasKey('5', $process);
|
$this->assertArrayHasKey('5', $process);
|
||||||
|
|
||||||
$this->assertEquals(0, $uglyQueue->getQueueItemCount());
|
$this->assertEquals(0, count($uglyQueue));
|
||||||
|
|
||||||
return $uglyQueue;
|
return $uglyQueue;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,75 +3,57 @@
|
|||||||
/**
|
/**
|
||||||
* Class UglyQueueManagerTest
|
* Class UglyQueueManagerTest
|
||||||
*/
|
*/
|
||||||
class UglyQueueManagerTest extends PHPUnit_Framework_TestCase
|
class UglyQueueManagerTest extends PHPUnit\Framework\TestCase
|
||||||
{
|
{
|
||||||
|
protected $baseDir;
|
||||||
|
|
||||||
protected $reallyTastySandwich = array(
|
protected $reallyTastySandwich = array(
|
||||||
'0' => 'beef broth',
|
'0' => 'beef broth',
|
||||||
'1' => 'barbeque sauce',
|
'1' => 'barbeque sauce',
|
||||||
'2' => 'boneless pork ribs',
|
'2' => 'boneless pork ribs',
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
protected function setUp(): void
|
||||||
* @covers \DCarbone\UglyQueueManager::__construct
|
|
||||||
* @covers \DCarbone\UglyQueueManager::init
|
|
||||||
* @covers \DCarbone\UglyQueue::unserialize
|
|
||||||
* @covers \DCarbone\UglyQueue::__get
|
|
||||||
* @covers \DCarbone\UglyQueueManager::addQueue
|
|
||||||
* @covers \DCarbone\UglyQueueManager::containsQueueWithName
|
|
||||||
* @uses \DCarbone\UglyQueueManager
|
|
||||||
* @uses \DCarbone\UglyQueue
|
|
||||||
* @return \DCarbone\UglyQueueManager
|
|
||||||
*/
|
|
||||||
public function testCanInitializeManagerWithConfigAndNoObservers()
|
|
||||||
{
|
{
|
||||||
$config = array(
|
$this->baseDir = realpath(__DIR__.'/../misc/queues');
|
||||||
'queue-base-dir' => __DIR__.'/../misc/queues'
|
}
|
||||||
);
|
|
||||||
|
|
||||||
$manager = \DCarbone\UglyQueueManager::init($config);
|
/**
|
||||||
|
* @covers \Cybercinch\UglyQueueManager::__construct
|
||||||
|
* @covers \Cybercinch\UglyQueue::unserialize
|
||||||
|
* @covers \Cybercinch\UglyQueueManager::addQueue
|
||||||
|
* @covers \Cybercinch\UglyQueueManager::containsQueueWithName
|
||||||
|
* @uses \Cybercinch\UglyQueueManager
|
||||||
|
* @uses \Cybercinch\UglyQueue
|
||||||
|
* @return \Cybercinch\UglyQueueManager
|
||||||
|
*/
|
||||||
|
public function testCanInitializeObjectWithValidPath()
|
||||||
|
{
|
||||||
|
$manager = new \Cybercinch\UglyQueueManager($this->baseDir);
|
||||||
|
|
||||||
$this->assertInstanceOf('\\DCarbone\\UglyQueueManager', $manager);
|
$this->assertInstanceOf('\\Cybercinch\\UglyQueueManager', $manager);
|
||||||
|
|
||||||
return $manager;
|
return $manager;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers \DCarbone\UglyQueueManager::init
|
* @covers \Cybercinch\UglyQueueManager::__construct
|
||||||
* @covers \DCarbone\UglyQueueManager::__construct
|
* @uses \Cybercinch\UglyQueueManager
|
||||||
* @uses \DCarbone\UglyQueueManager
|
|
||||||
* @expectedException \RuntimeException
|
|
||||||
*/
|
*/
|
||||||
public function testExceptionThrownDuringConstructionWithInvalidBasePathValue()
|
public function testExceptionThrownDuringConstructionWithInvalidBasePathValue()
|
||||||
{
|
{
|
||||||
$config = array(
|
$this->expectException(RuntimeException::class);
|
||||||
'queue-base-dir' => 'i do not exist!'
|
new \Cybercinch\UglyQueueManager('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\UglyQueueManager::containsQueueWithName
|
* @covers \Cybercinch\UglyQueueManager::containsQueueWithName
|
||||||
* @uses \DCarbone\UglyQueueManager
|
* @uses \Cybercinch\UglyQueueManager
|
||||||
* @depends testCanInitializeManagerWithConfigAndNoObservers
|
* @depends testCanInitializeObjectWithValidPath
|
||||||
* @param \DCarbone\UglyQueueManager $manager
|
* @param \Cybercinch\UglyQueueManager $manager
|
||||||
*/
|
*/
|
||||||
public function testCanDetermineIfValidQueueExistsInManager(\DCarbone\UglyQueueManager $manager)
|
public function testCanDetermineIfValidQueueExistsInManager(\Cybercinch\UglyQueueManager $manager)
|
||||||
{
|
{
|
||||||
$shouldBeTrue = $manager->containsQueueWithName('tasty-sandwich');
|
$shouldBeTrue = $manager->containsQueueWithName('tasty-sandwich');
|
||||||
|
|
||||||
@@ -79,12 +61,12 @@ class UglyQueueManagerTest extends PHPUnit_Framework_TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers \DCarbone\UglyQueueManager::containsQueueWithName
|
* @covers \Cybercinch\UglyQueueManager::containsQueueWithName
|
||||||
* @uses \DCarbone\UglyQueueManager
|
* @uses \Cybercinch\UglyQueueManager
|
||||||
* @depends testCanInitializeManagerWithConfigAndNoObservers
|
* @depends testCanInitializeObjectWithValidPath
|
||||||
* @param \DCarbone\UglyQueueManager $manager
|
* @param \Cybercinch\UglyQueueManager $manager
|
||||||
*/
|
*/
|
||||||
public function testCanDetermineQueueDoesNotExistInManager(\DCarbone\UglyQueueManager $manager)
|
public function testCanDetermineQueueDoesNotExistInManager(\Cybercinch\UglyQueueManager $manager)
|
||||||
{
|
{
|
||||||
$shouldBeFalse = $manager->containsQueueWithName('i should not exist');
|
$shouldBeFalse = $manager->containsQueueWithName('i should not exist');
|
||||||
|
|
||||||
@@ -92,96 +74,95 @@ class UglyQueueManagerTest extends PHPUnit_Framework_TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers \DCarbone\UglyQueueManager::getQueueWithName
|
* @covers \Cybercinch\UglyQueueManager::getQueueWithName
|
||||||
* @covers \DCarbone\UglyQueue::__get
|
* @uses \Cybercinch\UglyQueueManager
|
||||||
* @uses \DCarbone\UglyQueueManager
|
* @uses \Cybercinch\UglyQueue
|
||||||
* @uses \DCarbone\UglyQueue
|
* @depends testCanInitializeObjectWithValidPath
|
||||||
* @depends testCanInitializeManagerWithConfigAndNoObservers
|
* @param \Cybercinch\UglyQueueManager $manager
|
||||||
* @param \DCarbone\UglyQueueManager $manager
|
|
||||||
*/
|
*/
|
||||||
public function testCanGetUglyQueueObjectFromManager(\DCarbone\UglyQueueManager $manager)
|
public function testCanGetUglyQueueObjectFromManager(\Cybercinch\UglyQueueManager $manager)
|
||||||
{
|
{
|
||||||
$uglyQueue = $manager->getQueueWithName('tasty-sandwich');
|
$uglyQueue = $manager->getQueueWithName('tasty-sandwich');
|
||||||
|
|
||||||
$this->assertInstanceOf('\\DCarbone\\UglyQueue', $uglyQueue);
|
$this->assertInstanceOf('\\Cybercinch\\UglyQueue', $uglyQueue);
|
||||||
$this->assertEquals('tasty-sandwich', $uglyQueue->name);
|
$this->assertEquals('tasty-sandwich', $uglyQueue->getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers \DCarbone\UglyQueueManager::getQueueWithName
|
* @covers \Cybercinch\UglyQueueManager::getQueueWithName
|
||||||
* @uses \DCarbone\UglyQueueManager
|
* @uses \Cybercinch\UglyQueueManager
|
||||||
* @expectedException \InvalidArgumentException
|
* @depends testCanInitializeObjectWithValidPath
|
||||||
* @depends testCanInitializeManagerWithConfigAndNoObservers
|
* @param \Cybercinch\UglyQueueManager $manager
|
||||||
* @param \DCarbone\UglyQueueManager $manager
|
|
||||||
*/
|
*/
|
||||||
public function testExceptionThrownWhenTryingToGetNonExistentQueueFromManager(\DCarbone\UglyQueueManager $manager)
|
public function testExceptionThrownWhenTryingToGetNonExistentQueueFromManager(\Cybercinch\UglyQueueManager $manager)
|
||||||
{
|
{
|
||||||
$shouldNotExist = $manager->getQueueWithName('sandwiches');
|
$this->expectException(InvalidArgumentException::class);
|
||||||
|
$manager->getQueueWithName('sandwiches');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers \DCarbone\UglyQueueManager::getQueueList
|
* @covers \Cybercinch\UglyQueueManager::getQueueList
|
||||||
* @uses \DCarbone\UglyQueueManager
|
* @uses \Cybercinch\UglyQueueManager
|
||||||
* @depends testCanInitializeManagerWithConfigAndNoObservers
|
* @depends testCanInitializeObjectWithValidPath
|
||||||
* @param \DCarbone\UglyQueueManager $manager
|
* @param \Cybercinch\UglyQueueManager $manager
|
||||||
*/
|
*/
|
||||||
public function testCanGetListOfQueuesInManager(\DCarbone\UglyQueueManager $manager)
|
public function testCanGetListOfQueuesInManager(\Cybercinch\UglyQueueManager $manager)
|
||||||
{
|
{
|
||||||
$queueList = $manager->getQueueList();
|
$queueList = $manager->getQueueList();
|
||||||
|
|
||||||
$this->assertInternalType('array', $queueList);
|
$this->assertIsArray($queueList);
|
||||||
$this->assertCount(1, $queueList);
|
$this->assertCount(1, $queueList);
|
||||||
$this->assertContains('tasty-sandwich', $queueList);
|
$this->assertContains('tasty-sandwich', $queueList);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers \DCarbone\UglyQueueManager::getQueueWithName
|
* @covers \Cybercinch\UglyQueueManager::getQueueWithName
|
||||||
* @covers \DCarbone\UglyQueueManager::addQueue
|
* @covers \Cybercinch\UglyQueueManager::addQueue
|
||||||
* @uses \DCarbone\UglyQueueManager
|
* @uses \Cybercinch\UglyQueueManager
|
||||||
* @uses \DCarbone\UglyQueue
|
* @uses \Cybercinch\UglyQueue
|
||||||
* @expectedException \RuntimeException
|
* @depends testCanInitializeObjectWithValidPath
|
||||||
* @depends testCanInitializeManagerWithConfigAndNoObservers
|
* @param \Cybercinch\UglyQueueManager $manager
|
||||||
* @param \DCarbone\UglyQueueManager $manager
|
|
||||||
*/
|
*/
|
||||||
public function testExceptionThrownWhenReAddingQueueToManager(\DCarbone\UglyQueueManager $manager)
|
public function testExceptionThrownWhenReAddingQueueToManager(\Cybercinch\UglyQueueManager $manager)
|
||||||
{
|
{
|
||||||
|
$this->expectException(RuntimeException::class);
|
||||||
$uglyQueue = $manager->getQueueWithName('tasty-sandwich');
|
$uglyQueue = $manager->getQueueWithName('tasty-sandwich');
|
||||||
|
|
||||||
$manager->addQueue($uglyQueue);
|
$manager->addQueue($uglyQueue);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers \DCarbone\UglyQueueManager::addQueueAtPath
|
* @covers \Cybercinch\UglyQueueManager::addQueueAtPath
|
||||||
* @covers \DCarbone\UglyQueueManager::addQueue
|
* @covers \Cybercinch\UglyQueueManager::addQueue
|
||||||
* @covers \DCarbone\UglyQueueManager::getQueueWithName
|
* @covers \Cybercinch\UglyQueueManager::getQueueWithName
|
||||||
* @uses \DCarbone\UglyQueueManager
|
* @uses \Cybercinch\UglyQueueManager
|
||||||
* @uses \DCarbone\UglyQueue
|
* @uses \Cybercinch\UglyQueue
|
||||||
* @depends testCanInitializeManagerWithConfigAndNoObservers
|
* @depends testCanInitializeObjectWithValidPath
|
||||||
* @param \DCarbone\UglyQueueManager $manager
|
* @param \Cybercinch\UglyQueueManager $manager
|
||||||
*/
|
*/
|
||||||
public function testCanInitializeNewQueueAndAddToManager(\DCarbone\UglyQueueManager $manager)
|
public function testCanInitializeNewQueueAndAddToManager(\Cybercinch\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');
|
||||||
|
|
||||||
$this->assertInstanceOf('\\DCarbone\\UglyQueue', $uglyQueue);
|
$this->assertInstanceOf('\\Cybercinch\\UglyQueue', $uglyQueue);
|
||||||
$this->assertEquals('really-tasty-sandwich', $uglyQueue->name);
|
$this->assertEquals('really-tasty-sandwich', $uglyQueue->getName());
|
||||||
|
|
||||||
$queueList = $manager->getQueueList();
|
$queueList = $manager->getQueueList();
|
||||||
|
|
||||||
$this->assertInternalType('array', $queueList);
|
$this->assertIsArray($queueList);
|
||||||
$this->assertCount(2, $queueList);
|
$this->assertCount(2, $queueList);
|
||||||
$this->assertContains('really-tasty-sandwich', $queueList);
|
$this->assertContains('really-tasty-sandwich', $queueList);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers \DCarbone\UglyQueueManager::removeQueueByName
|
* @covers \Cybercinch\UglyQueueManager::removeQueueByName
|
||||||
* @uses \DCarbone\UglyQueueManager
|
* @uses \Cybercinch\UglyQueueManager
|
||||||
* @depends testCanInitializeManagerWithConfigAndNoObservers
|
* @depends testCanInitializeObjectWithValidPath
|
||||||
* @param \DCarbone\UglyQueueManager $manager
|
* @param \Cybercinch\UglyQueueManager $manager
|
||||||
*/
|
*/
|
||||||
public function testCanRemoveQueueFromManagerByName(\DCarbone\UglyQueueManager $manager)
|
public function testCanRemoveQueueFromManagerByName(\Cybercinch\UglyQueueManager $manager)
|
||||||
{
|
{
|
||||||
$manager->removeQueueByName('really-tasty-sandwich');
|
$manager->removeQueueByName('really-tasty-sandwich');
|
||||||
|
|
||||||
@@ -192,12 +173,12 @@ class UglyQueueManagerTest extends PHPUnit_Framework_TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
// /**
|
// /**
|
||||||
// * @covers \DCarbone\UglyQueue::queueExists
|
// * @covers \Cybercinch\UglyQueue::queueExists
|
||||||
// * @uses \DCarbone\UglyQueue
|
// * @uses \Cybercinch\UglyQueue
|
||||||
// * @depends testCanInitializeNewUglyQueue
|
// * @depends testCanInitializeNewUglyQueue
|
||||||
// * @param \DCarbone\UglyQueue $uglyQueue
|
// * @param \Cybercinch\UglyQueue $uglyQueue
|
||||||
// */
|
// */
|
||||||
// public function testCanDetermineExistenceOfExistingQueue(\DCarbone\UglyQueue $uglyQueue)
|
// public function testCanDetermineExistenceOfExistingQueue(\Cybercinch\UglyQueue $uglyQueue)
|
||||||
// {
|
// {
|
||||||
// $exists = $uglyQueue->queueExists('tasty-sandwich');
|
// $exists = $uglyQueue->queueExists('tasty-sandwich');
|
||||||
//
|
//
|
||||||
@@ -205,12 +186,12 @@ class UglyQueueManagerTest extends PHPUnit_Framework_TestCase
|
|||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// /**
|
// /**
|
||||||
// * @covers \DCarbone\UglyQueue::queueExists
|
// * @covers \Cybercinch\UglyQueue::queueExists
|
||||||
// * @uses \DCarbone\UglyQueue
|
// * @uses \Cybercinch\UglyQueue
|
||||||
// * @depends testCanInitializeNewUglyQueue
|
// * @depends testCanInitializeNewUglyQueue
|
||||||
// * @param \DCarbone\UglyQueue $uglyQueue
|
// * @param \Cybercinch\UglyQueue $uglyQueue
|
||||||
// */
|
// */
|
||||||
// public function testCanDetermineExistenceOfNonExistingQueue(\DCarbone\UglyQueue $uglyQueue)
|
// public function testCanDetermineExistenceOfNonExistingQueue(\Cybercinch\UglyQueue $uglyQueue)
|
||||||
// {
|
// {
|
||||||
// $exists = $uglyQueue->queueExists('nasty-sandwich');
|
// $exists = $uglyQueue->queueExists('nasty-sandwich');
|
||||||
//
|
//
|
||||||
@@ -218,12 +199,12 @@ class UglyQueueManagerTest extends PHPUnit_Framework_TestCase
|
|||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// /**
|
// /**
|
||||||
// * @covers \DCarbone\UglyQueue::getInitializedQueueList
|
// * @covers \Cybercinch\UglyQueue::getInitializedQueueList
|
||||||
// * @uses \DCarbone\UglyQueue
|
// * @uses \Cybercinch\UglyQueue
|
||||||
// * @depends testCanInitializeNewUglyQueue
|
// * @depends testCanInitializeNewUglyQueue
|
||||||
// * @param \DCarbone\UglyQueue $uglyQueue
|
// * @param \Cybercinch\UglyQueue $uglyQueue
|
||||||
// */
|
// */
|
||||||
// public function testCanGetListOfInitializedQueues(\DCarbone\UglyQueue $uglyQueue)
|
// public function testCanGetListOfInitializedQueues(\Cybercinch\UglyQueue $uglyQueue)
|
||||||
// {
|
// {
|
||||||
// $queueList = $uglyQueue->getInitializedQueueList();
|
// $queueList = $uglyQueue->getInitializedQueueList();
|
||||||
//
|
//
|
||||||
|
|||||||
Reference in New Issue
Block a user