Failed Conditions
Pull Request — master (#102)
by
unknown
01:38
created

ClosuresTest::filterAllowNullAndNullValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace TraderInteractive\Filter;
4
5
use PHPUnit\Framework\TestCase;
6
use TraderInteractive\Exceptions\FilterException;
7
8
/**
9
 * @coversDefaultClass \TraderInteractive\Filter\Closures
10
 * @covers ::<private>
11
 */
12
final class ClosuresTest extends TestCase
13
{
14
    /**
15
     * @test
16
     * @covers ::filter
17
     */
18
    public function filterAllowNullAndNullValue()
19
    {
20
        $result = Closures::filter(null, true);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $result is correct as TraderInteractive\Filter...res::filter(null, true) targeting TraderInteractive\Filter\Closures::filter() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
21
        $this->assertSame(null, $result);
22
    }
23
24
    /**
25
     * @test
26
     * @covers ::filter
27
     */
28
    public function filterAllowNullIsFalseAndNullValue()
29
    {
30
        $this->expectException(FilterException::class);
31
        Closures::filter(null, true);
32
    }
33
34
    /**
35
     * @test
36
     * @covers ::filter
37
     */
38
    public function filterClosure()
39
    {
40
        $closureFunction = function () {
41
            return 'do nothing';
42
        };
43
        $result = Closures::filter($closureFunction);
44
        $this->assertTrue($result instanceof \Closure);
45
    }
46
47
    /**
48
     * @test
49
     * @covers ::filter
50
     */
51
    public function filterCallable()
52
    {
53
        function doNothing()
54
        {
55
            return 'do nothing';
56
        };
57
        $result = Closures::filter('doNothing');
58
        $this->assertTrue($result instanceof \Closure);
59
    }
60
61
    /**
62
     * @test
63
     * @covers ::filter
64
     */
65
    public function filterNotCallableString()
66
    {
67
        $this->expectException(FilterException::class);
68
        Closures::filter('string');
69
    }
70
71
    /**
72
     * @test
73
     * @covers ::filter
74
     */
75
    public function filterNotCallableInt()
76
    {
77
        $this->expectException(FilterException::class);
78
        Closures::filter(123);
79
    }
80
}
81