Passed
Push — master ( bef855...6fcd14 )
by Sérgio
07:04
created

CondTest::whenDoNotPassSecoundArgument()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Prelude\Tests;
4
5
use function Prelude\cond;
6
use function Prelude\equals;
7
use function Prelude\always;
8
9
class CondTest extends \PHPUnit_Framework_TestCase
10
{
11
    /**
12
     * @test
13
     */
14
    public function shouldReturnMatchedCond()
15
    {
16
        $fn = cond([
17
            [equals(0), always('water freezes at 0°C')],
18
            [equals(100), always('water boils at 100°C')],
19
            [always(true), function ($temp) {
20
                return 'nothing special happens at '.$temp.'°C';
21
            }]
22
        ]);
23
24
        $this->assertEquals('water freezes at 0°C', $fn(0));
25
        $this->assertEquals('nothing special happens at 50°C', $fn(50));
26
        $this->assertEquals('water boils at 100°C', $fn(100));
27
    }
28
29
    /**
30
     * @test
31
     * @expectedException \InvalidArgumentException
32
     */
33
    public function shouldThrowInvalidArgumentExceptionWhenAnyMatch()
34
    {
35
        $fn = cond([
36
            [equals([]), always(true)]
37
        ]);
38
39
        $fn(true);
40
    }
41
42
    /**
43
     * @test
44
     * @expectedException \InvalidArgumentException
45
     */
46
    public function whenDoNotPassSecoundArgument()
47
    {
48
        $fn = cond([
49
            [equals([])]
50
        ]);
51
52
        $fn(true);
53
    }
54
}
55