public function testSend() { $sentData = new Deferred(); $sentData->promise()->then(function () { $this->assertEquals('test', func_get_args()[0]); }, function () { $this->fail(); }); $stream = $this->getMockStream(); $stream->expects($this->once())->method('write')->willReturnCallback(function () use(&$sentData) { $args = func_get_args(); if (isset($args[0])) { $sentData->resolve($args[0]); } else { $sentData->reject(); } }); $factory = new RequestFactory(); $connection = new Connection($stream, $factory); $connection->sendData('test'); }