Skip to content

Commit

Permalink
Tests\Core\AllTests: simplify creation of the test suite
Browse files Browse the repository at this point in the history
As the refactor will add a lot of new unit test files, let's automate the creation of the test suite some more by automatically adding all Test files within the `Test\Core` directory.
  • Loading branch information
jrfnl committed Aug 27, 2019
1 parent 91e4384 commit 3bb2ffa
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 23 deletions.
42 changes: 20 additions & 22 deletions tests/Core/AllTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,17 @@
* A test class for testing the core.
*
* @author Greg Sherwood <[email protected]>
* @copyright 2006-2015 Squiz Pty Ltd (ABN 77 084 670 600)
* @author Juliette Reinders Folmer <[email protected]>
* @copyright 2006-2019 Squiz Pty Ltd (ABN 77 084 670 600)
* @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
*/

namespace PHP_CodeSniffer\Tests\Core;

use PHP_CodeSniffer\Tests\FileList;
use PHPUnit\TextUI\TestRunner;
use PHPUnit\Framework\TestSuite;

require_once 'IsCamelCapsTest.php';
require_once 'ErrorSuppressionTest.php';
require_once 'File/FindEndOfStatementTest.php';
require_once 'File/FindExtendedClassNameTest.php';
require_once 'File/FindImplementedInterfaceNamesTest.php';
require_once 'File/GetMemberPropertiesTest.php';
require_once 'File/GetMethodParametersTest.php';
require_once 'File/GetMethodPropertiesTest.php';
require_once 'File/IsReferenceTest.php';
require_once 'Filters/Filter/AcceptTest.php';

class AllTests
{

Expand All @@ -47,16 +38,23 @@ public static function main()
public static function suite()
{
$suite = new TestSuite('PHP CodeSniffer Core');
$suite->addTestSuite('PHP_CodeSniffer\Tests\Core\IsCamelCapsTest');
$suite->addTestSuite('PHP_CodeSniffer\Tests\Core\ErrorSuppressionTest');
$suite->addTestSuite('PHP_CodeSniffer\Tests\Core\File\FindEndOfStatementTest');
$suite->addTestSuite('PHP_CodeSniffer\Tests\Core\File\FindExtendedClassNameTest');
$suite->addTestSuite('PHP_CodeSniffer\Tests\Core\File\FindImplementedInterfaceNamesTest');
$suite->addTestSuite('PHP_CodeSniffer\Tests\Core\File\GetMemberPropertiesTest');
$suite->addTestSuite('PHP_CodeSniffer\Tests\Core\File\GetMethodParametersTest');
$suite->addTestSuite('PHP_CodeSniffer\Tests\Core\File\GetMethodPropertiesTest');
$suite->addTestSuite('PHP_CodeSniffer\Tests\Core\File\IsReferenceTest');
$suite->addTestSuite('PHP_CodeSniffer\Tests\Core\Filters\Filter\AcceptTest');

$testFileIterator = new FileList(__DIR__, '', '`Test\.php$`Di');
foreach ($testFileIterator->fileIterator as $file) {
if (strpos($file, 'AbstractMethodUnitTest.php') !== false) {
continue;
}

include_once $file;

$class = str_replace(__DIR__, '', $file);
$class = str_replace('.php', '', $class);
$class = str_replace('/', '\\', $class);
$class = 'PHP_CodeSniffer\Tests\Core'.$class;

$suite->addTestSuite($class);
}

return $suite;

}//end suite()
Expand Down
2 changes: 1 addition & 1 deletion tests/FileList.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class FileList
*
* @var \DirectoryIterator
*/
protected $fileIterator;
public $fileIterator;

/**
* Base regex to use if no filter regex is provided.
Expand Down

0 comments on commit 3bb2ffa

Please sign in to comment.