2020-09-28 15:57:00 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace Psl\Tests\Fun;
|
|
|
|
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
use Psl\Fun;
|
|
|
|
use Psl\Str;
|
|
|
|
|
|
|
|
final class AfterTest extends TestCase
|
|
|
|
{
|
|
|
|
public function testItCombinesAFunctionToExecuteAFunctionAfterAnotherFunction(): void
|
|
|
|
{
|
|
|
|
$x = Fun\after(
|
2020-10-15 10:18:03 +02:00
|
|
|
static fn (string $x): string => $x . ' world',
|
|
|
|
static fn (string $z): string => $z . '!!'
|
2020-09-28 15:57:00 +02:00
|
|
|
);
|
|
|
|
|
2020-10-15 10:18:03 +02:00
|
|
|
static::assertSame('Hello world!!', $x('Hello'));
|
2020-09-28 15:57:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testItCombinesAFunctionThatDealWithDifferentTypes(): void
|
|
|
|
{
|
|
|
|
$x = Fun\after(
|
2020-10-15 10:18:03 +02:00
|
|
|
static fn (string $x): int => Str\length($x),
|
|
|
|
static fn (int $z): string => $z . '!'
|
2020-09-28 15:57:00 +02:00
|
|
|
);
|
|
|
|
|
2020-10-15 10:18:03 +02:00
|
|
|
static::assertSame('5!', $x('Hello'));
|
2020-09-28 15:57:00 +02:00
|
|
|
}
|
|
|
|
}
|