Failed Conditions
Pull Request — master (#75)
by
unknown
03:37
created

BooleansTest   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 119
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 2
dl 0
loc 119
rs 10
c 0
b 0
f 0

10 Methods

Rating   Name   Duplication   Size   Complexity  
A filterBasic() 0 12 1
A filterAllowNullIsNotBool() 0 4 1
A filterAllowNullIsTrueAndNullValue() 0 4 1
A filterNonStringAndNonBoolValue() 0 4 1
A filterInvalidString() 0 4 1
A filterCustomTrueValues() 0 4 1
A filterCustomFalseValues() 0 4 1
A filterCustomBoolValuesInvalidString() 0 4 1
A convert() 0 5 1
A convertValueNotBool() 0 4 1
1
<?php
2
3
namespace TraderInteractive\Filter;
4
5
use PHPUnit\Framework\TestCase;
6
7
/**
8
 * @coversDefaultClass \TraderInteractive\Filter\Booleans
9
 */
10
final class BooleansTest extends TestCase
11
{
12
    /**
13
     * @test
14
     * @covers ::filter
15
     */
16
    public function filterBasic()
17
    {
18
        $this->assertTrue(Booleans::filter(true));
0 ignored issues
show
Bug introduced by
It seems like \TraderInteractive\Filter\Booleans::filter(true) targeting TraderInteractive\Filter\Booleans::filter() can also be of type null; however, PHPUnit\Framework\Assert::assertTrue() does only seem to accept boolean, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
19
        $this->assertTrue(Booleans::filter('   true'));
0 ignored issues
show
Bug introduced by
It seems like \TraderInteractive\Filte...eans::filter(' true') targeting TraderInteractive\Filter\Booleans::filter() can also be of type null; however, PHPUnit\Framework\Assert::assertTrue() does only seem to accept boolean, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
20
        $this->assertTrue(Booleans::filter(' TRUE '));
0 ignored issues
show
Bug introduced by
It seems like \TraderInteractive\Filte...leans::filter(' TRUE ') targeting TraderInteractive\Filter\Booleans::filter() can also be of type null; however, PHPUnit\Framework\Assert::assertTrue() does only seem to accept boolean, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
21
        $this->assertTrue(Booleans::filter('True '));
0 ignored issues
show
Bug introduced by
It seems like \TraderInteractive\Filte...oleans::filter('True ') targeting TraderInteractive\Filter\Booleans::filter() can also be of type null; however, PHPUnit\Framework\Assert::assertTrue() does only seem to accept boolean, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
22
23
        $this->assertFalse(Booleans::filter('false   '));
0 ignored issues
show
Bug introduced by
It seems like \TraderInteractive\Filte...ans::filter('false ') targeting TraderInteractive\Filter\Booleans::filter() can also be of type null; however, PHPUnit\Framework\Assert::assertFalse() does only seem to accept boolean, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
24
        $this->assertFalse(Booleans::filter('FALSE  '));
0 ignored issues
show
Bug introduced by
It seems like \TraderInteractive\Filte...eans::filter('FALSE ') targeting TraderInteractive\Filter\Booleans::filter() can also be of type null; however, PHPUnit\Framework\Assert::assertFalse() does only seem to accept boolean, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
25
        $this->assertFalse(Booleans::filter(' False '));
0 ignored issues
show
Bug introduced by
It seems like \TraderInteractive\Filte...eans::filter(' False ') targeting TraderInteractive\Filter\Booleans::filter() can also be of type null; however, PHPUnit\Framework\Assert::assertFalse() does only seem to accept boolean, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
26
        $this->assertFalse(Booleans::filter(false));
0 ignored issues
show
Bug introduced by
It seems like \TraderInteractive\Filter\Booleans::filter(false) targeting TraderInteractive\Filter\Booleans::filter() can also be of type null; however, PHPUnit\Framework\Assert::assertFalse() does only seem to accept boolean, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
27
    }
28
29
    /**
30
     * @test
31
     * @covers ::filter
32
     * @expectedException \InvalidArgumentException
33
     * @expectedExceptionMessage $allowNull was not a bool
34
     */
35
    public function filterAllowNullIsNotBool()
36
    {
37
        Booleans::filter('true', 1);
0 ignored issues
show
Documentation introduced by
1 is of type integer, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
38
    }
39
40
    /**
41
     * @test
42
     * @covers ::filter
43
     */
44
    public function filterAllowNullIsTrueAndNullValue()
45
    {
46
        $this->assertNull(Booleans::filter(null, true));
47
    }
48
49
    /**
50
     * @test
51
     * @covers ::filter
52
     * @expectedException \TraderInteractive\Filter\Exception
53
     * @expectedExceptionMessage "1" $value is not a string
54
     */
55
    public function filterNonStringAndNonBoolValue()
56
    {
57
        Booleans::filter(1);
58
    }
59
60
    /**
61
     * @test
62
     * @covers ::filter
63
     * @expectedException \TraderInteractive\Filter\Exception
64
     * @expectedExceptionMessage invalid is not 'true' or 'false' disregarding case and whitespace
65
     */
66
    public function filterInvalidString()
67
    {
68
        Booleans::filter('invalid');
69
    }
70
71
    /**
72
     * @test
73
     * @covers ::filter
74
     */
75
    public function filterCustomTrueValues()
76
    {
77
        $this->assertTrue(Booleans::filter('Y', false, ['y']));
0 ignored issues
show
Bug introduced by
It seems like \TraderInteractive\Filte...'Y', false, array('y')) targeting TraderInteractive\Filter\Booleans::filter() can also be of type null; however, PHPUnit\Framework\Assert::assertTrue() does only seem to accept boolean, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
78
    }
79
80
    /**
81
     * @test
82
     * @covers ::filter
83
     */
84
    public function filterCustomFalseValues()
85
    {
86
        $this->assertFalse(Booleans::filter('0', false, ['true'], ['0']));
0 ignored issues
show
Bug introduced by
It seems like \TraderInteractive\Filte...ay('true'), array('0')) targeting TraderInteractive\Filter\Booleans::filter() can also be of type null; however, PHPUnit\Framework\Assert::assertFalse() does only seem to accept boolean, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
87
    }
88
89
    /**
90
     * @test
91
     * @covers ::filter
92
     * @expectedException \TraderInteractive\Filter\Exception
93
     * @expectedExceptionMessage true is not 'y' or '1' or 'n' or '0' disregarding case and whitespace
94
     */
95
    public function filterCustomBoolValuesInvalidString()
96
    {
97
        $this->assertFalse(Booleans::filter('true', false, ['y', '1'], ['n', '0']));
0 ignored issues
show
Bug introduced by
It seems like \TraderInteractive\Filte... '1'), array('n', '0')) targeting TraderInteractive\Filter\Booleans::filter() can also be of type null; however, PHPUnit\Framework\Assert::assertFalse() does only seem to accept boolean, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
98
    }
99
100
    /**
101
     * Verify basic behavior of convert().
102
     *
103
     * @test
104
     * @covers ::convert
105
     *
106
     * @return void
107
     */
108
    public function convert()
109
    {
110
        $this->assertSame('yes', Booleans::convert(true, 'yes', 'no'));
111
        $this->assertSame('bar', Booleans::convert(false, 'foo', 'bar'));
112
    }
113
114
    /**
115
     * Verify behavior of convert() when $value is not boolean
116
     *
117
     * @test
118
     * @covers ::convert
119
     * @expectedException \TraderInteractive\Filter\Exception
120
     * @expectedExceptionMessage $value was not a bool
121
     *
122
     * @return void
123
     */
124
    public function convertValueNotBool()
125
    {
126
        Booleans::convert('abc');
0 ignored issues
show
Documentation introduced by
'abc' is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
127
    }
128
}
129