diff --git a/composer.json b/composer.json index 09e50e8..6c52704 100644 --- a/composer.json +++ b/composer.json @@ -8,12 +8,10 @@ "evenement/evenement": "^2.0|^1.0" }, "require-dev": { - "react/event-loop": "^0.4|^0.3", - "react/promise": "^2.0|^1.0" + "react/event-loop": "^0.4|^0.3" }, "suggest": { - "react/event-loop": "^0.4", - "react/promise": "^2.0" + "react/event-loop": "^0.4" }, "autoload": { "psr-4": { diff --git a/src/BufferedSink.php b/src/BufferedSink.php deleted file mode 100644 index a6b35c0..0000000 --- a/src/BufferedSink.php +++ /dev/null @@ -1,59 +0,0 @@ -deferred = new Deferred(); - - $this->on('pipe', array($this, 'handlePipeEvent')); - $this->on('error', array($this, 'handleErrorEvent')); - } - - public function handlePipeEvent($source) - { - Util::forwardEvents($source, $this, array('error')); - } - - public function handleErrorEvent($e) - { - $this->deferred->reject($e); - } - - public function write($data) - { - $this->buffer .= $data; - $this->deferred->progress($data); - } - - public function close() - { - if ($this->closed) { - return; - } - - parent::close(); - $this->deferred->resolve($this->buffer); - } - - public function promise() - { - return $this->deferred->promise(); - } - - public static function createPromise(ReadableStreamInterface $stream) - { - $sink = new static(); - $stream->pipe($sink); - - return $sink->promise(); - } -} diff --git a/tests/BufferedSinkTest.php b/tests/BufferedSinkTest.php deleted file mode 100644 index ee374d6..0000000 --- a/tests/BufferedSinkTest.php +++ /dev/null @@ -1,194 +0,0 @@ -promise(); - - $this->assertInstanceOf('React\Promise\PromiseInterface', $contents); - } - - /** @test */ - public function endShouldResolvePromiseWithBufferContents() - { - $callback = $this->expectCallableOnceWith('foo'); - - $sink = new BufferedSink(); - $sink - ->promise() - ->then($callback); - - $sink->write('foo'); - $sink->end(); - } - - /** @test */ - public function closeWithEmptyBufferShouldResolveToEmptyString() - { - $callback = $this->expectCallableOnceWith(''); - - $sink = new BufferedSink(); - $sink - ->promise() - ->then($callback); - - $sink->close(); - $sink->close(); - } - - /** @test */ - public function closeTwiceShouldBeFine() - { - $callback = $this->expectCallableOnce(); - - $sink = new BufferedSink(); - $sink - ->promise() - ->then($callback); - - $sink->close(); - $sink->close(); - } - - /** @test */ - public function resovedValueShouldContainMultipleWrites() - { - $callback = $this->expectCallableOnceWith('foobarbaz'); - - $sink = new BufferedSink(); - $sink - ->promise() - ->then($callback); - - $sink->write('foo'); - $sink->write('bar'); - $sink->write('baz'); - $sink->end(); - } - - /** @test */ - public function dataWrittenOnEndShouldBeBuffered() - { - $callback = $this->expectCallableOnceWith('foobar'); - - $sink = new BufferedSink(); - $sink - ->promise() - ->then($callback); - - $sink->write('foo'); - $sink->end('bar'); - } - - /** @test */ - public function errorsShouldRejectPromise() - { - $errback = $this->expectCallableOnceWith($this->callback(function ($e) { - return $e instanceof \Exception && 'Shit happens' === $e->getMessage(); - })); - - $sink = new BufferedSink(); - $sink - ->promise() - ->then($this->expectCallableNever(), $errback); - - $sink->emit('error', array(new \Exception('Shit happens'))); - } - - /** @test */ - public function writeShouldTriggerProgressOnPromise() - { - $callback = $this->createCallableMock(); - $callback - ->expects($this->at(0)) - ->method('__invoke') - ->with('foo'); - $callback - ->expects($this->at(1)) - ->method('__invoke') - ->with('bar'); - $callback - ->expects($this->at(2)) - ->method('__invoke') - ->with('baz'); - - $sink = new BufferedSink(); - $sink - ->promise() - ->then(null, null, $callback); - - $sink->write('foo'); - $sink->write('bar'); - $sink->end('baz'); - } - - /** @test */ - public function forwardedErrorsFromPipeShouldRejectPromise() - { - $errback = $this->expectCallableOnceWith($this->callback(function ($e) { - return $e instanceof \Exception && 'Shit happens' === $e->getMessage(); - })); - - $sink = new BufferedSink(); - $sink - ->promise() - ->then($this->expectCallableNever(), $errback); - - $readable = new ReadableStream(); - $readable->pipe($sink); - $readable->emit('error', array(new \Exception('Shit happens'))); - } - - /** @test */ - public function pipeShouldSucceedAndResolve() - { - $callback = $this->expectCallableOnceWith('foobar'); - - $sink = new BufferedSink(); - $sink - ->promise() - ->then($callback); - - $readable = new ReadableStream(); - $readable->pipe($sink); - $readable->emit('data', array('foo')); - $readable->emit('data', array('bar')); - $readable->close(); - } - - /** @test */ - public function factoryMethodShouldImplicitlyPipeAndPromise() - { - $callback = $this->expectCallableOnceWith('foo'); - - $readable = new ReadableStream(); - - BufferedSink::createPromise($readable) - ->then($callback); - - $readable->emit('data', array('foo')); - $readable->close(); - } - - private function expectCallableOnceWith($value) - { - $callback = $this->createCallableMock(); - $callback - ->expects($this->once()) - ->method('__invoke') - ->with($value); - - return $callback; - } -}