示例#1
0
            expect($foo)->toReceiveNext('bar');
            $foo->message();
            $foo::version();
            $foo->bar();
        });
        it("expects called methods to not be called in a different order", function () {
            $foo = new Foo();
            expect($foo)->toReceive('message');
            expect($foo)->not->toReceiveNext('bar');
            $foo->bar();
            $foo->message();
        });
        it("expects to work as `toReceive` for the first call", function () {
            $foo = new Foo();
            expect($foo)->toReceiveNext('message');
            $foo->message();
        });
        it("expects called methods are consumated", function () {
            $foo = new Foo();
            expect($foo)->toReceive('message');
            expect($foo)->not->toReceiveNext('message');
            $foo->message();
        });
        it("expects called methods are consumated using classname", function () {
            $foo = new Foo();
            expect('Kahlan\\Spec\\Fixture\\Plugin\\Pointcut\\Foo')->toReceive('message');
            expect('Kahlan\\Spec\\Fixture\\Plugin\\Pointcut\\Foo')->not->toReceiveNext('message');
            $foo->message();
        });
    });
});
示例#2
0
             $foo = new Foo();
             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 !');
示例#3
0
     allow('Kahlan\\Spec\\Fixture\\Plugin\\Pointcut\\Foo')->toReceive('::magic')->with('hello')->andReturn('world');
     allow('Kahlan\\Spec\\Fixture\\Plugin\\Pointcut\\Foo')->toReceive('::magic')->with('world')->andReturn('hello');
     expect(Foo::magic('hello'))->toBe('world');
     expect(Foo::magic('world'))->toBe('hello');
 });
 it("throws an exception when trying to call `toReceive()`", function () {
     expect(function () {
         allow('Kahlan\\Spec\\Fixture\\Plugin\\Pointcut\\Foo')->toBeCalled('magicHello')->andReturn('Hello World!');
     })->toThrow(new Exception("Error `toBeCalled()` are are only available on functions not classes/instances."));
 });
 context("with multiple return values", function () {
     it("stubs a method", function () {
         allow('Kahlan\\Spec\\Fixture\\Plugin\\Pointcut\\Foo')->toReceive('message')->andReturn('Good Evening World!', 'Good Bye World!');
         $foo = new Foo();
         expect($foo->message())->toBe('Good Evening World!');
         $foo2 = new Foo();
         expect($foo2->message())->toBe('Good Bye World!');
     });
 });
 context("with chain of methods", function () {
     it("expects called chain to be called", function () {
         allow('Kahlan\\Spec\\Fixture\\Plugin\\Pointcut\\Foo')->toReceive('::getQuery', '::newQuery', '::from')->andReturn('something');
         $query = Foo::getQuery();
         $select = $query::newQuery();
         expect($select::from())->toBe('something');
     });
 });
 context("with chain of methods and arguments requirements", function () {
     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);