2020-10-09 14:54:24 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace Psl\Tests\Fun;
|
|
|
|
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
use Psl\Fun;
|
|
|
|
|
|
|
|
final class WhenTest extends TestCase
|
|
|
|
{
|
|
|
|
public function testItRunsLeftFunction(): void
|
|
|
|
{
|
|
|
|
$greet = Fun\when(
|
|
|
|
static fn(string $name): bool => $name === 'Jos',
|
|
|
|
static fn(string $name): string => 'Bonjour ' . $name . '!',
|
|
|
|
static fn(string $name): string => 'Hello ' . $name . '!'
|
|
|
|
);
|
|
|
|
|
2020-10-15 10:18:03 +02:00
|
|
|
static::assertSame('Bonjour Jos!', $greet('Jos'));
|
2020-10-09 14:54:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testItRunsRightfunction(): void
|
|
|
|
{
|
|
|
|
$greet = Fun\when(
|
|
|
|
static fn(string $name): bool => $name === 'Jos',
|
|
|
|
static fn(string $name): string => 'Bonjour ' . $name . '!',
|
|
|
|
static fn(string $name): string => 'Hello ' . $name . '!'
|
|
|
|
);
|
|
|
|
|
2020-10-15 10:18:03 +02:00
|
|
|
static::assertSame('Hello World!', $greet('World'));
|
2020-10-09 14:54:24 +02:00
|
|
|
}
|
|
|
|
}
|