5
5
namespace test \Functional ;
6
6
7
7
use FunctionalPHP \FantasyLand \Monad ;
8
+ use Widmogrod \Common \ValueOfInterface ;
8
9
use Widmogrod \Functional as f ;
9
10
use Widmogrod \Monad \Either ;
11
+ use Widmogrod \Monad \IO ;
10
12
use Widmogrod \Monad \Maybe ;
11
13
12
14
class LiftM2Test extends \PHPUnit \Framework \TestCase
@@ -19,14 +21,13 @@ public function test_it_should_lift2M(
19
21
Monad $ mb ,
20
22
callable $ transformation ,
21
23
string $ expectedFQCN ,
22
- $ expectedExtracted = null
24
+ callable $ valueAssertion = null
23
25
) {
24
26
$ mc = f \liftM2 ($ transformation , $ ma , $ mb );
25
27
26
28
$ this ->assertInstanceOf ($ expectedFQCN , $ mc );
27
-
28
- if ($ expectedExtracted !== null ) {
29
- $ this ->assertSame ($ expectedExtracted , f \valueOf ($ mc ));
29
+ if ($ valueAssertion !== null ) {
30
+ $ valueAssertion ($ mc );
30
31
}
31
32
}
32
33
@@ -36,6 +37,10 @@ public function monadsProvider()
36
37
return $ a + $ b ;
37
38
};
38
39
40
+ $ sameValueOf = f \curryN (2 , function ($ expected , ValueOfInterface $ actual ) {
41
+ $ this ->assertSame ($ expected , f \valueOf ($ actual ));
42
+ });
43
+
39
44
return [
40
45
'maybe all nothing ' => [
41
46
Maybe \nothing (),
@@ -60,32 +65,48 @@ public function monadsProvider()
60
65
Maybe \just (2 ),
61
66
$ sumIntegers ,
62
67
Maybe \Just::class,
63
- 3
68
+ $ sameValueOf ( 3 )
64
69
],
65
70
'either all left ' => [
66
71
Either \left ('a ' ),
67
72
Either \left ('b ' ),
68
73
$ sumIntegers ,
69
- Either \Left::class
74
+ Either \Left::class,
75
+ $ sameValueOf ('a ' )
70
76
],
71
77
'either first right ' => [
72
78
Either \right (3 ),
73
79
Either \left ('b ' ),
74
80
$ sumIntegers ,
75
- Either \Left::class
81
+ Either \Left::class,
82
+ $ sameValueOf ('b ' )
76
83
],
77
84
'either second right ' => [
78
85
Either \left ('a ' ),
79
86
Either \right (4 ),
80
87
$ sumIntegers ,
81
- Either \Left::class
88
+ Either \Left::class,
89
+ $ sameValueOf ('a ' )
82
90
],
83
91
'either all right ' => [
84
92
Either \right (3 ),
85
93
Either \right (4 ),
86
94
$ sumIntegers ,
87
95
Either \Right::class,
88
- 7
96
+ $ sameValueOf (7 )
97
+ ],
98
+ 'io ' => [
99
+ IO ::of (function () {
100
+ return 1 ;
101
+ }),
102
+ IO ::of (function () {
103
+ return 2 ;
104
+ }),
105
+ $ sumIntegers ,
106
+ IO ::class,
107
+ function (IO $ io ) {
108
+ $ this ->assertSame (3 , $ io ->run ());
109
+ }
89
110
]
90
111
];
91
112
}
0 commit comments