189 lines
6.5 KiB
PHP
189 lines
6.5 KiB
PHP
<?php
|
|
|
|
/**
|
|
* DomFramework - Tests
|
|
* @package domframework
|
|
* @author Dominique Fournier <dominique@fournier38.fr>
|
|
* @license BSD
|
|
*/
|
|
|
|
namespace Domframework\Tests;
|
|
|
|
use Domframework\Getopts;
|
|
|
|
/**
|
|
* Test the GetOpts
|
|
*/
|
|
class GetoptsTest extends \PHPUnit_Framework_TestCase
|
|
{
|
|
public function testEmpty1()
|
|
{
|
|
// Empty
|
|
$getopts = new Getopts();
|
|
$res = $getopts->help();
|
|
$this->assertSame($res, "No option defined\n");
|
|
}
|
|
|
|
public function testSimu1()
|
|
{
|
|
$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 testAdd1()
|
|
{
|
|
$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", ["help","help2"], "Help of the software");
|
|
$this->assertSame(is_object($res), true);
|
|
}
|
|
|
|
public function testAdd2()
|
|
{
|
|
$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", ["help","help2"], "Help of the software");
|
|
$res = $getopts->add("Debug", "d", "debug", "Debug", "DebugLevel", 2);
|
|
$this->assertSame(is_object($res), true);
|
|
}
|
|
|
|
public function testScan1()
|
|
{
|
|
$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", ["help","help2"], "Help of the software");
|
|
$getopts->add("Debug", "d", "debug", "Debug", "DebugLevel", 2);
|
|
$res = $getopts->scan();
|
|
}
|
|
|
|
public function testGetShort1()
|
|
{
|
|
// One unique value (-h -> true/false)
|
|
$getopts = new Getopts();
|
|
$getopts->simulate("sim\ ulate -h -d -d ");
|
|
$getopts->add("Help", "?h", ["help","help2"], "Help of the software");
|
|
$getopts->add("Debug", "d", "debug", "Debug", "DebugLevel", 2);
|
|
$res = $getopts->get("Help");
|
|
$this->assertSame($res, true);
|
|
}
|
|
|
|
public function testGetShort2()
|
|
{
|
|
// Multiple values, two set (-d -d)
|
|
$getopts = new Getopts();
|
|
$getopts->simulate("sim\ ulate -h -d -d ");
|
|
$getopts->add("Help", "?h", ["help","help2"], "Help of the software");
|
|
$getopts->add("Debug", "d", "debug", "Debug", "DebugLevel", 2);
|
|
$res = $getopts->get("Debug");
|
|
$this->assertSame($res, [true,true]);
|
|
}
|
|
|
|
public function testGetShort3()
|
|
{
|
|
// Multiple values, one set (-d)
|
|
$getopts = new Getopts();
|
|
$getopts->simulate("sim\ ulate -h -d ");
|
|
$getopts->add("Help", "?h", ["help","help2"], "Help of the software");
|
|
$getopts->add("Debug", "d", "debug", "Debug", "DebugLevel", 2);
|
|
$res = $getopts->get("Debug");
|
|
$this->assertSame($res, [true]);
|
|
}
|
|
|
|
public function testGetShort4()
|
|
{
|
|
// Multiple values, None set (-d)
|
|
$getopts = new Getopts();
|
|
$getopts->simulate("sim\ ulate -h ");
|
|
$getopts->add("Help", "?h", ["help","help2"], "Help of the software");
|
|
$getopts->add("Debug", "d", "debug", "Debug", "DebugLevel", 2);
|
|
$res = $getopts->get("Debug");
|
|
$this->assertSame($res, []);
|
|
}
|
|
|
|
public function testGetLong1()
|
|
{
|
|
// One unique value (--help -> true/false)
|
|
$getopts = new Getopts();
|
|
$getopts->simulate("sim\ ulate --help -d -d ");
|
|
$getopts->add("Help", "?h", ["help","help2"], "Help of the software");
|
|
$getopts->add("Debug", "d", "debug", "Debug", "DebugLevel", 2);
|
|
$res = $getopts->get("Help");
|
|
$this->assertSame($res, true);
|
|
}
|
|
|
|
public function testGetLong2()
|
|
{
|
|
// Multiple values, two set (-debug --debug)
|
|
$getopts = new Getopts();
|
|
$getopts->simulate("sim\ ulate -h --debug --debug ");
|
|
$getopts->add("Help", "?h", ["help","help2"], "Help of the software");
|
|
$getopts->add("Debug", "d", "debug", "Debug", "DebugLevel", 2);
|
|
$res = $getopts->get("Debug");
|
|
$this->assertSame($res, [true,true]);
|
|
}
|
|
|
|
public function testGetLong3()
|
|
{
|
|
// Multiple values, one set (-d)
|
|
$getopts = new Getopts();
|
|
$getopts->simulate("sim\ ulate --help -d ");
|
|
$getopts->add("Help", "?h", ["help","help2"], "Help of the software");
|
|
$getopts->add("Debug", "d", "debug", "Debug", "DebugLevel", 2);
|
|
$res = $getopts->get("Debug");
|
|
$this->assertSame($res, [true]);
|
|
}
|
|
|
|
public function testGetLong4()
|
|
{
|
|
// Multiple values, None set (-d)
|
|
$getopts = new Getopts();
|
|
$getopts->simulate("sim\ ulate -h");
|
|
$getopts->add("Help", "?h", ["help","help2"], "Help of the software");
|
|
$getopts->add("Debug", "d", "debug", "Debug", "DebugLevel", 2);
|
|
$res = $getopts->get("Debug");
|
|
$this->assertSame($res, []);
|
|
}
|
|
|
|
public function testRestOfLine1()
|
|
{
|
|
$getopts = new Getopts();
|
|
$getopts->simulate("sim\ ulate -h -d -d -- -bla final");
|
|
$getopts->add("Help", "?h", ["help","help2"], "Help of the software");
|
|
$getopts->add("Debug", "d", "debug", "Debug", "DebugLevel", 2);
|
|
$res = $getopts->restOfLine();
|
|
$this->assertSame($res, ["-bla", "final"]);
|
|
}
|
|
|
|
public function testRestOfLine2()
|
|
{
|
|
$getopts = new Getopts();
|
|
$getopts->simulate("sim\ ulate bla final");
|
|
$getopts->add("Help", "?h", ["help","help2"], "Help of the software");
|
|
$getopts->add("Debug", "d", "debug", "Debug", "DebugLevel", 2);
|
|
$res = $getopts->restOfLine();
|
|
$this->assertSame($res, ["bla", "final"]);
|
|
}
|
|
|
|
public function testRestOfLine3()
|
|
{
|
|
$getopts = new Getopts();
|
|
$getopts->simulate("sim\ ulate -- -bla final");
|
|
$getopts->add("Help", "?h", ["help","help2"], "Help of the software");
|
|
$getopts->add("Debug", "d", "debug", "Debug", "DebugLevel", 2);
|
|
$res = $getopts->restOfLine();
|
|
$this->assertSame($res, ["-bla", "final"]);
|
|
}
|
|
|
|
public function testProgramName1()
|
|
{
|
|
$getopts = new Getopts();
|
|
$getopts->simulate("sim\ ulate -h -d -d -- -bla final");
|
|
$getopts->add("Help", "?h", ["help","help2"], "Help of the software");
|
|
$getopts->add("Debug", "d", "debug", "Debug", "DebugLevel", 2);
|
|
$res = $getopts->programName();
|
|
$this->assertSame($res, "sim ulate");
|
|
}
|
|
}
|