add tests
authorMichael Wallner <mike@php.net>
Fri, 6 Mar 2015 22:06:45 +0000 (23:06 +0100)
committerMichael Wallner <mike@php.net>
Fri, 6 Mar 2015 22:06:45 +0000 (23:06 +0100)
src/pharext/CliArgs.php
tests/src/pharext/FilteredSourceDirTest.php [new file with mode: 0644]
tests/src/pharext/GitSourceDirTest.php [new file with mode: 0644]

index 99992bd321cca327e2b2e6e72300dd97c9b0c941..717bc00449b4f2479cbcc2089b2198f17796dd77 100644 (file)
@@ -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 (file)
index 0000000..c1b2b1f
--- /dev/null
@@ -0,0 +1,41 @@
+<?php
+
+namespace pharext;
+
+require __DIR__."/../../autoload.php";
+
+class Cmd2 implements Command
+{
+       use CliCommand;
+       function __construct() {
+               $this->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 (file)
index 0000000..36f2f1f
--- /dev/null
@@ -0,0 +1,37 @@
+<?php
+
+namespace pharext;
+
+require_once __DIR__."/../../autoload.php";
+
+class Cmd implements Command
+{
+       use CliCommand;
+       function __construct() {
+               $this->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);
+       }
+}