Can't mock my repository in acceptance test!

Posted 2 years ago by selmonal

Please see the code below. The getUnconfirmedStudentsCount mocked method doesn't call. My tests are fail.

<?php

use Mockery as m;
use App\Models\Student;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Foundation\Testing\WithoutMiddleware;

class DashboardStatsTest extends TestCase
{
    use DatabaseTransactions;

    /** @test */
    public function an_employee_sees_the_count_of_unconfirmed_students()
    {
        $this->instance(
            'App\Contracts\Repositories\StudentRepository', 
            $studentRepository = m::mock('App\Contracts\Repositories\StudentRepository')
        );

        $studentRepository->shouldReceive('getUnconfirmedStudentsCount')->once()->andReturn(10300);

        $this->visit('/')->see(10300);
    }
}

Please sign in or create an account to participate in this conversation.