expect($foo->message())->toBe('Good Evening World!');
$foo2 = new Foo();
expect($foo2->message())->toBe('Good Bye World!');
$foo3 = new Foo();
expect($foo3->bar())->toBe('Hello Bar!');
});
it("stubs methods using closure", function () {
Stub::on('Kahlan\\Spec\\Fixture\\Plugin\\Pointcut\\Foo')->methods(['message' => function () {
return 'Good Evening World!';
}, 'bar' => function () {
return 'Hello Bar!';
}]);
$foo = new Foo();
expect($foo->message())->toBe('Good Evening World!');
$foo2 = new Foo();
expect($foo2->bar())->toBe('Hello Bar!');
});
it("throw an exception with invalid definition", function () {
$closure = function () {
$foo = new Foo();
Stub::on('Kahlan\\Spec\\Fixture\\Plugin\\Pointcut\\Foo')->methods(['bar' => 'Hello Bar!']);
};
$message = "Stubbed method definition for `bar` must be a closure or an array of returned value(s).";
expect($closure)->toThrow(new InvalidArgumentException($message));
});
});
});
context("with a trait", function () {
it("stubs a method", function () {
Stub::on('Kahlan\\Spec\\Fixture\\Plugin\\Pointcut\\SubBar')->method('traitMethod')->andReturn('trait method stubbed !');
$subBar = new SubBar();