endtoend-test-psl/tests/Psl/Fun/PipeTest.php
2020-10-15 11:05:30 +02:00

41 lines
952 B
PHP

<?php
declare(strict_types=1);
namespace Psl\Tests\Fun;
use PHPUnit\Framework\TestCase;
use Psl\Fun;
use Psl\Str;
final class PipeTest extends TestCase
{
public function testItCombinesMultipleFunctionToExecutesInOrder(): void
{
$x = Fun\pipe(
static fn (string $x): string => $x . ' world',
static fn (string $y): string => $y . '?',
static fn (string $z): string => $z . '!',
);
static::assertSame('Hello world?!', $x('Hello'));
}
public function testItCombinesMultipleFunctionsThatDealWithDifferentTypes(): void
{
$x = Fun\pipe(
static fn (string $x): int => Str\length($x),
static fn (int $y): string => $y . '!'
);
static::assertSame('5!', $x('Hello'));
}
public function testItCanCreateAnEmptyCombination(): void
{
$x = Fun\pipe();
static::assertSame('Hello', $x('Hello'));
}
}