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

NextStepTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 47
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A shouldReturnFour() 0 11 2
A shouldReturnConcatString() 0 12 1
A shouldReturnJustFirstCallback() 0 10 1
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