Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentLanglet committed Aug 18, 2024
1 parent 6faa507 commit f77868e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/Environment/StubbedEnvironment.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,20 @@ public function __construct(
*/
public static function satisfiesTwigVersion(int $major, int $minor = 0, int $patch = 0): bool
{
return $major + 1 >= self::MAJOR_VERSION
&& $minor >= self::MINOR_VERSION
&& $patch >= self::RELEASE_VERSION;
if ($major + 1 < self::MAJOR_VERSION) {
return true;
}
if ($major + 1 > self::MAJOR_VERSION) {
return false;
}
if ($minor < self::MINOR_VERSION) {
return true;
}
if ($minor > self::MINOR_VERSION) {
return false;
}

return self::RELEASE_VERSION >= $patch;
}

/**
Expand Down
22 changes: 22 additions & 0 deletions tests/Environment/StubbedEnvironmentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,28 @@

final class StubbedEnvironmentTest extends TestCase
{
public function testSatisfiesTwigVersion(): void
{
$version = InstalledVersions::getVersion('twig/twig');
static::assertNotNull($version);
$explodedVersion = explode('.', ltrim($version, 'v'));
$major = (int) $explodedVersion[0];
$minor = (int) ($explodedVersion[1] ?? 0);
$patch = (int) ($explodedVersion[2] ?? 0);

static::assertTrue(StubbedEnvironment::satisfiesTwigVersion($major, $minor, $patch));
static::assertTrue(StubbedEnvironment::satisfiesTwigVersion($major - 1, $minor, $patch));
static::assertTrue(StubbedEnvironment::satisfiesTwigVersion($major - 1, $minor + 1, $patch + 1));
static::assertTrue(StubbedEnvironment::satisfiesTwigVersion($major, $minor - 1, $patch));
static::assertTrue(StubbedEnvironment::satisfiesTwigVersion($major, $minor - 1, $patch + 1));
static::assertTrue(StubbedEnvironment::satisfiesTwigVersion($major, $minor, $patch - 1));
static::assertFalse(StubbedEnvironment::satisfiesTwigVersion($major + 1, $minor, $patch));
static::assertFalse(StubbedEnvironment::satisfiesTwigVersion($major + 1, $minor - 1, $patch - 1));
static::assertFalse(StubbedEnvironment::satisfiesTwigVersion($major, $minor + 1, $patch));
static::assertFalse(StubbedEnvironment::satisfiesTwigVersion($major, $minor + 1, $patch - 1));
static::assertFalse(StubbedEnvironment::satisfiesTwigVersion($major, $minor, $patch + 1));
}

public function testFilterIsStubbed(): void
{
$env = new StubbedEnvironment();
Expand Down

0 comments on commit f77868e

Please sign in to comment.