Howdy folks, relatively new to unit testing in Laravel. I'm trying to mock an eloquent model using the following pattern mentioned in the docs for 11.x, but the mock doesnt seem to be getting injected properly:
$storePhoneNumber = Mockery::mock();
$storePhoneNumber->twilio_phone_number_sid = self::$sid;
$storePhoneNumber->notification_email = self::$testEmail;
$storePhoneNumber->phone_number = self::$testPhoneNumber;
$this->storePhoneNumber->shouldReceive('where')
->with('phone_number', self::$testPhoneNumber)
->once()
->andReturn(Mockery::self())
->shouldReceive('first')
->once()
->andReturn($storePhoneNumber);
$this->instance(StorePhoneNumber::class, $this->storePhoneNumber);
In the class I'm attempting to fetch a record from the StorePhoneNumber model inside of a method, but the model isnt getting mocked and has no records, so it returns null instead of returning the object I'm passing to andReturn().
What am I missing here? I want to avoid using the database here as much as possible, as I've managed to mock all of the other external services I'm using (mostly Twilio).