public function times($times = null)
    {
        // API compat with mockery
        if ($this->atLeastWasCalled && $times !== null) {
            $this->atLeastWasCalled = false;
            $this->atLeast($times);
        } elseif ($times !== null) {
            if ($times === 0) {
                $this->never();
            } else {
                // normal operation
                $count = 0;
                $this->expectation->setPostPerformCallback(function() use (&$count, $times){
                    $count++;
                    $this->commentBuilder->incrementCallCount();
                    if ($count === $times) {
                        $this->expectation->setSatisfied(true);
                        $this->expectation->setPerformCallback(function($name, $args) use ($times) {
                            $message = "Unexpected call to {$this->methodName}";

                            if (count($args)) {
                                $message .= " with " . Util::printArray($args);
                            }

                            $message .= " - already called $times times";

                            throw new UnexpectedCallException($message);
                        });
                    }
                });

                $this->commentBuilder->setTimes($times);
                $this->commentBuilder->setAtLeast(false);
            }
        }
        
        return $this;
    }