Example #1
0
         allow($foo)->toReceive('a', 'b', 'c')->andReturn('something');
         expect($foo)->not->toReceive('a', 'c', 'b')->once();
         $query = $foo->a();
         $select = $query->b();
         $select->c();
     });
     it('auto monkey patch core classes using a stub when possible', function () {
         allow('PDO')->toReceive('prepare', 'fetchAll')->andReturn([['name' => 'bob']]);
         expect('PDO')->toReceive('prepare')->once();
         $user = new User();
         expect($user->all())->toBe([['name' => 'bob']]);
     });
     it('allows to mix static/dynamic methods', function () {
         allow('Kahlan\\Spec\\Fixture\\Plugin\\Monkey\\User')->toReceive('::create', 'all')->andReturn([['name' => 'bob']]);
         expect('Kahlan\\Spec\\Fixture\\Plugin\\Monkey\\User')->toReceive('::create', 'all')->once();
         $user = User::create();
         expect($user->all())->toBe([['name' => 'bob']]);
     });
 });
 context("with chain of methods and arguments requirements", function () {
     it("expects called method to be called with correct arguments", function () {
         $foo = new Foo();
         expect($foo)->toReceive('message')->where(['message' => ['My Message', 'My Other Message']]);
         $foo->message('My Message', 'My Other Message');
     });
     it("expects stubbed chain called with matching arguments are called", function () {
         $foo = new Foo();
         allow($foo)->toReceive('a', 'b', 'c');
         expect($foo)->toReceive('a', 'b', 'c')->where(['a' => [1], 'b' => [2], 'c' => [3]]);
         $query = $foo->a(1);
         $select = $query->b(2);
Example #2
0
         it("expects stubbed chain to return the stubbed value when required arguments are matching", function () {
             allow('Kahlan\\Spec\\Fixture\\Plugin\\Pointcut\\Foo')->toReceive('::getQuery', '::newQuery', '::from')->where(['::getQuery' => [1], '::newQuery' => [2], '::from' => [3]])->andReturn('something');
             $query = Foo::getQuery(1);
             $select = $query::newQuery(2);
             expect($select::from(3))->toBe('something');
         });
         it("expects stubbed chain to not return the stubbed value when required arguments doesn't match", function () {
             allow('Kahlan\\Spec\\Fixture\\Plugin\\Pointcut\\Foo')->toReceive('::getQuery', '::newQuery', '::from')->where(['::getQuery' => [1], '::newQuery' => [2], '::from' => [3]])->andReturn('something');
             $query = Foo::getQuery(1);
             $select = $query::newQuery(2);
             expect($select::from(0))->not->toBe('something');
         });
     });
     it('makes built-in PHP class to work', function () {
         allow('PDO')->toBeOK();
         $user = new User();
         expect($user->all())->toBeTruthy();
     });
 });
 context("with a trait", function () {
     it("stubs a method", function () {
         allow('Kahlan\\Spec\\Fixture\\Plugin\\Pointcut\\SubBar')->toReceive('traitMethod')->andReturn('trait method stubbed !');
         $subBar = new SubBar();
         expect($subBar->traitMethod())->toBe('trait method stubbed !');
         $subBar2 = new SubBar();
         expect($subBar2->traitMethod())->toBe('trait method stubbed !');
     });
 });
 context("with functions", function () {
     it("expects stubbed method to be stubbed as expected", function () {
         $mon = new Mon();