expect($mon->time())->toBe(456);
});
it("expects stubbed method to be stubbed as expected using closures", function () {
$mon = new Mon();
allow('time')->toBe(function () {
return 123;
}, function () {
return 456;
});
expect($mon->time())->toBe(123);
expect($mon->time())->toBe(456);
});
it("expects stubbed method to be stubbed only when the with constraint is respected", function () {
$mon = new Mon();
allow('Kahlan\\Spec\\Fixture\\Plugin\\Monkey\\rand')->toBeCalled()->with(10, 20)->andReturn(40);
expect($mon->rand(0, 10))->toBe(5);
expect($mon->rand(10, 20))->toBe(40);
});
it('makes built-in PHP function to work', function () {
allow('file_get_contents')->toBeOK();
$mon = new Mon();
expect($mon->loadFile())->toBe(null);
});
it("throws an exception when trying to call `toReceive()`", function () {
expect(function () {
allow('time')->toReceive('something')->andReturn(123, 456);
})->toThrow(new Exception("Error `toReceive()` are only available on classes/instances not functions."));
});
});
it("throws an exception when trying to call `andReturn()` right away", function () {
expect(function () {