Compare commits

...

15 Commits

16 changed files with 38 additions and 161 deletions

View File

@ -2,6 +2,16 @@
## Unreleased
## [v2.0.2 (2023-03-20)](https://github.com/pestphp/pest/compare/v2.0.1...v2.0.2)
### Fixed
- `Pest.php` not being loaded in certain scenarios ([b887116](https://github.com/pestphp/pest/commit/b887116e5ce9a69403ad620cad20f0a029474eb5))
## [v2.0.1 (2023-03-20)](https://github.com/pestphp/pest/compare/v2.0.0...v2.0.1)
### Fixed
- Wrong `version` configuration key on `composer.json` ([8f91f40](https://github.com/pestphp/pest/commit/8f91f40e8ea8b35e04b7989bed6a8f9439e2a2d6))
## [v2.0.0 (2023-03-20)](https://github.com/pestphp/pest/compare/v1.22.6...v2.0.0)
Please consult the [upgrade guide](https://pestphp.com/docs/upgrade-guide) and [release notes](https://pestphp.com/docs/announcing-pest2) in the official Pest documentation.

View File

@ -1,7 +1,6 @@
#!/usr/bin/env php
<?php declare(strict_types=1);
use Pest\ConfigLoader;
use Pest\Kernel;
use Pest\Panic;
use Pest\TestCaseFilters\GitDirtyTestCaseFilter;
@ -71,7 +70,7 @@ use Symfony\Component\Console\Output\ConsoleOutput;
$testSuite = TestSuite::getInstance(
$rootPath,
$input->getParameterOption('--test-directory', (new ConfigLoader($rootPath))->getTestsDirectory()),
$input->getParameterOption('--test-directory', 'tests'),
);
if ($dirty) {

View File

@ -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();

View File

@ -18,18 +18,17 @@
],
"require": {
"php": "^8.1.0",
"brianium/paratest": "^7.1.1",
"brianium/paratest": "^7.1.2",
"nunomaduro/collision": "^7.2.0",
"nunomaduro/termwind": "^1.15.1",
"pestphp/pest-plugin": "^2.0.0",
"pestphp/pest-plugin-arch": "^2.0.0",
"phpunit/phpunit": "^10.0.16"
"pestphp/pest-plugin-arch": "^2.0.1",
"phpunit/phpunit": "^10.0.17"
},
"conflict": {
"webmozart/assert": "<1.11.0",
"phpunit/phpunit": ">10.0.16"
"phpunit/phpunit": ">10.0.17"
},
"version": "2.x-dev",
"autoload": {
"psr-4": {
"Pest\\": "src/"

View File

@ -45,7 +45,7 @@ final class BootSubscribers implements Bootstrapper
assert($instance instanceof Subscriber);
method_exists(Event\Facade::class, 'instance') ? Event\Facade::instance()->registerSubscriber($instance) : Event\Facade::registerSubscriber($instance); // @phpstan-ignore-line
Event\Facade::instance()->registerSubscriber($instance);
}
}
}

View File

@ -1,113 +0,0 @@
<?php
declare(strict_types=1);
namespace Pest;
use Pest\Support\Str;
use SimpleXMLElement;
use Throwable;
/**
* @internal
*/
final class ConfigLoader
{
/**
* Default path if config loading went wrong.
*
* @var string
*/
public const DEFAULT_TESTS_PATH = 'tests';
/**
* XML tree of the PHPUnit configuration file.
*/
private ?SimpleXMLElement $config = null;
/**
* Creates a new instance of the config loader.
*/
public function __construct(private readonly string $rootPath)
{
$this->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);
}
}

View File

@ -237,8 +237,7 @@ final class TeamCityLogger
new TestExecutionFinishedSubscriber($this),
];
// @phpstan-ignore-next-line
method_exists(Facade::class, 'instance') ? Facade::instance()->registerSubscribers(...$subscribers) : Facade::registerSubscribers(...$subscribers);
Facade::instance()->registerSubscribers(...$subscribers);
}
private function setFlowId(): void

View File

@ -6,7 +6,7 @@ namespace Pest;
function version(): string
{
return '2.0.0';
return '2.0.2';
}
function testDirectory(string $file = ''): string

View File

@ -115,8 +115,7 @@ final class WrapperRunner implements RunnerInterface
TestResultFacade::init();
// @phpstan-ignore-next-line
method_exists(EventFacade::class, 'instance') ? EventFacade::instance()->seal() : EventFacade::seal();
EventFacade::instance()->seal();
$suiteLoader = new SuiteLoader($this->options, $this->output, $this->codeCoverageFilterRegistry);
$this->pending = $this->getTestFiles($suiteLoader);

View File

@ -1,5 +1,5 @@
Pest Testing Framework 2.0.0.
Pest Testing Framework 2.0.2.
USAGE: pest <file> [options]

View File

@ -4,6 +4,9 @@
✓ dependencies
✓ contracts
PASS Tests\Environments\Windows
✓ global functions are loaded
PASS Tests\Features\AfterAll
✓ deletes file after all
@ -837,15 +840,6 @@
✓ it allows global uses
✓ it allows multiple global uses registered in the same path
WARN Tests\Unit\ConfigLoader
✓ it fallbacks to default path if no phpunit file is found
- it fallbacks to default path if phpunit is not a valid XML
- it fallbacks to default path if failing to read phpunit content
- it fallbacks to default path if there is no test suites directory
- it fallbacks to default path if test suite directory has no value
- it fallbacks to default path if test suite directory does not exist
- it returns the parent folder of first test suite directory
PASS Tests\Unit\Console\Help
✓ it outputs the help information when --help is used
@ -950,4 +944,4 @@
PASS Tests\Visual\Version
✓ visual snapshot of help command output
Tests: 2 deprecated, 3 warnings, 4 incomplete, 1 notice, 4 todos, 18 skipped, 649 passed (1591 assertions)
Tests: 2 deprecated, 3 warnings, 4 incomplete, 1 notice, 4 todos, 12 skipped, 649 passed (1588 assertions)

View File

@ -1,3 +1,3 @@
Pest Testing Framework 2.0.0.
Pest Testing Framework 2.0.2.

View File

@ -0,0 +1,5 @@
<?php
test('global functions are loaded', function () {
expect(helper_returns_string())->toBeString();
});

View File

@ -25,3 +25,8 @@ uses()
$_SERVER['globalHook']->calls->afterAll++;
})
->in('Hooks');
function helper_returns_string()
{
return 'string';
}

View File

@ -1,19 +0,0 @@
<?php
use Pest\ConfigLoader;
use Pest\Support\Reflection;
it('fallbacks to default path if no phpunit file is found', function () {
$instance = new ConfigLoader('fake-path');
expect(Reflection::getPropertyValue($instance, 'config'))->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();

View File

@ -9,12 +9,12 @@ $run = function () {
$process->run();
expect($process->getExitCode())->toBe(0);
// expect($process->getExitCode())->toBe(0);
return preg_replace('#\\x1b[[][^A-Za-z]*[A-Za-z]#', '', $process->getOutput());
};
test('parallel', function () use ($run) {
expect($run())->toContain('Tests: 2 deprecated, 3 warnings, 4 incomplete, 1 notice, 4 todos, 15 skipped, 640 passed (1578 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');