php - Error using Mockery/phpUnit in Laravel -
i'm novice developer trying test suite started existing laravel app have not experience in testing. right i'm trying tests built out confidence , experience write more substantial tests. i'm trying test relationship on model(i realize it's not sensible tests) , trying create mocked model object so(i understand it's better in memory in sqlite db major goal here test controllers don't know how deal authentication issue there). have following simple, stupid test:
public function testfoo() { $lead = m::mock('lead'); $this->mock->shouldreceive('program')->once(); $this->assertequals($lead->program_id, $lead->program->id); }
but following error:
leadtest::testfoo badmethodcallexception: received mockery_0_lead::getattribute(), no expectations specified
i don't understand error trying tell me , i'm finding no googling issue or reading through docs can find.
i assume i'm not setting expected return values pretty general test , doesn't seem right hard code expected return values. missing here?
i'm testing laravel relationship make sure have things set up/implemented correctly:
public function program() { return $this->belongsto('program'); }
the problem was missing expected return value. should've been this:
$this->mock->shouldreceive('program')->once()->andreturn(someobjectorvalue);
and assertion should've been like:
$this->assertequals(someobjectorvalue, $lead->program->id);
the mockery docs lot more verbose thought. http://docs.mockery.io/en/latest/reference/expectations.html