It is necessary to satisfy this condition:

if ($entity instanceof EditorAttributes) { // .... } 

$entity - there is still no class that would create an object that satisfies the condition. You need to somehow create a mock object to go further in the unit test.

    1 answer 1

    PHPUnit can create Mock'i ​​based on interfaces, which is called "out of the box". For this, in the base class of the test there is a special method TestCase::getMock .

    For example, to create a Mock that implements your interface, you can use the following code:

     class FooTest extends PHPUnit\Framework\TestCase { public function testFoo() { $mock = $this->getMock('\EditorAttributes'); $this->assertTrue($mock instanceof \EditorAttributes); } } 

    If you need Mock to implement more than one interface, you can pass an array with the names of the target interfaces to TestCase::getMock :

     class FooTest extends PHPUnit\Framework\TestCase { public function testFoo() { $mock = $this->getMock(['\EditorAttributes', '\ReaderAttributes']); $this->assertTrue($mock instanceof \EditorAttributes); $this->assertTrue($mock instanceof \ReaderAttributes); } }