mardi 1 décembre 2015

How to fix mockery mock object throwing BadMethodCallException?

In a silex application I have a KafkaAPiClient class which has the method postMessages.

Yet when mocking the class in a test:

<?php
namespace unit\Request;

use Kopernikus\KafkaWriter\KafkaApiClient;

/**
 * MockeryMethodsNotBeingCallableTest
 **/
class MockeryMethodsNotBeingCallableTest extends \PHPUnit_Framework_TestCase
{
    public function testMockMethodIsCallable()
    {
        $leMock = \Mockery::mock(KafkaApiClient::class);
        $leMock->postMessages([]);
    }
}

I am getting:

1) unit\Request\MockeryMethodsNotBeingCallableTest::testMockMethodIsCallable
BadMethodCallException: Method Mockery_11_Kopernikus_KafkaWriter_KafkaApiClient::postMessages() does not exist on this mock object

~/le-project/tests/unit/Request/MockeryMethodsNotBeingCallableTest.php:14

I am confused, I was expecting for the mock to not do anything yet allow the methods to be called so that I later could add my expectations on it.

What am I doing wrong?

Aucun commentaire:

Enregistrer un commentaire