Skip to content

Commit

Permalink
Backport some tests from 3.x
Browse files Browse the repository at this point in the history
  • Loading branch information
sanmai committed Jun 3, 2019
1 parent 30659dd commit a9c6f69
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
22 changes: 22 additions & 0 deletions tests/EdgeCasesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,28 @@ public function testFilterAnyFalseValueCustomCallback()
$this->assertCount(0, $pipeline->toArray());
}

public function testNonUniqueKeys()
{
$pipeline = \Pipeline\map(function () {
yield 'foo' => 'bar';
yield 'foo' => 'baz';
});

$this->assertSame([
'foo' => 'baz',
], iterator_to_array($pipeline));

$pipeline = \Pipeline\map(function () {
yield 'foo' => 'bar';
yield 'foo' => 'baz';
});

$this->assertSame([
'bar',
'baz',
], $pipeline->toArray());
}

public function testMapUnprimed()
{
$pipeline = new Standard();
Expand Down
17 changes: 17 additions & 0 deletions tests/ErrorsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,21 @@ public function testPipelineInPipelineUsesSelf()

$pipeline->reduce();
}

/**
* @covers \Pipeline\Standard::unpack()
*/
public function testUnpackNonIterable()
{
$pipeline = new \Pipeline\Standard();

$pipeline->map(function () {
yield 1;
yield [2, 3];
})->unpack();

$this->expectException(Warning::class);
$this->expectExceptionMessage('Only arrays and Traversables can be unpacked');
$pipeline->toArray();
}
}

0 comments on commit a9c6f69

Please sign in to comment.