* @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;
--- /dev/null
+<?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
--- /dev/null
+<?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);
+ }
+}