-
-
Notifications
You must be signed in to change notification settings - Fork 317
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test the one 'getter' method of the CommandlineArgument class (#1154)
- Loading branch information
Showing
1 changed file
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
class CommandlineArgumentTest extends \PHPUnit\Framework\TestCase | ||
{ | ||
/** | ||
* Test the one 'getter' method of the CommandlineArgument class | ||
* | ||
* @return void | ||
*/ | ||
public function testGetParts() | ||
{ | ||
$command = "usblamp -s -r 5 red green blue off"; | ||
$exploded = explode(" ", "-s -r 5 red green blue off"); | ||
$commandline = new Commandline($command); | ||
$arguments = ($commandline->arguments); | ||
foreach ($arguments as $counter => $argument) { | ||
$parts = $argument->getParts(); | ||
$this->assertEquals($exploded[$counter], $parts[0]); | ||
$this->assertEquals(false, $argument->escape); | ||
} | ||
} | ||
|
||
public function testSetEscape() | ||
{ | ||
$command = "usblamp -s -r 5 red green blue off"; | ||
$commandline = new Commandline($command); | ||
$argument = new CommandlineArgument($commandline); | ||
$this->assertEquals($argument->escape, false); | ||
$argument->setEscape(true); | ||
$this->assertEquals($argument->escape, true); | ||
} | ||
|
||
public function testSetline() | ||
{ | ||
$commandline = new Commandline(); | ||
$argument = new CommandlineArgument($commandline); | ||
$argument->setLine(null); | ||
$parts = $argument->getParts(); | ||
$this->assertEquals($parts, []); | ||
$argument->setLine("perl -pie 's/foo/bar/g' test.txt"); | ||
$parts = $argument->getParts(); | ||
$this->assertNotEquals($parts, []); | ||
|
||
} | ||
} |