Esempio n. 1
0
 public function testGetFirstError()
 {
     $this->if($includer = new testedClass($adapter = new atoum\test\adapter()))->then->variable($includer->getFirstError())->isNull()->if($adapter->set_error_handler = function ($errorHandler) {
         set_error_handler($errorHandler);
         return null;
     })->and($fileWithError = stream::get())->and($fileWithError->file_get_contents = '<?php trigger_error(\'' . ($message = uniqid()) . '\', E_USER_WARNING); ?>')->and($includer->includePath($fileWithError))->then->array($error = $includer->getFirstError())->isNotEmpty()->integer($error[0])->isEqualTo(E_USER_WARNING)->string($error[1])->isEqualTo($message);
 }
Esempio n. 2
0
 public function testDecorate()
 {
     $this->if($decorator = new testedClass())->then->string($decorator->decorate())->isEmpty()->string($decorator->decorate(null))->isEmpty()->string($decorator->decorate(array()))->isEmpty()->string($decorator->decorate(array(1)))->isEqualTo('integer(1)')->string($decorator->decorate(array(1, 2)))->isEqualTo('integer(1), integer(2)')->string($decorator->decorate(array(1.0)))->isEqualTo('float(1)')->string($decorator->decorate(array(1.0, 2.1)))->isEqualTo('float(' . 1.0 . '), float(' . 2.1 . ')')->string($decorator->decorate(array(true)))->isEqualTo('TRUE')->string($decorator->decorate(array(false)))->isEqualTo('FALSE')->string($decorator->decorate(array(false, true)))->isEqualTo('FALSE, TRUE')->string($decorator->decorate(array(null)))->isEqualTo('NULL')->string($decorator->decorate(array($this)))->isEqualTo('object(' . __CLASS__ . ')')->if($stream = mock\stream::get())->and($stream->fopen = true)->and($resource = fopen($stream, 'r'))->and($dump = function () use($resource) {
         ob_start();
         var_dump($resource);
         return ob_get_clean();
     })->then->string($decorator->decorate(array($resource)))->isEqualTo($dump());
 }
Esempio n. 3
0
 public function testIsWrited()
 {
     $this->if($asserter = new asserters\stream($generator = new asserter\generator()))->then->exception(function () use($asserter) {
         $asserter->isWrited();
     })->isInstanceOf('mageekguy\\atoum\\exceptions\\logic')->hasMessage('Stream is undefined')->if($streamController = atoum\mock\stream::get($streamName = uniqid()))->and($streamController->file_put_contents = strlen($contents = uniqid()))->and($asserter->setWith($streamName))->then->exception(function () use(&$line, $asserter) {
         $line = __LINE__;
         $asserter->isWrited();
     })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage($failMessage = sprintf($generator->getLocale()->_('stream %s is not writed'), $streamName))->when(function () use($streamName, $contents) {
         file_put_contents('atoum://' . $streamName, $contents);
     })->object($asserter->isWrited())->isIdenticalTo($asserter);
 }
Esempio n. 4
0
 public function testIsWrited()
 {
     $this->if($asserter = $this->newTestedInstance)->then->exception(function () use($asserter) {
         $asserter->isWrited();
     })->isInstanceOf('mageekguy\\atoum\\exceptions\\logic')->hasMessage('Stream is undefined')->if($streamController = atoum\mock\stream::get($streamName = uniqid()), $streamController->file_put_contents = strlen($contents = uniqid()), $asserter->setWith($streamName)->setLocale($locale = new \mock\atoum\locale()), $this->calling($locale)->_ = $streamNotWrited = uniqid())->then->exception(function () use($asserter) {
         $asserter->isWrited();
     })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage($streamNotWrited)->mock($locale)->call('_')->withArguments('stream %s is not written', $streamController)->once->exception(function () use($asserter, &$failMessage) {
         $asserter->isWrited($failMessage = uniqid());
     })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage($failMessage)->when(function () use($streamName, $contents) {
         file_put_contents('atoum://' . $streamName, $contents);
     })->object($asserter->isWrited())->isIdenticalTo($asserter)->if($streamController = atoum\mock\stream::get(uniqid()), $streamController->file_put_contents = strlen($contents = uniqid()), $asserter->setWith($streamController))->then->exception(function () use($asserter) {
         $asserter->isWrited();
     })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage($streamNotWrited)->mock($locale)->call('_')->withArguments('stream %s is not written', $streamController)->once->exception(function () use($asserter, &$failMessage) {
         $asserter->isWrited($failMessage = uniqid());
     })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage($failMessage)->when(function () use($streamController, $contents) {
         file_put_contents($streamController, $contents);
     })->object($asserter->isWrited())->isIdenticalTo($asserter);
 }
Esempio n. 5
0
 public function testSetDirectorySeparator()
 {
     $this->string(mock\stream::setDirectorySeparator('foo/bar', '/'))->isEqualTo('foo/bar')->string(mock\stream::setDirectorySeparator('foo\\bar', '/'))->isEqualTo('foo/bar')->string(mock\stream::setDirectorySeparator('foo/bar', '\\'))->isEqualTo('foo\\bar')->string(mock\stream::setDirectorySeparator('foo\\bar', '\\'))->isEqualTo('foo\\bar')->string(mock\stream::setDirectorySeparator('foo' . DIRECTORY_SEPARATOR . 'bar'))->isEqualTo('foo' . DIRECTORY_SEPARATOR . 'bar')->string(mock\stream::setDirectorySeparator('foo' . (DIRECTORY_SEPARATOR == '/' ? '\\' : '/') . 'bar'))->isEqualTo('foo' . DIRECTORY_SEPARATOR . 'bar');
 }
Esempio n. 6
0
 public function testRun()
 {
     $this->if->extension('phar')->isLoaded()->and($originDirectory = stream::get())->and($originDirectory->opendir = true)->and($adapter = new atoum\test\adapter())->and($adapter->php_sapi_name = function () {
         return 'cli';
     })->and($adapter->realpath = function ($path) {
         return $path;
     })->and($adapter->is_dir = function () {
         return true;
     })->and($adapter->is_file = function () {
         return true;
     })->and($adapter->unlink = function () {
     })->and($generator = new phar\generator(uniqid(), $adapter))->then->exception(function () use($generator) {
         $generator->run();
     })->isInstanceOf('mageekguy\\atoum\\exceptions\\runtime')->hasMessage('Origin directory must be defined')->if($generator->setOriginDirectory((string) $originDirectory))->then->exception(function () use($generator) {
         $generator->run();
     })->isInstanceOf('mageekguy\\atoum\\exceptions\\runtime')->hasMessage('Destination directory must be defined')->if($generator->setDestinationDirectory(uniqid()))->then->exception(function () use($generator) {
         $generator->run();
     })->isInstanceOf('mageekguy\\atoum\\exceptions\\runtime')->hasMessage('Stub file must be defined')->if($generator->setStubFile($stubFile = uniqid()))->and($adapter->is_readable = function () {
         return false;
     })->then->exception(function () use($generator) {
         $generator->run();
     })->isInstanceOf('mageekguy\\atoum\\exceptions\\runtime')->hasMessage('Origin directory \'' . $generator->getOriginDirectory() . '\' is not readable')->if($adapter->is_readable = function ($path) use($originDirectory) {
         return $path === (string) $originDirectory;
     })->and($adapter->is_writable = function () {
         return false;
     })->then->exception(function () use($generator) {
         $generator->run();
     })->isInstanceOf('mageekguy\\atoum\\exceptions\\runtime')->hasMessage('Destination directory \'' . $generator->getDestinationDirectory() . '\' is not writable')->if($adapter->is_writable = function () {
         return true;
     })->then->exception(function () use($generator) {
         $generator->run();
     })->isInstanceOf('mageekguy\\atoum\\exceptions\\runtime')->hasMessage('Stub file \'' . $generator->getStubFile() . '\' is not readable')->if($adapter->is_readable = function ($path) use($originDirectory, $stubFile) {
         return $path === (string) $originDirectory || $path === $stubFile;
     })->and($generator->setPharFactory(function ($name) use(&$phar) {
         $pharController = new mock\controller();
         $pharController->__construct = function () {
         };
         $pharController->setStub = function () {
         };
         $pharController->setMetadata = function () {
         };
         $pharController->buildFromIterator = function () {
         };
         $pharController->setSignatureAlgorithm = function () {
         };
         $pharController->offsetGet = function () {
         };
         $pharController->offsetSet = function () {
         };
         return $phar = new \mock\phar($name);
     }))->and($adapter->file_get_contents = function ($file) {
         return false;
     })->then->exception(function () use($generator) {
         $generator->run();
     })->isInstanceOf('mageekguy\\atoum\\exceptions\\runtime')->hasMessage('ABOUT file is missing in \'' . $generator->getOriginDirectory() . '\'')->if($adapter->file_get_contents = function ($file) use($generator, &$description) {
         switch ($file) {
             case $generator->getOriginDirectory() . DIRECTORY_SEPARATOR . 'ABOUT':
                 return $description = uniqid();
             default:
                 return false;
         }
     })->then->exception(function () use($generator) {
         $generator->run();
     })->isInstanceOf('mageekguy\\atoum\\exceptions\\runtime')->hasMessage('COPYING file is missing in \'' . $generator->getOriginDirectory() . '\'')->if($adapter->file_get_contents = function ($file) use($generator, &$description, &$licence, &$stub) {
         switch ($file) {
             case $generator->getOriginDirectory() . DIRECTORY_SEPARATOR . 'ABOUT':
                 return $description = uniqid();
             case $generator->getOriginDirectory() . DIRECTORY_SEPARATOR . 'COPYING':
                 return $licence = uniqid();
             case $generator->getStubFile():
                 return $stub = uniqid();
             default:
                 return uniqid();
         }
     })->then->object($generator->run())->isIdenticalTo($generator)->mock($phar)->call('__construct')->withArguments($generator->getDestinationDirectory() . DIRECTORY_SEPARATOR . atoum\scripts\phar\generator::phar, null, null, null)->once()->call('setMetadata')->withArguments(array('version' => atoum\version, 'author' => atoum\author, 'support' => atoum\mail, 'repository' => atoum\repository, 'description' => $description, 'licence' => $licence))->once()->call('setStub')->withArguments($stub, null)->once()->call('buildFromIterator')->withArguments(new iterators\recursives\atoum\source($generator->getOriginDirectory(), '1'), null)->once()->call('setSignatureAlgorithm')->withArguments(\phar::SHA1, null)->once()->if($superglobals = new atoum\superglobals())->and($superglobals->_SERVER = array('argv' => array(uniqid(), '--help')))->and($generator->setArgumentsParser(new atoum\script\arguments\parser($superglobals)))->and($stdout = new \mock\mageekguy\atoum\writers\std\out())->and($stdout->getMockController()->write = function () {
     })->and($stderr = new \mock\mageekguy\atoum\writers\std\err())->and($stderr->getMockController()->write = function () {
     })->and($generator->setOutputWriter($stdout))->and($generator->setHelpWriter($stdout))->and($generator->setErrorWriter($stderr))->then->object($generator->run())->isIdenticalTo($generator)->mock($stdout)->call('write')->withArguments(sprintf($generator->getLocale()->_('Usage: %s [options]'), $generator->getName()) . PHP_EOL)->once()->call('write')->withArguments($generator->getLocale()->_('Available options are:') . PHP_EOL)->once()->call('write')->withArguments('                                -h, --help: ' . $generator->getLocale()->_('Display this help') . PHP_EOL)->once()->call('write')->withArguments('   -d <directory>, --directory <directory>: ' . $generator->getLocale()->_('Destination directory <dir>') . PHP_EOL)->once()->if($generator->setPharFactory(function ($name) use(&$phar) {
         $pharController = new mock\controller();
         $pharController->__construct = function () {
         };
         $pharController->setStub = function () {
         };
         $pharController->setMetadata = function () {
         };
         $pharController->buildFromIterator = function () {
         };
         $pharController->setSignatureAlgorithm = function () {
         };
         $pharController->offsetGet = function () {
         };
         $pharController->offsetSet = function () {
         };
         return $phar = new \mock\phar($name);
     }))->then->object($generator->run(array('-d', $directory = uniqid())))->isIdenticalTo($generator)->string($generator->getDestinationDirectory())->isEqualTo($directory)->mock($phar)->call('__construct')->withArguments($generator->getDestinationDirectory() . DIRECTORY_SEPARATOR . atoum\scripts\phar\generator::phar, null, null, null)->once()->call('setMetadata')->withArguments(array('version' => atoum\version, 'author' => atoum\author, 'support' => atoum\mail, 'repository' => atoum\repository, 'description' => $description, 'licence' => $licence))->once()->call('setStub')->withArguments($stub, null)->once()->call('buildFromIterator')->withArguments(new iterators\recursives\atoum\source($generator->getOriginDirectory(), '1'), null)->once()->call('setSignatureAlgorithm')->withArguments(\phar::SHA1, null)->once()->adapter($adapter)->call('unlink')->withArguments($directory . DIRECTORY_SEPARATOR . phar\generator::phar)->once();
 }
Esempio n. 7
0
 /**
  * Test RemoveStream method.
  */
 public function testRemoveStream()
 {
     $this->proxyMethodTest('removeStream', array(Stream::get()));
 }
Esempio n. 8
0
 public function testKey()
 {
     $this->if($sourceDirectory = stream::get())->and($sourceDirectory->opendir = true)->and($sourceDirectory->rewinddir = true)->and($sourceDirectory->readdir = false)->and($sourceDirectory->closedir = true)->and($iterator = new iterators\recursives\atoum\source($sourceDirectory))->then->integer($iterator->key())->isZero()->if($file = stream::getSubStream($sourceDirectory))->and($sourceDirectory->readdir[1] = $file->getBasename())->and($sourceDirectory->readdir[2] = false)->and($iterator = new iterators\recursives\atoum\source($sourceDirectory))->then->string($iterator->key())->isEqualTo($file)->if($sourceDirectory->readdir[1] = '.file')->and($iterator = new iterators\recursives\atoum\source($sourceDirectory))->then->integer($iterator->key())->isZero()->if($iterator = new iterators\recursives\atoum\source($sourceDirectory, $pharDirectory = uniqid()))->then->string($iterator->key())->isEmpty()->if($sourceDirectory->readdir[1] = $file->getBasename())->and($iterator = new iterators\recursives\atoum\source($sourceDirectory, $pharDirectory = uniqid()))->then->string($iterator->key())->isEqualTo($pharDirectory . DIRECTORY_SEPARATOR . $file->getBasename())->if($sourceDirectory->readdir[1] = '.file')->and($iterator = new iterators\recursives\atoum\source($sourceDirectory, $pharDirectory = uniqid()))->then->string($iterator->key())->isEmpty();
 }
Esempio n. 9
0
 public function testUseConfigFile()
 {
     $this->if($runner = new testedClass(uniqid()))->and($runner->setLocale($locale = new \mock\mageekguy\atoum\locale()))->then->exception(function () use($runner, &$file) {
         $runner->useConfigFile($file = uniqid());
     })->isInstanceOf('mageekguy\\atoum\\includer\\exception')->hasMessage('Unable to find configuration file \'' . $file . '\'')->mock($locale)->call('_')->withArguments('Unable to find configuration file \'%s\'')->once()->if($configFile = stream::get())->and($configFile->file_get_contents = '<?php $runner->disableCodeCoverage(); ?>')->then->boolean($runner->getRunner()->codeCoverageIsEnabled())->isTrue()->object($runner->useConfigFile((string) $configFile))->isIdenticalTo($runner)->boolean($runner->getRunner()->codeCoverageIsEnabled())->isFalse();
 }
Esempio n. 10
0
 public function setWith($stream)
 {
     parent::setWith($stream);
     $this->streamController = atoum\mock\stream::get($stream);
     return $this;
 }
Esempio n. 11
0
 public function testCleanDestinationDirectory()
 {
     $this->if($destinationDirectory = stream::get())->and($destinationDirectory->opendir = true)->and($destinationDirectory->readdir[1] = $directory = stream::getSubStream($destinationDirectory))->and($directory->opendir = true)->and($directory->readdir[1] = $firstFile = stream::getSubStream($directory))->and($firstFile->unlink = true)->and($directory->readdir[2] = $secondFile = stream::getSubStream($directory))->and($secondFile->unlink = true)->and($directory->readdir[3] = false)->and($destinationDirectory->readdir[2] = $emptyDirectory = stream::getSubStream($destinationDirectory))->and($emptyDirectory->opendir = true)->and($emptyDirectory->readdir[1] = false)->and($destinationDirectory->readdir[3] = $otherDirectory = stream::getSubStream($destinationDirectory))->and($otherDirectory->opendir = true)->and($otherDirectory->readdir[1] = $otherFirstFile = stream::getSubStream($otherDirectory))->and($otherFirstFile->unlink = true)->and($otherDirectory->readdir[2] = $otherSecondFile = stream::getSubStream($otherDirectory))->and($otherSecondFile->unlink = true)->and($otherDirectory->readdir[3] = false)->and($destinationDirectory->readdir[4] = $file = stream::getSubStream($destinationDirectory))->and($file->unlink = true)->and($destinationDirectory->readdir[5] = false)->and($field = new \mock\mageekguy\atoum\report\fields\runner\coverage\html(uniqid(), (string) $destinationDirectory))->and($field->setAdapter($adapter = new test\adapter()))->and($adapter->rmdir = function () {
     })->and($adapter->unlink = function () {
     })->then->object($field->cleanDestinationDirectory())->isIdenticalTo($field)->adapter($adapter)->call('unlink')->withArguments((string) $firstFile)->once()->call('unlink')->withArguments((string) $secondFile)->once()->call('rmdir')->withArguments((string) $directory)->once()->call('unlink')->withArguments((string) $otherFirstFile)->once()->call('unlink')->withArguments((string) $otherSecondFile)->once()->call('rmdir')->withArguments((string) $otherDirectory)->once()->call('unlink')->withArguments((string) $file)->once()->call('rmdir')->withArguments((string) $emptyDirectory)->once()->call('rmdir')->withArguments((string) $destinationDirectory)->never()->if($field->getMockController()->getDestinationDirectoryIterator->throw = new \exception())->then->object($field->cleanDestinationDirectory())->isIdenticalTo($field);
 }
Esempio n. 12
0
 public function testCleanWorkingDirectory()
 {
     $this->if($adapter = new atoum\test\adapter())->and($adapter->extension_loaded = true)->and($adapter->unlink = function () {
     })->and($adapter->rmdir = function () {
     })->and($workingDirectory = stream::get('workingDirectory'))->and($workingDirectory->opendir = true)->and($workingDirectory->readdir[1] = $aDirectory = stream::getSubStream($workingDirectory))->and($aDirectory->opendir = true)->and($aDirectory->readdir[1] = $firstFile = stream::getSubStream($aDirectory))->and($firstFile->unlink = true)->and($aDirectory->readdir[2] = $secondFile = stream::getSubStream($aDirectory))->and($secondFile->unlink = true)->and($aDirectory->readdir[3] = false)->and($workingDirectory->readdir[2] = $emptyDirectory = stream::getSubStream($workingDirectory))->and($emptyDirectory->opendir = true)->and($emptyDirectory->readdir[1] = false)->and($workingDirectory->readdir[3] = $anOtherDirectory = stream::getSubStream($workingDirectory))->and($anOtherDirectory->opendir = true)->and($anOtherDirectory->readdir[1] = $anOtherFirstFile = stream::getSubStream($anOtherDirectory))->and($anOtherFirstFile->unlink = true)->and($anOtherDirectory->readdir[2] = $anOtherSecondFile = stream::getSubStream($anOtherDirectory))->and($anOtherSecondFile->unlink = true)->and($anOtherDirectory->readdir[3] = false)->and($workingDirectory->readdir[4] = $aFile = stream::getSubStream($workingDirectory))->and($aFile->unlink = true)->and($workingDirectory->readdir[5] = false)->and($svn = new \mock\mageekguy\atoum\scripts\builder\vcs\svn($adapter, $svnController = new mock\controller()))->and($svn->setWorkingDirectory('atoum://workingDirectory'))->then->object($svn->cleanWorkingDirectory())->isIdenticalTo($svn)->adapter($adapter)->call('unlink')->withArguments((string) $firstFile)->once()->call('unlink')->withArguments((string) $secondFile)->once()->call('rmdir')->withArguments((string) $aDirectory)->once()->call('rmdir')->withArguments((string) $emptyDirectory)->once()->call('unlink')->withArguments((string) $anOtherFirstFile)->once()->call('unlink')->withArguments((string) $anOtherSecondFile)->once()->call('rmdir')->withArguments((string) $anOtherDirectory)->once()->call('unlink')->withArguments((string) $aFile)->once()->call('rmdir')->withArguments((string) $workingDirectory)->never();
 }
Esempio n. 13
0
 public function setWith($stream)
 {
     $this->streamName = $stream;
     $this->streamController = atoum\mock\stream::get($stream);
     return $this;
 }
Esempio n. 14
0
 public function testIncludePath()
 {
     $this->assert->if($includer = new atoum\includer())->and($unknownFile = stream::get())->then->exception(function () use($includer, $unknownFile) {
         $includer->includePath($unknownFile);
     })->isInstanceOf('mageekguy\\atoum\\includer\\exception')->hasMessage('Unable to include \'' . $unknownFile . '\'')->if($file = stream::get())->and($file->file_get_contents = $fileContents = uniqid())->then->object($includer->includePath($file))->isIdenticalTo($includer)->output->isEqualTo($fileContents)->if($fileWithError = stream::get())->and($fileWithError->file_get_contents = '<?php trigger_error(\'' . ($message = uniqid()) . '\', E_USER_WARNING); ?>')->then->object($includer->includePath($fileWithError))->isIdenticalTo($includer)->error->withType(E_USER_WARNING)->withMessage($message)->exists();
 }