Пример #1
0
 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();
 }
Пример #2
0
 public function testCreatePhar()
 {
     $builder = new \mock\mageekguy\atoum\scripts\builder(uniqid(), $adapter = new atoum\test\adapter());
     $builder->setTaggerEngine($taggerEngine = new \mock\mageekguy\atoum\scripts\tagger\engine())->disablePharCreation();
     $taggerEngine->getMockController()->tagVersion = function () {
     };
     $this->assert->boolean($builder->createPhar())->isTrue();
     $builder->enablePharCreation();
     $vcsController = new mock\controller();
     $vcsController->__construct = function () {
     };
     $vcsController->getNextRevisions = array();
     $vcsController->exportRepository = function () {
     };
     $builder->setVcs($vcs = new \mock\mageekguy\atoum\scripts\builder\vcs(null, $vcsController));
     $this->assert->exception(function () use($builder) {
         $builder->createPhar();
     })->isInstanceOf('mageekguy\\atoum\\exceptions\\logic')->hasMessage('Unable to create phar, destination directory is undefined');
     $builder->setDestinationDirectory($destinationDirectory = uniqid());
     $this->assert->exception(function () use($builder) {
         $builder->createPhar();
     })->isInstanceOf('mageekguy\\atoum\\exceptions\\logic')->hasMessage('Unable to create phar, working directory is undefined');
     $builder->setWorkingDirectory($workingDirectory = uniqid());
     $builder->setPhpPath($php = uniqid())->setPharGeneratorScript($pharGeneratorScript = uniqid());
     $builderController = $builder->getMockController();
     $builderController->writeErrorInErrorsDirectory = function () {
     };
     $adapter->file_get_contents = false;
     $this->assert->boolean($builder->createPhar())->isTrue();
     $vcsController->getNextRevisions = function () use(&$revision) {
         static $i = 0;
         return ++$i > 1 ? array() : array($revision = rand(1, PHP_INT_MAX));
     };
     $builder->disableUnitTestChecking();
     $adapter->proc_open = false;
     $this->assert->boolean($builder->createPhar())->isFalse()->mock($builder)->call('writeErrorInErrorsDirectory')->withArguments('Unable to execute \'' . escapeshellarg($php) . ' -d phar.readonly=0 -f ' . escapeshellarg($workingDirectory . \DIRECTORY_SEPARATOR . $pharGeneratorScript) . ' -- -d ' . escapeshellarg($destinationDirectory) . '\'')->once()->mock($vcs)->call('setRevision')->withArguments($revision)->once()->call('setWorkingDirectory')->withArguments($workingDirectory)->once()->call('exportRepository')->once();
     $adapter->proc_open = function ($bin, $descriptors, &$stream) use(&$stdErr, &$pipes, &$resource) {
         $pipes = array(2 => $stdErr = uniqid());
         $stream = $pipes;
         return $resource = uniqid();
     };
     $adapter->stream_get_contents = function () {
         return '';
     };
     $adapter->fclose = function () {
     };
     $adapter->proc_close = function () {
     };
     $adapter->date = $date = uniqid();
     $vcsController->resetCalls()->getNextRevisions = function () use(&$revision) {
         static $i = 0;
         return ++$i > 1 ? array() : array($revision = rand(1, PHP_INT_MAX));
     };
     $this->assert->boolean($builder->createPhar())->isTrue()->mock($taggerEngine)->call('setVersion')->withArguments('nightly-' . $revision . '-' . $date)->once()->call('tagVersion')->atLeastOnce()->adapter($adapter)->call('proc_open')->withArguments(escapeshellarg($php) . ' -d phar.readonly=0 -f ' . escapeshellarg($workingDirectory . \DIRECTORY_SEPARATOR . $pharGeneratorScript) . ' -- -d ' . escapeshellarg($destinationDirectory), array(2 => array('pipe', 'w')), $pipes)->once()->call('stream_get_contents')->withArguments($stdErr)->once()->call('fclose')->withArguments($stdErr)->once()->call('proc_close')->withArguments($resource)->once()->call('date')->withArguments('YmdHi')->atLeastOnce()->mock($vcs)->call('setRevision')->withArguments($revision)->once()->call('setWorkingDirectory')->withArguments($workingDirectory)->once()->call('exportRepository')->once();
     $adapter->resetCalls();
     $builder->getMockController()->resetCalls();
     $vcsController->resetCalls()->getNextRevisions = function () use(&$revision) {
         static $i = 0;
         return ++$i > 1 ? array() : array($revision = rand(1, PHP_INT_MAX));
     };
     $this->assert->boolean($builder->createPhar($tag = uniqid()))->isTrue()->mock($taggerEngine)->call('setVersion')->withArguments($tag)->once()->call('tagVersion')->once()->adapter($adapter)->call('proc_open')->withArguments(escapeshellarg($php) . ' -d phar.readonly=0 -f ' . escapeshellarg($workingDirectory . \DIRECTORY_SEPARATOR . $pharGeneratorScript) . ' -- -d ' . escapeshellarg($destinationDirectory), array(2 => array('pipe', 'w')), $pipes)->once()->call('stream_get_contents')->withArguments($stdErr)->once()->call('fclose')->withArguments($stdErr)->once()->call('proc_close')->withArguments($resource)->once()->call('date')->never()->mock($vcs)->call('setRevision')->withArguments($revision)->once()->call('setWorkingDirectory')->withArguments($workingDirectory)->once()->call('exportRepository')->once();
     $adapter->resetCalls();
     $builder->getMockController()->resetCalls();
     $vcsController->resetCalls()->getNextRevisions = function () use(&$revision) {
         static $i = 0;
         return ++$i > 1 ? array() : array($revision = rand(1, PHP_INT_MAX));
     };
     $adapter->stream_get_contents = function () use(&$stdErrContents) {
         return $stdErrContents = uniqid();
     };
     $this->assert->boolean($builder->createPhar())->isFalse()->adapter($adapter)->call('proc_open')->withArguments(escapeshellarg($php) . ' -d phar.readonly=0 -f ' . escapeshellarg($workingDirectory . \DIRECTORY_SEPARATOR . $pharGeneratorScript) . ' -- -d ' . escapeshellarg($destinationDirectory), array(2 => array('pipe', 'w')), $pipes)->once()->call('stream_get_contents')->withArguments($stdErr)->once()->call('fclose')->withArguments($stdErr)->once()->call('proc_close')->withArguments($resource)->once()->mock($builder)->call('writeErrorInErrorsDirectory')->withArguments($stdErrContents)->once()->mock($vcs)->call('setRevision')->withArguments($revision)->once()->call('setWorkingDirectory')->withArguments($workingDirectory)->once()->call('exportRepository')->once();
     $builder->setRevisionFile($revisionFile = uniqid());
     $adapter->stream_get_contents = function () {
         return '';
     };
     $adapter->file_get_contents = false;
     $adapter->file_put_contents = function () {
     };
     $vcsController->resetCalls()->getNextRevisions = function () use(&$revision) {
         static $i = 0;
         return ++$i > 1 ? array() : array($revision = rand(1, PHP_INT_MAX));
     };
     $this->assert->boolean($builder->createPhar())->isTrue()->adapter($adapter)->call('file_get_contents')->withArguments($revisionFile)->once()->call('proc_open')->withArguments(escapeshellarg($php) . ' -d phar.readonly=0 -f ' . escapeshellarg($workingDirectory . \DIRECTORY_SEPARATOR . $pharGeneratorScript) . ' -- -d ' . escapeshellarg($destinationDirectory), array(2 => array('pipe', 'w')), $pipes)->once()->call('stream_get_contents')->withArguments($stdErr)->once()->call('fclose')->withArguments($stdErr)->once()->call('proc_close')->withArguments($resource)->once()->mock($vcs)->call('setRevision')->withArguments($revision)->once()->call('setWorkingDirectory')->withArguments($workingDirectory)->once()->call('exportRepository')->once();
     $adapter->file_get_contents = false;
     $adapter->file_put_contents = function () {
     };
     $vcsController->resetCalls()->getNextRevisions = function () use(&$revision) {
         static $i = 0;
         return ++$i > 1 ? array() : array($revision = rand(1, PHP_INT_MAX));
     };
     $this->assert->boolean($builder->createPhar())->isTrue()->adapter($adapter)->call('file_get_contents')->withArguments($revisionFile)->once()->call('proc_open')->withArguments(escapeshellarg($php) . ' -d phar.readonly=0 -f ' . escapeshellarg($workingDirectory . \DIRECTORY_SEPARATOR . $pharGeneratorScript) . ' -- -d ' . escapeshellarg($destinationDirectory), array(2 => array('pipe', 'w')), $pipes)->once()->call('stream_get_contents')->withArguments($stdErr)->once()->call('fclose')->withArguments($stdErr)->once()->call('proc_close')->withArguments($resource)->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();
     $vcsController->resetCalls()->getNextRevisions = function () use(&$revision) {
         static $i = 0;
         return ++$i > 1 ? array() : array($revision = rand(1, PHP_INT_MAX));
     };
     $adapter->file_put_contents = false;
     $this->assert->exception(function () use($builder) {
         $builder->createPhar();
     })->isInstanceOf('mageekguy\\atoum\\exceptions\\runtime')->hasMessage('Unable to save last revision in file \'' . $revisionFile . '\'');
     $vcsController->resetCalls();
     $vcsController->getNextRevisions[1] = array(1, 2, 3);
     $vcsController->getNextRevisions[2] = array(2, 3);
     $vcsController->getNextRevisions[3] = array(3);
     $vcsController->getNextRevisions[4] = array();
     $adapter->file_put_contents = function () {
     };
     $this->assert->boolean($builder->createPhar())->isTrue()->adapter($adapter)->call('file_get_contents')->withArguments($revisionFile)->once()->call('proc_open')->withArguments(escapeshellarg($php) . ' -d phar.readonly=0 -f ' . escapeshellarg($workingDirectory . \DIRECTORY_SEPARATOR . $pharGeneratorScript) . ' -- -d ' . escapeshellarg($destinationDirectory), array(2 => array('pipe', 'w')), $pipes)->exactly(3)->call('stream_get_contents')->withArguments($stdErr)->once()->call('fclose')->withArguments($stdErr)->once()->call('proc_close')->withArguments($resource)->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();
     $vcsController->resetCalls();
     $vcsController->getNextRevisions[1] = array(4);
     $vcsController->getNextRevisions[2] = array();
     $adapter->file_get_contents = 1;
     $this->assert->boolean($builder->createPhar())->isTrue()->adapter($adapter)->call('file_get_contents')->withArguments($revisionFile)->once()->call('proc_open')->withArguments(escapeshellarg($php) . ' -d phar.readonly=0 -f ' . escapeshellarg($workingDirectory . \DIRECTORY_SEPARATOR . $pharGeneratorScript) . ' -- -d ' . escapeshellarg($destinationDirectory), array(2 => array('pipe', 'w')), $pipes)->once()->call('stream_get_contents')->withArguments($stdErr)->once()->call('fclose')->withArguments($stdErr)->once()->call('proc_close')->withArguments($resource)->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();
 }