Skip to content

Commit

Permalink
Merge pull request #16 from worksome/feature/pest-3.x
Browse files Browse the repository at this point in the history
feat: add support for Pest 3.x
  • Loading branch information
owenvoke authored Sep 13, 2024
2 parents b77c3bf + f107c33 commit a67ffff
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 21 deletions.
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
"php": "^8.2",
"illuminate/contracts": "^10.0 || ^11.0",
"nuwave/lighthouse": "^6.36",
"pestphp/pest": "^2.34",
"pestphp/pest-plugin-laravel": "^2.3"
"pestphp/pest": "^2.35 || ^3.0",
"pestphp/pest-plugin-laravel": "^2.3 || ^3.0"
},
"require-dev": {
"nunomaduro/collision": "^7.10 || ^8.1",
"nunomaduro/collision": "^7.10 || ^8.4",
"larastan/larastan": "^2.9",
"orchestra/testbench": "^8.22 || ^9.0",
"worksome/coding-style": "^2.10.2"
"orchestra/testbench": "^8.26 || ^9.0",
"worksome/coding-style": "^2.11"
},
"autoload": {
"psr-4": {
Expand Down
6 changes: 3 additions & 3 deletions src/Collector.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ private function __construct()
public static function reset(): void
{
$filePath = self::filePath();

if (! file_exists($filePath)) {
return;
}

unlink($filePath);
}

/**
* @return array<int, string>
*/
/** @return array<int, string> */
public static function parseResult(): array
{
$data = file_get_contents(self::filePath());
Expand Down
2 changes: 1 addition & 1 deletion src/PestGraphqlCoverageServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function register(): void
return;
}

// Check if gql coverage is enabled, either via parallel or non-parallel
// Check if GraphQL coverage is enabled, either via parallel or non-parallel.
if (Plugin::isEnabled()) {
/** @var Repository $config */
$config = $this->app->get(Repository::class);
Expand Down
41 changes: 29 additions & 12 deletions src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Illuminate\Support\Arr;
use Pest\Contracts\Plugins\AddsOutput;
use Pest\Contracts\Plugins\HandlesArguments;
use Pest\Plugins\Concerns\HandleArguments;
use Pest\Plugins\Parallel;
use RuntimeException;
use Symfony\Component\Console\Input\ArrayInput;
Expand All @@ -20,15 +21,14 @@

class Plugin implements AddsOutput, HandlesArguments
{
use HandleArguments;

private const SERVER_VARIABLE_NAME = 'GQL_COVERAGE_ENABLED';

public int $maxUntestedFieldsCount = 10;

public string $schemaCommand = 'php artisan lighthouse:print-schema';

/**
* The minimum coverage.
*/
public float $coverageMin = 0.0;

public function __construct(private readonly OutputInterface $output)
Expand All @@ -42,12 +42,14 @@ public static function isEnabled(): bool

public function handleArguments(array $arguments): array
{
if (! ($coverageIndex = array_search('--gql-coverage', $arguments)) && ! self::isEnabled()) {
$hasOption = $this->hasArgument('--gql-coverage', $arguments);

if (! $hasOption && ! self::isEnabled()) {
return $arguments;
}

if ($coverageIndex) {
unset($arguments[$coverageIndex]);
if ($hasOption) {
$arguments = $this->popArgument('--gql-coverage', $arguments);
}

$this->handleEnablingCoverage($arguments);
Expand All @@ -71,7 +73,7 @@ private function handleEnablingCoverage(array &$arguments): void
private function handleMinCoverage(array &$arguments): void
{
$coverageMinRegex = /** @lang RegExp */
'/^--gql-min=(\d+)$/';
'/^--gql-min=(?<value>\d+)$/';
$min = preg_grep($coverageMinRegex, $arguments);

if ($min === false || count($min) === 0) {
Expand All @@ -81,13 +83,18 @@ private function handleMinCoverage(array &$arguments): void
unset($arguments[array_keys($min)[0]]);

preg_match($coverageMinRegex, array_pop($min), $matches);
$this->coverageMin = (int) $matches[1];

if (! isset($matches['value'])) {
return;
}

$this->coverageMin = (int) $matches['value'];
}

private function handleSchemaCommand(array &$arguments): void
{
$schemaCommandRegex = /** @lang RegExp */
'/^--schema-command=(.*)$/';
'/^--schema-command=(?<value>.*)$/';
$command = preg_grep($schemaCommandRegex, $arguments);

if ($command === false || count($command) === 0) {
Expand All @@ -98,13 +105,17 @@ private function handleSchemaCommand(array &$arguments): void

preg_match($schemaCommandRegex, array_pop($command), $matches);

$this->schemaCommand = $matches[1];
if (! isset($matches['value'])) {
return;
}

$this->schemaCommand = $matches['value'];
}

private function handleMaxUntestedFields(array &$arguments): void
{
$maxUntestedFieldsRegex = /** @lang RegExp */
'/^--gql-untested-count=(.*)$/';
'/^--gql-untested-count=(?<value>.*)$/';
$command = preg_grep($maxUntestedFieldsRegex, $arguments);

if ($command === false || count($command) === 0) {
Expand All @@ -115,7 +126,13 @@ private function handleMaxUntestedFields(array &$arguments): void

preg_match($maxUntestedFieldsRegex, array_pop($command), $matches);

$this->maxUntestedFieldsCount = is_numeric($matches[1]) ? (int) $matches[1] : $this->maxUntestedFieldsCount;
if (! isset($matches['value'])) {
return;
}

$this->maxUntestedFieldsCount = is_numeric($matches['value'])
? (int) $matches['value']
: $this->maxUntestedFieldsCount;
}

public function addOutput(int $exitCode): int
Expand Down

0 comments on commit a67ffff

Please sign in to comment.