Passed
Push — master ( 64f111...9a1763 )
by Alexander
01:06
created

BooleanBehaviorTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testInt() 0 15 1
A testBool() 0 15 1
1
<?php
2
3
namespace Horat1us\Yii\Tests\Behaviors;
4
5
use Horat1us\Yii\Tests\Mocks\BooleanBehaviorMock;
6
use PHPUnit\Framework\TestCase;
7
8
/**
9
 * Class BooleanBehaviorTest
10
 * @package Horat1us\Yii\Tests\Behaviors
11
 */
12
class BooleanBehaviorTest extends TestCase
13
{
14
    public function testInt()
15
    {
16
        $model = new BooleanBehaviorMock();
17
        $model->intValue = '1';
0 ignored issues
show
Documentation Bug introduced by
The property $intValue was declared of type integer, but '1' is of type string. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
18
        $model->validate();
19
        $this->assertTrue($model->intValue === 1);
0 ignored issues
show
Unused Code Bug introduced by
The strict comparison === seems to always evaluate to false as the types of $model->intValue (string) and 1 (integer) can never be identical. Maybe you want to use a loose comparison == instead?
Loading history...
20
21
        $model->intValue = true;
0 ignored issues
show
Documentation Bug introduced by
The property $intValue was declared of type integer, but true is of type boolean. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
22
        $model->validate();
23
        $this->assertTrue($model->intValue === 1);
24
25
        $model->intValue = 'true';
0 ignored issues
show
Documentation Bug introduced by
The property $intValue was declared of type integer, but 'true' is of type string. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
26
        $model->validate();
27
        $this->assertTrue($model->intValue === 1);
0 ignored issues
show
Unused Code Bug introduced by
The strict comparison === seems to always evaluate to false as the types of $model->intValue (string) and 1 (integer) can never be identical. Maybe you want to use a loose comparison == instead?
Loading history...
28
    }
29
30
    public function testBool()
31
    {
32
        $model = new BooleanBehaviorMock();
33
        $model->boolValue = '1';
0 ignored issues
show
Documentation Bug introduced by
The property $boolValue was declared of type boolean, but '1' is of type string. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
34
        $model->validate();
35
        $this->assertTrue($model->boolValue);
0 ignored issues
show
Documentation introduced by
$model->boolValue 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...
36
37
        $model->boolValue = 1;
0 ignored issues
show
Documentation Bug introduced by
The property $boolValue was declared of type boolean, but 1 is of type integer. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
38
        $model->validate();
39
        $this->assertTrue($model->boolValue);
0 ignored issues
show
Documentation introduced by
$model->boolValue 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...
40
41
        $model->boolValue = 'true';
0 ignored issues
show
Documentation Bug introduced by
The property $boolValue was declared of type boolean, but 'true' is of type string. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
42
        $model->validate();
43
        $this->assertTrue($model->boolValue);
0 ignored issues
show
Documentation introduced by
$model->boolValue 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...
44
    }
45
}