From b887116e5ce9a69403ad620cad20f0a029474eb5 Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Mon, 20 Mar 2023 17:34:42 +0000 Subject: [PATCH] fix: `Pest.php` file not loaded in certain environments --- bin/pest | 3 +- bin/worker.php | 3 +- src/ConfigLoader.php | 113 ------------------------------------ tests/Unit/ConfigLoader.php | 19 ------ tests/Visual/Parallel.php | 2 +- 5 files changed, 3 insertions(+), 137 deletions(-) delete mode 100644 src/ConfigLoader.php delete mode 100644 tests/Unit/ConfigLoader.php diff --git a/bin/pest b/bin/pest index 8de2b9de..f480581f 100755 --- a/bin/pest +++ b/bin/pest @@ -1,7 +1,6 @@ #!/usr/bin/env php getParameterOption('--test-directory', (new ConfigLoader($rootPath))->getTestsDirectory()), + $input->getParameterOption('--test-directory', 'tests'), ); if ($dirty) { diff --git a/bin/worker.php b/bin/worker.php index 9fa983c7..f3b6b7b3 100644 --- a/bin/worker.php +++ b/bin/worker.php @@ -4,7 +4,6 @@ declare(strict_types=1); use ParaTest\WrapperRunner\ApplicationForWrapperWorker; use ParaTest\WrapperRunner\WrapperWorker; -use Pest\ConfigLoader; use Pest\Kernel; use Pest\Plugins\Actions\CallsHandleArguments; use Pest\TestSuite; @@ -18,7 +17,7 @@ $bootPest = (static function (): void { $rootPath = dirname(PHPUNIT_COMPOSER_INSTALL, 2); $testSuite = TestSuite::getInstance($rootPath, $workerArgv->getParameterOption( '--test-directory', - (new ConfigLoader($rootPath))->getTestsDirectory() + 'tests' )); $input = new ArgvInput(); diff --git a/src/ConfigLoader.php b/src/ConfigLoader.php deleted file mode 100644 index 870003c1..00000000 --- a/src/ConfigLoader.php +++ /dev/null @@ -1,113 +0,0 @@ -loadConfiguration(); - } - - /** - * Get the tests directory or fallback to default path. - */ - public function getTestsDirectory(): string - { - $suiteDirectory = []; - if (is_null($this->config)) { - return self::DEFAULT_TESTS_PATH; - } - - $suiteDirectory = $this->config->xpath('/phpunit/testsuites/testsuite/directory'); - - if ($suiteDirectory === []) { - return self::DEFAULT_TESTS_PATH; - } - - $directory = (string) ($suiteDirectory[0] ?? ''); - - if ($directory === '') { - return self::DEFAULT_TESTS_PATH; - } - - // Return the whole directory if only a separator found (e.g. `./tests`) - if (substr_count($directory, DIRECTORY_SEPARATOR) === 1) { - return is_dir($directory) ? $directory : self::DEFAULT_TESTS_PATH; - } - - $basePath = Str::beforeLast($directory, DIRECTORY_SEPARATOR); - - return is_dir($basePath) ? $basePath : self::DEFAULT_TESTS_PATH; - } - - /** - * Get the configuration file path. - */ - public function getConfigurationFilePath(): string|bool - { - $candidates = [ - $this->rootPath.'/phpunit.xml', - $this->rootPath.'/phpunit.dist.xml', - $this->rootPath.'/phpunit.xml.dist', - ]; - - foreach ($candidates as $candidate) { - if (is_file($candidate)) { - return realpath($candidate); - } - } - - return false; - } - - /** - * Load the configuration file. - */ - private function loadConfiguration(): void - { - $configPath = $this->getConfigurationFilePath(); - - if (is_bool($configPath)) { - return; - } - - $oldReportingLevel = error_reporting(0); - $content = file_get_contents($configPath); - - if ($content !== false) { - try { - $this->config = new SimpleXMLElement($content); - } catch (Throwable) { // @phpstan-ignore-line - // @ignoreException - } - } - - // Restore the correct error reporting - error_reporting($oldReportingLevel); - } -} diff --git a/tests/Unit/ConfigLoader.php b/tests/Unit/ConfigLoader.php deleted file mode 100644 index cae011ba..00000000 --- a/tests/Unit/ConfigLoader.php +++ /dev/null @@ -1,19 +0,0 @@ -toBeNull(); - expect($instance->getConfigurationFilePath())->toBeFalse(); - expect($instance->getTestsDirectory())->toBe(ConfigLoader::DEFAULT_TESTS_PATH); -}); - -it('fallbacks to default path if phpunit is not a valid XML')->skip(); -it('fallbacks to default path if failing to read phpunit content')->skip(); -it('fallbacks to default path if there is no test suites directory')->skip(); -it('fallbacks to default path if test suite directory has no value')->skip(); -it('fallbacks to default path if test suite directory does not exist')->skip(); -it('returns the parent folder of first test suite directory')->skip(); diff --git a/tests/Visual/Parallel.php b/tests/Visual/Parallel.php index d985d69f..484da13b 100644 --- a/tests/Visual/Parallel.php +++ b/tests/Visual/Parallel.php @@ -15,6 +15,6 @@ $run = function () { }; test('parallel', function () use ($run) { - expect($run())->toContain('Tests: 2 deprecated, 3 warnings, 4 incomplete, 1 notice, 4 todos, 15 skipped, 641 passed (1579 assertions)') + expect($run())->toContain('Tests: 2 deprecated, 3 warnings, 4 incomplete, 1 notice, 4 todos, 9 skipped, 640 passed (1576 assertions)') ->toContain('Parallel: 3 processes'); })->skip(PHP_OS_FAMILY === 'Windows');