Expected arguments when invoking the mock.

@throws \Exception
@return MockBuilder
352104
public function with()
    {
        $methodArguments = new MethodArguments();
        $this->currentWith = $methodArguments->getMethodArgumentValues(
            func_get_args(),
            $this->getClassName() . "::" . $this->currentRules[0]
        );
        foreach ($this->currentRules as $rule) {
            if ($this->rules[$rule][md5('null')]['hasSetTimes']) {
                $renderer = new ValueRenderer();
                $converter = new NumberToTimesConverter();
                $args = $renderer->renderAll($this->currentWith);
                $times = $this->rules[$rule][md5('null')]['times'];
                $convertToMethod = $converter->convertToMethod($times);
                throw new Exception(
                    sprintf(
                        "%s:\n  ->expects('%s')->with(%s)->%s",
                        "When using with you must specify expectations for each with()",
                        $rule,
                        $args,
                        $convertToMethod
                    )
                );
            }
            $this->rules[$rule][md5('null')]['times'] = -1;
        }
        $this->setupWith(
            new Action\ReturnValueAction(array(null)),
            $this->isExpecting ? 1 : -1
        );

        return $this;
    }
1217446
private function constructArguments()
    {
        $arguments = '';

        foreach ($this->ionSwitches as $name => $value) {
            if ($value) {
                $arguments .= "--$name ";
            }
        }

        foreach ($this->ionOptions as $name => $value) {
            /**
             * action-if-no-loader value is a php source snippet so it is
             * better to handle it this way to prevent quote problems!
             */
            if ($name == 'action-if-no-loader') {
                $arguments .= "--$name \"$value\" ";
            } else {
                $arguments .= "--$name '$value' ";
            }
        }

        foreach ($this->ionOptionsXS as $name => $value) {
            foreach (explode(' ', $value) as $arg) {
                $arguments .= "--$name '$arg' ";
            }
        }

        foreach ($this->comments as $comment) {
            $arguments .= "--add-comment '" . $comment->getValue() . "' ";
        }

        if (!empty($this->targetOption)) {
            switch ($this->targetOption) {
                case "replace":
                case "merge":
                case "update":
                case "rename":
                    $arguments .= "--" . $this->targetOption . "-target ";
                    break;
                default:
                    throw new BuildException("Unknown target option '" . $this->targetOption . "'");
            }
        }

        if ($this->fromDir != '') {
            $arguments .= $this->fromDir . ' ';
        }

        if ($this->toDir != '') {
            $arguments .= "-o " . $this->toDir . ' ';
        }

        return $arguments;
    }
1256869
public function new()
    {
        if (isset($this->constructor)) {
            $constructor = $this->constructor;
            $arguments = func_get_args();
            $callback = array_pop($arguments);

            $input_count = isset($constructor['inputs']) ? count($constructor['inputs']) : 0;
            if (count($arguments) < $input_count) {
                throw new InvalidArgumentException('Please make sure you have put all constructor params and callback.');
            }
            if (is_callable($callback) !== true) {
                throw new \InvalidArgumentException('The last param must be callback function.');
            }
            if (!isset($this->bytecode)) {
                throw new \InvalidArgumentException('Please call bytecode($bytecode) before new().');
            }
            $params = array_splice($arguments, 0, $input_count);
            $data = $this->ethabi->encodeParameters($constructor, $params);
            $transaction = [];

            if (count($arguments) > 0) {
                $transaction = $arguments[0];
            }
            $transaction['data'] = '0x' . $this->bytecode . Utils::stripZero($data);

            $this->eth->sendTransaction($transaction, function ($err, $transaction) use ($callback){
                if ($err !== null) {
                    return call_user_func($callback, $err, null);
                }
                return call_user_func($callback, null, $transaction);
            });
        }
    }
1132738
protected function bindExpectedToObject()
    {
        $accessor = PropertyAccess::createPropertyAccessor();

        $values = array_merge($this->expectedValues, $this->expectedMocks, $this->expectedMocksCollections);

        foreach ($values as $property => $value) {
            if (is_array($value)) {
                $addMethod = 'add'.ucfirst($property);
                foreach ($value as $mock) {
                    $this->getObjectToTest()->$addMethod($mock);
                }
            } else {
                if ($accessor->isWritable($this->getObjectToTest(), $property)) {
                    // Use direct access to property to avoid "only variables should be passed by reference"
                    $accessor->setValue($this->objectToTest, $property, $value);
                }
            }
        }

        // Tear down
        unset($values);
        unset($accessor);

        return $this;
    }
805412
public function checkCommandArguments()
    {
        foreach ($this->commandArguments as $index => $argument) {
            $argument->addParameters($this->arguments);

            if ($argument->isRequired() && !$argument->hasBeenProvided()) {
                throw new \Parable\Console\Exception(
                    "Required argument with index #{$index} '{$argument->getName()}' not provided."
                );
            }
        }
    }
432098
public function build(): SetReturnValueRequest
	{
		$instance = new SetReturnValueRequest();
		if ($this->newValue === null) {
			throw new BuilderException('Property [newValue] is required.');
		}
		$instance->newValue = $this->newValue;
		return $instance;
	}
644620
public function build(): RequestDataRequest
	{
		$instance = new RequestDataRequest();
		if ($this->securityOrigin === null) {
			throw new BuilderException('Property [securityOrigin] is required.');
		}
		$instance->securityOrigin = $this->securityOrigin;
		if ($this->databaseName === null) {
			throw new BuilderException('Property [databaseName] is required.');
		}
		$instance->databaseName = $this->databaseName;
		if ($this->objectStoreName === null) {
			throw new BuilderException('Property [objectStoreName] is required.');
		}
		$instance->objectStoreName = $this->objectStoreName;
		if ($this->indexName === null) {
			throw new BuilderException('Property [indexName] is required.');
		}
		$instance->indexName = $this->indexName;
		if ($this->skipCount === null) {
			throw new BuilderException('Property [skipCount] is required.');
		}
		$instance->skipCount = $this->skipCount;
		if ($this->pageSize === null) {
			throw new BuilderException('Property [pageSize] is required.');
		}
		$instance->pageSize = $this->pageSize;
		$instance->keyRange = $this->keyRange;
		return $instance;
	}
489195
public function getPromise(): PromiseInterface
    {
        if (! $this->requestOrign && ! $this->promise) throw new RequestBuildExpection('please give a request.');
        if (! $this->promise) {
            $this->promise = $this->_getClient()->sendAsync($this->requestOrign, $this->requestOption);
        }
        if ($this->responseIsJson && ! $this->isJsonCallbackPassed) {
            array_unshift($this->callbackOfSuccess, function ($res) {
                return json_decode($res, true);
            });
            $this->isJsonCallbackPassed = true;
        }
        return $this->promise;
    }
417095
protected function addArgumentsNode()
    {
        $builder = new TreeBuilder();
        $node    = $builder->root('arguments');

        $node
            ->prototype('variable')
            ->end();

        return $node;
    }
634191
public function mock()
    {
        $image = is_null($this->thumbnail)
            ? $this->imagePath()
            : $this->thumbnailPath();

        return $image;
    }
1068051
private function assembleConstructorArgs()
    {
        $params = $this->getConstructorArgs();
        $args = [];
        $givenParams = array_keys($this->parameters);
        foreach ($params as $param) {
            if (in_array($param->getName(), $givenParams)) {
                $args[] = $this->parameters[$param->getName()];
            } else {
                $paramClass = $param->getClass();
                if ($paramClass == null) {
                    throw new \Exception('Missing constructor argument '.$param->getName());
                }
                $paramClass = $paramClass->getName();
                foreach ($this->dependencies as $dependency) {
                    if ($dependency->isInstanceOf($paramClass)) {
                        $args[] = $dependency->getInstance();
                        break;
                    }
                }
            }
        }
        return $args;
    }
1061008
public function build(): EvaluateRequest
	{
		$instance = new EvaluateRequest();
		if ($this->expression === null) {
			throw new BuilderException('Property [expression] is required.');
		}
		$instance->expression = $this->expression;
		$instance->objectGroup = $this->objectGroup;
		$instance->includeCommandLineAPI = $this->includeCommandLineAPI;
		$instance->silent = $this->silent;
		$instance->contextId = $this->contextId;
		$instance->returnByValue = $this->returnByValue;
		$instance->generatePreview = $this->generatePreview;
		$instance->userGesture = $this->userGesture;
		$instance->awaitPromise = $this->awaitPromise;
		$instance->throwOnSideEffect = $this->throwOnSideEffect;
		$instance->timeout = $this->timeout;
		return $instance;
	}
105447
protected function generateClass()
    {
        if ($this->class != null) {
            throw new Exception("The class has already been generated");
        }

        $classBaseType = $this->getBaseTypeClass();

        $this->class = new PhpClass(
            $this->phpIdentifier,
            false,
            $classBaseType,
            null,
            false,
            $this->abstract
        );

        $constructorComment = new PhpDocComment();
        $constructorSource = '';
        $constructorParameters = array();
        $accessors = array();

        // Add base type members to constructor parameter list first and call base class constructor
        $parentMembers = $this->getBaseTypeMembers($this);
        if (!empty($parentMembers)) {
            foreach ($parentMembers as $member) {
                $type = Validator::validateType($member->getType());
                $name = Validator::validateAttribute($member->getName());

                if (!$member->getNullable()) {
                    $constructorComment->addParam(PhpDocElementFactory::getParam($type, $name, ''));
                    $constructorParameters[$name] = Validator::validateTypeHint($type);
                }
            }
            $constructorSource .= '  parent::__construct(' . $this->buildParametersString($constructorParameters, false) . ');' . PHP_EOL;
        }

        // Add member variables
        foreach ($this->members as $member) {
            $type = Validator::validateType($member->getType());
            $name = Validator::validateAttribute($member->getName());
            $typeHint = Validator::validateTypeHint($type);

            $comment = new PhpDocComment();
            $comment->setVar(PhpDocElementFactory::getVar($type, $name, ''));
            $var = new PhpVariable('protected', $name, 'null', $comment);
            $this->class->addVariable($var);

            if (!$member->getNullable()) {
                if ($type == '\DateTime') {
                    if ($this->config->get('constructorParamsDefaultToNull')) {
                        $constructorSource .= '  $this->' . $name . ' = $' . $name . ' ? $' . $name . '->format(\DateTime::ATOM) : null;' . PHP_EOL;
                    } else {
                        $constructorSource .= '  $this->' . $name . ' = $' . $name . '->format(\DateTime::ATOM);' . PHP_EOL;
                    }
                } else {
                    $constructorSource .= '  $this->' . $name . ' = $' . $name . ';' . PHP_EOL;
                }
                $constructorComment->addParam(PhpDocElementFactory::getParam($type, $name, ''));
                $constructorParameters[$name] = $typeHint;
            }

            $getterComment = new PhpDocComment();
            $getterComment->setReturn(PhpDocElementFactory::getReturn($type, ''));
            if ($type == '\DateTime') {
                $getterCode = '  if ($this->' . $name . ' == null) {' . PHP_EOL
                    . '    return null;' . PHP_EOL
                    . '  } else {' . PHP_EOL
                    . '    try {' . PHP_EOL
                    . '      return new \DateTime($this->' . $name . ');' . PHP_EOL
                    . '    } catch (\Exception $e) {' . PHP_EOL
                    . '      return false;' . PHP_EOL
                    . '    }' . PHP_EOL
                    . '  }' . PHP_EOL;
            } else {
                $getterCode = '  return $this->' . $name . ';' . PHP_EOL;
            }
            $getter = new PhpFunction('public', 'get' . ucfirst($name), '', $getterCode, $getterComment);
            $accessors[] = $getter;

            $setterComment = new PhpDocComment();
            $setterComment->addParam(PhpDocElementFactory::getParam($type, $name, ''));
            $setterComment->setReturn(PhpDocElementFactory::getReturn($this->phpNamespacedIdentifier, ''));
            if ($type == '\DateTime') {
                if ($member->getNullable()) {
                    $setterCode = '  if ($' . $name . ' == null) {' . PHP_EOL
                        . '   $this->' . $name . ' = null;' . PHP_EOL
                        . '  } else {' . PHP_EOL
                        . '    $this->' . $name . ' = $' . $name . '->format(\DateTime::ATOM);' . PHP_EOL
                        . '  }' . PHP_EOL;
                } else {
                    $setterCode = '  $this->' . $name . ' = $' . $name . '->format(\DateTime::ATOM);' . PHP_EOL;
                }
            } else {
                $setterCode = '  $this->' . $name . ' = $' . $name . ';' . PHP_EOL;
            }
            $setterCode .= '  return $this;' . PHP_EOL;
            $setter = new PhpFunction(
                'public',
                'set' . ucfirst($name),
                $this->buildParametersString(
                    array($name => $typeHint),
                    true,
                    // If the type of a member is nullable we should allow passing null to the setter. If the type
                    // of the member is a class and not a primitive this is only possible if setter parameter has
                    // a default null value. We can detect whether the type is a class by checking the type hint.
                    $member->getNullable() && !empty($typeHint)
                ),
                $setterCode,
                $setterComment
            );
            $accessors[] = $setter;
        }

        $constructor = new PhpFunction(
            'public',
            '__construct',
            $this->buildParametersString(
                $constructorParameters,
                true,
                $this->config->get('constructorParamsDefaultToNull')
            ),
            $constructorSource,
            $constructorComment
        );
        $this->class->addFunction($constructor);

        foreach ($accessors as $accessor) {
            $this->class->addFunction($accessor);
        }
    }
345924
protected function abortIfRequiredArgumentsAreMissing($expectedArguments, $actualArguments)
    {
        $actualArgumentNames = array_keys($actualArguments);
        /** @var $expectedArgument ArgumentDefinition */
        foreach ($expectedArguments as $expectedArgument) {
            if ($expectedArgument->isRequired() && !in_array($expectedArgument->getName(), $actualArgumentNames)) {
                throw new Exception('Required argument "' . $expectedArgument->getName() . '" was not supplied.', 1237823699);
            }
        }
    }
791294
public function invoke()
    {
        $arguments = $this->arguments;

        if (($serverHost = $arguments->{'server-host'}) !== null) {
            $this->server = new Server($serverHost, $arguments->{'server-root'});
            $this->server->start();
        }

        //Include bootstrap file if set
        if (($bootstrapFile = $arguments->bootstrap)) {
            require $bootstrapFile;
        }

        echo 'testphase v' . Testphase::getVersion() . PHP_EOL;

        if ($arguments->help) {
            echo 'Help:' . PHP_EOL;
            $printer = new ConsoleOptionPrinter;
            echo $printer->render(static::getArgumentSpecifications());
            return 0;
        } elseif ($arguments->debug) {
            echo 'Enabled options: ' . PHP_EOL;

            foreach ($arguments as $key => $spec) {
                echo $spec;
            }
        }

        try {
            $testParserCollection = $this->getTestParserCollection();
        } catch (\Exception $e) {
            echo $e->getMessage();
            return $this->stop(1);
        }

        //Statistics object
        $stats = (object)[
            'tests' => count($testParserCollection),
            'success' => 0,
            'error' => 0,
            'failure' => 0,
            'ignore' => 0,
            'incomplete' => 0,
            'errors' => []
        ];

        $testIndex = 0;

        foreach ($testParserCollection as $test) {

            //Check if subdir argument is set
            if (isset($arguments->subdir) && $arguments->subdir !== null) {
                //If so check if file name passes the given pattern

                //Remove base dir from filename
                $cleanFilename = trim(
                    str_replace(
                        $arguments->dir,
                        '',
                        $test->getFilename()
                    ),
                    '/'
                );

                $match = false;

                //Check if file name matches any of the subdir patterns
                foreach ($arguments->subdir as $pattern) {
                    $pattern = '@' . $pattern . '@';
                    if (!!preg_match($pattern, $cleanFilename)) {
                        $match = $match || true;
                        break;
                    }
                }

                if (!$match) {
                    //Ignore
                    $stats->ignore += 1;
                    if ($arguments->verbose) {
                        echo sprintf(
                            'I %s',
                            $test->getFilename()
                        ) . PHP_EOL;
                    } else {
                        echo 'I';
                    }
                    continue;
                }
            }

            $meta = $test->getMeta();

            if (isset($meta->ignore) && $meta->ignore) {
                if ($arguments->verbose) {
                    echo sprintf(
                        'I %s',
                        $test->getFilename()
                    ) . PHP_EOL;
                } else {
                    echo 'I';
                }
                $stats->ignore += 1;
                continue;
            }


            if (isset($meta->incomplete) && $meta->incomplete !== false) {
                $stats->incomplete += 1;
            }

            try {
                //Complete test's testphase collection
                $test->createTest();
            } catch (\Exception $e) {
                echo sprintf(
                    'Unable to create test from file "%s" %s With message: "%s"',
                    $test->getFilename(),
                    PHP_EOL,
                    $e->getMessage()
                ) . PHP_EOL;
                return $this->stop(1);
            }

            $testphaseCollection = $test->getTest();

            //Include number of additional testphase collections
            $stats->tests += count($testphaseCollection) - 1;
    
            //Iterate though test parser's testphase collection
            foreach ($testphaseCollection as $testphase) {
                try {
                    $testphase->run(function (
                        $responseStatusCode,
                        $responseHeaders,
                        $responseBody,
                        $responseBodyObject = null
                    ) use (
                        $test,
                        $arguments
                    ) {
                        //todo move to TestParser
                        $export = $test->getExport();

                        //Fetch all test exports and add them as globals
                        foreach ($export as $key => $value) {
                            $path = explode('.', $value);

                            $pathValue = $responseBodyObject;

                            foreach ($path as $p) {
                                //@todo implement array index
                                $arrayIndex = 0;

                                if (is_array($pathValue)) {
                                    $pathValue = $pathValue[$arrayIndex]->{$p};
                                } else {
                                    $pathValue = $pathValue->{$p};
                                }
                            }

                            Globals::set($key, $pathValue);
                        }

                        if ($arguments->debug) {
                            echo 'Response Status Code:' . PHP_EOL;
                            echo $responseStatusCode . PHP_EOL;
                            echo 'Response Headers:' . PHP_EOL;
                            print_r($responseHeaders);
                            echo PHP_EOL;
                            echo 'Response Body:' . PHP_EOL;
                            echo json_encode($responseBodyObject, JSON_PRETTY_PRINT) . PHP_EOL;
                        }
                    });

                    //Echo successful char
                    if ($arguments->verbose) {
                        echo sprintf(
                            '. %s',
                            $test->getFilename()
                        ) . PHP_EOL;
                    } else {
                        echo '.';
                    }
                    $stats->success += 1;
                } catch (UnsetGlobalException $e) {

                    //Error message
                    $message = $e->getMessage();

                    $message = sprintf(
                        self::colored('Test "%s" failed with message', 'red') . PHP_EOL . ' %s' . PHP_EOL,
                        $test->getFilename(),
                        $message
                    );

                    //push message to error message
                    $stats->errors[] = $message;

                    //Echo unsuccessful char
                    if ($arguments->verbose) {
                        echo sprintf(
                                'F %s',
                                $test->getFilename()
                            ) . PHP_EOL;
                    } else {
                        echo 'F';
                    }

                    //print if immediate
                    if ($arguments->immediate) {
                        echo PHP_EOL . $message . PHP_EOL;
                    }

                    //Error message
                    $stats->error += 1;
                } catch (\Exception $e) {

                    //Error message
                    $message = $e->getMessage();

                    if ($arguments->debug) {
                        $message .= PHP_EOL . $testphase->getResponseBody();
                    }

                    $message = sprintf(
                        self::colored('Test "%s" failed with message', 'red') . PHP_EOL . ' %s' . PHP_EOL,
                        $test->getFilename(),
                        $message
                    );

                    if (get_class($e) == IncorrectParametersException::class) {
                        $message .= 'Incorrect:' . PHP_EOL
                            . json_encode($e->getParameters(), JSON_PRETTY_PRINT) . PHP_EOL;
                    } elseif (get_class($e) == MissingParametersException::class) {
                        $message .= 'Missing:' . PHP_EOL
                            . json_encode($e->getParameters(), JSON_PRETTY_PRINT) . PHP_EOL;
                    }

                    //push message to error message
                    $stats->errors[] = $message;

                    //Echo unsuccessful char
                    if ($arguments->verbose) {
                        echo sprintf(
                            'F %s',
                            $test->getFilename()
                        ) . PHP_EOL;
                    } else {
                        echo 'F';
                    }

                    //print if immediate
                    if ($arguments->immediate) {
                        echo PHP_EOL . $message . PHP_EOL;
                    }

                    $stats->failure += 1;
                }
                ++$testIndex;
                //Show only 80 characters per line
                if (!($testIndex % 79)) {
                    echo PHP_EOL;
                }
            }
        }

        echo PHP_EOL;

        if ($arguments->{'show-globals'}) {
            echo 'Globals:' . PHP_EOL;
            echo Globals::toString() . PHP_EOL;
        }

        //don't print if immediate is true
        if (!$arguments->immediate && !empty($stats->errors)) {
            echo 'Errors:' . PHP_EOL;
            foreach ($stats->errors as $e) {
                echo $e . PHP_EOL;
            }
        }

        echo 'Complete!' . PHP_EOL;
        echo 'Tests:' . $stats->tests . ', ';
        Binary::output('Successful: ' . $stats->success, 'green');
        echo ', ';
        Binary::output('Ignored: ' . $stats->ignore, 'yellow');
        echo ', ';
        Binary::output('Incomplete: ' . $stats->incomplete, 'yellow');
        echo ', ';
        Binary::output('Error: ' . $stats->error, 'red');
        echo ', ';
        Binary::output('Failure: ' . $stats->failure . PHP_EOL, 'red');


        echo 'Memory usage: ' . (int)(memory_get_usage(true)/1048576) . ' MB' . PHP_EOL;
        echo 'Elapsed time: ' . (time() - $_SERVER['REQUEST_TIME']) . ' s' . PHP_EOL;

        if ($stats->error > 0) {
            return $this->stop(1);
        }
        if ($stats->failure > 0) {
            return $this->stop(2);
        }

        return $this->stop(0);
    }
473466
public function prepareArguments()
    {
        if (!$this->argumentsInitialized) {
            $thisClassName = get_class($this);
            if (isset(self::$argumentDefinitionCache[$thisClassName])) {
                $this->argumentDefinitions = self::$argumentDefinitionCache[$thisClassName];
            } else {
                $this->registerRenderMethodArguments();
                $this->initializeArguments();
                self::$argumentDefinitionCache[$thisClassName] = $this->argumentDefinitions;
            }
            $this->argumentsInitialized = true;
        }
        return $this->argumentDefinitions;
    }
1297242
public function get_instance() {
        if ( empty( $this->options->instance ) ) {
            return $this;
        }

        if ( ! is_callable( $this->options->instance ) ) {
            throw new Exception( sprintf( '`%s` is not callable', $this->options->instance ) );
        }

        return call_user_func( $this->options->instance );
    }