コード例 #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
 /**
  * generate one test from a single testable object and writes it to fs
  *
  * @param \PhpUnitTestGenerator\Testable\Object $object
  * @return \PhpUnitTestGenerator\Generator\Test
  */
 public function generateTestFromTestable(\PhpUnitTestGenerator\Testable\Object $object)
 {
     $test = new Test($this->getFilenameOfTestByOriginalFilename($object->getFilename()), $object);
     $test->setBaseClass($this->configuration->getBaseClass());
     $isTestFinalized = false;
     foreach ($this->getObjectProviders() as $objectProvider) {
         /* @var $objectProvider Provider\Definition\ObjectInterface */
         if (true === $objectProvider->canHandleTestableObject($object)) {
             if (true === $objectProvider->canFinalizeTestableObject($object)) {
                 $objectProvider->handleTestableObject($object, $test);
                 $isTestFinalized = true;
             } elseif ($isTestFinalized === false) {
                 $objectProvider->handleTestableObject($object, $test);
             }
         }
     }
     if ($isTestFinalized === false) {
         foreach ($this->getMethodProviders() as $methodProvider) {
             /* @var $methodProvider Provider\Definition\MethodInterface */
             foreach ($test->getTestedMethods() as $testMethod) {
                 try {
                     if (true === $methodProvider->canHandleTestableMethod($testMethod)) {
                         if (true === $methodProvider->canFinalizeTestableMethod($testMethod)) {
                             $methodProvider->handleTestableMethod($testMethod);
                             $test->addTestedMethod($testMethod);
                             $isTestFinalized = true;
                         } elseif ($isTestFinalized) {
                             $methodProvider->handleTestableMethod($testMethod);
                             $test->addTestedMethod($testMethod);
                         }
                     }
                 } catch (\Exception $e) {
                     Logger::getInstance()->logException($e, $object);
                 }
             }
         }
     }
     /**/
     $test->write();
     return $test;
 }