Completed
Push — master ( cd2604...399c1f )
by Matthieu
03:36
created

KeepFilterTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testApply() 0 11 1
A testIntegration() 0 12 1
1
<?php
2
3
namespace DeepCopyTest\Filter;
4
5
use DeepCopy\DeepCopy;
6
use DeepCopy\Filter\KeepFilter;
7
use DeepCopy\Matcher\PropertyMatcher;
8
9
/**
10
 * Test Keep filter
11
 */
12
class KeepFilterTest extends \PHPUnit_Framework_TestCase
13
{
14
    public function testApply()
15
    {
16
        $object = new \stdClass();
17
        $keepObject = new \stdClass();
18
        $object->foo = $keepObject;
19
20
        $filter = new KeepFilter();
21
        $filter->apply($object, 'foo', null);
0 ignored issues
show
Documentation introduced by Matthieu Napoli
null is of type null, but the function expects a callable.

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...
22
23
        $this->assertSame($keepObject, $object->foo);
24
    }
25
26
    public function testIntegration()
27
    {
28
        $o = new KeepFilterTestFixture();
29
        $o->property1 = new \stdClass();
30
31
        $deepCopy = new DeepCopy();
32
        $deepCopy->addFilter(new KeepFilter(), new PropertyMatcher(get_class($o), 'property1'));
33
        /** @var KeepFilterTestFixture $new */
34
        $new = $deepCopy->copy($o);
35
36
        $this->assertSame($o->property1, $new->property1);
37
    }
38
}
39
40
class KeepFilterTestFixture
41
{
42
    public $property1;
43
}
44