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(); }
public function testResetCalls() { $this->if($mockController = new testedClass())->and($mockController->{$method = uniqid()} = function () { })->then->array($mockController->getCalls())->isEmpty()->if($mockController->invoke($method, array()))->then->array($mockController->getCalls())->isNotEmpty()->object($mockController->resetCalls())->isIdenticalTo($mockController)->array($mockController->getCalls())->isEmpty(); }
public function testResetCalls() { $this->if($mockController = new testedClass())->and($mockController->{$method = uniqid()} = function () { })->then->sizeof($mockController->getCalls())->isZero()->if($mockController->invoke($method, array()))->then->sizeof($mockController->getCalls())->isGreaterThan(0)->object($mockController->resetCalls())->isIdenticalTo($mockController)->sizeof($mockController->getCalls())->isZero(); }