Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

psmail's avatar

Mockery error

Hi

I am trying - again - to get a grip on testing. I have started with this test ...

public function testMe()
{
    // Arrange
    $tenantContext = Mockery::mock('TenantContextInterface');
    $tenantContext->shouldReceive('id')->andReturn(99);
    $resources = new ResourcesRepo($tenantContext);

    // Act

    // Assert
}

... and get this error ...

ErrorException: Argument 1 passed to BRZ\Resources\ResourcesMysqlRepository::__construct() must implement interface BRZ\MultiTenant\TenantContextInterface, instance of Mockery_0__TenantContextInterface given, called in /home/vagrant/Code/InterimNew/tests/integration/ResourcesMysqlRepositoryTest.php on line 33 and defined

Any thoughts? Cheers.

0 likes
4 replies
devinfd's avatar
devinfd
Best Answer
Level 13

Give it what it wants. Replace Mockery::mock('TenantContextInterface'); with Mockery::mock('BRZ\MultiTenant\TenantContextInterface');

1 like
thepsion5's avatar

@devinfd is correct. When you see an error like that, it usually means one of two things:

  1. Mockery couldn't find the class/interface you're trying to mock, so it instead created a generic mock

  2. You're mocking the wrong class/interface

1 like

Please or to participate in this conversation.