I try to run a phpunit test for my Laravel 6.0 application, but when trying to mock a method, I get this message as it cannot find the class/method:
Mockery\Exception\InvalidCountException: Method scrapeGoogleData() from Mockery_2_App_Http_Controllers_Scraper should be called exactly 1 times but called 0 times.
My test code is:
namespace Tests\Feature;
use Tests\TestCase;
use App\Http\Controllers\Scraper;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\RefreshDatabase;
class ScrapeTest extends TestCase
{
use RefreshDatabase;
/** @test */
public function test_scrapeGoogleData() {
$this->mock(Scraper::class, function ($mock) {
$mock->shouldReceive('scrapeGoogleData')->once();
});
Scraper::scrape('www.google.com');
}
The "scrapeGoogleData" method is definitely ran as it's called from the Scraper::scrape
method. But for some reason, mockery cannot see that. I get this error:
Mockery\Exception\InvalidCountException: Method scrapeGoogleData() from Mockery_2_App_Http_Controllers_Scraper should be called exactly 1 times but called 0 times.
What am I doing wrong?