Skip to content

Commit

Permalink
More robust skipping
Browse files Browse the repository at this point in the history
  • Loading branch information
sanmai committed Nov 7, 2022
1 parent e90d579 commit a72fd09
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions tests/AppendPrependTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use const PHP_VERSION_ID;
use PHPUnit\Framework\TestCase;
use function Pipeline\take;
use function reset;

/**
* @covers \Pipeline\Standard
Expand Down Expand Up @@ -76,17 +77,15 @@ public function provideAppendArrays(): iterable
*/
public function testPush(array $expected, ?array $initialValue, ...$iterables): void
{
$useKeys = !is_numeric(key($expected));
if ($useKeys && PHP_VERSION_ID < 80000) {
$this->markTestIncomplete('PHP 7 fails with an error: Cannot unpack array with string keys');
}
$this->skipOnPHP7($expected);

$pipeline = take($initialValue);

foreach ($iterables as $iterable) {
$pipeline->push(...$iterable ?? []);
}

$useKeys = !is_numeric(key($expected));
$this->assertSame($expected, $pipeline->toArray($useKeys));
}

Expand Down Expand Up @@ -138,17 +137,15 @@ public function providePrependArrays(): iterable
*/
public function testUnshift(array $expected, ?array $initialValue, ...$iterables): void
{
$useKeys = !is_numeric(key($expected));
if ($useKeys && PHP_VERSION_ID < 80000) {
$this->markTestIncomplete('PHP 7 fails with an error: Cannot unpack array with string keys');
}
$this->skipOnPHP7($expected);

$pipeline = take($initialValue);

foreach ($iterables as $iterable) {
$pipeline->unshift(...$iterable ?? []);
}

$useKeys = !is_numeric(key($expected));
$this->assertSame($expected, $pipeline->toArray($useKeys));
}

Expand All @@ -175,4 +172,11 @@ public function testPrepend(array $expected, ?iterable $initialValue, ...$iterab
$useKeys = !is_numeric(key($expected));
$this->assertSame($expected, $pipeline->toArray($useKeys));
}

private function skipOnPHP7(array $expected): void
{
if (!is_numeric(reset($expected)) && PHP_VERSION_ID < 80000) {
$this->markTestSkipped('PHP 7 fails with an error: Cannot unpack array with string keys');
}
}
}

0 comments on commit a72fd09

Please sign in to comment.