public function testCreate() { $process = Phake::mock('React\\ChildProcess\\Process'); $loop = Phake::mock('React\\EventLoop\\LoopInterface'); $poolPromise = Flexible::create($process, $loop); $this->assertInstanceOf('React\\Promise\\PromiseInterface', $poolPromise); $promiseHasResolved = false; $poolPromise->then(function ($pool) use(&$promiseHasResolved) { $this->assertInstanceOf('WyriHaximus\\React\\ChildProcess\\Pool\\Pool\\Flexible', $pool); $this->assertInstanceOf('WyriHaximus\\React\\ChildProcess\\Pool\\PoolInterface', $pool); $promiseHasResolved = true; }); $this->assertTrue($promiseHasResolved); }
public function testManagerReadyQueueEmptyIsBusy() { $message = Factory::rpc('beer', ['foo' => 'bar']); $worker = Phake::mock('WyriHaximus\\React\\ChildProcess\\Pool\\WorkerInterface'); $queue = Phake::mock('WyriHaximus\\React\\ChildProcess\\Pool\\QueueInterface'); $manager = Phake::mock('WyriHaximus\\React\\ChildProcess\\Pool\\ManagerInterface'); $timer = Phake::mock('React\\EventLoop\\Timer\\TimerInterface'); Phake::when($worker)->isBusy()->thenReturn(true); Phake::when($queue)->count()->thenReturn(0); Phake::when($queue)->dequeue()->thenReturn($message); Phake::when($manager)->on($this->isType('string'), $this->isType('callable'))->thenReturnCallback(function ($event, $function) use($worker) { $function($worker); }); $poolInstance = null; $process = Phake::mock('React\\ChildProcess\\Process'); $loop = Phake::mock('React\\EventLoop\\LoopInterface'); Phake::when($loop)->addPeriodicTimer($this->isType('float'), $this->isType('callable'))->thenReturnCallback(function ($interval, $function) use($timer) { $function($timer); }); Flexible::create($process, $loop, [Options::MANAGER => $manager, Options::QUEUE => $queue, Options::TTL => 0])->then(function ($pool) use($message) { $pool->rpc($message); }); Phake::verify($timer)->cancel(); }