CondTest::shouldReturnMatchedCond()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

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