Skip to content

Commit

Permalink
Merge pull request #1362 from dracony/4.1
Browse files Browse the repository at this point in the history
Fixes skipping of parent classes
  • Loading branch information
whatthejeff committed Jul 29, 2014
2 parents 07d5a9e + 070672d commit e4c97ee
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/Framework/TestSuite.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ class PHPUnit_Framework_TestSuite implements PHPUnit_Framework_Test, PHPUnit_Fra
*/
protected $testCase = false;

/**
* @var array
*/
protected $foundClasses = array();

/**
* @var PHPUnit_Runner_Filter_Factory
*/
Expand Down Expand Up @@ -356,18 +361,25 @@ public function addTestFile($filename, $phptOptions = array())

$classes = get_declared_classes();
$filename = PHPUnit_Util_Fileloader::checkAndLoad($filename);
$newClasses = array_values(array_diff(get_declared_classes(), $classes));
$newClasses = array_diff(get_declared_classes(), $classes);
foreach($newClasses as $className) {
$this->foundClasses[]= $className;
}

$baseName = str_replace('.php', '', basename($filename));

foreach ($newClasses as $className) {
end($this->foundClasses);
while($className = current($this->foundClasses)) {
if (substr($className, 0 - strlen($baseName)) == $baseName) {
$class = new ReflectionClass($className);

if ($class->getFileName() == $filename) {
$newClasses = array($className);
unset($this->foundClasses[key($this->foundClasses)]);
break;
}
}
prev($this->foundClasses);
}

foreach ($newClasses as $className) {
Expand Down
16 changes: 16 additions & 0 deletions tests/Framework/SuiteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ public static function suite()
$suite->addTest(new Framework_SuiteTest('testShadowedTests'));
$suite->addTest(new Framework_SuiteTest('testBeforeClassAndAfterClassAnnotations'));
$suite->addTest(new Framework_SuiteTest('testBeforeAnnotation'));
$suite->addTest(new Framework_SuiteTest('testDontSkipInheritedClass'));

return $suite;
}
Expand Down Expand Up @@ -213,4 +214,19 @@ public function testBeforeAnnotation()
$this->assertEquals(2, BeforeAndAfterTest::$afterWasRun);
}

public function testDontSkipInheritedClass()
{
$suite = new PHPUnit_Framework_TestSuite(
'DontSkipInheritedClass'
);

$dir = dirname(__DIR__) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'Inheritance' . DIRECTORY_SEPARATOR;

$suite->addTestFile($dir.'InheritanceA.php');
$suite->addTestFile($dir.'InheritanceB.php');
$result = $suite->run();
$this->assertEquals(2, count($result));

}

}
8 changes: 8 additions & 0 deletions tests/_files/Inheritance/InheritanceA.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

require_once(__DIR__.'/InheritanceB.php');

class InheritanceA extends InheritanceB
{

}
9 changes: 9 additions & 0 deletions tests/_files/Inheritance/InheritanceB.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

class InheritanceB extends PHPUnit_Framework_TestCase
{
public function testSomething()
{

}
}

0 comments on commit e4c97ee

Please sign in to comment.