matteosister / GitElephant

An abstraction layer for git written in PHP
GNU Lesser General Public License v3.0
613 stars 74 forks source link

Doesn't work with vfStream mock filesystem #111

Closed samgavinio closed 7 years ago

samgavinio commented 7 years ago

Was trying to write a PHPUnit test for a console command that makes use of Repository with PHPUnit's recommended virtual filesystem and it appears that this doesn't play well with it.

vfsStreamWrapper::register();
vfsStreamWrapper::setRoot(new vfsStreamDirectory('example'));

mkdir(vfsStream::url('example/gitrepo'));
$repository = Repository::open(vfsStream::url('example/gitrepo'));
$repository->init();

// Create any file within vfs://example/gitrepo then try to commit it
...
$repository->stage();
$repository->commit('This is a dummy commit');

Instead of managing the git repository within the virtual filesystem, Repository is trying to use the current working directory on the actual filesystem which is why I run into issues with initialising and commiting into the supposedly new git repository:

   ["repositoryPath":"GitElephant\Command\Caller\Caller":private]=>
    string(19) "vfs://example/gitrepo"
    ["outputLines":"GitElephant\Command\Caller\Caller":private]=>
    array(2) {
      [0]=>
      string(110) "Reinitialized existing Git repository in /Users/currentworkingdirectory/.git/"
      [1]=>
      string(0) ""
    }

The reinitialization warning is because my current working directory is another git repository but this shouldn't have happened in the first place if the virtual filesystem was used.

samgavinio commented 7 years ago

After investigating this further, it seems that this is an issue with proc_open when Symfony\Component\Process\Process.php makes a call to execute the git commands. The correct virtual directory is passed but somehow proc_open falls back to the current working directory on the actual filesystem. From the looks of it, doesn't look like anything can be done about it currently.