Skip to content

Commit

Permalink
Merge pull request #13 from clue-labs/all-args
Browse files Browse the repository at this point in the history
Fix `all()` to assume null values if no event data is passed
  • Loading branch information
WyriHaximus authored Dec 22, 2017
2 parents 3c9018d + 04a8528 commit 3bc2c27
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ function all(EventEmitterInterface $stream, $event = 'data')
}

$buffer = array();
$bufferer = function ($data) use (&$buffer) {
$bufferer = function ($data = null) use (&$buffer) {
$buffer []= $data;
};
$stream->on($event, $bufferer);
Expand Down
13 changes: 13 additions & 0 deletions tests/AllTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,19 @@ public function testEmittingDataOnStreamResolvesWithArrayOfData()
$this->expectPromiseResolveWith(array('hello', 'world'), $promise);
}

public function testEmittingCustomEventOnStreamResolvesWithArrayOfCustomEventData()
{
$stream = new ThroughStream();
$promise = Stream\all($stream, 'a');

$stream->emit('a', array('hello'));
$stream->emit('b', array('ignored'));
$stream->emit('a');
$stream->close();

$this->expectPromiseResolveWith(array('hello', null), $promise);
}

public function testEmittingErrorOnStreamRejects()
{
$stream = new ThroughStream();
Expand Down

0 comments on commit 3bc2c27

Please sign in to comment.