Compare commits

..

12 Commits

10 changed files with 49 additions and 34 deletions

View File

@ -2,6 +2,13 @@
## Unreleased
## [v2.2.3 (2023-03-24)](https://github.com/pestphp/pest/compare/v2.2.2...v2.2.3)
### Fixed
- Unnecessary dataset on dataset arguments missmatch ([#736](https://github.com/pestphp/pest/pull/736))
- Parallel arguments on plugins order ([#703](https://github.com/pestphp/pest/pull/703))
- Arch plugin runtime exceptions on bad phpdocs ([2f2b51c](https://github.com/pestphp/pest/commit/2f2b51ce3d1b000be9d6add0e785fd0044931b3b))
## [v2.2.2 (2023-03-23)](https://github.com/pestphp/pest/compare/v2.2.1...v2.2.2)
### Fixed

View File

@ -21,8 +21,8 @@
"brianium/paratest": "^7.1.2",
"nunomaduro/collision": "^7.3.3",
"nunomaduro/termwind": "^1.15.1",
"pestphp/pest-plugin": "^2.0.0",
"pestphp/pest-plugin-arch": "^2.0.1",
"pestphp/pest-plugin": "^2.0.1",
"pestphp/pest-plugin-arch": "^2.0.2",
"phpunit/phpunit": "^10.0.18"
},
"conflict": {

View File

@ -2,7 +2,7 @@ ARG PHP=8.1
FROM php:${PHP}-cli-alpine
RUN apk update \
&& apk add zip libzip-dev icu-dev
&& apk add zip libzip-dev icu-dev git
RUN docker-php-ext-configure zip
RUN docker-php-ext-install zip

View File

@ -241,7 +241,7 @@ trait Testable
continue;
}
if (in_array($testParameterTypes[$argumentIndex], [\Closure::class, 'callable', 'mixed'])) {
if (in_array($testParameterTypes[$argumentIndex], [Closure::class, 'callable', 'mixed'])) {
continue;
}
@ -255,7 +255,7 @@ trait Testable
return $arguments;
}
if (in_array($testParameterTypes[0], [\Closure::class, 'callable'])) {
if (in_array($testParameterTypes[0], [Closure::class, 'callable'])) {
return $arguments;
}
@ -291,7 +291,7 @@ trait Testable
return;
}
throw new DatasetArgsCountMismatch($this->dataName(), $requiredParametersCount, $suppliedParametersCount);
throw new DatasetArgsCountMismatch($requiredParametersCount, $suppliedParametersCount);
}
/**

View File

@ -10,7 +10,7 @@ namespace Pest\Contracts\Plugins;
interface HandlesArguments
{
/**
* Adds arguments before of the Test Suite execution.
* Adds arguments before the Test Suite execution.
*
* @param array<int, string> $arguments
* @return array<int, string>

View File

@ -8,8 +8,8 @@ use Exception;
final class DatasetArgsCountMismatch extends Exception
{
public function __construct(string $dataName, int $requiredCount, int $suppliedCount)
public function __construct(int $requiredCount, int $suppliedCount)
{
parent::__construct(sprintf('Test expects %d arguments but dataset [%s] only provides %d', $requiredCount, $dataName, $suppliedCount));
parent::__construct(sprintf('Test expects %d arguments but dataset only provides %d', $requiredCount, $suppliedCount));
}
}

View File

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

View File

@ -14,15 +14,16 @@ use Pest\Support\Arr;
use Pest\Support\Container;
use Pest\TestSuite;
use function Pest\version;
use Stringable;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Console\Output\OutputInterface;
final class Parallel implements HandlesArguments
{
use HandleArguments;
private const GLOBAL_PREFIX = 'PEST_PARALLEL_GLOBAL_';
private const HANDLERS = [
Parallel\Handlers\Parallel::class,
Parallel\Handlers\Pest::class,
@ -59,6 +60,33 @@ final class Parallel implements HandlesArguments
return ((int) $argvValue) === 1;
}
/**
* Sets a global value that can be accessed by the parent process and all workers.
*/
public static function setGlobal(string $key, string|int|bool|Stringable $value): void
{
$data = ['value' => $value instanceof Stringable ? $value->__toString() : $value];
$_ENV[self::GLOBAL_PREFIX.$key] = json_encode($data, JSON_THROW_ON_ERROR);
}
/**
* Returns the given global value if one has been set.
*/
public static function getGlobal(string $key): string|int|bool|null
{
$placesToCheck = [$_SERVER, $_ENV];
foreach ($placesToCheck as $location) {
if (array_key_exists(self::GLOBAL_PREFIX.$key, $location)) {
// @phpstan-ignore-next-line
return json_decode((string) $location[self::GLOBAL_PREFIX.$key], true, 512, JSON_THROW_ON_ERROR)['value'] ?? null;
}
}
return null;
}
/**
* {@inheritdoc}
*/
@ -86,12 +114,6 @@ final class Parallel implements HandlesArguments
*/
private function runTestSuiteInParallel(array $arguments): int
{
if (! class_exists(ParaTestCommand::class)) {
$this->askUserToInstallParatest();
return Command::FAILURE;
}
$handlers = array_filter(
array_map(fn ($handler): object|string => Container::getInstance()->get($handler), self::HANDLERS),
fn ($handler): bool => $handler instanceof HandlesArguments,
@ -128,20 +150,6 @@ final class Parallel implements HandlesArguments
);
}
/**
* Outputs a message to the user asking them to install ParaTest as a dev dependency.
*/
private function askUserToInstallParatest(): void
{
/** @var OutputInterface $output */
$output = Container::getInstance()->get(OutputInterface::class);
$output->writeln([
'<fg=red>Pest Parallel requires ParaTest to run.</>',
'Please run <fg=yellow>composer require --dev brianium/paratest</>.',
]);
}
/**
* Builds an instance of the Paratest command.
*/

View File

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

View File

@ -1,3 +1,3 @@
Pest Testing Framework 2.2.2.
Pest Testing Framework 2.2.3.