public function testCreatePhar()
 {
     $this->if($builder = new \mock\mageekguy\atoum\scripts\builder(uniqid(), $adapter = new atoum\test\adapter()))->and($builder->setTaggerEngine($taggerEngine = new \mock\mageekguy\atoum\scripts\tagger\engine()))->and($this->calling($taggerEngine)->tagVersion = function () {
     })->and($builder->disablePharCreation())->then->boolean($builder->createPhar())->isTrue()->if($builder->enablePharCreation())->and->mockGenerator->shunt('__construct')->and($builder->setVcs($vcs = new \mock\mageekguy\atoum\scripts\builder\vcs()))->and($this->calling($vcs)->getNextRevisions = array())->and($this->calling($vcs)->exportRepository = function () {
     })->then->exception(function () use($builder) {
         $builder->createPhar();
     })->isInstanceOf('mageekguy\\atoum\\exceptions\\logic')->hasMessage('Unable to create phar, destination directory is undefined')->if($builder->setDestinationDirectory($destinationDirectory = uniqid()))->then->exception(function () use($builder) {
         $builder->createPhar();
     })->isInstanceOf('mageekguy\\atoum\\exceptions\\logic')->hasMessage('Unable to create phar, working directory is undefined')->if($builder->setWorkingDirectory($workingDirectory = uniqid()))->and($builder->setPhp($php = new \mock\mageekguy\atoum\php()))->and($this->calling($php)->run = $php)->and($builder->setPharGeneratorScript($pharGeneratorScript = uniqid()))->and($this->calling($builder)->writeErrorInErrorsDirectory = function () {
     })->and($adapter->file_get_contents = false)->then->boolean($builder->createPhar())->isTrue()->if($this->calling($vcs)->getNextRevisions = function () use(&$revision) {
         static $i = 0;
         return ++$i > 1 ? array() : array($revision = rand(1, PHP_INT_MAX));
     })->and($builder->disableUnitTestChecking())->and($this->calling($php)->getExitCode = rand(1, PHP_INT_MAX))->and($this->calling($php)->getStderr = $stderr = uniqid())->then->boolean($builder->createPhar())->isFalse()->mock($builder)->call('writeErrorInErrorsDirectory')->withArguments('Unable to run ' . $php . ': ' . $stderr)->once()->mock($vcs)->call('setRevision')->withArguments($revision)->once()->call('setWorkingDirectory')->withArguments($workingDirectory)->once()->call('exportRepository')->once()->if($this->calling($php)->getExitCode = 0)->and($adapter->date = $date = uniqid())->and($this->calling($vcs)->getNextRevisions = function () use(&$revision) {
         static $i = 0;
         return ++$i > 1 ? array() : array($revision = rand(1, PHP_INT_MAX));
     })->and($this->resetMock($vcs))->then->boolean($builder->createPhar())->isTrue()->mock($taggerEngine)->call('setVersion')->withArguments('nightly-' . $revision . '-' . $date)->once()->call('tagVersion')->atLeastOnce()->mock($vcs)->call('setRevision')->withArguments($revision)->once()->call('setWorkingDirectory')->withArguments($workingDirectory)->once()->call('exportRepository')->once()->if($this->resetMock($vcs))->and($this->resetMock($taggerEngine))->and($this->calling($vcs)->getNextRevisions = function () use(&$revision) {
         static $i = 0;
         return ++$i > 1 ? array() : array($revision = rand(1, PHP_INT_MAX));
     })->then->boolean($builder->createPhar($tag = uniqid()))->isTrue()->mock($taggerEngine)->call('setVersion')->withArguments($tag)->once()->call('tagVersion')->once()->mock($vcs)->call('setRevision')->withArguments($revision)->once()->call('setWorkingDirectory')->withArguments($workingDirectory)->once()->call('exportRepository')->once()->if($builder->setRevisionFile($revisionFile = uniqid()))->and($adapter->file_get_contents = false)->and($adapter->file_put_contents = function () {
     })->and($this->resetMock($vcs))->and($this->calling($vcs)->getNextRevisions = function () use(&$revision) {
         static $i = 0;
         return ++$i > 1 ? array() : array($revision = rand(1, PHP_INT_MAX));
     })->then->boolean($builder->createPhar())->isTrue()->adapter($adapter)->call('file_get_contents')->withArguments($revisionFile)->once()->call('file_put_contents')->withArguments($revisionFile, $revision, \LOCK_EX)->once()->mock($vcs)->call('setRevision')->withArguments($revision)->once()->call('setWorkingDirectory')->withArguments($workingDirectory)->once()->call('exportRepository')->once()->if($this->resetMock($vcs))->and($this->calling($vcs)->getNextRevisions = function () use(&$revision) {
         static $i = 0;
         return ++$i > 1 ? array() : array($revision = rand(1, PHP_INT_MAX));
     })->and($adapter->file_put_contents = false)->then->exception(function () use($builder) {
         $builder->createPhar();
     })->isInstanceOf('mageekguy\\atoum\\exceptions\\runtime')->hasMessage('Unable to save last revision in file \'' . $revisionFile . '\'')->if($this->resetMock($vcs))->and($this->calling($vcs)->getNextRevisions[1] = array(1, 2, 3))->and($this->calling($vcs)->getNextRevisions[2] = array(2, 3))->and($this->calling($vcs)->getNextRevisions[3] = array(3))->and($this->calling($vcs)->getNextRevisions[4] = array())->and($adapter->file_put_contents = function () {
     })->and($adapter->resetCalls())->then->boolean($builder->createPhar())->isTrue()->adapter($adapter)->call('file_get_contents')->withArguments($revisionFile)->once()->call('file_put_contents')->withArguments($revisionFile, 3, \LOCK_EX)->once()->mock($vcs)->call('setRevision')->withArguments(1)->once()->call('setRevision')->withArguments(2)->once()->call('setRevision')->withArguments(3)->once()->call('setWorkingDirectory')->withArguments($workingDirectory)->atLeastOnce()->call('exportRepository')->atLeastOnce()->if($this->resetMock($vcs))->and($this->calling($vcs)->getNextRevisions[1] = array(4))->and($this->calling($vcs)->getNextRevisions[2] = array())->and($adapter->file_get_contents = 1)->and($adapter->resetCalls())->then->boolean($builder->createPhar())->isTrue()->adapter($adapter)->call('file_get_contents')->withArguments($revisionFile)->once()->call('file_put_contents')->withArguments($revisionFile, 4, \LOCK_EX)->once()->mock($vcs)->call('setRevision')->withArguments(4)->once()->call('setWorkingDirectory')->withArguments($workingDirectory)->once()->call('exportRepository')->once();
 }