Skip to content

Commit

Permalink
feat: add support for Pest 3.x
Browse files Browse the repository at this point in the history
  • Loading branch information
owenvoke committed Sep 9, 2024
1 parent b77c3bf commit b839acb
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 15 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
27 changes: 21 additions & 6 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 Down Expand Up @@ -81,6 +83,11 @@ private function handleMinCoverage(array &$arguments): void
unset($arguments[array_keys($min)[0]]);

preg_match($coverageMinRegex, array_pop($min), $matches);

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

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

Expand All @@ -98,6 +105,10 @@ private function handleSchemaCommand(array &$arguments): void

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

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

$this->schemaCommand = $matches[1];
}

Expand All @@ -115,6 +126,10 @@ private function handleMaxUntestedFields(array &$arguments): void

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

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

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

Expand Down

0 comments on commit b839acb

Please sign in to comment.