예제 #1
0
파일: generator.php 프로젝트: ivannis/atoum
 public function testGenerate()
 {
     $this->if($generator = new testedClass())->and($generator->setAdapter($adapter = new atoum\test\adapter()))->and($generator->setPathFactory($pathFactory = new \mock\mageekguy\atoum\fs\path\factory()))->and($generator->setTemplateParser($templateParser = new \mock\mageekguy\atoum\template\parser()))->then->exception(function () use($generator) {
         $generator->generate(uniqid());
     })->isInstanceOf('mageekguy\\atoum\\test\\generator\\exception')->hasMessage('Tested classes directory is undefined')->if($generator->setTestedClassesDirectory($classesDirectory = uniqid()))->then->exception(function () use($generator) {
         $generator->generate(uniqid());
     })->isInstanceOf('mageekguy\\atoum\\test\\generator\\exception')->hasMessage('Tests directory is undefined')->if($generator->setTestClassesDirectory($testsDirectory = DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR, array('a', 'b', 'c'))))->then->exception(function () use($generator) {
         $generator->generate(uniqid());
     })->isInstanceOf('mageekguy\\atoum\\test\\generator\\exception')->hasMessage('Tested class namespace is undefined')->if($generator->setTestedClassNamespace($testedClassNamespace = uniqid()))->then->exception(function () use($generator) {
         $generator->generate(uniqid());
     })->isInstanceOf('mageekguy\\atoum\\test\\generator\\exception')->hasMessage('Test class namespace is undefined')->if($generator->setTestClassNamespace($testClassNamespace = uniqid()))->and($testClassesDirectoryPath = new \mock\mageekguy\atoum\fs\path(DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR, array('a', 'b', 'c'))))->and($this->calling($testClassesDirectoryPath)->exists = true)->and($this->calling($testClassesDirectoryPath)->getRealPath = $testClassesDirectoryPath)->and($testedClassPath = new \mock\mageekguy\atoum\fs\path(DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR, array('x', 'y', 'z', 'f.php'))))->and($this->calling($testedClassPath)->putContents = $testedClassPath)->and($testClassPath = new \mock\mageekguy\atoum\fs\path(DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR, array('a', 'b', 'c', 'd', 'e', 'f.php'))))->and($this->calling($testClassPath)->getRealParentDirectoryPath = new \mock\mageekguy\atoum\fs\path(DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR, array('a', 'b', 'c', 'd', 'e'))))->and($this->calling($testClassPath)->getRealPath = $testClassPath)->and($this->calling($testClassPath)->putContents = $testClassPath)->and($this->calling($pathFactory)->build = function ($path) use($testClassesDirectoryPath, $testClassPath, $testedClassPath) {
         switch ($path) {
             case (string) $testClassesDirectoryPath . DIRECTORY_SEPARATOR:
                 return $testClassesDirectoryPath;
             case (string) $testClassPath:
                 return $testClassPath;
             default:
                 return $testedClassPath;
         }
     })->then->object($generator->generate((string) $testClassPath))->isIdenticalTo($generator)->mock($templateParser)->call('parseFile')->withArguments($generator->getTemplatesDirectory() . DIRECTORY_SEPARATOR . 'testClass.php')->once();
 }