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

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

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\SetNullFilter;
7
use DeepCopy\Matcher\PropertyMatcher;
8
9
/**
10
 * Test SetNull filter
11
 */
12
class SetNullFilterTest extends \PHPUnit_Framework_TestCase
13
{
14
    public function testApply()
15
    {
16
        $filter = new SetNullFilter();
17
        $object = new \stdClass();
18
        $object->foo = 'bar';
19
        $object->bim = 'bam';
20
        $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...
21
22
        $this->assertNull($object->foo);
23
        $this->assertEquals('bam', $object->bim);
24
    }
25
26
    public function testIntegration()
27
    {
28
        $o = new SetNullFilterTestFixture();
29
        $o->property1 = new \stdClass();
30
31
        $deepCopy = new DeepCopy();
32
        $deepCopy->addFilter(new SetNullFilter(), new PropertyMatcher(get_class($o), 'property1'));
33
        /** @var SetNullFilterTestFixture $new */
34
        $new = $deepCopy->copy($o);
35
36
        $this->assertNull($new->property1);
37
    }
38
}
39
40
class SetNullFilterTestFixture
41
{
42
    public $property1;
43
}
44