Skip to content

Commit 5793f9e

Browse files
committed
Convert to constraint sub command; Extract ModeOption & SourceOption attributes; Update pestphp/pest to v4.1
1 parent ca6748c commit 5793f9e

381 files changed

Lines changed: 877 additions & 1058 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 & 9 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'
@@ -74,9 +74,7 @@ jobs:
7474
dependency-versions: ${{ matrix.dependency-versions }}
7575
composer-options: --no-audit --optimize-autoloader
7676

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
77+
- run: composer pest:e2e -- --ci --bail --stop-on-incomplete --fail-on-all-issues
8078

8179
codecov:
8280
needs: pest

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
},
3535
"require-dev": {
3636
"mockery/mockery": "^1.6.12",
37-
"pestphp/pest": "^3.7.1",
37+
"pestphp/pest": "^4.1",
3838
"roave/security-advisories": "dev-latest"
3939
},
4040
"autoload": {

phpunit.xml

Lines changed: 2 additions & 3 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,7 +11,6 @@
1111
</testsuites>
1212
<source>
1313
<include>
14-
<directory suffix=".php">./app</directory>
1514
<directory suffix=".php">./src</directory>
1615
</include>
1716
</source>
@@ -20,6 +19,6 @@
2019
<!-- Height of the terminal -->
2120
<env name="LINES" value="50" force="true"/>
2221
<!-- Width of the terminal -->
23-
<env name="COLUMNS" value="80" force="true"/>
22+
<env name="COLUMNS" value="120" force="true"/>
2423
</php>
2524
</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: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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+
14+
#[AsCommand(
15+
name: 'constraint',
16+
description: 'List PHP versions that satisfy the given constraint',
17+
)]
18+
class ConstraintCommand extends Command
19+
{
20+
public function __construct(
21+
private readonly MatrixFactory $matrixFactory = new MatrixFactory,
22+
) {
23+
parent::__construct();
24+
}
25+
26+
public function __invoke(
27+
SymfonyStyle $io,
28+
#[Argument(description: 'The version constraint.')]
29+
string $constraint,
30+
#[SourceOption]
31+
string $source = Source::Auto->value,
32+
#[ModeOption]
33+
string $mode = Mode::MinorOnly->value,
34+
): int {
35+
try {
36+
$matrix = $this->matrixFactory->make(
37+
Source::fromValue($source),
38+
Mode::fromValue($mode),
39+
);
40+
41+
$versions = $matrix->satisfiedBy($constraint);
42+
if (empty($versions)) {
43+
throw new RuntimeException(
44+
sprintf("Error! No PHP versions could satisfy the constraint '%s'.", $constraint)
45+
);
46+
}
47+
48+
$result = json_encode(
49+
(object)[
50+
'constraint' => $constraint,
51+
'versions' => Versions::sort(...$versions),
52+
'lowest' => Versions::lowest(...$versions),
53+
'highest' => Versions::highest(...$versions),
54+
],
55+
JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT
56+
);
57+
58+
$io->writeln($result);
59+
60+
return Command::SUCCESS;
61+
} catch (\UnexpectedValueException $e) {
62+
$io
63+
->getErrorStyle()
64+
->error(
65+
$e->getMessage(),
66+
);
67+
68+
return Command::FAILURE;
69+
}
70+
}
71+
}

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)