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 cd6732f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/Environment/StubbedEnvironment.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,22 @@ 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;
$version = explode('.', self::VERSION);

if ($major < $version[0]) {
return true;
}
if ($major > $version[0]) {
return false;
}
if ($minor < $version[1]) {
return true;
}
if ($minor > $version[1]) {
return false;
}

return $version[2] >= $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('.', $version);
$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 cd6732f

Please sign in to comment.