Skip to content

Commit 7bd3b36

Browse files
authored
Convert to constraint sub command; Extract ModeOption & SourceOption attributes; Update pestphp/pest to v4.1 (#43)
1 parent ca6748c commit 7bd3b36

398 files changed

Lines changed: 765 additions & 1169 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/test.yml

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,18 @@ jobs:
3232
with:
3333
php-version: '8.4'
3434
coverage: ${{ matrix.coverage }}
35-
env:
36-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3735

3836
- uses: ramsey/composer-install@v3
3937
with:
4038
dependency-versions: ${{ matrix.dependency-versions }}
4139
composer-options: --no-audit --optimize-autoloader
4240

43-
# TODO: `--fail-on-incomplete` doesn't fail
44-
# See: https://github.com/pestphp/pest/issues/1328
45-
- run: composer pest:unit -- --coverage-clover coverage-unit.xml --ci --bail --stop-on-incomplete --fail-on-incomplete
46-
- run: composer pest:feature -- --coverage-clover coverage-feature.xml --ci --bail --stop-on-incomplete --fail-on-incomplete
41+
- run: composer pest:unit -- ${COVERAGE} --ci --bail --stop-on-incomplete --fail-on-all-issues
42+
env:
43+
COVERAGE: ${{ matrix.coverage == 'xdebug' && '--coverage-clover coverage-unit.xml' || '' }}
44+
- run: composer pest:feature -- ${COVERAGE} --ci --bail --stop-on-incomplete --fail-on-all-issues
45+
env:
46+
COVERAGE: ${{ matrix.coverage == 'xdebug' && '--coverage-clover coverage-feature.xml' || '' }}
4747

4848
- uses: actions/upload-artifact@v4
4949
if: matrix.coverage == 'xdebug'
@@ -66,17 +66,13 @@ jobs:
6666
with:
6767
php-version: '8.4'
6868
coverage: none
69-
env:
70-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
7169

7270
- uses: ramsey/composer-install@v3
7371
with:
7472
dependency-versions: ${{ matrix.dependency-versions }}
7573
composer-options: --no-audit --optimize-autoloader
7674

77-
# TODO: `--fail-on-incomplete` doesn't fail
78-
# See: https://github.com/pestphp/pest/issues/1328
79-
- run: composer pest:e2e -- --ci --bail --stop-on-incomplete --fail-on-incomplete
75+
- run: composer pest:e2e -- --ci --bail --stop-on-incomplete --fail-on-all-issues
8076

8177
codecov:
8278
needs: pest

composer.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,13 @@
2828
"require": {
2929
"php": "^8.4",
3030
"composer-runtime-api": "^2.2",
31-
"composer/semver": "^3.4.3",
32-
"guzzlehttp/guzzle": "^7.9.2",
33-
"symfony/console": "^7.2.1"
31+
"composer/semver": "^3.4.4",
32+
"guzzlehttp/guzzle": "^7.10",
33+
"symfony/console": "^7.3.4"
3434
},
3535
"require-dev": {
3636
"mockery/mockery": "^1.6.12",
37-
"pestphp/pest": "^3.7.1",
38-
"roave/security-advisories": "dev-latest"
37+
"pestphp/pest": "^4.1.2"
3938
},
4039
"autoload": {
4140
"psr-4": {

phpunit.xml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.3/phpunit.xsd"
3+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/12.4/phpunit.xsd"
44
bootstrap="vendor/autoload.php"
55
colors="true"
66
>
@@ -11,15 +11,12 @@
1111
</testsuites>
1212
<source>
1313
<include>
14-
<directory suffix=".php">./app</directory>
1514
<directory suffix=".php">./src</directory>
1615
</include>
1716
</source>
1817

1918
<php>
20-
<!-- Height of the terminal -->
21-
<env name="LINES" value="50" force="true"/>
2219
<!-- Width of the terminal -->
23-
<env name="COLUMNS" value="80" force="true"/>
20+
<env name="COLUMNS" value="120" force="true"/>
2421
</php>
2522
</phpunit>

src/Console/Application.php

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,15 @@ class Application
1313

1414
public static function make(): ConsoleApplication
1515
{
16-
$application = new ConsoleApplication(
16+
$app = new ConsoleApplication(
1717
self::NAME,
1818
InstalledVersions::getPrettyVersion('typisttech/php-matrix') ?? 'unknown',
1919
);
2020

21-
$command = new Command;
21+
$app->addCommands([
22+
new ConstraintCommand,
23+
]);
2224

23-
$application->add($command);
24-
$application->setDefaultCommand(
25-
$command->getName(),
26-
true
27-
);
28-
29-
return $application;
25+
return $app;
3026
}
3127
}

src/Console/Command.php

Lines changed: 0 additions & 136 deletions
This file was deleted.

src/Console/ConstraintCommand.php

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace TypistTech\PhpMatrix\Console;
6+
7+
use RuntimeException;
8+
use Symfony\Component\Console\Attribute\Argument;
9+
use Symfony\Component\Console\Attribute\AsCommand;
10+
use Symfony\Component\Console\Command\Command;
11+
use Symfony\Component\Console\Style\SymfonyStyle;
12+
use TypistTech\PhpMatrix\Versions;
13+
use UnexpectedValueException;
14+
15+
#[AsCommand(
16+
name: 'constraint',
17+
description: 'List PHP versions that satisfy the given constraint',
18+
)]
19+
class ConstraintCommand extends Command
20+
{
21+
use PrintErrorTrait;
22+
23+
public function __construct(
24+
private readonly MatrixFactory $matrixFactory = new MatrixFactory,
25+
) {
26+
parent::__construct();
27+
}
28+
29+
public function __invoke(
30+
SymfonyStyle $io,
31+
#[Argument(description: 'The version constraint.')]
32+
string $constraint,
33+
#[SourceOption]
34+
string $source = Source::Auto->value,
35+
#[ModeOption]
36+
string $mode = Mode::MinorOnly->value,
37+
): int {
38+
$matrix = $this->matrixFactory->make(
39+
Source::fromValue($source),
40+
Mode::fromValue($mode),
41+
);
42+
43+
try {
44+
$versions = $matrix->satisfiedBy($constraint);
45+
} catch (UnexpectedValueException $e) {
46+
$this->printError(
47+
$io,
48+
$e->getMessage()
49+
);
50+
51+
return Command::FAILURE;
52+
}
53+
54+
if (empty($versions)) {
55+
$this->printError(
56+
$io,
57+
sprintf('No PHP versions could satisfy the constraint "%s".', $constraint)
58+
);
59+
60+
return Command::FAILURE;
61+
}
62+
63+
$result = json_encode(
64+
(object)[
65+
'constraint' => $constraint,
66+
'versions' => Versions::sort(...$versions),
67+
'lowest' => Versions::lowest(...$versions),
68+
'highest' => Versions::highest(...$versions),
69+
],
70+
JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT
71+
);
72+
73+
$io->writeln($result);
74+
75+
return Command::SUCCESS;
76+
}
77+
}

src/Console/FromNameTrait.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace TypistTech\PhpMatrix\Console;
6+
7+
use Symfony\Component\Console\Exception\InvalidArgumentException;
8+
9+
trait FromNameTrait
10+
{
11+
public static function fromValue(string $value): self
12+
{
13+
$case = self::tryFrom($value);
14+
15+
if ($case === null) {
16+
$message = sprintf(
17+
'[ERROR] Invalid --%1$s "%2$s". Available %1$ss: [%3$s]',
18+
self::NAME,
19+
$value,
20+
implode(', ', array_column(self::cases(), 'value')),
21+
);
22+
throw new InvalidArgumentException($message);
23+
}
24+
25+
return $case;
26+
}
27+
}

src/Console/Mode.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace TypistTech\PhpMatrix\Console;
66

7+
use Symfony\Component\Console\Exception\InvalidArgumentException;
78
use TypistTech\PhpMatrix\Matrix;
89
use TypistTech\PhpMatrix\MatrixInterface;
910
use TypistTech\PhpMatrix\MinorOnlyMatrix;
@@ -14,6 +15,10 @@ enum Mode: string
1415
case Full = 'full';
1516
case MinorOnly = 'minor-only';
1617

18+
use FromNameTrait;
19+
20+
public const string NAME = 'mode';
21+
1722
public function matrix(ReleasesInterface $releases): MatrixInterface
1823
{
1924
return match ($this) {

src/Console/ModeOption.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace TypistTech\PhpMatrix\Console;
6+
7+
use Symfony\Component\Console\Attribute\Option;
8+
9+
#[\Attribute(\Attribute::TARGET_PARAMETER)]
10+
class ModeOption extends Option
11+
{
12+
public function __construct()
13+
{
14+
parent::__construct(
15+
Mode::description(),
16+
Mode::NAME,
17+
null,
18+
Mode::cases(),
19+
);
20+
}
21+
}

0 commit comments

Comments
 (0)