I'm writing tests for a model which fires an event when one of its properties is changed. Unfortunately, I can't figure out the best way to test this. The model code is:
class Foo extends Eloquent {
public function setNameAttribute($value) {
$this->attributes['name'] = $value;
if($this->exists && ($this->original['name'] != $value)) {
Event::fire('foo.NameChange', array($this));
}
}
}
My initial test for the event fire:
$bar = Foo::first();
Event::shouldReceive('fire')->once()->with('foo.NameChange', array($bar));
$bar->name = 'test';
The problem is, the above tests still pass if:
How can i make my tests pass only if one foo.NameChange
event occurred? All other senario's should fail my test.
You have to call Mockery::close()
in your tearDown()
method.
See the Mockery docs on PHPUnit integration.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With