Test Setup Failed
Branch master (ddb003)
by Ducatel
02:20
created

TypedArrayTest::testWithString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 19
rs 9.4285
cc 1
eloc 13
nc 1
nop 0
1
<?php
2
3
namespace Ducatel\PHPCollection\Test;
4
5
use Ducatel\PHPCollection\TypedArray;
6
7
class TypedArrayTest extends \PHPUnit_Framework_TestCase
8
{
9
    /**
10
     * @expectedException \TypeError
11
     */
12
    public function testWithBool() {
13
14
        $typedArray = new TypedArray( function($obj){ return is_bool($obj);});
15
        $this->assertEquals(0, $typedArray->count());
16
17
        $this->assertFalse($typedArray->add("test"));
0 ignored issues
show
Documentation introduced by
'test' is of type string, but the function expects a object.

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...
18
        $this->assertFalse($typedArray->add(new \stdClass()));
19
20
        $this->assertNotFalse($typedArray->add(true));
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a object.

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...
21
        $this->assertEquals(1, $typedArray->count());
22
        $this->assertFalse($typedArray->contains(false));
23
        $this->assertTrue($typedArray->contains(true));
24
25
        $this->assertNotFalse($typedArray->add(false));
0 ignored issues
show
Documentation introduced by
false is of type boolean, but the function expects a object.

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...
26
        $this->assertEquals(2, $typedArray->count());
27
        $this->assertTrue($typedArray->contains(false));
28
        $this->assertTrue($typedArray->contains(true));
29
30
        $this->assertFalse($typedArray->delete(42));
31
        $this->assertFalse($typedArray->delete(6));
32
33
        $total = $typedArray->count();
34
        $typedArray->delete(0);
35
        $this->assertEquals($total -1 , $typedArray->count());
36
37
        $typedArray->contains(42);
38
    }
39
40
    /**
41
     * @expectedException \TypeError
42
     */
43
    public function testWithString() {
44
        $typedArray = new TypedArray( function($obj){ return is_string($obj);});
45
46
47
        $this->assertFalse($typedArray->add(true));
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a object.

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...
48
        $this->assertFalse($typedArray->add(new \stdClass()));
49
        $this->assertFalse($typedArray->add(42));
0 ignored issues
show
Documentation introduced by
42 is of type integer, but the function expects a object.

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...
50
51
        $this->assertNotFalse($typedArray->add('plop'));
0 ignored issues
show
Documentation introduced by
'plop' is of type string, but the function expects a object.

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...
52
        $this->assertFalse($typedArray->contains('123'));
53
        $this->assertFalse($typedArray->contains('PloP'));
54
        $this->assertTrue($typedArray->contains('plop'));
55
56
        $this->assertNotFalse($typedArray->add("123"));
0 ignored issues
show
Documentation introduced by
'123' is of type string, but the function expects a object.

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...
57
        $this->assertTrue($typedArray->contains('123'));
58
        $this->assertTrue($typedArray->contains('plop'));
59
60
        $typedArray->contains(42);
61
    }
62
63
    /**
64
     * @expectedException \TypeError
65
     */
66 View Code Duplication
    public function testWithObject() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
67
68
        $mockBuilder = $this->getMockBuilder('\PDO')->disableOriginalConstructor();
69
        $typedArray = new TypedArray('\PDO');
70
        $this->assertNotFalse($typedArray->add($mockBuilder->getMock()));
71
72
        $this->assertFalse($typedArray->add(true));
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a object.

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...
73
        $this->assertFalse($typedArray->add(new \stdClass()));
74
        $this->assertFalse($typedArray->add(42));
0 ignored issues
show
Documentation introduced by
42 is of type integer, but the function expects a object.

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...
75
76
        $typedArray->delete('plpo');
77
    }
78
79 View Code Duplication
    public function testWithObjectImplementEquatable() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
80
81
        $mock = $this->getMockBuilder('Ducatel\PHPCollection\Base\Equatable')->getMock();
82
        $mock->method('equals')
83
            ->willReturn(true);
84
85
        $typedArray = new TypedArray('Ducatel\PHPCollection\Base\Equatable');
86
        $this->assertNotFalse($typedArray->add($mock));
87
        $this->assertFalse($typedArray->add(true));
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a object.

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...
88
        $this->assertFalse($typedArray->add(new \stdClass()));
89
        $this->assertFalse($typedArray->add(42));
0 ignored issues
show
Documentation introduced by
42 is of type integer, but the function expects a object.

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...
90
    }
91
92
    public function testWithCustomEqualsFunction() {
93
94
        $isStringFct = function($obj){ return is_string($obj);};
95
        $isEquals = function ($obj1, $obj2){ return (strcasecmp($obj1, $obj2) == 0);};
96
        $typedArray = new TypedArray($isStringFct, $isEquals);
97
98
        $this->assertFalse($typedArray->add(true));
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a object.

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...
99
        $this->assertFalse($typedArray->add(new \stdClass()));
100
        $this->assertFalse($typedArray->add(42));
0 ignored issues
show
Documentation introduced by
42 is of type integer, but the function expects a object.

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...
101
102
        $this->assertNotFalse($typedArray->add('plop'));
0 ignored issues
show
Documentation introduced by
'plop' is of type string, but the function expects a object.

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...
103
        $this->assertFalse($typedArray->contains('123'));
104
        $this->assertTrue($typedArray->contains('plop'));
105
        $this->assertTrue($typedArray->contains('PloP'));
106
    }
107
108
109
}
110