mirror of
https://github.com/danog/endtoend-test-psl.git
synced 2024-12-03 10:08:33 +01:00
34 lines
879 B
PHP
34 lines
879 B
PHP
|
<?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 . '!'
|
||
|
);
|
||
|
|
||
|
self::assertSame('Bonjour Jos!', $greet('Jos'));
|
||
|
}
|
||
|
|
||
|
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 . '!'
|
||
|
);
|
||
|
|
||
|
self::assertSame('Hello World!', $greet('World'));
|
||
|
}
|
||
|
}
|