diff --git a/src/unit/engine/PhpunitTestEngine.php b/src/unit/engine/PhpunitTestEngine.php --- a/src/unit/engine/PhpunitTestEngine.php +++ b/src/unit/engine/PhpunitTestEngine.php @@ -129,11 +129,13 @@ substr($file, 0, -4).'Test.php', ); - $search = self::getSearchLocationsForTests($path); + $search = $this->getSearchLocationsForTests($path); foreach ($search as $search_path) { foreach ($possible_files as $possible_file) { + $full_path = $search_path.$possible_file; + if (!Filesystem::pathExists($full_path)) { // If the file doesn't exist, it's clearly a miss. continue; @@ -142,10 +144,12 @@ // Don't look above the project root. continue; } + if (0 == strcasecmp(Filesystem::resolvePath($full_path), $path)) { // Don't return the original file. continue; } + return $full_path; } } @@ -193,11 +197,16 @@ * @param string PHP file to locate test cases for. * @return list List of directories to search for tests in. */ - public static function getSearchLocationsForTests($path) { + public function getSearchLocationsForTests($path) { $file = basename($path); $dir = dirname($path); - $test_dir_names = array('tests', 'Tests'); + $test_dir_names = $this->getConfigurationManager()->getConfigFromAnySource( + 'phpunit_test_dirs'); + + if (empty($test_dir_names)) { + $test_dir_names = array('tests', 'Tests'); + } $try_directories = array(); diff --git a/src/unit/engine/__tests__/PHPUnitTestEngineTestCase.php b/src/unit/engine/__tests__/PHPUnitTestEngineTestCase.php --- a/src/unit/engine/__tests__/PHPUnitTestEngineTestCase.php +++ b/src/unit/engine/__tests__/PHPUnitTestEngineTestCase.php @@ -8,6 +8,14 @@ public function testSearchLocations() { $path = '/path/to/some/file/X.php'; + $root = dirname(phutil_get_library_root('arcanist')); + $working_copy = ArcanistWorkingCopyIdentity::newFromPath($root); + $configuration_manager = new ArcanistConfigurationManager(); + $configuration_manager->setWorkingCopyIdentity($working_copy); + + $phpunitTestEngine = new PhpunitTestEngine(); + $phpunitTestEngine->setConfigurationManager($configuration_manager); + $this->assertEqual( array( '/path/to/some/file/', @@ -36,7 +44,38 @@ '/tests/path/to/some/file/', '/Tests/path/to/some/file/', ), - PhpunitTestEngine::getSearchLocationsForTests($path)); + $phpunitTestEngine->getSearchLocationsForTests($path)); + } + + public function testConfiguredSearchLocations() { + $path = '/path/to/some/file/X.php'; + + $root = dirname(phutil_get_library_root('arcanist')); + $working_copy = ArcanistWorkingCopyIdentity::newFromPath($root); + $configuration_manager = new ArcanistConfigurationManager(); + $configuration_manager->setWorkingCopyIdentity($working_copy); + $configuration_manager->setRuntimeConfig( + 'phpunit_test_dirs', array('tests/Unit')); + $phpunitTestEngine = new PhpunitTestEngine(); + $phpunitTestEngine->setConfigurationManager($configuration_manager); + + $this->assertEqual( + array( + '/path/to/some/file/', + '/path/to/some/file/tests/Unit/', + '/path/to/some/tests/Unit/', + '/path/to/tests/Unit/', + '/path/tests/Unit/', + '/tests/Unit/', + '/path/to/tests/Unit/file/', + '/path/tests/Unit/some/file/', + '/tests/Unit/to/some/file/', + '/path/to/some/tests/Unit/file/', + '/path/to/tests/Unit/some/file/', + '/path/tests/Unit/to/some/file/', + '/tests/Unit/path/to/some/file/', + ), + $phpunitTestEngine->getSearchLocationsForTests($path)); } }