/** * Load the config. * * @param string $argv The command line string. */ public function loadConfig($argv = []) { $commandLine = new CommandLine(); $commandLine->option('config', ['default' => 'kahlan-config.php']); $commandLine->option('help', ['type' => 'boolean']); $commandLine->option('version', ['type' => 'boolean']); $commandLine->parse($argv); $run = function ($commandLine) { if (file_exists($commandLine->get('config'))) { require $commandLine->get('config'); } }; $run($commandLine); $this->_commandLine->parse($argv, false); if ($commandLine->get('help')) { return $this->_help(); } if ($commandLine->get('version')) { return $this->_version(); } }
foreach ($cast as $c) { expect($c)->toBeA('string'); } }); it("casts boolean", function () { $commandLine = new CommandLine(); $cast = $commandLine->cast(["true", "false", "some_string", null, 10], "boolean"); expect($cast)->toBeAn('array'); expect(count($cast))->toBe(5); list($bTrue, $bFalse, $string, $null, $number) = $cast; expect($bTrue)->toBeA('boolean')->toBe(true); expect($bFalse)->toBeA('boolean')->toBe(false); expect($string)->toBeA('boolean')->toBe(true); expect($null)->toBeA('boolean')->toBe(false); expect($number)->toBeA('boolean')->toBe(true); }); it("casts numeric", function () { $commandLine = new CommandLine(); $cast = $commandLine->cast([true, "false", "some_string", null, 10], "numeric"); expect($cast)->toBeAn('array'); expect(count($cast))->toBe(5); expect(implode($cast))->toBe("100110"); }); it("casts value into array", function () { $commandLine = new CommandLine(); $cast = $commandLine->cast("string", "string", true); expect($cast)->toBeA("array"); expect($cast)->toContain("string"); }); }); });