1
0
mirror of https://github.com/danog/parallel.git synced 2024-12-03 10:07:49 +01:00
parallel/tests/Sync/ChannelTest.php
2015-08-03 00:58:08 -05:00

45 lines
1017 B
PHP

<?php
namespace Icicle\Tests\Concurrent\Sync;
use Icicle\Concurrent\Sync\Channel;
use Icicle\Loop;
use Icicle\Coroutine;
class ChannelTest extends \PHPUnit_Framework_TestCase
{
public function testCreate()
{
list($a, $b) = Channel::create();
$this->assertInstanceOf(Channel::class, $a);
$this->assertInstanceOf(Channel::class, $b);
}
public function testClose()
{
list($a, $b) = Channel::create();
// Close $a. $b should close on next read...
$a->close();
new Coroutine\Coroutine($b->receive());
Loop\run();
$this->assertFalse($a->isOpen());
$this->assertFalse($b->isOpen());
}
public function testSendReceive()
{
list($a, $b) = Channel::create();
$a->send('hello')->then(function () use ($b) {
return new Coroutine\Coroutine($b->receive());
})->done(function ($data) {
$this->assertEquals('hello', $data);
});
Loop\run();
}
}