本文整理汇总了PHP中PHPUnit_Util_Filesystem类的典型用法代码示例。如果您正苦于以下问题:PHP PHPUnit_Util_Filesystem类的具体用法?PHP PHPUnit_Util_Filesystem怎么用?PHP PHPUnit_Util_Filesystem使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PHPUnit_Util_Filesystem类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: load
/**
* @param string $suiteClassName
* @param string $suiteClassFile
* @return ReflectionClass
* @throws PHPUnit_Framework_Exception
*/
public function load($suiteClassName, $suiteClassFile = '')
{
$suiteClassName = str_replace('.php', '', $suiteClassName);
if (empty($suiteClassFile)) {
$suiteClassFile = PHPUnit_Util_Filesystem::classNameToFilename($suiteClassName);
}
Core_FileReader::addFile($suiteClassFile);
}
示例2: checkAndLoad
/**
* Checks if a PHP sourcefile is readable.
* The sourcefile is loaded through the load() method.
*
* @param string $filename
* @throws RuntimeException
*/
public static function checkAndLoad($filename)
{
$includePathFilename = PHPUnit_Util_Filesystem::fileExistsInIncludePath($filename);
if (!$includePathFilename || !is_readable($includePathFilename)) {
throw new RuntimeException(sprintf('Cannot open file "%s".' . "\n", $filename));
}
self::load($includePathFilename);
return $includePathFilename;
}
示例3: __construct
/**
* @param string $type The type of concrete Log subclass to use.
* Currently, valid values are 'console',
* 'syslog', 'sql', 'file', and 'mcal'.
* @param string $name The name of the actually log file, table, or
* other specific store to use. Defaults to an
* empty string, with which the subclass will
* attempt to do something intelligent.
* @param string $ident The identity reported to the log system.
* @param array $conf A hash containing any additional configuration
* information that a subclass might need.
* @param int $maxLevel Maximum priority level at which to log.
*/
public function __construct($type, $name = '', $ident = '', $conf = array(), $maxLevel = PEAR_LOG_DEBUG)
{
if (PHPUnit_Util_Filesystem::fileExistsInIncludePath('Log.php')) {
require_once 'Log.php';
} else {
throw new RuntimeException('Log is not available.');
}
$this->log = Log::factory($type, $name, $ident, $conf, $maxLevel);
}
示例4: phpunit_autoload
function phpunit_autoload($class)
{
if (strpos($class, 'PHPUnit_') === 0) {
$file = str_replace('_', '/', $class) . '.php';
$file = PHPUnit_Util_Filesystem::fileExistsInIncludePath($file);
if ($file) {
require_once $file;
}
}
}
示例5: phpunit_autoload
function phpunit_autoload($class)
{
if (strpos($class, 'PHPUnit_') === 0) {
$file = str_replace('_', '/', $class) . '.php';
$file = PHPUnit_Util_Filesystem::fileExistsInIncludePath($file);
if ($file) {
require_once $file;
PHP_CodeCoverage_Filter::getInstance()->addFileToBlacklist($file, 'PHPUNIT');
}
}
}
示例6: load
/**
* @param string $suiteClassName
* @param string $suiteClassFile
* @return ReflectionClass
* @throws RuntimeException
*/
public function load($suiteClassName, $suiteClassFile = '')
{
$suiteClassName = str_replace('.php', '', $suiteClassName);
if (empty($suiteClassFile)) {
$suiteClassFile = PHPUnit_Util_Filesystem::classNameToFilename($suiteClassName);
}
if (!class_exists($suiteClassName, FALSE)) {
PHPUnit_Util_Class::collectStart();
$filename = PHPUnit_Util_Fileloader::checkAndLoad($suiteClassFile);
$loadedClasses = PHPUnit_Util_Class::collectEnd();
}
if (!class_exists($suiteClassName, FALSE) && !empty($loadedClasses)) {
$offset = 0 - strlen($suiteClassName);
foreach ($loadedClasses as $loadedClass) {
$class = new ReflectionClass($loadedClass);
if (substr($loadedClass, $offset) === $suiteClassName && $class->getFileName() == $filename) {
$suiteClassName = $loadedClass;
break;
}
}
}
if (!class_exists($suiteClassName, FALSE) && !empty($loadedClasses)) {
$testCaseClass = 'PHPUnit_Framework_TestCase';
foreach ($loadedClasses as $loadedClass) {
$class = new ReflectionClass($loadedClass);
$classFile = $class->getFileName();
if ($class->isSubclassOf($testCaseClass) && !$class->isAbstract()) {
$suiteClassName = $loadedClass;
$testCaseClass = $loadedClass;
if ($classFile == realpath($suiteClassFile)) {
break;
}
}
if ($class->hasMethod('suite')) {
$method = $class->getMethod('suite');
if (!$method->isAbstract() && $method->isPublic() && $method->isStatic()) {
$suiteClassName = $loadedClass;
if ($classFile == realpath($suiteClassFile)) {
break;
}
}
}
}
}
if (class_exists($suiteClassName, FALSE)) {
$class = new ReflectionClass($suiteClassName);
$filePath = $GLOBALS['base_dir'] . DIRECTORY_SEPARATOR . 'tests' . DIRECTORY_SEPARATOR . 'phpunit' . DIRECTORY_SEPARATOR . $suiteClassFile;
if ($class->getFileName() == realpath($filePath)) {
return $class;
}
}
throw new PHPUnit_Framework_Exception(sprintf('Class %s could not be found in %s.', $suiteClassName, $suiteClassFile));
}
示例7: load
/**
*
* @param string $suiteClassName
* @param string $suiteClassFile
*
* @return ReflectionClass
*
* @throws PHPUnit_Framework_Exception
*/
public function load($suiteClassName, $suiteClassFile = '')
{
$suiteClassName = str_replace('.php', '', $suiteClassName);
if (empty($suiteClassFile)) {
$suiteClassFile = PHPUnit_Util_Filesystem::classNameToFilename($suiteClassName);
}
if (!class_exists($suiteClassName, false)) {
$loadedClasses = get_declared_classes();
$filename = PHPUnit_Util_Fileloader::checkAndLoad($suiteClassFile);
$loadedClasses = array_values(array_diff(get_declared_classes(), $loadedClasses));
}
if (!class_exists($suiteClassName, false) && !empty($loadedClasses)) {
$offset = 0 - strlen($suiteClassName);
foreach ($loadedClasses as $loadedClass) {
$class = new ReflectionClass($loadedClass);
if (substr($loadedClass, $offset) === $suiteClassName && $class->getFileName() == $filename) {
$suiteClassName = $loadedClass;
break;
}
}
}
if (!class_exists($suiteClassName, false) && !empty($loadedClasses)) {
$testCaseClass = 'PHPUnit_Framework_TestCase';
foreach ($loadedClasses as $loadedClass) {
$class = new ReflectionClass($loadedClass);
$classFile = $class->getFileName();
if ($class->isSubclassOf($testCaseClass) && !$class->isAbstract()) {
$suiteClassName = $loadedClass;
$testCaseClass = $loadedClass;
if ($classFile == realpath($suiteClassFile)) {
break;
}
}
if ($class->hasMethod('suite')) {
$method = $class->getMethod('suite');
if (!$method->isAbstract() && $method->isPublic() && $method->isStatic()) {
$suiteClassName = $loadedClass;
if ($classFile == realpath($suiteClassFile)) {
break;
}
}
}
}
}
if (class_exists($suiteClassName, false)) {
$class = new ReflectionClass($suiteClassName);
if ($class->getFileName() == realpath($suiteClassFile)) {
return $class;
}
}
throw new PHPUnit_Framework_Exception(sprintf("Class '%s' could not be found in '%s'.", $suiteClassName, $suiteClassFile));
}
示例8: load
/**
* Loads a PHP sourcefile.
*
* @param string $filename
* @return mixed
* @since Method available since Release 3.0.0
*/
public static function load($filename)
{
$filename = PHPUnit_Util_Filesystem::fileExistsInIncludePath($filename);
$oldVariableNames = array_keys(get_defined_vars());
include_once $filename;
$newVariables = get_defined_vars();
$newVariableNames = array_diff(array_keys($newVariables), $oldVariableNames);
foreach ($newVariableNames as $variableName) {
if ($variableName != 'oldVariableNames') {
$GLOBALS[$variableName] = $newVariables[$variableName];
}
}
return $filename;
}
示例9: load
/**
* Loads a PHP sourcefile.
*
* @param string $filename
* @return mixed
* @since Method available since Release 3.0.0
*/
public static function load($filename)
{
$_filename = PHPUnit_Util_Filesystem::fileExistsInIncludePath($filename);
if (!$_filename) {
throw new RuntimeException(sprintf('Cannot open file "%s".' . "\n", $filename));
}
$filename = $_filename;
$oldVariableNames = array_keys(get_defined_vars());
unset($_filename);
include_once $filename;
$newVariables = get_defined_vars();
$newVariableNames = array_diff(array_keys($newVariables), $oldVariableNames);
foreach ($newVariableNames as $variableName) {
if ($variableName != 'oldVariableNames') {
$GLOBALS[$variableName] = $newVariables[$variableName];
}
}
return $filename;
}
示例10: render
/**
* Renders the report.
*
* @param PHPUnit_Framework_TestResult $result
* @param string $title
* @param string $target
* @param string $charset
* @param boolean $yui
* @param boolean $highlight
* @param integer $lowUpperBound
* @param integer $highLowerBound
*/
public static function render(PHPUnit_Framework_TestResult $result, $target, $title = '', $charset = 'ISO-8859-1', $yui = TRUE, $highlight = FALSE, $lowUpperBound = 35, $highLowerBound = 70)
{
$target = PHPUnit_Util_Filesystem::getDirectory($target);
self::$templatePath = sprintf('%s%sReport%sTemplate%s', dirname(__FILE__), DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR);
$codeCoverageInformation = $result->getCodeCoverageInformation();
$files = PHPUnit_Util_CodeCoverage::getSummary($codeCoverageInformation);
$commonPath = PHPUnit_Util_Filesystem::reducePaths($files);
$items = self::buildDirectoryStructure($files);
unset($codeCoverageInformation);
if ($title == '') {
$topTestSuite = $result->topTestSuite();
if ($topTestSuite instanceof PHPUnit_Framework_TestSuite) {
$title = $topTestSuite->getName();
}
}
unset($result);
$root = new PHPUnit_Util_Report_Node_Directory($commonPath, NULL);
self::addItems($root, $items, $files, $yui, $highlight);
self::copyFiles($target);
PHPUnit_Util_CodeCoverage::clearSummary();
$root->render($target, $title, $charset, $lowUpperBound, $highLowerBound);
}
示例11: __construct
/**
* 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);
}
示例12: render
//.........这里部分代码省略.........
foreach ($this->codeLines as $line) {
if (strpos($line, '@codeCoverageIgnore') !== FALSE) {
if (strpos($line, '@codeCoverageIgnoreStart') !== FALSE) {
$ignore = TRUE;
} else {
if (strpos($line, '@codeCoverageIgnoreEnd') !== FALSE) {
$ignore = FALSE;
}
}
}
$css = '';
if (!$ignore && isset($this->executedLines[$i])) {
$count = '';
// Array: Line is executable and was executed.
// count(Array) = Number of tests that hit this line.
if (is_array($this->executedLines[$i])) {
$color = 'lineCov';
$numTests = count($this->executedLines[$i]);
$count = sprintf('%8d', $numTests);
if ($this->yui) {
$buffer = '';
foreach ($this->executedLines[$i] as $test) {
if (!isset($test->__liHtml)) {
$test->__liHtml = '';
if ($test instanceof PHPUnit_Framework_SelfDescribing) {
$testName = $test->toString();
if ($test instanceof PHPUnit_Framework_TestCase) {
switch ($test->getStatus()) {
case PHPUnit_Runner_BaseTestRunner::STATUS_PASSED:
$testCSS = ' class=\\"testPassed\\"';
break;
case PHPUnit_Runner_BaseTestRunner::STATUS_FAILURE:
$testCSS = ' class=\\"testFailure\\"';
break;
case PHPUnit_Runner_BaseTestRunner::STATUS_ERROR:
$testCSS = ' class=\\"testError\\"';
break;
case PHPUnit_Runner_BaseTestRunner::STATUS_INCOMPLETE:
case PHPUnit_Runner_BaseTestRunner::STATUS_SKIPPED:
$testCSS = ' class=\\"testIncomplete\\"';
break;
default:
$testCSS = '';
}
}
}
$test->__liHtml .= sprintf('<li%s>%s</li>', $testCSS, $testName);
}
$buffer .= $test->__liHtml;
}
if ($numTests > 1) {
$header = $numTests . ' tests cover';
} else {
$header = '1 test covers';
}
$header .= ' line ' . $i;
$yuiTemplate->setVar(array('line' => $i, 'header' => $header, 'tests' => $buffer), FALSE);
$this->yuiPanelJS .= $yuiTemplate->render();
}
} else {
if ($this->executedLines[$i] == -1) {
$color = 'lineNoCov';
$count = sprintf('%8d', 0);
} else {
$color = 'lineDeadCode';
$count = ' ';
}
}
$css = sprintf('<span class="%s"> %s : ', $color, $count);
}
$fillup = array_shift($this->codeLinesFillup);
if ($fillup > 0) {
$line .= str_repeat(' ', $fillup);
}
$lines .= sprintf('<span class="lineNum" id="container%d"><a name="%d"></a><a href="#%d" id="line%d">%8d</a> </span>%s%s%s' . "\n", $i, $i, $i, $i, $i, !empty($css) ? $css : ' : ', !$this->highlight ? htmlspecialchars($line) : $line, !empty($css) ? '</span>' : '');
$i++;
}
$items = '';
foreach ($this->classes as $className => $classData) {
$numCalledClasses = $classData['executedLines'] > 0 ? 1 : 0;
$calledClassesPercent = $numCalledClasses == 1 ? 100 : 0;
$numCalledMethods = 0;
$numMethods = count($classData['methods']);
foreach ($classData['methods'] as $method) {
if ($method['executedLines'] > 0) {
$numCalledMethods++;
}
}
$items .= $this->doRenderItem(array('name' => sprintf('<b><a href="#%d">%s</a></b>', $classData['startLine'], $className), 'numClasses' => 1, 'numCalledClasses' => $numCalledClasses, 'calledClassesPercent' => sprintf('%01.2f', $calledClassesPercent), 'numMethods' => $numMethods, 'numCalledMethods' => $numCalledMethods, 'calledMethodsPercent' => $this->calculatePercent($numCalledMethods, $numMethods), 'numExecutableLines' => $classData['executableLines'], 'numExecutedLines' => $classData['executedLines'], 'executedLinesPercent' => $this->calculatePercent($classData['executedLines'], $classData['executableLines'])), $lowUpperBound, $highLowerBound);
foreach ($classData['methods'] as $methodName => $methodData) {
$numCalledMethods = $methodData['executedLines'] > 0 ? 1 : 0;
$calledMethodsPercent = $numCalledMethods == 1 ? 100 : 0;
$items .= $this->doRenderItem(array('name' => sprintf(' <a href="#%d">%s</a>', $methodData['startLine'], PHPUnit_Util_Class::getMethodSignature(new ReflectionMethod($className, $methodName))), 'numClasses' => '', 'numCalledClasses' => '', 'calledClassesPercent' => '', 'numMethods' => 1, 'numCalledMethods' => $numCalledMethods, 'calledMethodsPercent' => sprintf('%01.2f', $calledMethodsPercent), 'numExecutableLines' => $methodData['executableLines'], 'numExecutedLines' => $methodData['executedLines'], 'executedLinesPercent' => $this->calculatePercent($methodData['executedLines'], $methodData['executableLines'])), $lowUpperBound, $highLowerBound, 'method_item.html');
}
}
$this->setTemplateVars($template, $title, $charset);
$template->setVar(array('lines' => $lines, 'total_item' => $this->renderTotalItem($lowUpperBound, $highLowerBound, FALSE), 'items' => $items, 'yuiPanelJS' => $this->yuiPanelJS));
$cleanId = PHPUnit_Util_Filesystem::getSafeFilename($this->getId());
$template->renderTo($target . $cleanId . '.html');
}
示例13: __construct
/**
* @param string $type The type of concrete Log subclass to use.
* Currently, valid values are 'console',
* 'syslog', 'sql', 'file', and 'mcal'.
* @param string $name The name of the actually log file, table, or
* other specific store to use. Defaults to an
* empty string, with which the subclass will
* attempt to do something intelligent.
* @param string $ident The identity reported to the log system.
* @param array $conf A hash containing any additional configuration
* information that a subclass might need.
* @param int $maxLevel Maximum priority level at which to log.
*/
public function __construct($type, $name = '', $ident = '', $conf = array(), $maxLevel = PEAR_LOG_DEBUG)
{
if (PHPUnit_Util_Filesystem::fileExistsInIncludePath('Log.php')) {
PHPUnit_Util_Filesystem::collectStart();
require_once 'Log.php';
$this->log = Log::factory($type, $name, $ident, $conf, $maxLevel);
foreach (PHPUnit_Util_Filesystem::collectEnd() as $blacklistedFile) {
PHPUnit_Util_Filter::addFileToFilter($blacklistedFile, 'PHPUNIT');
}
} else {
throw new RuntimeException('Log is not available.');
}
}
示例14: updateTicket
protected function updateTicket($ticketId, $newStatus, $message, $resolution)
{
if (PHPUnit_Util_Filesystem::fileExistsInIncludePath('XML/RPC2/Client.php')) {
PHPUnit_Util_Filesystem::collectStart();
require_once 'XML/RPC2/Client.php';
$ticket = XML_RPC2_Client::create($this->scheme . '://' . $this->username . ':' . $this->password . '@' . $this->hostpath, array('prefix' => 'ticket.'));
try {
$ticketInfo = $ticket->get($ticketId);
} catch (XML_RPC2_FaultException $e) {
throw new PHPUnit_Framework_Exception(sprintf("Trac fetch failure: %d: %s\n", $e->getFaultCode(), $e->getFaultString()));
}
try {
printf("Updating Trac ticket #%d, status: %s\n", $ticketId, $newStatus);
$ticket->update($ticketId, $message, array('status' => $newStatus, 'resolution' => $resolution));
} catch (XML_RPC2_FaultException $e) {
throw new PHPUnit_Framework_Exception(sprintf("Trac update failure: %d: %s\n", $e->getFaultCode(), $e->getFaultString()));
}
foreach (PHPUnit_Util_Filesystem::collectEnd() as $blacklistedFile) {
PHPUnit_Util_Filter::addFileToFilter($blacklistedFile, 'PHPUNIT');
}
} else {
throw new PHPUnit_Framework_Exception('XML_RPC2 is not available.');
}
}
示例15: phpunitAutoload
function phpunitAutoload($class)
{
require_once $this->phpUnitPath . '/PHPUnit/Util/Filesystem.php';
if (strpos($class, 'PHPUnit_') === 0 || strpos($class, 'PHP_') === 0 || strpos($class, 'Text_') === 0 || strpos($class, 'File_') === 0 || strpos($class, 'Doctrine') === 0 || strpos($class, 'SebastianBergmann') === 0) {
$file = \PHPUnit_Util_Filesystem::classNameToFilename($class);
if (file_exists($this->phpUnitPath . '/' . $file)) {
require_once $file;
}
}
}