php-ipc/tests/Msg/QueueTest.php

70 lines
1.4 KiB
PHP
Raw Permalink Normal View History

2018-04-15 14:41:46 +00:00
<?php
namespace NoccyLabs\Ipc\Msg;
use NoccyLabs\Ipc\Key\FileKey;
class QueueTest extends \PhpUnit\Framework\TestCase
{
public function testSendingAndReceiving()
{
$key = new FileKey(__FILE__);
$queue = new Queue($key);
$queue->send(1, "Hello World");
$ret = $queue->receive(1, $type);
$this->assertEquals("Hello World", $ret);
$this->assertEquals(1, $type);
}
public function testSendingAndReceivingWithTypes()
{
$key = new FileKey(__FILE__);
$queue = new Queue($key);
$queue->send(1, "Hello World");
$queue->send(2, "Hello World");
$queue->send(3, "Hello World");
$ret = $queue->receive(1, $type);
$this->assertEquals(1, $type);
$ret = $queue->receive(2, $type);
$this->assertEquals(2, $type);
$ret = $queue->receive(3, $type);
$this->assertEquals(3, $type);
}
public function testReceivingFromFront()
{
$key = new FileKey(__FILE__);
$queue = new Queue($key);
$queue->send(1, "Hello World");
$queue->send(2, "Hello World");
$queue->send(3, "Hello World");
$ret = $queue->receive(0, $type);
$this->assertEquals(1, $type);
$ret = $queue->receive(0, $type);
$this->assertEquals(2, $type);
$ret = $queue->receive(0, $type);
$this->assertEquals(3, $type);
}
}