1
0
mirror of https://github.com/danog/parallel.git synced 2024-12-02 17:52:14 +01:00
parallel/tests/Worker/FunctionsTest.php

81 lines
1.8 KiB
PHP
Raw Normal View History

2016-01-15 01:08:06 +01:00
<?php
namespace Icicle\Tests\Concurrent\Worker;
use Icicle\Concurrent\Worker;
2016-01-23 07:00:56 +01:00
use Icicle\Concurrent\Worker\{Environment, Pool, Task, WorkerFactory};
2016-01-15 01:08:06 +01:00
use Icicle\Coroutine\Coroutine;
use Icicle\Tests\Concurrent\TestCase;
class FunctionsTest extends TestCase
{
public function testPool()
2016-01-15 01:08:06 +01:00
{
$pool = $this->getMock(Pool::class);
Worker\pool($pool);
2016-01-23 18:37:01 +01:00
$this->assertTrue($pool === Worker\pool());
2016-01-15 01:08:06 +01:00
}
/**
* @depends testPool
2016-01-15 01:08:06 +01:00
*/
public function testEnqueue()
{
$pool = $this->getMock(Pool::class);
$pool->method('enqueue')
->will($this->returnCallback(function (Task $task) {
2016-01-23 18:37:01 +01:00
return yield $task->run($this->getMock(Environment::class));
2016-01-15 01:08:06 +01:00
}));
Worker\pool($pool);
$value = 42;
$task = new TestTask($value);
$coroutine = new Coroutine(Worker\enqueue($task));
$this->assertSame($value, $coroutine->wait());
}
/**
* @depends testPool
2016-01-15 01:08:06 +01:00
*/
public function testGet()
2016-01-15 01:08:06 +01:00
{
$pool = $this->getMock(Pool::class);
$pool->expects($this->once())
->method('get')
2016-01-15 01:08:06 +01:00
->will($this->returnValue($this->getMock(Worker\Worker::class)));
Worker\pool($pool);
2016-01-15 01:08:06 +01:00
$worker = Worker\get();
2016-01-15 01:08:06 +01:00
}
public function testFactory()
2016-01-15 01:08:06 +01:00
{
$factory = $this->getMock(WorkerFactory::class);
Worker\factory($factory);
2016-01-23 18:37:01 +01:00
$this->assertTrue($factory === Worker\factory());
2016-01-15 01:08:06 +01:00
}
/**
* @depends testFactory
2016-01-15 01:08:06 +01:00
*/
public function testCreate()
{
$factory = $this->getMock(WorkerFactory::class);
$factory->expects($this->once())
->method('create')
->will($this->returnValue($this->getMock(Worker\Worker::class)));
Worker\factory($factory);
$worker = Worker\create();
}
}