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

tests/DeepCopyTest/Filter/KeepFilterTest.php (1 issue)

mismatching argument types.

Documentation Minor

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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
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