function used by __construct($val) not being mocked

Posted 8 months ago by techguy92

I'm new to Testing and mocking. I need help on how to mock particular functions in my __construct class for one of my objects. These functions pull data from a database and return values to populate object properties.

I'm currently using Laravel 5.5

Here is what I have

namespace Tests\Unit;

use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Mockery;
use App\Event;
use Test\TestCase;
use stdClass;

class EventTest extends TestCase
    const TEST_EVENT_ID = 2;

public function testInstanceEventWithInteger()
$testResponse = (object)[
            'name' => 'TEST Event',
            'description' => 'Test Event',
            'beginDate' => '2018-05-04',
            'orgCode' => '014',

        $event = Mockery::mock(Event::class, [self::TEST_EVENT_ID])->makePartial();
            ->andReturn('LHS Harmon');
    $this->assertSame($event->name, 'TEST Event');

But instead of mocking the functions, I get the data from the database and not the data from my $testResponse. Am I doing this all wrong or what am I missing to get this to retrieve the data from the mocked functions instead of the pulling from the actual database

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

Laracasts Mascot

Hi, Have We Met Yet?

Did you know that, in addition to the forum, Laracasts includes well over 1000 lessons on modern web development? All for the price of one lunch out per month.

Sign Me Up


Reply to

Use Markdown with GitHub-flavored code blocks.