本文整理汇总了PHP中PHPUnit_Util_Class::getPackageInformation方法的典型用法代码示例。如果您正苦于以下问题:PHP PHPUnit_Util_Class::getPackageInformation方法的具体用法?PHP PHPUnit_Util_Class::getPackageInformation怎么用?PHP PHPUnit_Util_Class::getPackageInformation使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PHPUnit_Util_Class
的用法示例。
在下文中一共展示了PHPUnit_Util_Class::getPackageInformation方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* Constructor.
*
* @param ReflectionClass $class
* @param array $codeCoverage
*/
protected function __construct(ReflectionClass $class, &$codeCoverage = array())
{
$this->class = $class;
$className = $class->getName();
$packageInformation = PHPUnit_Util_Class::getPackageInformation($className);
if (!empty($packageInformation['fullPackage'])) {
$this->package = $packageInformation['fullPackage'];
}
$this->setCoverage($codeCoverage);
$this->dit = count(PHPUnit_Util_Class::getHierarchy($class->getName())) - 1;
$this->impl = count($class->getInterfaces());
foreach ($this->class->getMethods() as $method) {
if ($method->getDeclaringClass()->getName() == $className) {
$this->methods[$method->getName()] = PHPUnit_Util_Metrics_Function::factory($method, $codeCoverage);
} else {
$this->inheritedMethods[$method->getName()] = PHPUnit_Util_Metrics_Function::factory($method, $codeCoverage);
}
}
$this->calculateAttributeMetrics();
$this->calculateMethodMetrics();
$this->calculateNumberOfChildren();
$this->calculatePolymorphismFactor();
$this->calculateDependencies();
}
示例2: startTestSuite
/**
* A testsuite started.
*
* @param PHPUnit_Framework_TestSuite $suite
* @since Method available since Release 2.2.0
*/
public function startTestSuite(PHPUnit_Framework_TestSuite $suite)
{
$testSuite = $this->document->createElement('testsuite');
$testSuite->setAttribute('name', $suite->getName());
if (class_exists($suite->getName(), FALSE)) {
try {
$class = new ReflectionClass($suite->getName());
$testSuite->setAttribute('file', $class->getFileName());
$packageInformation = PHPUnit_Util_Class::getPackageInformation($suite->getName(), $class->getDocComment());
if (!empty($packageInformation['namespace'])) {
$testSuite->setAttribute('namespace', $packageInformation['namespace']);
}
if (!empty($packageInformation['fullPackage'])) {
$testSuite->setAttribute('fullPackage', $packageInformation['fullPackage']);
}
if (!empty($packageInformation['category'])) {
$testSuite->setAttribute('category', $packageInformation['category']);
}
if (!empty($packageInformation['package'])) {
$testSuite->setAttribute('package', $packageInformation['package']);
}
if (!empty($packageInformation['subpackage'])) {
$testSuite->setAttribute('subpackage', $packageInformation['subpackage']);
}
} catch (ReflectionException $e) {
}
}
if ($this->testSuiteLevel > 0) {
$this->testSuites[$this->testSuiteLevel]->appendChild($testSuite);
} else {
$this->root->appendChild($testSuite);
}
$this->testSuiteLevel++;
$this->testSuites[$this->testSuiteLevel] = $testSuite;
$this->testSuiteTests[$this->testSuiteLevel] = 0;
$this->testSuiteAssertions[$this->testSuiteLevel] = 0;
$this->testSuiteErrors[$this->testSuiteLevel] = 0;
$this->testSuiteFailures[$this->testSuiteLevel] = 0;
$this->testSuiteTimes[$this->testSuiteLevel] = 0;
}
示例3: process
/**
* @param PHPUnit_Framework_TestResult $result
* @todo Count conditionals.
*/
public function process(PHPUnit_Framework_TestResult $result)
{
$time = time();
$document = new DOMDocument('1.0', 'UTF-8');
$document->formatOutput = TRUE;
$coverage = $document->createElement('coverage');
$coverage->setAttribute('generated', $time);
$coverage->setAttribute('phpunit', PHPUnit_Runner_Version::id());
$document->appendChild($coverage);
$project = $document->createElement('project');
$project->setAttribute('name', $result->topTestSuite()->getName());
$project->setAttribute('timestamp', $time);
$coverage->appendChild($project);
$codeCoverageInformation = $result->getCodeCoverageInformation();
$files = PHPUnit_Util_CodeCoverage::getSummary($codeCoverageInformation);
$packages = array();
$projectFiles = 0;
$projectLoc = 0;
$projectNcloc = 0;
$projectClasses = 0;
$projectMethods = 0;
$projectCoveredMethods = 0;
$projectConditionals = 0;
$projectCoveredConditionals = 0;
$projectStatements = 0;
$projectCoveredStatements = 0;
foreach ($files as $filename => $data) {
$projectFiles++;
$fileClasses = 0;
$fileConditionals = 0;
$fileCoveredConditionals = 0;
$fileStatements = 0;
$fileCoveredStatements = 0;
$fileMethods = 0;
$fileCoveredMethods = 0;
$file = $document->createElement('file');
$file->setAttribute('name', $filename);
$namespace = 'global';
$classes = PHPUnit_Util_Class::getClassesInFile($filename);
$lines = array();
foreach ($classes as $class) {
if ($class->isInterface()) {
continue;
}
$className = $class->getName();
$methods = $class->getMethods();
$packageInformation = PHPUnit_Util_Class::getPackageInformation($className);
$numMethods = 0;
$fileClasses++;
$projectClasses++;
if (!empty($packageInformation['namespace'])) {
$namespace = $packageInformation['namespace'];
}
$classConditionals = 0;
$classCoveredConditionals = 0;
$classStatements = 0;
$classCoveredStatements = 0;
$classCoveredMethods = 0;
foreach ($methods as $method) {
if ($method->getDeclaringClass()->getName() == $class->getName()) {
$startLine = $method->getStartLine();
$endLine = $method->getEndLine();
$tests = array();
for ($i = $startLine; $i <= $endLine; $i++) {
if (isset($files[$filename][$i])) {
if (is_array($files[$filename][$i])) {
foreach ($files[$filename][$i] as $_test) {
$add = TRUE;
foreach ($tests as $test) {
if ($test === $_test) {
$add = FALSE;
break;
}
}
if ($add) {
$tests[] = $_test;
}
}
$classCoveredStatements++;
}
$classStatements++;
}
}
$count = count($tests);
$lines[$startLine] = array('count' => $count, 'type' => 'method');
if ($count > 0) {
$classCoveredMethods++;
$fileCoveredMethods++;
$projectCoveredMethods++;
}
$classStatements--;
$numMethods++;
$fileMethods++;
$projectMethods++;
}
}
//.........这里部分代码省略.........
示例4: process
/**
* @param PHPUnit_Framework_TestResult $result
* @todo Count conditionals.
*/
public function process(PHPUnit_Framework_TestResult $result)
{
$time = time();
$document = new DOMDocument('1.0', 'UTF-8');
$document->formatOutput = TRUE;
$coverage = $document->createElement('coverage');
$coverage->setAttribute('generated', $time);
$coverage->setAttribute('phpunit', PHPUnit_Runner_Version::id());
$document->appendChild($coverage);
$project = $document->createElement('project');
$project->setAttribute('name', $result->topTestSuite()->getName());
$project->setAttribute('timestamp', $time);
$coverage->appendChild($project);
$codeCoverageInformation = $result->getCodeCoverageInformation();
$files = PHPUnit_Util_CodeCoverage::getSummary($codeCoverageInformation);
$packages = array();
$projectStatistics = array('files' => 0, 'loc' => 0, 'ncloc' => 0, 'classes' => 0, 'methods' => 0, 'coveredMethods' => 0, 'conditionals' => 0, 'coveredConditionals' => 0, 'statements' => 0, 'coveredStatements' => 0);
foreach ($files as $filename => $data) {
$namespace = 'global';
if (file_exists($filename)) {
$fileStatistics = array('classes' => 0, 'methods' => 0, 'coveredMethods' => 0, 'conditionals' => 0, 'coveredConditionals' => 0, 'statements' => 0, 'coveredStatements' => 0);
$file = $document->createElement('file');
$file->setAttribute('name', $filename);
$classesInFile = PHPUnit_Util_File::getClassesInFile($filename);
$lines = array();
foreach ($classesInFile as $className => $_class) {
$classStatistics = array('methods' => 0, 'coveredMethods' => 0, 'conditionals' => 0, 'coveredConditionals' => 0, 'statements' => 0, 'coveredStatements' => 0);
foreach ($_class['methods'] as $methodName => $method) {
$classStatistics['methods']++;
$methodCount = 0;
for ($i = $method['startLine']; $i <= $method['endLine']; $i++) {
$add = TRUE;
$count = 0;
if (isset($files[$filename][$i])) {
if ($files[$filename][$i] != -2) {
$classStatistics['statements']++;
}
if (is_array($files[$filename][$i])) {
$classStatistics['coveredStatements']++;
$count = count($files[$filename][$i]);
} else {
if ($files[$filename][$i] == -2) {
$add = FALSE;
}
}
} else {
$add = FALSE;
}
$methodCount = max($methodCount, $count);
if ($add) {
$lines[$i] = array('count' => $count, 'type' => 'stmt');
}
}
if ($methodCount > 0) {
$classStatistics['coveredMethods']++;
}
$lines[$method['startLine']] = array('count' => $methodCount, 'type' => 'method', 'name' => $methodName);
}
$packageInformation = PHPUnit_Util_Class::getPackageInformation($className, $_class['docComment']);
if (!empty($packageInformation['namespace'])) {
$namespace = $packageInformation['namespace'];
}
$class = $document->createElement('class');
$class->setAttribute('name', $className);
$class->setAttribute('namespace', $namespace);
if (!empty($packageInformation['fullPackage'])) {
$class->setAttribute('fullPackage', $packageInformation['fullPackage']);
}
if (!empty($packageInformation['category'])) {
$class->setAttribute('category', $packageInformation['category']);
}
if (!empty($packageInformation['package'])) {
$class->setAttribute('package', $packageInformation['package']);
}
if (!empty($packageInformation['subpackage'])) {
$class->setAttribute('subpackage', $packageInformation['subpackage']);
}
$file->appendChild($class);
$metrics = $document->createElement('metrics');
$metrics->setAttribute('methods', $classStatistics['methods']);
$metrics->setAttribute('coveredmethods', $classStatistics['coveredMethods']);
//$metrics->setAttribute('conditionals', $classStatistics['conditionals']);
//$metrics->setAttribute('coveredconditionals', $classStatistics['coveredConditionals']);
$metrics->setAttribute('statements', $classStatistics['statements']);
$metrics->setAttribute('coveredstatements', $classStatistics['coveredStatements']);
$metrics->setAttribute('elements', $classStatistics['conditionals'] + $classStatistics['statements'] + $classStatistics['methods']);
$metrics->setAttribute('coveredelements', $classStatistics['coveredConditionals'] + $classStatistics['coveredStatements'] + $classStatistics['coveredMethods']);
$class->appendChild($metrics);
$fileStatistics['methods'] += $classStatistics['methods'];
$fileStatistics['coveredMethods'] += $classStatistics['coveredMethods'];
$fileStatistics['conditionals'] += $classStatistics['conditionals'];
$fileStatistics['coveredConditionals'] += $classStatistics['coveredConditionals'];
$fileStatistics['statements'] += $classStatistics['statements'];
$fileStatistics['coveredStatements'] += $classStatistics['coveredStatements'];
$fileStatistics['classes']++;
}
//.........这里部分代码省略.........