/** * Load the config. * * @param string $argv The command line string. */ public function loadConfig($argv = []) { $args = new Args(); $args->argument('config', ['default' => 'kahlan-config.php']); $args->argument('help', ['type' => 'boolean']); $args->argument('version', ['type' => 'boolean']); $args->parse($argv); $run = function ($args) { if (file_exists($args->get('config'))) { require $args->get('config'); } }; $run($args); $this->_args->parse($argv, false); if ($args->get('help')) { return $this->_help(); } if ($args->get('version')) { return $this->_version(); } }
expect($args->get('argument1'))->toEqual('non_empty_value'); }); }); describe("->exists()", function () { it("returns `true` if the argument exists", function () { $args = new Args(); $actual = $args->parse(['command', '--argument1', '--argument2=true', '--argument3=false', '--argument4=0']); expect($args->exists('argument1'))->toBe(true); expect($args->exists('argument2'))->toBe(true); expect($args->exists('argument3'))->toBe(true); expect($args->exists('argument4'))->toBe(true); expect($args->exists('argument5'))->toBe(false); }); it("returns `true` if the argument as a default value", function () { $args = new Args(); $args->argument('argument1', ['type' => 'boolean']); $args->argument('argument2', ['type' => 'boolean', 'default' => false]); expect($args->exists('argument1'))->toBe(false); expect($args->exists('argument2'))->toBe(true); }); }); describe("->cast()", function () { it("casts array", function () { $args = new Args(); $cast = $args->cast(["some", "string", "and", 10], "string"); expect($cast)->toBeAn('array'); foreach ($cast as $c) { expect($c)->toBeA('string'); } }); it("casts boolean", function () {