diff --git a/src/Runners/PHPUnit/SuiteLoader.php b/src/Runners/PHPUnit/SuiteLoader.php index cd55f36e..8be00321 100644 --- a/src/Runners/PHPUnit/SuiteLoader.php +++ b/src/Runners/PHPUnit/SuiteLoader.php @@ -111,10 +111,9 @@ public function load(string $path = ''): void $this->loadConfiguration(); if ($path !== '') { - $testFileLoader = new TestFileLoader($this->options); - $this->files = array_merge( + $this->files = array_merge( $this->files, - $testFileLoader->loadPath($path) + (new Facade())->getFilesAsArray($path, ['Test.php']) ); } elseif ( isset($this->options->parallelSuite) diff --git a/src/Runners/PHPUnit/TestFileLoader.php b/src/Runners/PHPUnit/TestFileLoader.php deleted file mode 100644 index 1af8b9ba..00000000 --- a/src/Runners/PHPUnit/TestFileLoader.php +++ /dev/null @@ -1,163 +0,0 @@ - - */ - private $excludedFiles = []; - - /** - * When true, the SuiteLoader add the files to excluded files. - * - * @var bool - */ - private $excludingFiles = false; - - /** @var Options|null */ - private $options; - - public function __construct(?Options $options = null) - { - $this->options = $options; - } - - /** - * Loads a SuitePath and makes sure to - * take into account the excluded directory / files. - * - * @return string[] - */ - public function loadSuitePath(SuitePath $path): array - { - // First initialize the list of files and excluded files - $this->files = []; - $this->excludedFiles = []; - $this->excludingFiles = true; - foreach ($path->getExcludedPaths() as $excludedPath) { - $this->loadPath($excludedPath, $path->getPattern()); - } - - // Load the SuitePath - $this->excludingFiles = false; - $this->loadPath($path->getPath(), $path->getPattern()); - - // Reinitialise the excluded files - $this->excludedFiles = []; - - return $this->files; - } - - /** - * Loads suites based on a specific path. - * A valid path can be a directory or file. - * - * @return string[] - * - * @throws InvalidArgumentException - */ - public function loadPath(string $path, ?string $pattern = null): array - { - $this->files = []; - - $pattern = $pattern ?? self::TEST_PATTERN; - - $path = $path !== '' ? $path : $this->options->path; - - if (! file_exists($path)) { - throw new InvalidArgumentException("$path is not a valid directory or file"); - } - - if (is_dir($path)) { - $this->loadDir($path, $pattern); - } elseif (file_exists($path)) { - $this->loadFile($path); - } - - return $this->files; - } - - /** - * Loads suites from a directory. - */ - private function loadDir(string $path, string $pattern = self::TEST_PATTERN): void - { - $path = realpath($path); - $files = scandir($path); - foreach ($files as $file) { - $this->tryLoadTests($path . DIRECTORY_SEPARATOR . $file, $pattern); - } - } - - /** - * Load a single suite file. - */ - private function loadFile(string $path): void - { - $this->tryLoadTests($path, self::FILE_PATTERN); - } - - /** - * Attempts to load suites from a path. - * - * @param string $pattern regular expression for matching file names - */ - private function tryLoadTests(string $path, string $pattern = self::TEST_PATTERN): void - { - if (preg_match($pattern, $path)) { - if ($this->excludingFiles) { - $this->excludedFiles[$path] = $path; - } elseif (! array_key_exists($path, $this->excludedFiles)) { - $this->files[] = $path; - } - } - - if (preg_match(self::$dotPattern, $path) || ! is_dir($path)) { - return; - } - - $this->loadDir($path, $pattern); - } -} diff --git a/test/Unit/Runners/PHPUnit/SuiteLoaderTest.php b/test/Unit/Runners/PHPUnit/SuiteLoaderTest.php index 541ba5af..783436e3 100644 --- a/test/Unit/Runners/PHPUnit/SuiteLoaderTest.php +++ b/test/Unit/Runners/PHPUnit/SuiteLoaderTest.php @@ -4,7 +4,6 @@ namespace ParaTest\Tests\Unit\Runners\PHPUnit; -use InvalidArgumentException; use ParaTest\Runners\PHPUnit\ExecutableTest; use ParaTest\Runners\PHPUnit\Options; use ParaTest\Runners\PHPUnit\Suite; @@ -35,7 +34,7 @@ public function testOptionsCanBeNull(): void public function testLoadThrowsExceptionWithInvalidPath(): void { - $this->expectException(InvalidArgumentException::class); + $this->expectException(RuntimeException::class); $loader = new SuiteLoader(); $loader->load('/path/to/nowhere'); @@ -200,7 +199,7 @@ public function testLoadSuiteFromConfigWithBadSuitePath(): void public function testLoadFileGetsPathOfFile(): void { - $path = $this->fixture('failing-tests/UnitTestWithClassAnnotationTest.php'); + $path = $this->fixture('failing-tests' . DS . 'UnitTestWithClassAnnotationTest.php'); $paths = $this->getLoadedPaths($path); static::assertEquals($path, array_shift($paths)); } @@ -219,7 +218,7 @@ private function getLoadedPaths(string $path, ?SuiteLoader $loader = null): arra public function testLoadFileShouldLoadFileWhereNameDoesNotEndInTest(): void { - $path = $this->fixture('passing-tests/TestOfUnits.php'); + $path = $this->fixture('passing-tests' . DS . 'TestOfUnits.php'); $paths = $this->getLoadedPaths($path); static::assertEquals($path, array_shift($paths)); } diff --git a/test/Unit/Runners/PHPUnit/TestFileLoaderTest.php b/test/Unit/Runners/PHPUnit/TestFileLoaderTest.php deleted file mode 100644 index 61a9829e..00000000 --- a/test/Unit/Runners/PHPUnit/TestFileLoaderTest.php +++ /dev/null @@ -1,37 +0,0 @@ - 'group1']); - $testFileLoader = new TestFileLoader($options); - static::assertEquals($options, $this->getObjectValue($testFileLoader, 'options')); - } - - public function testOptionsCanBeNull(): void - { - $testFileLoader = new TestFileLoader(); - static::assertNull($this->getObjectValue($testFileLoader, 'options')); - } - - public function testLoadThrowsExceptionWithInvalidPath(): void - { - $this->expectException(InvalidArgumentException::class); - - $testFileLoader = new TestFileLoader(); - $testFileLoader->loadPath('path/to/nowhere'); - } -}