PHPUnit, mocked interfaces, and instanceof PHPUnit, mocked interfaces, and instanceof php php

PHPUnit, mocked interfaces, and instanceof


there is also assertInstanceOf as of 3.5.0

Example:

$this->assertInstanceOf('\Models\User', $this->userService->findById(1));


This works for me:

$mock = $this->getMock('TestInterface');$this->assertTrue($mock instanceof TestInterface);

Maybe it's a typo or maybe $instance isn't what you think it is?


Use PhpUnit function assertInstanceOf.

Example:

$this->assertInstanceOf(ResponseInterface::class, $signInResponse);