forked from ben-xo/dir2cast
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: tests which involve getopt() are hard and I'm belligerent
- Loading branch information
Showing
5 changed files
with
246 additions
and
10 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
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,75 @@ | ||
<?php declare(strict_types=1); | ||
|
||
use PHPUnit\Framework\TestCase; | ||
|
||
final class FakeGetoptTest extends TestCase | ||
{ | ||
public function test_fake_getopt_no_args() | ||
{ | ||
$this->assertEquals( | ||
fake_getopt(array('php', '--halp'), '', array()), | ||
array() | ||
); | ||
$this->assertEquals( | ||
fake_getopt(array('php'), '', array()), | ||
array() | ||
); | ||
} | ||
public function test_fake_getopt_no_match() | ||
{ | ||
$this->assertEquals( | ||
fake_getopt(array('php', '--halp'), '', array('help')), | ||
array() | ||
); | ||
$this->assertEquals( | ||
fake_getopt(array('php'), '', array('help')), | ||
array() | ||
); | ||
} | ||
|
||
public function test_fake_getopt_bool_arg() | ||
{ | ||
$this->assertEquals( | ||
fake_getopt(array('php', '--help'), '', array('help')), | ||
array('help' => false) | ||
); | ||
} | ||
public function test_fake_getopt_string_arg() | ||
{ | ||
$this->assertEquals( | ||
fake_getopt(array('php', '--media-dir'), '', array('media-dir::')), | ||
array('media-dir' => '') | ||
); | ||
$this->assertEquals( | ||
fake_getopt(array('php', '--media-dir='), '', array('media-dir::')), | ||
array() // XXX: seems to be a bug in getopt | ||
); | ||
$this->assertEquals( | ||
fake_getopt(array('php', '--media-dir=test'), '', array('media-dir::')), | ||
array('media-dir' => 'test') | ||
); | ||
} | ||
public function test_fake_getopt_escaping() | ||
{ | ||
$this->assertEquals( | ||
fake_getopt(array('php', "--media-dir= "), '', array('media-dir::')), | ||
array('media-dir' => ' ') | ||
); | ||
print(fake_getopt_command(array('php', '--media-dir=""'), '', array('media-dir::'))); | ||
$this->assertEquals( | ||
fake_getopt(array('php', '--media-dir=""'), '', array('media-dir::')), | ||
array('media-dir' => '""') | ||
); | ||
$this->assertEquals( | ||
fake_getopt(array('php', "--media-dir=''"), '', array('media-dir::')), | ||
array('media-dir' => "''") | ||
); | ||
} | ||
public function test_fake_getopt_both_arg_types() | ||
{ | ||
$this->assertEquals( | ||
fake_getopt(array('php', '--help', '--media-dir'), '', array('help', 'media-dir::')), | ||
array('help' => false, 'media-dir' => '') | ||
); | ||
} | ||
} |
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,23 @@ | ||
<?php declare(strict_types=1); | ||
|
||
use PHPUnit\Framework\TestCase; | ||
|
||
final class FourOhFourTest extends TestCase | ||
{ | ||
public static function setUpBeforeClass(): void | ||
{ | ||
prepare_testing_dir(); | ||
} | ||
|
||
public function test_non_existent_dir_prints_bare_error_CLI_case(): void | ||
{ | ||
exec('php dir2cast.php --output=out.xml --media-dir=imaginary-dir', $output, $returncode); | ||
$this->assertEquals("Not Found: imaginary-dir", implode("\n", $output)); | ||
$this->assertEquals(254, $returncode); // 254 is -2 | ||
} | ||
|
||
public static function tearDownAfterClass(): void | ||
{ | ||
chdir('..'); | ||
} | ||
} |
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
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