endtoend-test-psl/tests/Psl/Fun/PipeTest.php
2020-09-28 14:57:00 +01:00

41 lines
911 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(
fn (string $x): string => $x . ' world',
fn (string $y): string => $y . '?',
fn (string $z): string => $z . '!',
);
self::assertSame('Hello world?!', $x('Hello'));
}
public function testItCombinesMultipleFunctionsThatDealWithDifferentTypes(): void
{
$x = Fun\pipe(
fn (string $x): int => Str\length($x),
fn (int $y): string => $y . '!'
);
self::assertSame('5!', $x('Hello'));
}
public function testItCanCreateAnEmptyCombination(): void
{
$x = Fun\pipe();
self::assertSame('Hello', $x('Hello'));
}
}