kahlan\matcher\ToReceive::times PHP Method

times() public method

Gets/sets the number of occurences.
public times ( integer $times = null ) : mixed
$times integer The number of occurences to set or none to get it.
return mixed The number of occurences on get or `self` otherwise.
    public function times($times = null)
    {
        if (!func_num_args()) {
            return $this->_times;
        }
        $this->_times = $times;
        return $this;
    }

Usage Example

Beispiel #1
0
     $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 not received call the specified number of times", function () {
     $stub = Stub::create();
     $matcher = new ToReceive($stub, 'method');
     $matcher->times(2);
     $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', 'called times' => 2]);
 });
 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!']]);
 });