コード例 #1
0
 public function logException(\Exception $exception, \PhpUnitTestGenerator\Testable\Object $object)
 {
     $file = Configuration::getInstance()->getTargetDirectory() . DIRECTORY_SEPARATOR . "test-generator-error.log";
     if (!file_exists(Configuration::getInstance()->getTargetDirectory())) {
         mkdir(Configuration::getInstance()->getTargetDirectory());
         chmod(Configuration::getInstance()->getTargetDirectory(), 0755);
     }
     file_put_contents($file, $exception->getMessage() . " in file " . $object->getFilename() . "\n\n", FILE_APPEND);
     //file_put_contents($file, serialize($exception) . "\n\n\n");
 }
コード例 #2
0
 /**
  * Executes the current command.
  *
  * @param InputInterface $input
  * @param OutputInterface $output
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $configuration = Configuration::getInstance();
     //launch indexer
     $indexer = new \PhpUnitTestGenerator\Indexer\IndexerFilesystem();
     //launch generator
     $generator = new \PhpUnitTestGenerator\Generator\Generator($configuration);
     //build index
     $index = $indexer->indexFilesFromConfiguration($configuration);
     //generate tests
     $results = $generator->generateTestsFromCollection($index);
     //print output
     $output->writeln("Generated " . $results->count() . " tests for " . $index->count() . " classes: " . $configuration->getSourceDirectory() . " --> " . $configuration->getTargetDirectory() . ".");
 }
コード例 #3
0
<?php

$configuration = \PhpUnitTestGenerator\Configuration\Configuration::getInstance();
//$configuration->setBaseClass("");
$configuration->setSourceDirectory(dirname(__FILE__) . '/example/src');
$configuration->setTargetDirectory(dirname(__FILE__) . '/example/test');
$configuration->setNamespaceMappings(array("Example" => "Example\\Tests"));
コード例 #4
0
 /**
  * renders the test object to real PHP code
  *
  * @return string
  */
 public function render()
 {
     $nsMappings = Configuration::getInstance()->getNamespaceMappings();
     if ($this->getNamespace() !== null && $this->getNamespace() != "") {
         $nsName = null;
         if (isset($nsMappings[$this->getNamespace()])) {
             $nsName = $nsMappings[$this->getNamespace()];
         } else {
             $nsOriginal = null;
             $nsTester = null;
             foreach ($nsMappings as $nsOrig => $nsTest) {
                 if (0 === strpos($this->getNamespace(), $nsOrig)) {
                     $nsOriginal = $nsOrig;
                     $nsTester = $nsTest;
                     break;
                 }
             }
             if ($nsOriginal !== null && $nsTester !== null) {
                 $nsName = str_replace($nsOriginal, $nsTester, $this->getNamespace());
             }
         }
         if ($nsName !== null) {
             $ns = "\nnamespace " . $nsName . ";";
             $ns .= "\nuse " . $this->getNamespace() . ";";
         } else {
             $ns = "\nnamespace " . $this->getNamespace() . ";";
         }
     } else {
         $ns = "";
     }
     $methods = "";
     foreach ($this->getWriteableTestedMethods() as $testedMethodContent) {
         $methods .= $testedMethodContent . "\n";
     }
     $tpl = new \Text_Template(\PhpUnitTestGenerator\Resource\Helper::getTemplateFileByName($this->getTestClassTemplate()));
     $tpl->setVar(array('namespace' => $ns, 'testClassName' => $this->getClassname(), 'className' => '\\' . $this->getOriginalFullClassName(), 'baseTestClass' => $this->getBaseClass(), 'methods' => $methods, 'constructorArgs' => $this->getConstructorArgs()));
     return $tpl->render();
 }
コード例 #5
0
 /**
  * Executes the current command.
  *
  * @param InputInterface $input
  * @param OutputInterface $output
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $configuration = Configuration::getInstance();
     $phpunit = new \PHPUnit_TextUI_Command();
     $phpunit->run(array('phpunit', "-c", realpath($configuration->getTargetDirectory()) . "/phpunit.xml"), true);
 }