Antonella's avatar

mock test: Mockery\Exception\BadMethodCallException: Received Mockery_0_App_ClassU_downloadCard::

I wrote this with DI:

 public function test_mock_get_data()
    {
        $this->mock(downloadCard::class, function ($mock) {
            $mock->shouldReceive('_downloadCardsFromBoard()')
                ->once()
                ->andReturn(new Request(
                    File::get('tests/test_data/cards.json'),
                    $status =200,
                    $headers=[],
                ))
                ->andReturnValues(json_decode(File::get('tests/test_data/cards.json'),TRUE));
        });


        $response = $this->artisan('trello-monitor:sync');

    }

give me follwing error:

Mockery\Exception\BadMethodCallException: Received Mockery_0_App_ClassU_downloadCard::_downloadCardsFromBoard(), but no expectations were specified

the artisan command is so done:

 $cards = $this->unirest->_downloadCardsFromBoard($boardId);

        foreach($cards as $index=>$card) {
            echo $index.' of '.count($cards)."\r\n";
            $this->unirest->createCard($card);
        }

essentially if I comment out the line:

// $this->unirest->createCard($card); 

the test passes but the command must be done like this, I don't know how to solve

0 likes
1 reply
markus.heb's avatar

Hi, I am a little bit late to the party but I had a similar error and found the solution.

You have to pay close attention to the method name.

I think in your case instead of ->shouldReceive('_downloadCardsFromBoard()') it should be ->shouldReceive('_downloadCardsFromBoard') without the braces at the end of the method name.

Hope this helps someone :)

Please or to participate in this conversation.