forked from widmogrod/php-functional
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEitherMonadTest.php
More file actions
35 lines (28 loc) · 835 Bytes
/
EitherMonadTest.php
File metadata and controls
35 lines (28 loc) · 835 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
declare(strict_types=1);
namespace example;
use PHPUnit\Framework\TestCase;
use Widmogrod\Functional as f;
use Widmogrod\Monad\Either;
use Widmogrod\Monad\Either as e;
function read($file)
{
return is_file($file)
? Either\Right::of(file_get_contents($file))
: Either\Left::of(sprintf('File "%s" does not exists', $file));
}
class EitherMonadTest extends TestCase
{
public function test_it_should_concat_content_of_two_files_only_when_files_exists()
{
$concatF = f\bindM2(function ($first, $second) {
return $first . $second;
});
$concat = $concatF(
read(__FILE__),
read('aaa')
);
$this->assertInstanceOf(Either\Left::class, $concat);
$this->assertEquals(e\left('File "aaa" does not exists'), $concat);
}
}