1
0
mirror of https://github.com/danog/parallel.git synced 2024-12-12 09:09:35 +01:00
parallel/tests/Sync/ChannelTest.php

45 lines
990 B
PHP
Raw Normal View History

2015-08-03 07:20:06 +02:00
<?php
namespace Icicle\Tests\Concurrent\Sync;
use Icicle\Concurrent\Sync\Channel;
use Icicle\Loop;
2015-08-03 07:58:08 +02:00
use Icicle\Coroutine;
2015-08-03 07:20:06 +02:00
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();
2015-08-03 07:58:08 +02:00
new Coroutine\Coroutine($b->receive());
2015-08-03 07:20:06 +02:00
Loop\run();
$this->assertFalse($a->isOpen());
$this->assertFalse($b->isOpen());
}
public function testSendReceive()
{
Coroutine\create(function () {
list($a, $b) = Channel::create();
2015-08-03 07:20:06 +02:00
yield $a->send('hello');
$data = (yield $b->receive());
2015-08-03 07:20:06 +02:00
$this->assertEquals('hello', $data);
});
Loop\run();
}
}