70 lines
1.4 KiB
PHP
70 lines
1.4 KiB
PHP
<?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);
|
|
|
|
}
|
|
|
|
|
|
} |