Passed
Push — master ( 3fec6d...d68188 )
by Sérgio
29s
created

NextStepTest::shouldReturnFour()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 7
nc 1
nop 0
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Prelude\Tests;
4
5
use function Prelude\nextStep;
6
7
class NextStepTest extends \PHPUnit_Framework_TestCase
8
{
9
    /**
10
     * @test
11
     */
12
    public function shouldReturnFour()
13
    {
14
        $inc = function ($x, $next) {
15
            return 4 === $x
16
                ? $x
17
                : $next($x + 1);
18
        };
19
        $steps = nextStep($inc, $inc, $inc, $inc, $inc);
20
21
        $this->assertEquals(4, $steps(1));
22
    }
23
24
    /**
25
     * @test
26
     */
27
    public function shouldReturnConcatString()
28
    {
29
        $steps = nextStep(function ($x, $next) {
30
            return $next("bar($x)");
31
        }, function ($x) {
32
            return "foo($x)";
33
        }, function ($x) {
34
            return "buzz($x)";
35
        });
36
37
        $this->assertEquals('foo(bar(fizz))', $steps('fizz'));
38
    }
39
40
    /**
41
     * @test
42
     */
43
    public function shouldReturnJustFirstCallback()
44
    {
45
        $steps = nextStep(function ($x) {
46
            return $x * 2;
47
        }, function ($x) {
48
            return $x + 10;
49
        });
50
51
        $this->assertEquals(10, $steps(5));
52
    }
53
}
54