Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

- Merge [5079:5085].

  • Loading branch information...
commit 2b3e04e0cc5e786b4179064c4fc1866e8b5b9a32 1 parent d19de25
@sebastianbergmann authored
View
30 PHPUnit/Util/Class.php
@@ -270,7 +270,7 @@ public static function getPackageInformation($className, $docComment)
if (strpos($className, '\\') !== FALSE) {
$result['namespace'] = self::arrayToName(
- explode('\\', $className), '\\'
+ explode('\\', $className)
);
}
@@ -418,14 +418,38 @@ public static function getObjectAttribute($object, $attributeName)
}
/**
+ *
+ *
+ * @param string $className
+ * @return array
+ * @since Method available since Release 3.4.0
+ */
+ public static function parseFullyQualifiedClassName($className)
+ {
+ $result = array(
+ 'namespace' => '',
+ 'className' => $className,
+ 'fullyQualifiedClassName' => $className
+ );
+
+ if (strpos($className, '\\') !== FALSE) {
+ $tmp = explode('\\', $className);
+ $result['className'] = $tmp[count($tmp)-1];
+ $result['namespace'] = self::arrayToName($tmp);
+ }
+
+ return $result;
+ }
+
+ /**
* Returns the package information of a user-defined class.
*
- * @param array $parts
+ * @param array $parts
* @param string $join
* @return string
* @since Method available since Release 3.2.12
*/
- protected static function arrayToName(array $parts, $join)
+ protected static function arrayToName(array $parts, $join = '\\')
{
$result = '';
View
43 PHPUnit/Util/Skeleton.php
@@ -45,6 +45,7 @@
*/
require_once 'PHPUnit/Util/Filter.php';
+require_once 'PHPUnit/Util/Class.php';
require_once 'PHPUnit/Util/Template.php';
PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT');
@@ -64,31 +65,63 @@
abstract class PHPUnit_Util_Skeleton
{
/**
- * @var string
+ * @var array
*/
protected $inClassName;
/**
- * @var string
+ * @var string
*/
protected $inSourceFile;
/**
- * @var string
+ * @var array
*/
protected $outClassName;
/**
- * @var string
+ * @var string
*/
protected $outSourceFile;
/**
+ * Constructor.
+ *
+ * @param string $inClassName
+ * @param string $inSourceFile
+ * @param string $outClassName
+ * @param string $outSourceFile
+ * @since Method available since Release 3.4.0
+ */
+ public function __construct($inClassName, $inSourceFile = '', $outClassName = '', $outSourceFile = '')
+ {
+ $this->inClassName = PHPUnit_Util_Class::parseFullyQualifiedClassName(
+ $inClassName
+ );
+
+ $this->outClassName = PHPUnit_Util_Class::parseFullyQualifiedClassName(
+ $outClassName
+ );
+
+ $this->inSourceFile = str_replace(
+ $this->inClassName['fullyQualifiedClassName'],
+ $this->inClassName['className'],
+ $inSourceFile
+ );
+
+ $this->outSourceFile = str_replace(
+ $this->outClassName['fullyQualifiedClassName'],
+ $this->outClassName['className'],
+ $outSourceFile
+ );
+ }
+
+ /**
* @return string
*/
public function getOutClassName()
{
- return $this->outClassName;
+ return $this->outClassName['fullyQualifiedClassName'];
}
/**
View
11 PHPUnit/Util/Skeleton/Class.php
@@ -101,10 +101,9 @@ public function __construct($inClassName, $inSourceFile = '', $outClassName = ''
$outSourceFile = dirname($inSourceFile) . DIRECTORY_SEPARATOR . $outClassName . '.php';
}
- $this->inClassName = $inClassName;
- $this->inSourceFile = $inSourceFile;
- $this->outClassName = $outClassName;
- $this->outSourceFile = $outSourceFile;
+ parent::__construct(
+ $inClassName, $inSourceFile, $outClassName, $outSourceFile
+ );
}
/**
@@ -148,7 +147,7 @@ public function generate()
$classTemplate->setVar(
array(
- 'className' => $this->outClassName,
+ 'className' => $this->outClassName['fullyQualifiedClassName'],
'methods' => $methods,
'date' => date('Y-m-d'),
'time' => date('H:i:s')
@@ -225,7 +224,7 @@ protected function findVariablesThatReferenceClass()
case T_STRING: {
if ($inNew) {
- if ($_value == $this->outClassName) {
+ if ($_value == $this->outClassName['fullyQualifiedClassName']) {
$variables[] = $this->findVariableName($i);
}
}
View
4 PHPUnit/Util/Skeleton/Template/TestClass.tpl.dist
@@ -1,11 +1,11 @@
-<?php
+<?php{namespace}
require_once 'PHPUnit/Framework.php';{requireClassFile}
/**
* Test class for {className}.
* Generated by PHPUnit on {date} at {time}.
*/
-class {className}Test extends PHPUnit_Framework_TestCase
+class {testClassName} extends PHPUnit_Framework_TestCase
{
/**
* @var {className}
View
23 PHPUnit/Util/Skeleton/Test.php
@@ -147,10 +147,9 @@ public function __construct($inClassName, $inSourceFile = '', $outClassName = ''
$outSourceFile = dirname($inSourceFile) . DIRECTORY_SEPARATOR . $outClassName . '.php';
}
- $this->inClassName = $inClassName;
- $this->inSourceFile = $inSourceFile;
- $this->outClassName = $outClassName;
- $this->outSourceFile = $outSourceFile;
+ parent::__construct(
+ $inClassName, $inSourceFile, $outClassName, $outSourceFile
+ );
}
/**
@@ -161,7 +160,7 @@ public function __construct($inClassName, $inSourceFile = '', $outClassName = ''
*/
public function generate($verbose = FALSE)
{
- $class = new ReflectionClass($this->inClassName);
+ $class = new ReflectionClass($this->inClassName['fullyQualifiedClassName']);
$methods = '';
$incompleteMethods = '';
@@ -169,7 +168,7 @@ public function generate($verbose = FALSE)
if (!$method->isConstructor() &&
!$method->isAbstract() &&
$method->isPublic() &&
- $method->getDeclaringClass()->getName() == $this->inClassName) {
+ $method->getDeclaringClass()->getName() == $this->inClassName['fullyQualifiedClassName']) {
$assertAnnotationFound = FALSE;
if (preg_match_all('/@assert(.*)$/Um', $method->getDocComment(), $annotations)) {
@@ -289,7 +288,7 @@ public function generate($verbose = FALSE)
'assertion' => isset($assertion) ? $assertion : '',
'expected' => $matches[3],
'origMethodName' => $origMethodName,
- 'className' => $this->inClassName,
+ 'className' => $this->inClassName['fullyQualifiedClassName'],
'methodName' => $methodName
)
);
@@ -343,9 +342,17 @@ public function generate($verbose = FALSE)
$requireClassFile = '';
}
+ if ($this->outClassName['namespace'] != '') {
+ $namespace = "\nnamespace " . $this->outClassName['namespace'] . ";\n";
+ } else {
+ $namespace = '';
+ }
+
$classTemplate->setVar(
array(
- 'className' => $this->inClassName,
+ 'namespace' => $namespace,
+ 'className' => $this->inClassName['className'],
+ 'testClassName' => $this->outClassName['className'],
'requireClassFile' => $requireClassFile,
'methods' => $methods . $incompleteMethods,
'date' => date('Y-m-d'),
Please sign in to comment.
Something went wrong with that request. Please try again.