Skip to content

Instantly share code, notes, and snippets.

@beberlei
Last active August 29, 2015 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save beberlei/8a33ae940829f1186da2 to your computer and use it in GitHub Desktop.
Save beberlei/8a33ae940829f1186da2 to your computer and use it in GitHub Desktop.
PHPUnit necessary chanegs for PHP7 Coercive Typehints
diff --git a/src/Framework/TestSuite.php b/src/Framework/TestSuite.php
index 1b3b339..71ee4a9 100644
--- a/src/Framework/TestSuite.php
+++ b/src/Framework/TestSuite.php
@@ -878,7 +878,11 @@ public static function isTestMethod(ReflectionMethod $method)
// @scenario on TestCase::testMethod()
// @test on TestCase::testMethod()
- $doc_comment = $method->getDocComment();
+ $doc_comment = (string)$method->getDocComment();
+
+ if (!$doc_comment) {
+ return false;
+ }
return strpos($doc_comment, '@test') !== false ||
strpos($doc_comment, '@scenario') !== false;
diff --git a/src/Util/ErrorHandler.php b/src/Util/ErrorHandler.php
index d56a37d..8527d01 100644
--- a/src/Util/ErrorHandler.php
+++ b/src/Util/ErrorHandler.php
@@ -55,7 +55,7 @@ public static function handleError($errno, $errstr, $errfile, $errline)
self::$errorStack[] = array($errno, $errstr, $errfile, $errline);
- $trace = debug_backtrace(false);
+ $trace = debug_backtrace(0);
array_shift($trace);
foreach ($trace as $frame) {
diff --git a/src/Util/Test.php b/src/Util/Test.php
index 1d51df2..bbcc0b0 100644
--- a/src/Util/Test.php
+++ b/src/Util/Test.php
@@ -172,9 +172,9 @@ private static function getLinesToBeCoveredOrUsed($className, $methodName, $mode
public static function getRequirements($className, $methodName)
{
$reflector = new ReflectionClass($className);
- $docComment = $reflector->getDocComment();
+ $docComment = (string)$reflector->getDocComment();
$reflector = new ReflectionMethod($className, $methodName);
- $docComment .= "\n" . $reflector->getDocComment();
+ $docComment .= "\n" . (string)$reflector->getDocComment();
$requires = array();
if ($count = preg_match_all(self::REGEX_REQUIRES_OS, $docComment, $matches)) {
@@ -229,7 +229,7 @@ public static function getMissingRequirements($className, $methodName)
}
}
- if (!empty($required['OS']) && !preg_match($required['OS'], PHP_OS)) {
+ if (!empty($required['OS']) && !preg_match((string)$required['OS'], PHP_OS)) {
$missing[] = sprintf('Operating system matching %s is required.', $required['OS']);
}
@@ -268,10 +268,10 @@ public static function getMissingRequirements($className, $methodName)
public static function getExpectedException($className, $methodName)
{
$reflector = new ReflectionMethod($className, $methodName);
- $docComment = $reflector->getDocComment();
+ $docComment = (string)$reflector->getDocComment();
$docComment = substr($docComment, 3, -2);
- if (preg_match(self::REGEX_EXPECTED_EXCEPTION, $docComment, $matches)) {
+ if ($docComment && preg_match(self::REGEX_EXPECTED_EXCEPTION, $docComment, $matches)) {
$annotations = self::parseTestMethodAnnotations(
$className,
$methodName
@@ -353,10 +353,10 @@ private static function parseAnnotationContent($message)
public static function getProvidedData($className, $methodName)
{
$reflector = new ReflectionMethod($className, $methodName);
- $docComment = $reflector->getDocComment();
+ $docComment = (string)$reflector->getDocComment();
$data = null;
- if (preg_match(self::REGEX_DATA_PROVIDER, $docComment, $matches)) {
+ if ($docComment && preg_match(self::REGEX_DATA_PROVIDER, $docComment, $matches)) {
$dataProviderMethodNameNamespace = explode('\\', $matches[1]);
$leaf = explode('::', array_pop($dataProviderMethodNameNamespace));
$dataProviderMethodName = array_pop($leaf);
@@ -422,7 +422,7 @@ public static function parseTestMethodAnnotations($className, $methodName = '')
{
if (!isset(self::$annotationCache[$className])) {
$class = new ReflectionClass($className);
- self::$annotationCache[$className] = self::parseAnnotations($class->getDocComment());
+ self::$annotationCache[$className] = self::parseAnnotations((string)$class->getDocComment());
}
if (!empty($methodName) && !isset(self::$annotationCache[$className . '::' . $methodName])) {
@@ -448,6 +448,10 @@ public static function parseTestMethodAnnotations($className, $methodName = '')
*/
private static function parseAnnotations($docblock)
{
+ if (!$docblock) {
+ return array();
+ }
+
$annotations = array();
// Strip away the docblock header and footer to ease parsing of one line annotations
$docblock = substr($docblock, 3, -2);
@@ -923,7 +927,7 @@ private static function resolveReflectionObjectsToLines(array $reflectors)
*/
private static function isBeforeClassMethod(ReflectionMethod $method)
{
- return $method->isStatic() && strpos($method->getDocComment(), '@beforeClass') !== false;
+ return $method->isStatic() && strpos((string)$method->getDocComment(), '@beforeClass') !== false;
}
/**
@@ -933,7 +937,7 @@ private static function isBeforeClassMethod(ReflectionMethod $method)
*/
private static function isBeforeMethod(ReflectionMethod $method)
{
- return preg_match('/@before\b/', $method->getDocComment());
+ return preg_match('/@before\b/', (string)$method->getDocComment());
}
/**
@@ -943,7 +947,7 @@ private static function isBeforeMethod(ReflectionMethod $method)
*/
private static function isAfterClassMethod(ReflectionMethod $method)
{
- return $method->isStatic() && strpos($method->getDocComment(), '@afterClass') !== false;
+ return $method->isStatic() && strpos((string)$method->getDocComment(), '@afterClass') !== false;
}
/**
@@ -953,6 +957,6 @@ private static function isAfterClassMethod(ReflectionMethod $method)
*/
private static function isAfterMethod(ReflectionMethod $method)
{
- return preg_match('/@after\b/', $method->getDocComment());
+ return preg_match('/@after\b/', (string)$method->getDocComment());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment