Exemple #1
0
 public function name()
 {
     if (CLI::get_opt('help') === NULL) {
         CLI::show_help('name');
         exit;
     }
     $name = CLI::get_opt('name');
     if ($name === FALSE) {
         CLI::terminate('name', 'You need to specify a name');
     }
     echo "Your name is {$name}" . PHP_EOL;
 }
Exemple #2
0
        $x = CLI::get_opt('x');
        // -x Reverts to NULL as there's no value assigned to it.
        $test->expects($age)->to()->equal('10');
        $test->expects($name)->to()->equal('yorick');
        $test->expects($desc)->to()->equal('hello world');
        $test->expects($x)->to()->be_type_of('NULL');
        $test->expects($x)->to()->equal(NULL);
    });
    Test::add("Get all options along with their values", function ($test) {
        CLI::set_opt(NULL, 'name', 'Enter your name');
        $GLOBALS['argv'] = array('cli.php', 'hello', '--name', 'yorick');
        $opts = CLI::opts();
        $test->expects($opts)->to()->be_type_of('array');
        $test->expects($opts['name']['value'])->to()->equal('yorick');
    });
    Test::add("Get all options along with their values for a specific method", function ($test) {
        CLI::set_opt('hello', 'name', 'Enter your name');
        $GLOBALS['argv'] = array('cli.php', 'hello', '--name', 'yorick');
        $opts = CLI::opts('hello');
        $test->expects($opts)->to()->be_type_of('array');
        $test->expects($opts['name']['value'])->to()->equal('yorick');
    });
    Test::add("Check if all required options are set", function ($test) {
        CLI::set_opt(NULL, 'name', 'Enter your name', TRUE);
        $GLOBALS['argv'] = array('cli.php', 'hello', '--name', 'yorick');
        $has_opts = CLI::has_opts();
        $test->expects($has_opts)->to()->be_type_of('boolean');
        $test->expects($has_opts)->to()->equal(TRUE);
    });
});
Test::run_all();