Files
DomFramework/Tests/getoptsTest.php

176 lines
6.1 KiB
PHP

<?php
/** Test the GetOpts */
class getoptsTest extends PHPUnit_Framework_TestCase
{
public function test_empty1 ()
{
// Empty
$getopts = new getopts ();
$res = $getopts->help ();
$this->assertSame ($res, "No option defined\n");
}
public function test_simu1 ()
{
$getopts = new getopts ();
$res = $getopts->simulate ("sim\ ulate -h -d -d -f ii -o 1\ 2 -o \"2 2\" -o 3 -- -bla final");
$this->assertSame (is_object ($res), true);
}
public function test_add1 ()
{
$getopts = new getopts ();
$getopts->simulate ("sim\ ulate -h -d -d -f ii -o 1\ 2 -o \"2 2\" -o 3 -- -bla final");
$res = $getopts->add ("Help", "?h", array ("help","help2"), "Help of the software");
$this->assertSame (is_object ($res), true);
}
public function test_add2 ()
{
$getopts = new getopts ();
$getopts->simulate ("sim\ ulate -h -d -d -f ii -o 1\ 2 -o \"2 2\" -o 3 -- -bla final");
$getopts->add ("Help", "?h", array ("help","help2"), "Help of the software");
$res = $getopts->add ("Debug", "d", "debug", "Debug", "DebugLevel", 2);
$this->assertSame (is_object ($res), true);
}
public function test_scan1 ()
{
$this->expectException ("Exception", "Provided tokens are not known: -f,-o,-o,-o");
$getopts = new getopts ();
$getopts->simulate ("sim\ ulate -h -d -d -f ii -o 1\ 2 -o \"2 2\" -o 3 -- -bla final");
$getopts->add ("Help", "?h", array ("help","help2"), "Help of the software");
$getopts->add ("Debug", "d", "debug", "Debug", "DebugLevel", 2);
$res = $getopts->scan ();
}
public function test_getShort1 ()
{
// One unique value (-h -> true/false)
$getopts = new getopts ();
$getopts->simulate ("sim\ ulate -h -d -d ");
$getopts->add ("Help", "?h", array ("help","help2"), "Help of the software");
$getopts->add ("Debug", "d", "debug", "Debug", "DebugLevel", 2);
$res = $getopts->get ("Help");
$this->assertSame ($res, true);
}
public function test_getShort2 ()
{
// Multiple values, two set (-d -d)
$getopts = new getopts ();
$getopts->simulate ("sim\ ulate -h -d -d ");
$getopts->add ("Help", "?h", array ("help","help2"), "Help of the software");
$getopts->add ("Debug", "d", "debug", "Debug", "DebugLevel", 2);
$res = $getopts->get ("Debug");
$this->assertSame ($res, array (true,true));
}
public function test_getShort3 ()
{
// Multiple values, one set (-d)
$getopts = new getopts ();
$getopts->simulate ("sim\ ulate -h -d ");
$getopts->add ("Help", "?h", array ("help","help2"), "Help of the software");
$getopts->add ("Debug", "d", "debug", "Debug", "DebugLevel", 2);
$res = $getopts->get ("Debug");
$this->assertSame ($res, array (true));
}
public function test_getShort4 ()
{
// Multiple values, None set (-d)
$getopts = new getopts ();
$getopts->simulate ("sim\ ulate -h ");
$getopts->add ("Help", "?h", array ("help","help2"), "Help of the software");
$getopts->add ("Debug", "d", "debug", "Debug", "DebugLevel", 2);
$res = $getopts->get ("Debug");
$this->assertSame ($res, array ());
}
public function test_getLong1 ()
{
// One unique value (--help -> true/false)
$getopts = new getopts ();
$getopts->simulate ("sim\ ulate --help -d -d ");
$getopts->add ("Help", "?h", array ("help","help2"), "Help of the software");
$getopts->add ("Debug", "d", "debug", "Debug", "DebugLevel", 2);
$res = $getopts->get ("Help");
$this->assertSame ($res, true);
}
public function test_getLong2 ()
{
// Multiple values, two set (-debug --debug)
$getopts = new getopts ();
$getopts->simulate ("sim\ ulate -h --debug --debug ");
$getopts->add ("Help", "?h", array ("help","help2"), "Help of the software");
$getopts->add ("Debug", "d", "debug", "Debug", "DebugLevel", 2);
$res = $getopts->get ("Debug");
$this->assertSame ($res, array (true,true));
}
public function test_getLong3 ()
{
// Multiple values, one set (-d)
$getopts = new getopts ();
$getopts->simulate ("sim\ ulate --help -d ");
$getopts->add ("Help", "?h", array ("help","help2"), "Help of the software");
$getopts->add ("Debug", "d", "debug", "Debug", "DebugLevel", 2);
$res = $getopts->get ("Debug");
$this->assertSame ($res, array (true));
}
public function test_getLong4 ()
{
// Multiple values, None set (-d)
$getopts = new getopts ();
$getopts->simulate ("sim\ ulate -h");
$getopts->add ("Help", "?h", array ("help","help2"), "Help of the software");
$getopts->add ("Debug", "d", "debug", "Debug", "DebugLevel", 2);
$res = $getopts->get ("Debug");
$this->assertSame ($res, array ());
}
public function test_restOfLine1 ()
{
$getopts = new getopts ();
$getopts->simulate ("sim\ ulate -h -d -d -- -bla final");
$getopts->add ("Help", "?h", array ("help","help2"), "Help of the software");
$getopts->add ("Debug", "d", "debug", "Debug", "DebugLevel", 2);
$res = $getopts->restOfLine ();
$this->assertSame ($res, array ("-bla", "final"));
}
public function test_restOfLine2 ()
{
$getopts = new getopts ();
$getopts->simulate ("sim\ ulate bla final");
$getopts->add ("Help", "?h", array ("help","help2"), "Help of the software");
$getopts->add ("Debug", "d", "debug", "Debug", "DebugLevel", 2);
$res = $getopts->restOfLine ();
$this->assertSame ($res, array ("bla", "final"));
}
public function test_restOfLine3 ()
{
$getopts = new getopts ();
$getopts->simulate ("sim\ ulate -- -bla final");
$getopts->add ("Help", "?h", array ("help","help2"), "Help of the software");
$getopts->add ("Debug", "d", "debug", "Debug", "DebugLevel", 2);
$res = $getopts->restOfLine ();
$this->assertSame ($res, array ("-bla", "final"));
}
public function test_programName1 ()
{
$getopts = new getopts ();
$getopts->simulate ("sim\ ulate -h -d -d -- -bla final");
$getopts->add ("Help", "?h", array ("help","help2"), "Help of the software");
$getopts->add ("Debug", "d", "debug", "Debug", "DebugLevel", 2);
$res = $getopts->programName ();
$this->assertSame ($res, "sim ulate");
}
}