Failed Conditions
Pull Request — master (#1)
by
unknown
02:39 queued 14s
created

BooleansTest::convert()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace TraderInteractive\Filter;
4
5
use PHPUnit\Framework\TestCase;
6
7
/**
8
 * @coversDefaultClass \TraderInteractive\Filter\Booleans
9
 * @covers ::<private>
10
 */
11
final class BooleansTest extends TestCase
12
{
13
    /**
14
     * @test
15
     * @covers ::filter
16
     */
17
    public function filterBasic()
18
    {
19
        $this->assertTrue(Booleans::filter(true));
20
        $this->assertTrue(Booleans::filter('   true'));
21
        $this->assertTrue(Booleans::filter(' TRUE '));
22
        $this->assertTrue(Booleans::filter('True '));
23
24
        $this->assertFalse(Booleans::filter('false   '));
25
        $this->assertFalse(Booleans::filter('FALSE  '));
26
        $this->assertFalse(Booleans::filter(' False '));
27
        $this->assertFalse(Booleans::filter(false));
28
    }
29
30
    /**
31
     * @test
32
     * @covers ::filter
33
     */
34
    public function filterAllowNullIsTrueAndNullValue()
35
    {
36
        $this->assertNull(Booleans::filter(null, true));
0 ignored issues
show
Bug introduced by
Are you sure the usage of TraderInteractive\Filter...ans::filter(null, true) targeting TraderInteractive\Filter\Booleans::filter() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

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

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

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

Loading history...
37
    }
38
39
    /**
40
     * @test
41
     * @covers ::filter
42
     * @expectedException \TraderInteractive\Exceptions\FilterException
43
     * @expectedExceptionMessage "1" $value is not a string
44
     */
45
    public function filterNonStringAndNonBoolValue()
46
    {
47
        Booleans::filter(1);
48
    }
49
50
    /**
51
     * @test
52
     * @covers ::filter
53
     * @expectedException \TraderInteractive\Exceptions\FilterException
54
     * @expectedExceptionMessage invalid is not 'true' or 'false' disregarding case and whitespace
55
     */
56
    public function filterInvalidString()
57
    {
58
        Booleans::filter('invalid');
59
    }
60
61
    /**
62
     * @test
63
     * @covers ::filter
64
     */
65
    public function filterCustomTrueValues()
66
    {
67
        $this->assertTrue(Booleans::filter('Y', false, ['y']));
68
    }
69
70
    /**
71
     * @test
72
     * @covers ::filter
73
     */
74
    public function filterCustomFalseValues()
75
    {
76
        $this->assertFalse(Booleans::filter('0', false, ['true'], ['0']));
77
    }
78
79
    /**
80
     * @test
81
     * @covers ::filter
82
     * @expectedException \TraderInteractive\Exceptions\FilterException
83
     * @expectedExceptionMessage true is not 'y' or '1' or 'n' or '0' disregarding case and whitespace
84
     */
85
    public function filterCustomBoolValuesInvalidString()
86
    {
87
        $this->assertFalse(Booleans::filter('true', false, ['y', '1'], ['n', '0']));
88
    }
89
90
    /**
91
     * Verify basic behavior of convert().
92
     *
93
     * @test
94
     * @covers ::convert
95
     *
96
     * @return void
97
     */
98
    public function convert()
99
    {
100
        $this->assertSame('yes', Booleans::convert(true, 'yes', 'no'));
101
        $this->assertSame('bar', Booleans::convert(false, 'foo', 'bar'));
102
    }
103
}
104