From a71cd17f8c7e6553898ea1b64cea97a93df29afd Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sat, 15 Dec 2018 18:15:47 +0100 Subject: [PATCH] WPCS 2.0.0: Remove unit test work-arounds for PHPCS 2.x The duplicates of the PHPCS 2.x test controller files can now be removed. We also no longer need to load our `PHPCSAliases` file, not even for the autoloading of the abstract classes as PHPCS 3.1.0+handles this without problem. For PHPUnit 7.x support, PHPCS does need a bootstrap file, but that is included with PHPCS, so all we need to do is reference that file in the command send to PHPUnit. --- .gitattributes | 1 - .github/CONTRIBUTING.md | 25 +- .phpcs.xml.dist | 4 - .travis.yml | 2 +- Test/AllTests.php | 72 ---- Test/Standards/AbstractSniffUnitTest.php | 460 ----------------------- Test/Standards/AllSniffs.php | 157 -------- Test/bootstrap.php | 42 --- Test/phpcs2-bootstrap.php | 53 --- Test/phpcs3-bootstrap.php | 61 --- bin/pre-commit | 2 +- phpunit.xml.dist | 1 - 12 files changed, 11 insertions(+), 869 deletions(-) delete mode 100644 Test/AllTests.php delete mode 100644 Test/Standards/AbstractSniffUnitTest.php delete mode 100644 Test/Standards/AllSniffs.php delete mode 100644 Test/bootstrap.php delete mode 100644 Test/phpcs2-bootstrap.php delete mode 100644 Test/phpcs3-bootstrap.php diff --git a/.gitattributes b/.gitattributes index 5e6e2b7903..c12f94cfb3 100644 --- a/.gitattributes +++ b/.gitattributes @@ -9,7 +9,6 @@ /phpunit.xml.dist export-ignore /.github export-ignore /bin export-ignore -/Test export-ignore /WordPress/Tests export-ignore # diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 861f5a6c56..2693701a61 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -89,7 +89,7 @@ N.B.: If you installed WPCS using Composer, make sure you used `--prefer-source` If you already have PHPUnit installed on your system: Congrats, you're all set. If not, you can navigate to the directory where the `PHP_CodeSniffer` repo is checked out and do `composer install` to install the `dev` dependencies. -Alternatively, you can [install PHPUnit](https://phpunit.de/manual/5.7/en/installation.html) as a PHAR file. +Alternatively, you can [install PHPUnit](https://phpunit.readthedocs.io/en/7.4/installation.html) as a PHAR file. ## Before running the unit tests @@ -111,37 +111,30 @@ The easiest way to do this is to add a `phpunit.xml` file to the root of your WP ## Running the unit tests -The WordPress Coding Standards are compatible with both PHPCS 2.x as well as 3.x. This has some implications for running the unit tests. - * Make sure you have registered the directory in which you installed WPCS with PHPCS using; ```sh phpcs --config-set installed_paths path/to/WPCS ``` * Navigate to the directory in which you installed WPCS. -* To run the unit tests with PHPCS 3.x: - ```sh - phpunit --bootstrap="./Test/phpcs3-bootstrap.php" --filter WordPress /path/to/PHP_CodeSniffer/tests/AllTests.php - ``` -* To run the unit tests with PHPCS 2.x: +* To run the unit tests: ```sh - phpunit --bootstrap="./Test/phpcs2-bootstrap.php" --filter WordPress ./Test/AllTests.php + phpunit --filter WordPress --bootstrap="/path/to/PHP_CodeSniffer/tests/bootstrap.php" /path/to/PHP_CodeSniffer/tests/AllTests.php ``` Expected output: ``` -PHPUnit 6.5.8 by Sebastian Bergmann and contributors. +PHPUnit 7.5.0 by Sebastian Bergmann and contributors. -Runtime: PHP 7.2.7 with Xdebug 2.6.0 +Runtime: PHP 7.2.13 Configuration: /WordPressCS/phpunit.xml -................................................................. 65 / 77 ( 84%) -............ 77 / 77 (100%) +............................................................ 60 / 60 (100%) -Tests generated 576 unique error codes; 51 were fixable (8.85%) +156 sniff test files generated 490 unique error codes; 59 were fixable (12.04%) -Time: 22.93 seconds, Memory: 40.00MB +Time: 18.02 seconds, Memory: 22.00MB -OK (77 tests, 0 assertions) +OK (60 tests, 0 assertions) ``` [![asciicast](https://asciinema.org/a/98078.png)](https://asciinema.org/a/98078) diff --git a/.phpcs.xml.dist b/.phpcs.xml.dist index 4bb6850731..84af17ae8a 100644 --- a/.phpcs.xml.dist +++ b/.phpcs.xml.dist @@ -7,11 +7,7 @@ - - /Test/AllTests.php - /Test/Standards/*.php /bin/class-ruleset-test.php - */vendor/* diff --git a/.travis.yml b/.travis.yml index 18cc71e459..e22e12dc6c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -65,7 +65,7 @@ script: # Lint the PHP files against parse errors. - if [[ "$LINT" == "1" ]]; then if find . -path ./vendor -prune -o -path ./bin -prune -o -name "*.php" -exec php -l {} \; | grep "^[Parse error|Fatal error]"; then exit 1; fi; fi # Run the unit tests. - - phpunit --filter WordPress $(pwd)/vendor/squizlabs/php_codesniffer/tests/AllTests.php + - phpunit --filter WordPress --bootstrap="$(pwd)/vendor/squizlabs/php_codesniffer/tests/bootstrap.php" $(pwd)/vendor/squizlabs/php_codesniffer/tests/AllTests.php # Test for fixer conflicts by running the auto-fixers of the complete WPCS over the test case files. # This is not an exhaustive test, but should give an early indication for typical fixer conflicts. # For the first run, the exit code will be 1 (= all fixable errors fixed). diff --git a/Test/AllTests.php b/Test/AllTests.php deleted file mode 100644 index de70f8ee19..0000000000 --- a/Test/AllTests.php +++ /dev/null @@ -1,72 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/* Start of WPCS adjustment */ -namespace WordPressCS\Test; - -use WordPressCS\Test\AllSniffs; -use PHP_CodeSniffer_AllTests; -use PHP_CodeSniffer_TestSuite; -/* End of WPCS adjustment */ - -/** - * A test class for running all PHP_CodeSniffer unit tests. - * - * Usage: phpunit AllTests.php - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class AllTests extends PHP_CodeSniffer_AllTests { - - /** - * Add all PHP_CodeSniffer test suites into a single test suite. - * - * @return PHPUnit_Framework_TestSuite - */ - public static function suite() - { - $GLOBALS['PHP_CODESNIFFER_STANDARD_DIRS'] = array(); - - // Use a special PHP_CodeSniffer test suite so that we can - // unset our autoload function after the run. - $suite = new PHP_CodeSniffer_TestSuite('PHP CodeSniffer'); - - /* Start of WPCS adjustment */ - // We need to point to the WPCS version of the referenced class - // and we may as well bypass the loading of the PHPCS core unit tests - // while we're at it too. - $suite->addTest(AllSniffs::suite()); - /* End of WPCS adjustment */ - - // Unregister this here because the PEAR tester loads - // all package suites before running then, so our autoloader - // will cause problems for the packages included after us. - spl_autoload_unregister(array('PHP_CodeSniffer', 'autoload')); - - return $suite; - - }//end suite() - - -}//end class diff --git a/Test/Standards/AbstractSniffUnitTest.php b/Test/Standards/AbstractSniffUnitTest.php deleted file mode 100644 index b92b81386d..0000000000 --- a/Test/Standards/AbstractSniffUnitTest.php +++ /dev/null @@ -1,460 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/* Start of WPCS adjustment */ -namespace WordPressCS\Test; - -use PHP_CodeSniffer; -use PHP_CodeSniffer_File; -use PHP_CodeSniffer_Exception; -use PHPUnit_Framework_TestCase; -use DirectoryIterator; -/* End of WPCS adjustment */ - -/** - * An abstract class that all sniff unit tests must extend. - * - * A sniff unit test checks a .inc file for expected violations of a single - * coding standard. Expected errors and warnings that are not found, or - * warnings and errors that are not expected, are considered test failures. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -abstract class AbstractSniffUnitTest extends PHPUnit_Framework_TestCase { - - /** - * Enable or disable the backup and restoration of the $GLOBALS array. - * Overwrite this attribute in a child class of TestCase. - * Setting this attribute in setUp() has no effect! - * - * @var boolean - */ - protected $backupGlobals = false; - - /** - * The PHP_CodeSniffer object used for testing. - * - * @var PHP_CodeSniffer - */ - protected static $phpcs = null; - - /** - * The path to the directory under which the sniff's standard lives. - * - * @var string - */ - public $standardsDir = null; - - - /** - * Sets up this unit test. - * - * @return void - */ - protected function setUp() - { - if (self::$phpcs === null) { - self::$phpcs = new PHP_CodeSniffer(); - } - - $class = \get_class($this); - $this->standardsDir = $GLOBALS['PHP_CODESNIFFER_STANDARD_DIRS'][$class]; - - }//end setUp() - - - /** - * Get a list of all test files to check. - * - * These will have the same base as the sniff name but different extensions. - * We ignore the .php file as it is the class. - * - * @param string $testFileBase The base path that the unit tests files will have. - * - * @return string[] - */ - protected function getTestFiles($testFileBase) - { - $testFiles = array(); - - $dir = substr($testFileBase, 0, strrpos($testFileBase, \DIRECTORY_SEPARATOR)); - $di = new DirectoryIterator($dir); - - foreach ($di as $file) { - $path = $file->getPathname(); - if (substr($path, 0, \strlen($testFileBase)) === $testFileBase) { - - /* Start of WPCS adjustment */ - // If we're changing things anyway, we may as well exclude backup files - // from the test runs ;-) - if ($path !== $testFileBase.'php' && substr($path, -5) !== 'fixed' - && substr($path, -3) !== 'bak' && substr($path, -4) !== 'orig' - ) { - $testFiles[] = $path; - } - /* End of WPCS adjustment */ - } - } - - // Put them in order. - sort($testFiles); - - return $testFiles; - - }//end getTestFiles() - - - /** - * Should this test be skipped for some reason. - * - * @return void - */ - protected function shouldSkipTest() - { - return false; - - }//end shouldSkipTest() - - - /** - * Tests the extending classes Sniff class. - * - * @return void - * @throws PHPUnit_Framework_Error - */ - public final function testSniff() - { - // Skip this test if we can't run in this environment. - if ($this->shouldSkipTest() === true) { - $this->markTestSkipped(); - } - - // The basis for determining file locations. - $basename = substr(\get_class($this), 0, -8); - - /* Start of WPCS adjustment */ - // Support the use of PHP namespaces. - if (strpos($basename, '\\') !== false) { - $basename = str_replace('\\', '_', $basename); - } - /* End of WPCS adjustment */ - - // The name of the coding standard we are testing. - $standardName = substr($basename, 0, strpos($basename, '_')); - - // The code of the sniff we are testing. - $parts = explode('_', $basename); - $sniffCode = $parts[0].'.'.$parts[2].'.'.$parts[3]; - - $testFileBase = $this->standardsDir.\DIRECTORY_SEPARATOR.str_replace('_', \DIRECTORY_SEPARATOR, $basename).'UnitTest.'; - - // Get a list of all test files to check. - $testFiles = $this->getTestFiles($testFileBase); - - self::$phpcs->initStandard($standardName, array($sniffCode)); - self::$phpcs->setIgnorePatterns(array()); - - $failureMessages = array(); - foreach ($testFiles as $testFile) { - $filename = basename($testFile); - - try { - $cliValues = $this->getCliValues($filename); - self::$phpcs->cli->setCommandLineValues($cliValues); - $phpcsFile = self::$phpcs->processFile($testFile); - } catch (\Exception $e) { - $this->fail('An unexpected exception has been caught: '.$e->getMessage()); - } - - $failures = $this->generateFailureMessages($phpcsFile); - $failureMessages = array_merge($failureMessages, $failures); - - if ($phpcsFile->getFixableCount() > 0) { - // Attempt to fix the errors. - $phpcsFile->fixer->fixFile(); - $fixable = $phpcsFile->getFixableCount(); - if ($fixable > 0) { - $failureMessages[] = "Failed to fix $fixable fixable violations in $filename"; - } - - // Check for a .fixed file to check for accuracy of fixes. - $fixedFile = $testFile.'.fixed'; - if (file_exists($fixedFile) === true) { - $diff = $phpcsFile->fixer->generateDiff($fixedFile); - if (trim($diff) !== '') { - $filename = basename($testFile); - $fixedFilename = basename($fixedFile); - $failureMessages[] = "Fixed version of $filename does not match expected version in $fixedFilename; the diff is\n$diff"; - } - } - } - }//end foreach - - if (empty($failureMessages) === false) { - $this->fail(implode(\PHP_EOL, $failureMessages)); - } - - }//end runTest() - - - /** - * Generate a list of test failures for a given sniffed file. - * - * @param PHP_CodeSniffer_File $file The file being tested. - * - * @return array - * @throws PHP_CodeSniffer_Exception - */ - public function generateFailureMessages(PHP_CodeSniffer_File $file) - { - $testFile = $file->getFilename(); - - $foundErrors = $file->getErrors(); - $foundWarnings = $file->getWarnings(); - $expectedErrors = $this->getErrorList(basename($testFile)); - $expectedWarnings = $this->getWarningList(basename($testFile)); - - if (\is_array($expectedErrors) === false) { - throw new PHP_CodeSniffer_Exception('getErrorList() must return an array'); - } - - if (\is_array($expectedWarnings) === false) { - throw new PHP_CodeSniffer_Exception('getWarningList() must return an array'); - } - - /* - We merge errors and warnings together to make it easier - to iterate over them and produce the errors string. In this way, - we can report on errors and warnings in the same line even though - it's not really structured to allow that. - */ - - $allProblems = array(); - $failureMessages = array(); - - foreach ($foundErrors as $line => $lineErrors) { - foreach ($lineErrors as $column => $errors) { - if (isset($allProblems[$line]) === false) { - $allProblems[$line] = array( - 'expected_errors' => 0, - 'expected_warnings' => 0, - 'found_errors' => array(), - 'found_warnings' => array(), - ); - } - - $foundErrorsTemp = array(); - foreach ($allProblems[$line]['found_errors'] as $foundError) { - $foundErrorsTemp[] = $foundError; - } - - $errorsTemp = array(); - foreach ($errors as $foundError) { - $errorsTemp[] = $foundError['message'].' ('.$foundError['source'].')'; - - $source = $foundError['source']; - if (\in_array($source, $GLOBALS['PHP_CODESNIFFER_SNIFF_CODES']) === false) { - $GLOBALS['PHP_CODESNIFFER_SNIFF_CODES'][] = $source; - } - - if ($foundError['fixable'] === true - && \in_array($source, $GLOBALS['PHP_CODESNIFFER_FIXABLE_CODES']) === false - ) { - $GLOBALS['PHP_CODESNIFFER_FIXABLE_CODES'][] = $source; - } - } - - $allProblems[$line]['found_errors'] = array_merge($foundErrorsTemp, $errorsTemp); - }//end foreach - - if (isset($expectedErrors[$line]) === true) { - $allProblems[$line]['expected_errors'] = $expectedErrors[$line]; - } else { - $allProblems[$line]['expected_errors'] = 0; - } - - unset($expectedErrors[$line]); - }//end foreach - - foreach ($expectedErrors as $line => $numErrors) { - if (isset($allProblems[$line]) === false) { - $allProblems[$line] = array( - 'expected_errors' => 0, - 'expected_warnings' => 0, - 'found_errors' => array(), - 'found_warnings' => array(), - ); - } - - $allProblems[$line]['expected_errors'] = $numErrors; - } - - foreach ($foundWarnings as $line => $lineWarnings) { - foreach ($lineWarnings as $column => $warnings) { - if (isset($allProblems[$line]) === false) { - $allProblems[$line] = array( - 'expected_errors' => 0, - 'expected_warnings' => 0, - 'found_errors' => array(), - 'found_warnings' => array(), - ); - } - - $foundWarningsTemp = array(); - foreach ($allProblems[$line]['found_warnings'] as $foundWarning) { - $foundWarningsTemp[] = $foundWarning; - } - - $warningsTemp = array(); - foreach ($warnings as $warning) { - $warningsTemp[] = $warning['message'].' ('.$warning['source'].')'; - } - - $allProblems[$line]['found_warnings'] = array_merge($foundWarningsTemp, $warningsTemp); - }//end foreach - - if (isset($expectedWarnings[$line]) === true) { - $allProblems[$line]['expected_warnings'] = $expectedWarnings[$line]; - } else { - $allProblems[$line]['expected_warnings'] = 0; - } - - unset($expectedWarnings[$line]); - }//end foreach - - foreach ($expectedWarnings as $line => $numWarnings) { - if (isset($allProblems[$line]) === false) { - $allProblems[$line] = array( - 'expected_errors' => 0, - 'expected_warnings' => 0, - 'found_errors' => array(), - 'found_warnings' => array(), - ); - } - - $allProblems[$line]['expected_warnings'] = $numWarnings; - } - - // Order the messages by line number. - ksort($allProblems); - - foreach ($allProblems as $line => $problems) { - $numErrors = \count($problems['found_errors']); - $numWarnings = \count($problems['found_warnings']); - $expectedErrors = $problems['expected_errors']; - $expectedWarnings = $problems['expected_warnings']; - - $errors = ''; - $foundString = ''; - - if ($expectedErrors !== $numErrors || $expectedWarnings !== $numWarnings) { - $lineMessage = "[LINE $line]"; - $expectedMessage = 'Expected '; - $foundMessage = 'in '.basename($testFile).' but found '; - - if ($expectedErrors !== $numErrors) { - $expectedMessage .= "$expectedErrors error(s)"; - $foundMessage .= "$numErrors error(s)"; - if ($numErrors !== 0) { - $foundString .= 'error(s)'; - $errors .= implode(\PHP_EOL.' -> ', $problems['found_errors']); - } - - if ($expectedWarnings !== $numWarnings) { - $expectedMessage .= ' and '; - $foundMessage .= ' and '; - if ($numWarnings !== 0) { - if ($foundString !== '') { - $foundString .= ' and '; - } - } - } - } - - if ($expectedWarnings !== $numWarnings) { - $expectedMessage .= "$expectedWarnings warning(s)"; - $foundMessage .= "$numWarnings warning(s)"; - if ($numWarnings !== 0) { - $foundString .= 'warning(s)'; - if (empty($errors) === false) { - $errors .= \PHP_EOL.' -> '; - } - - $errors .= implode(\PHP_EOL.' -> ', $problems['found_warnings']); - } - } - - $fullMessage = "$lineMessage $expectedMessage $foundMessage."; - if ($errors !== '') { - $fullMessage .= " The $foundString found were:".\PHP_EOL." -> $errors"; - } - - $failureMessages[] = $fullMessage; - }//end if - }//end foreach - - return $failureMessages; - - }//end generateFailureMessages() - - - /** - * Get a list of CLI values to set before the file is tested. - * - * @param string $filename The name of the file being tested. - * - * @return array - */ - public function getCliValues($filename) - { - return array(); - - }//end getCliValues() - - - /** - * Returns the lines where errors should occur. - * - * The key of the array should represent the line number and the value - * should represent the number of errors that should occur on that line. - * - * @return array(int => int) - */ - protected abstract function getErrorList(); - - - /** - * Returns the lines where warnings should occur. - * - * The key of the array should represent the line number and the value - * should represent the number of warnings that should occur on that line. - * - * @return array(int => int) - */ - protected abstract function getWarningList(); - - -}//end class diff --git a/Test/Standards/AllSniffs.php b/Test/Standards/AllSniffs.php deleted file mode 100644 index c3768adfca..0000000000 --- a/Test/Standards/AllSniffs.php +++ /dev/null @@ -1,157 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/* Start of WPCS adjustment */ -namespace WordPressCS\Test; - -use PHP_CodeSniffer_Standards_AllSniffs; -use PHP_CodeSniffer; -use PHPUnit_Framework_TestSuite; -use RecursiveIteratorIterator; -use RecursiveDirectoryIterator; -/* End of WPCS adjustment */ - -/** - * A test class for testing all sniffs for installed standards. - * - * Usage: phpunit AllSniffs.php - * - * This test class loads all unit tests for all installed standards into a - * single test suite and runs them. Errors are reported on the command line. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class AllSniffs extends PHP_CodeSniffer_Standards_AllSniffs -{ - - /** - * Add all sniff unit tests into a test suite. - * - * Sniff unit tests are found by recursing through the 'Tests' directory - * of each installed coding standard. - * - * @return PHPUnit_Framework_TestSuite - */ - public static function suite() - { - $suite = new PHPUnit_Framework_TestSuite('PHP CodeSniffer Standards'); - - /* Start of WPCS adjustment */ - // Set the correct path to PHPCS. - $isInstalled = !is_file(\PHPCS_DIR.'/CodeSniffer.php'); - /* End of WPCS adjustment */ - - // Optionally allow for ignoring the tests for one or more standards. - $ignoreTestsForStandards = getenv('PHPCS_IGNORE_TESTS'); - if ($ignoreTestsForStandards === false) { - $ignoreTestsForStandards = array(); - } else { - $ignoreTestsForStandards = explode(',', $ignoreTestsForStandards); - } - - $installedPaths = PHP_CodeSniffer::getInstalledStandardPaths(); - foreach ($installedPaths as $path) { - $path = realpath($path); - $origPath = $path; - $standards = PHP_CodeSniffer::getInstalledStandards(true, $path); - - // If the test is running PEAR installed, the built-in standards - // are split into different directories; one for the sniffs and - // a different file system location for tests. - if ($isInstalled === true - && is_dir($path.\DIRECTORY_SEPARATOR.'Generic') === true - ) { - $path = dirname(__FILE__); - } - - foreach ($standards as $standard) { - if (\in_array($standard, $ignoreTestsForStandards, true)) { - continue; - } - - $testsDir = $path.\DIRECTORY_SEPARATOR.$standard.\DIRECTORY_SEPARATOR.'Tests'.\DIRECTORY_SEPARATOR; - - if (is_dir($testsDir) === false) { - // No tests for this standard. - continue; - } - - $di = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($testsDir)); - - foreach ($di as $file) { - // Skip hidden files. - if (substr($file->getFilename(), 0, 1) === '.') { - continue; - } - - // Tests must have the extension 'php'. - $parts = explode('.', $file); - $ext = array_pop($parts); - if ($ext !== 'php') { - continue; - } - - $filePath = $file->getPathname(); - $className = str_replace($path.\DIRECTORY_SEPARATOR, '', $filePath); - $className = substr($className, 0, -4); - $className = str_replace(\DIRECTORY_SEPARATOR, '_', $className); - - // Include the sniff here so tests can use it in their setup() methods. - $parts = explode('_', $className); - if (isset($parts[0],$parts[2],$parts[3]) === true) { - $sniffPath = $origPath.\DIRECTORY_SEPARATOR.$parts[0].\DIRECTORY_SEPARATOR.'Sniffs'.\DIRECTORY_SEPARATOR.$parts[2].\DIRECTORY_SEPARATOR.$parts[3]; - $sniffPath = substr($sniffPath, 0, -8).'Sniff.php'; - - if (file_exists($sniffPath) === true) { - include_once $sniffPath; - include_once $filePath; - - /* Start of WPCS adjustment */ - // Support the use of PHP namespaces. If the class name we included - // contains namespace separators instead of underscores, use this as the - // class name from now on. - $classNameNS = str_replace('_', '\\', $className); - if (class_exists($classNameNS, false) === true) { - $className = $classNameNS; - } - /* End of WPCS adjustment */ - - $GLOBALS['PHP_CODESNIFFER_STANDARD_DIRS'][$className] = $path; - $suite->addTestSuite($className); - } else { - self::$orphanedTests[] = $filePath; - } - } else { - self::$orphanedTests[] = $filePath; - } - }//end foreach - }//end foreach - }//end foreach - - return $suite; - - }//end suite() - - -}//end class diff --git a/Test/bootstrap.php b/Test/bootstrap.php deleted file mode 100644 index 996c887ce3..0000000000 --- a/Test/bootstrap.php +++ /dev/null @@ -1,42 +0,0 @@ -