allow($foo)->toReceive('a', 'b', 'c')->andReturn('something'); $query = $foo->a(); $select = $query->b(); expect($select->c())->toBe('something'); }); it('auto monkey patch core classes using a stub when possible', function () { allow('PDO')->toReceive('prepare', 'fetchAll')->andReturn([['name' => 'bob']]); $user = new User(); expect($user->all())->toBe([['name' => 'bob']]); }); it('allows to stubs a same method twice', function () { allow('PDO')->toReceive('prepare', 'fetchAll')->andReturn([['name' => 'bob']]); allow('PDO')->toReceive('prepare', 'execute')->andReturn(true); $user = new User(); expect($user->all())->toBe([['name' => 'bob']]); expect($user->success())->toBe(true); }); it('allows to mix static/dynamic methods', function () { allow('Kahlan\\Spec\\Fixture\\Plugin\\Monkey\\User')->toReceive('::create', 'all')->andReturn([['name' => 'bob']]); $user = User::create(); expect($user->all())->toBe([['name' => 'bob']]); }); it("throws an exception when trying to stub an instance of a built-in class", function () { expect(function () { allow(new DateTime()); })->toThrow(new InvalidArgumentException("Can't Stub built-in PHP instances, create a test double using `Double::instance()`.")); }); }); context("with chain of methods and arguments requirements", function () { it("stubs on matched arguments", function () { $foo = new Foo();