WhenTest::shouldReturnTruncate()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 11
nc 1
nop 0
dl 0
loc 18
rs 9.4285
c 1
b 0
f 0
1
<?php
2
3
namespace Prelude\Tests;
4
5
use function Prelude\when;
6
use function Prelude\pipe;
7
8
class WhenTest extends \PHPUnit\Framework\TestCase
9
{
10
    /**
11
     * @test
12
     */
13
    public function shouldReturnTruncate()
14
    {
15
        $append = function ($x) {
16
            return function ($y) use ($x) {
17
                return $y.$x;
18
            };
19
        };
20
        $chunk = function ($str) {
21
            return substr($str, 0, 10);
22
        };
23
        $pred = function ($str) {
24
            return strlen($str) > 10;
25
        };
26
        $truncate = when($pred)(pipe($chunk, $append('…')));
27
28
        $this->assertEquals('12345', $truncate('12345'));
29
        $this->assertEquals('0123456789…', $truncate('0123456789ABC'));
30
    }
31
}
32