저자: Sebastian Bergmann (sb@sebastian-bergmann.de)
예제 #1
0
 /**
  * Constructor.
  *
  * @param string $inClassName
  * @param string $inSourceFile
  * @param string $outClassName
  * @param string $outSourceFile
  * @throws RuntimeException
  */
 public function __construct($inClassName, $inSourceFile = '', $outClassName = '', $outSourceFile = '')
 {
     if (empty($inSourceFile)) {
         $inSourceFile = $inClassName . '.php';
     }
     if (!is_file($inSourceFile)) {
         throw new PHPUnit_Framework_Exception(sprintf('"%s" could not be opened.', $inSourceFile));
     }
     if (empty($outClassName)) {
         $outClassName = substr($inClassName, 0, strlen($inClassName) - 4);
     }
     if (empty($outSourceFile)) {
         $outSourceFile = dirname($inSourceFile) . DIRECTORY_SEPARATOR . $outClassName . '.php';
     }
     parent::__construct($inClassName, $inSourceFile, $outClassName, $outSourceFile);
 }
예제 #2
0
파일: Test.php 프로젝트: schwarer2006/wikia
    /**
     * Constructor.
     *
     * @param string $inClassName
     * @param string $inSourceFile
     * @param string $outClassName
     * @param string $outSourceFile
     * @throws RuntimeException
     */
    public function __construct($inClassName, $inSourceFile = '', $outClassName = '', $outSourceFile = '')
    {
        if (class_exists($inClassName)) {
            $reflector    = new ReflectionClass($inClassName);
            $inSourceFile = $reflector->getFileName();

            if ($inSourceFile === FALSE) {
                $inSourceFile = '<internal>';
            }

            unset($reflector);
        } else {
            if (empty($inSourceFile)) {
                $possibleFilenames = array(
                  $inClassName . '.php',
                  PHPUnit_Util_Filesystem::classNameToFilename($inClassName)
                );

                foreach ($possibleFilenames as $possibleFilename) {
                    if (is_file($possibleFilename)) {
                        $inSourceFile = $possibleFilename;
                    }
                }
            }

            if (empty($inSourceFile)) {
                throw new PHPUnit_Framework_Exception(
                  sprintf(
                    'Neither "%s" nor "%s" could be opened.',
                    $possibleFilenames[0],
                    $possibleFilenames[1]
                  )
                );
            }

            if (!is_file($inSourceFile)) {
                throw new PHPUnit_Framework_Exception(
                  sprintf(
                    '"%s" could not be opened.',

                    $inSourceFile
                  )
                );
            }

            $inSourceFile = realpath($inSourceFile);
            include_once $inSourceFile;

            if (!class_exists($inClassName)) {
                throw new PHPUnit_Framework_Exception(
                  sprintf(
                    'Could not find class "%s" in "%s".',

                    $inClassName,
                    $inSourceFile
                  )
                );
            }
        }

        if (empty($outClassName)) {
            $outClassName = $inClassName . 'Test';
        }

        if (empty($outSourceFile)) {
            $outSourceFile = dirname($inSourceFile) . DIRECTORY_SEPARATOR . $outClassName . '.php';
        }

        parent::__construct(
          $inClassName, $inSourceFile, $outClassName, $outSourceFile
        );
    }
예제 #3
0
<?php

// Use PHPUnit2 to create the skeletons.
//ATTENTION: needs phpunit2 bugfix
// http://pear.php.net/bugs/bug.php?id=6965
die("deactived for security reasons");
require_once 'PHPUnit/Util/Skeleton.php';
// Get all of the classes in PHP-GTK 2.
/* Get all classes and filter out Gtk classes only */
// Taken from Anant's updater script.
$classes = array();
$allClasses = get_declared_classes();
$extensions = array('Gtk', 'Gdk', 'Atk', 'Pango');
foreach ($extensions as $extension) {
    foreach ($allClasses as $oneClass) {
        if (strpos($oneClass, $extension) === 0) {
            $classes[] = $oneClass;
        }
    }
}
sort($classes);
foreach ($classes as $class) {
    // Create a skeleton for the class.
    $skeleton = new PHPUnit_Util_Skeleton($class);
    // Write the test.
    $skeleton->write();
}
 /**
  * @param  string  $test
  * @param  string  $testFile
  * @access protected
  * @static
  */
 protected static function doSkeleton($test, $testFile)
 {
     if ($test !== FALSE) {
         PHPUnit_TextUI_TestRunner::printVersionString();
         try {
             $skeleton = new PHPUnit_Util_Skeleton($test, $testFile);
             $skeleton->write();
         } catch (Exception $e) {
             print $e->getMessage() . "\n";
             printf('Could not write test class skeleton for "%s" to "%s".' . "\n", $test, $testFile);
             exit(PHPUnit_TextUI_TestRunner::FAILURE_EXIT);
         }
         printf('Wrote test class skeleton for "%s" to "%s".' . "\n", $test, $skeleton->getTestSourceFile());
         exit(PHPUnit_TextUI_TestRunner::SUCCESS_EXIT);
     }
 }
예제 #5
0
        }
        $smarty->assign('cols', @$_REQUEST['cols']);
        $smarty->assign('table', @$_REQUEST['table']);
        $smarty->assign('primary_key', $priKey);
        $php = $smarty->fetch('codegen.tpl');
        echo '<div style="background-color: #fff; border-left: 2px solid #000; padding-left: 10px; position: absolute; top: 5px; left: 500px;">';
        echo '<h1>Class Code <a href="#" onclick="new Effect.toggle(\'code\'); return false;">[+]</a></h1>';
        $testcode = str_replace(array('<?php', '?>'), '', $php);
        $testcode = str_replace('<', '&lt;', $testcode);
        $testcode = str_replace('>', '&gt;', $testcode);
        echo '<pre id="code">' . $testcode . "</pre>";
        $tmpfname = tempnam("/tmp", "FOO");
        $handle = fopen($tmpfname, "w");
        fwrite($handle, '<?php' . "\n\n" . $smarty->fetch('codegen.tpl') . "\n\n" . '?>');
        require_once 'PHPUnit/Util/Skeleton.php';
        $skeleton = new PHPUnit_Util_Skeleton($_REQUEST['class_name'], $tmpfname);
        echo '<h1>Test Code <a href="#" onclick="new Effect.Appear(\'test\'); return false;">[+]</a></h1>';
        $testcode = str_replace(array('<?php', '?>'), '', $skeleton->generate());
        $testcode = str_replace('<', '&lt;', $testcode);
        $testcode = str_replace('>', '&gt;', $testcode);
        echo '<pre id="test" style="display: none;">' . $testcode . "</pre>";
        echo '</div>';
        var_dump($_REQUEST);
    }
}
echo '</body>';
echo '</html>';
/*
$sql = 'describe address';
$r = Database::singleton()->query_fetch_all($sql);
var_dump($r);