public function testCheckUnitTests()
 {
     $this->if($builder = new \mock\mageekguy\atoum\scripts\builder(uniqid(), $adapter = new atoum\test\adapter()))->and($builder->disableUnitTestChecking())->then->boolean($builder->unitTestCheckingIsEnabled())->isFalse()->boolean($builder->checkUnitTests())->isTrue()->if($builder->enableUnitTestChecking())->then->exception(function () use($builder) {
         $builder->checkUnitTests();
     })->isInstanceOf('mageekguy\\atoum\\exceptions\\logic')->hasMessage('Unable to check unit tests, working directory is undefined')->if->mockGenerator->shunt('__construct')->and($vcs = new \mock\mageekguy\atoum\scripts\builder\vcs())->and($this->calling($vcs)->exportRepository = function () {
     })->and($builder->setVcs($vcs))->and($php = new \mock\mageekguy\atoum\php())->and($this->calling($php)->run = $php)->and($builder->setPhp($php))->and($builder->setWorkingDirectory($workingDirectory = uniqid()))->and($builder->setUnitTestRunnerScript($unitTestRunnerScript = uniqid()))->and($builder->setReportTitle($reportTitle = uniqid()))->and($builder->addRunnerConfigurationFile($runnerConfigurationFile = uniqid()))->and($score = new \mock\mageekguy\atoum\score())->and($this->calling($score)->getFailNumber = 0)->and($this->calling($score)->getExceptionNumber = 0)->and($this->calling($score)->getErrorNumber = 0)->and($adapter->sys_get_temp_dir = $tempDirectory = uniqid())->and($adapter->tempnam = $scoreFile = uniqid())->and($adapter->file_get_contents = $scoreFileContents = uniqid())->and($adapter->unserialize = $score)->and($adapter->unlink = true)->and($this->calling($builder)->writeErrorInErrorsDirectory = function () {
     })->then->boolean($builder->checkUnitTests())->isTrue()->mock($vcs)->call('setWorkingDirectory')->withArguments($workingDirectory)->once()->call('exportRepository')->once()->adapter($adapter)->call('sys_get_temp_dir')->once()->call('tempnam')->withArguments($tempDirectory, '')->once()->call('file_get_contents')->withArguments($scoreFile)->once()->call('unserialize')->withArguments($scoreFileContents)->once()->call('unlink')->withArguments($scoreFile)->once()->mock($score)->call('getFailNumber')->once()->call('getExceptionNumber')->once()->call('getErrorNumber')->once()->mock($php)->call('reset')->before($this->mock($php)->call('run'))->once()->call('addOption')->withArguments('-f', $workingDirectory . \DIRECTORY_SEPARATOR . $unitTestRunnerScript)->before($this->mock($php)->call('run'))->once()->call('addArgument')->withArguments('-ncc')->before($this->mock($php)->call('run'))->once()->call('addArgument')->withArguments('-d', $workingDirectory . \DIRECTORY_SEPARATOR . 'tests' . \DIRECTORY_SEPARATOR . 'units' . \DIRECTORY_SEPARATOR . 'classes')->before($this->mock($php)->call('run'))->once()->call('addArgument')->withArguments('-p', $php->getBinaryPath())->before($this->mock($php)->call('run'))->once()->call('addArgument')->withArguments('-sf', $scoreFile)->before($this->mock($php)->call('run'))->once()->call('addArgument')->withArguments('-c', $runnerConfigurationFile)->before($this->mock($php)->call('run'))->once()->if($this->calling($php)->getExitCode = 127)->then->boolean($builder->checkUnitTests())->isFalse()->mock($builder)->call('writeErrorInErrorsDirectory')->withArguments('Unable to find \'' . $php->getBinaryPath() . '\' or it is not executable')->once()->if($this->calling($php)->getExitCode = $exitCode = rand(1, 125))->and($this->calling($php)->getStdErr = $stdErr = uniqid())->then->boolean($builder->checkUnitTests())->isFalse()->mock($builder)->call('writeErrorInErrorsDirectory')->withArguments($php . ' failed with exit code \'' . $exitCode . '\': ' . $stdErr)->once()->if($this->calling($php)->getExitCode = $exitCode = rand(128, PHP_INT_MAX))->then->boolean($builder->checkUnitTests())->isFalse()->mock($builder)->call('writeErrorInErrorsDirectory')->withArguments($php . ' failed with exit code \'' . $exitCode . '\': ' . $stdErr)->once()->if($this->calling($php)->getExitCode = 0)->and($this->calling($php)->getStdErr = '')->then->boolean($builder->checkUnitTests())->isTrue()->if($this->calling($php)->getStdErr = $stdErrContents = uniqid())->then->boolean($builder->checkUnitTests())->isFalse()->mock($builder)->call('writeErrorInErrorsDirectory')->withArguments($stdErrContents)->once()->if($this->calling($php)->getStdErr = '')->and($adapter->file_get_contents = false)->and($this->resetMock($builder))->then->boolean($builder->checkUnitTests())->isFalse()->mock($builder)->call('writeErrorInErrorsDirectory')->withArguments('Unable to read score from file \'' . $scoreFile . '\'')->once()->if($adapter->file_get_contents = $scoreFileContents)->and($adapter->unserialize = false)->then->boolean($builder->checkUnitTests())->isFalse()->mock($builder)->call('writeErrorInErrorsDirectory')->withArguments('Unable to unserialize score from file \'' . $scoreFile . '\'')->once()->if($adapter->unserialize = uniqid())->then->boolean($builder->checkUnitTests())->isFalse()->mock($builder)->call('writeErrorInErrorsDirectory')->withArguments('Contents of file \'' . $scoreFile . '\' is not a score')->once()->if($adapter->unserialize = $score)->and($adapter->unlink = false)->then->exception(function () use($builder) {
         $builder->checkUnitTests();
     })->isInstanceOf('mageekguy\\atoum\\exceptions\\runtime')->hasMessage('Unable to delete score file \'' . $scoreFile . '\'')->if($adapter->unlink = true)->and($this->calling($score)->getFailNumber = rand(1, PHP_INT_MAX))->then->boolean($builder->checkUnitTests())->isFalse()->if($this->calling($score)->getFailNumber = 0)->and($this->calling($score)->getExceptionNumber = rand(1, PHP_INT_MAX))->then->boolean($builder->checkUnitTests())->isFalse()->if($this->calling($score)->getExceptionNumber = 0)->and($this->calling($score)->getErrorNumber = rand(1, PHP_INT_MAX))->then->boolean($builder->checkUnitTests())->isFalse();
 }
Beispiel #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();
 }