Add queuefile tests
git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@5266 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
@@ -70,10 +70,12 @@ class queuefile extends queue
|
||||
else
|
||||
$file->lockSH ($this->queue);
|
||||
$content = $file->file_get_contents ($this->queue);
|
||||
$entries = array ();
|
||||
foreach (explode ("\n", $content) as $json)
|
||||
$entries = explode ("\n", $content);
|
||||
// Explode return always one empty entry at end. Remove it
|
||||
array_pop ($entries);
|
||||
foreach ($entries as $key => $val)
|
||||
{
|
||||
$entries[] = json_decode ($json);
|
||||
$entries[$key] = json_decode ($val);
|
||||
}
|
||||
if ($delete)
|
||||
$file->file_put_contents ($this->queue, "");
|
||||
@@ -125,6 +127,8 @@ class queuefile extends queue
|
||||
$file->lockSH ($this->queue);
|
||||
$content = $file->file_get_contents ($this->queue);
|
||||
$entries = explode ("\n", $content);
|
||||
// Explode return always one empty entry at end. Remove it
|
||||
array_pop ($entries);
|
||||
if (count ($entries) === 0)
|
||||
$res = null;
|
||||
else
|
||||
@@ -155,6 +159,8 @@ class queuefile extends queue
|
||||
$file->lockSH ($this->queue);
|
||||
$content = $file->file_get_contents ($this->queue);
|
||||
$entries = explode ("\n", $content);
|
||||
// Explode return always one empty entry at end. Remove it
|
||||
array_pop ($entries);
|
||||
if (count ($entries) === 0)
|
||||
$res = null;
|
||||
else
|
||||
@@ -171,7 +177,8 @@ class queuefile extends queue
|
||||
// }}}
|
||||
|
||||
/** Get X entries starting at position Y
|
||||
* @param integer $start the starting position
|
||||
* @param integer $start the starting position (the entries start at position
|
||||
* zero)
|
||||
* @param integer $number The number of entries to get
|
||||
* @param boolean|null $delete If true, delete the read entries
|
||||
* @return array An array of mixed entries
|
||||
@@ -186,13 +193,18 @@ class queuefile extends queue
|
||||
$file->lockSH ($this->queue);
|
||||
$content = $file->file_get_contents ($this->queue);
|
||||
$entries = explode ("\n", $content);
|
||||
// Explode return always one empty entry at end. Remove it
|
||||
array_pop ($entries);
|
||||
$res = array ();
|
||||
if (count ($entries) > 0)
|
||||
{
|
||||
for ($i = $start ; $i < $start + $number ; $i++)
|
||||
{
|
||||
if (! key_exists ($i, $entries))
|
||||
{
|
||||
$file->lockUN ($this->queue);
|
||||
throw new \Exception ("Invalid entry requested", 406);
|
||||
}
|
||||
$json = $entries[$i];
|
||||
$content = json_decode ($json, true);
|
||||
if (json_last_error() === JSON_ERROR_NONE)
|
||||
|
||||
Reference in New Issue
Block a user