Completed
Push — master ( 81b739...8e6e04 )
by Matthieu
01:47
created

Doctrine/DoctrineEmptyCollectionFilterTest.php (1 issue)

Severity

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\Doctrine;
4
5
use DeepCopy\DeepCopy;
6
use DeepCopy\Filter\Doctrine\DoctrineEmptyCollectionFilter;
7
use DeepCopy\Matcher\PropertyMatcher;
8
use Doctrine\Common\Collections\ArrayCollection;
9
use Doctrine\Common\Collections\Collection;
10
11
/**
12
 * Test Doctrine Collection filter
13
 */
14
class DoctrineEmptyCollectionFilterTest extends \PHPUnit_Framework_TestCase
15
{
16
    public function testApply()
17
    {
18
        $object = new \StdClass();
19
20
        $collection = new ArrayCollection();
21
        $collection->add(new \StdClass());
22
23
        $object->foo = $collection;
24
25
        $filter = new DoctrineEmptyCollectionFilter();
26
        $filter->apply($object, 'foo', function($item){ return null; });
0 ignored issues
show
The parameter $item is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
27
28
        $this->assertTrue($object->foo instanceof Collection);
29
        $this->assertNotSame($collection, $object->foo);
30
        $this->assertTrue($object->foo->isEmpty());
31
    }
32
33
    public function testIntegration()
34
    {
35
        //Prepare object to copy
36
        $doctrineEmptyCollectionFixture = new \StdClass();
37
        $originalCollection = new ArrayCollection();
38
        $originalCollection->add(new \StdClass());
39
        $doctrineEmptyCollectionFixture->foo = $originalCollection;
40
41
        //Copy
42
        $deepCopy = new DeepCopy();
43
        $deepCopy->addFilter(new DoctrineEmptyCollectionFilter(), new PropertyMatcher(get_class($doctrineEmptyCollectionFixture), 'foo'));
44
        $copied = $deepCopy->copy($doctrineEmptyCollectionFixture);
45
46
        //Check result
47
        $this->assertTrue($copied->foo instanceof Collection);
48
        $this->assertNotSame($originalCollection, $copied->foo);
49
        $this->assertTrue($copied->foo->isEmpty());
50
    }
51
}
52