Skip to content

[ci] handle reset-password 8.1.10 version constraint #1201

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion src/Test/MakerTestDetails.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ final class MakerTestDetails
private string $rootNamespace = 'App';
private int $requiredPhpVersion = 80000;
private array $requiredPackageVersions = [];
private int $blockedPhpVersionUpper = 0;
private int $blockedPhpVersionLower = 0;

public function __construct(
private MakerInterface $maker,
Expand Down Expand Up @@ -73,6 +75,22 @@ public function setRequiredPhpVersion(int $version): self
return $this;
}

/**
* Skip a test from running between a range of PHP Versions.
*
* @param int $lowerLimit Versions below this value will be allowed
* @param int $upperLimit Versions above this value will be allowed
*
* @internal
*/
public function setSkippedPhpVersions(int $lowerLimit, int $upperLimit): self
{
$this->blockedPhpVersionUpper = $upperLimit;
$this->blockedPhpVersionLower = $lowerLimit;

return $this;
}

public function addRequiredPackageVersion(string $packageName, string $versionConstraint): self
{
$this->requiredPackageVersions[] = ['name' => $packageName, 'version_constraint' => $versionConstraint];
Expand Down Expand Up @@ -118,7 +136,22 @@ public function getDependencyBuilder(): DependencyBuilder

public function isSupportedByCurrentPhpVersion(): bool
{
return \PHP_VERSION_ID >= $this->requiredPhpVersion;
$hasPhpVersionConstraint = $this->blockedPhpVersionLower > 0 && $this->blockedPhpVersionUpper > 0;
$isSupported = false;

if (!$hasPhpVersionConstraint) {
$isSupported = true;
}

if (\PHP_VERSION_ID > $this->blockedPhpVersionUpper) {
$isSupported = true;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what makes sense to me:

if ($hasPhpVersionConstraint && \PHP_VERSION_ID >= $this->blockedPhpVersionLower && \PHP_VERSION_ID <= $this->blockedPhpVersionUpper) {
    return false;
}

It says:

If the a blocked range of php versions was specified AND the current php version is inside of that range (greater than or equal to the lower and less than or equal to the upper), return false: the current php version is not supported.


if (\PHP_VERSION_ID < $this->blockedPhpVersionLower) {
$isSupported = true;
}

return $isSupported && \PHP_VERSION_ID >= $this->requiredPhpVersion;
}

public function getRequiredPackageVersions(): array
Expand Down
5 changes: 5 additions & 0 deletions tests/Maker/MakeResetPasswordTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ protected function getMakerClass(): string
public function getTestDetails(): \Generator
{
yield 'it_generates_with_normal_setup' => [$this->createMakerTest()
->setSkippedPhpVersions(80100, 80109)
->run(function (MakerTestRunner $runner) {
$this->makeUser($runner);

Expand Down Expand Up @@ -81,6 +82,7 @@ public function getTestDetails(): \Generator
];

yield 'it_generates_with_translator_installed' => [$this->createMakerTest()
->setSkippedPhpVersions(80100, 80109)
->addExtraDependencies('symfony/translation')
->run(function (MakerTestRunner $runner) {
$this->makeUser($runner);
Expand All @@ -97,6 +99,7 @@ public function getTestDetails(): \Generator
];

yield 'it_generates_with_custom_config' => [$this->createMakerTest()
->setSkippedPhpVersions(80100, 80109)
->run(function (MakerTestRunner $runner) {
$runner->deleteFile('config/packages/reset_password.yaml');
$runner->writeFile(
Expand Down Expand Up @@ -131,6 +134,7 @@ public function getTestDetails(): \Generator
];

yield 'it_amends_configuration' => [$this->createMakerTest()
->setSkippedPhpVersions(80100, 80109)
->run(function (MakerTestRunner $runner) {
$runner->modifyYamlFile('config/packages/reset_password.yaml', function (array $config) {
$config['symfonycasts_reset_password']['lifetime'] = 9999;
Expand All @@ -157,6 +161,7 @@ public function getTestDetails(): \Generator
];

yield 'it_generates_with_custom_user' => [$this->createMakerTest()
->setSkippedPhpVersions(80100, 80109)
->run(function (MakerTestRunner $runner) {
$this->makeUser($runner, 'emailAddress', 'UserCustom', false);

Expand Down