resolve() public method

Resolves the matching.
public resolve ( ) : boolean
return boolean Returns `true` if successfully resolved, `false` otherwise.
Beispiel #1
0
                $foo::version();
            });
        });
    });
    describe("->description()", function () {
        it("returns the description message", function () {
            $stub = Stub::create();
            $matcher = new ToReceive($stub, 'method');
            $message = $matcher->message();
            expect($message)->toBeAnInstanceOf('Kahlan\\Plugin\\Call\\Message');
        });
        it("returns the description message for not received call", function () {
            $stub = Stub::create();
            $matcher = new ToReceive($stub, 'method');
            $matcher->resolve(['instance' => $matcher, 'params' => ['actual' => $stub, 'expected' => 'method', 'logs' => []]]);
            $actual = $matcher->description();
            expect($actual['description'])->toBe('receive the correct message.');
            expect($actual['params'])->toBe(['actual received' => ['__construct'], 'expected' => 'method']);
        });
        it("returns the description message for wrong passed arguments", function () {
            $stub = Stub::create();
            $matcher = new ToReceive($stub, 'method');
            $matcher->with('Hello World!');
            $stub->method('Good Bye!');
            $matcher->resolve(['instance' => $matcher, 'params' => ['actual' => $stub, 'expected' => 'method', 'logs' => []]]);
            $actual = $matcher->description();
            expect($actual['description'])->toBe('receive correct parameters.');
            expect($actual['params'])->toBe(['actual with' => ['Good Bye!'], 'expected with' => ['Hello World!']]);
        });
    });
});
Beispiel #2
0
        });
        it("returns the description message for wrong passed arguments", function () {
            $stub = Double::instance();
            $matcher = new ToReceive($stub, 'method');
            $matcher->with('Hello World!');
            $stub->method('Good Bye!');
            $matcher->resolve(['instance' => $matcher, 'data' => ['actual' => $stub, 'expected' => 'method', 'logs' => []]]);
            $actual = $matcher->description();
            expect($actual['description'])->toBe('receive the expected method with expected parameters.');
            expect($actual['data'])->toBe(['actual received' => 'method', 'actual received times' => 1, 'actual received parameters list' => [['Good Bye!']], 'expected to receive' => 'method', 'expected parameters' => ['Hello World!']]);
        });
    });
    describe("->ordered()", function () {
        it("throw an exception when trying to play with core instance", function () {
            expect(function () {
                $foo = new Foo();
                $matcher = new ToReceive($foo, 'a');
                $matcher->order;
            })->toThrow(new Exception("Unsupported attribute `order` only `ordered` is available."));
        });
    });
    describe("->resolve()", function () {
        it("throw an exception when not explicitly defining the stub value", function () {
            expect(function () {
                $foo = new Foo();
                $matcher = new ToReceive($foo, ['a', 'b', 'c']);
                $matcher->resolve(['instance' => $matcher, 'data' => ['actual' => $foo, 'expected' => ['a', 'b', 'c'], 'logs' => []]]);
            })->toThrow(new InvalidArgumentException("Kahlan can't Spy chained methods on real PHP code, you need to Stub the chain first."));
        });
    });
});