kahlan\matcher\ToBeCalled::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

Example #1
0
         });
     });
 });
 describe("->description()", function () {
     it("returns the description message for not received call", function () {
         $mon = new Mon();
         $matcher = new ToBeCalled('time');
         $matcher->resolve(['instance' => $matcher, 'data' => ['actual' => 'time', 'logs' => []]]);
         $actual = $matcher->description();
         expect($actual['description'])->toBe('be called.');
         expect($actual['data'])->toBe(['actual' => 'time()', 'actual called times' => 0, 'expected to be called' => 'time()']);
     });
     it("returns the description message for not received call the specified number of times", function () {
         $mon = new Mon();
         $matcher = new ToBeCalled('time');
         $matcher->times(2);
         $matcher->resolve(['instance' => $matcher, 'data' => ['actual' => 'time', 'logs' => []]]);
         $actual = $matcher->description();
         expect($actual['description'])->toBe('be called the expected times.');
         expect($actual['data'])->toBe(['actual' => 'time()', 'actual called times' => 0, 'expected to be called' => 'time()', 'expected called times' => 2]);
     });
     it("returns the description message for wrong passed arguments", function () {
         $mon = new Mon();
         $matcher = new ToBeCalled('time');
         $matcher->with('Hello World!');
         $mon->time();
         $matcher->resolve(['instance' => $matcher, 'data' => ['actual' => 'time', 'logs' => []]]);
         $actual = $matcher->description();
         expect($actual['description'])->toBe('be called with expected parameters.');
         expect($actual['data'])->toBe(['actual' => 'time()', 'actual called times' => 1, 'actual called parameters list' => [[]], 'expected to be called' => 'time()', 'expected parameters' => ['Hello World!']]);
     });