From: Michael Wallner Date: Fri, 6 Mar 2015 22:06:45 +0000 (+0100) Subject: add tests X-Git-Tag: v1.1.0~1 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=2b1a58c703d3589fe83e74e2e1f9448fdf1ad0b1;hp=38589272e6101c3ed7589fd71d604d288cf68b79;p=pharext%2Fpharext add tests --- diff --git a/src/pharext/CliArgs.php b/src/pharext/CliArgs.php index 99992bd..717bc00 100644 --- a/src/pharext/CliArgs.php +++ b/src/pharext/CliArgs.php @@ -79,7 +79,7 @@ class CliArgs implements \ArrayAccess * @return pharext\CliArgs self */ public function compile(array $spec = null) { - $this->orig = array_merge($this->orig, $spec); + $this->orig = array_merge($this->orig, (array) $spec); foreach ((array) $spec as $arg) { if (isset($arg[0])) { $this->spec["-".$arg[0]] = $arg; diff --git a/tests/src/pharext/FilteredSourceDirTest.php b/tests/src/pharext/FilteredSourceDirTest.php new file mode 100644 index 0000000..c1b2b1f --- /dev/null +++ b/tests/src/pharext/FilteredSourceDirTest.php @@ -0,0 +1,41 @@ +args = new CliArgs; + } + function run($argc, array $argv) { + } +} + +class FilteredSourceDirTest extends \PHPUnit_Framework_TestCase +{ + /** + * @var FilteredSourceDir + */ + protected $source; + + protected function setUp() { + $this->source = new FilteredSourceDir(new Cmd2, "."); + } + + public function testIterator() { + $gitdir = new GitSourceDir(new Cmd2, "."); + $gitfiles = iterator_to_array($gitdir); + sort($gitfiles); + + $filtered = array_values(iterator_to_array($this->source)); + $fltfiles = array_map(function($fi) { + return $fi->getRealpath(); + }, $filtered); + sort($fltfiles); + + $this->assertEquals($gitfiles, $fltfiles); + } +} \ No newline at end of file diff --git a/tests/src/pharext/GitSourceDirTest.php b/tests/src/pharext/GitSourceDirTest.php new file mode 100644 index 0000000..36f2f1f --- /dev/null +++ b/tests/src/pharext/GitSourceDirTest.php @@ -0,0 +1,37 @@ +args = new CliArgs; + } + function run($argc, array $argv) { + } +} + +class GitSourceDirTest extends \PHPUnit_Framework_TestCase +{ + /** + * @var GitSourceDir + */ + protected $source; + + protected function setUp() { + $this->source = new GitSourceDir(new Cmd, "."); + } + + public function testGetBaseDir() { + $this->assertSame($this->source->getBaseDir(), "."); + } + + public function testIterator() { + $git_files = `git ls-files | xargs -I{} -n1 echo \$(pwd)/{}`; + $dir_files = implode("\n", iterator_to_array($this->source->getIterator()))."\n"; + $this->assertSame($git_files, $dir_files); + } +}