Completed
Push — master ( 06c1ce...67d37c )
by Jeroen
06:20
created

Tests/unit/EventListener/MappingListenerTest.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 Kunstmaan\AdminBundle\Tests\EventListener;
4
5
use Doctrine\ORM\Event\LoadClassMetadataEventArgs;
6
use Doctrine\ORM\Mapping\ClassMetadata;
7
use Kunstmaan\AdminBundle\Entity\AclChangeset;
8
use Kunstmaan\AdminBundle\EventListener\MappingListener;
9
use PHPUnit\Framework\TestCase;
10
11
class MappingListenerTest extends TestCase
12
{
13
    public function testListener()
14
    {
15
        $args = $this->createMock(LoadClassMetadataEventArgs::class);
16
        $meta = $this->createMock(ClassMetadata::class);
17
18
        $meta->table = ['name' => 'test_table'];
0 ignored issues
show
Accessing table on the interface PHPUnit\Framework\MockObject\MockObject suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
19
20
        $args->expects($this->once())->method('getClassMetadata')->willReturn($meta);
21
        $meta->expects($this->once())->method('getName')->willReturn(AclChangeset::class);
22
        $meta->expects($this->once())->method('mapManyToOne')->willReturn(AclChangeset::class);
23
        $meta->expects($this->once())->method('mapManyToMany')->willReturn(AclChangeset::class);
24
25
        $listener = new MappingListener(AclChangeset::class);
26
        $listener->loadClassMetadata($args);
27
    }
28
}
29