|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Rector\Tests\VersionBonding; |
| 6 | + |
| 7 | +use PHPUnit\Framework\TestCase; |
| 8 | +use Rector\Composer\InstalledPackageResolver; |
| 9 | +use Rector\Tests\VersionBonding\Fixture\ComposerPackageConstraintRector; |
| 10 | +use Rector\Tests\VersionBonding\Fixture\NoInterfaceRector; |
| 11 | +use Rector\VersionBonding\ComposerPackageConstraintFilter; |
| 12 | + |
| 13 | +final class ComposerPackageConstraintFilterTest extends TestCase |
| 14 | +{ |
| 15 | + private ComposerPackageConstraintFilter $composerPackageConstraintFilter; |
| 16 | + |
| 17 | + protected function setUp(): void |
| 18 | + { |
| 19 | + $installedPackageResolver = new InstalledPackageResolver(getcwd()); |
| 20 | + |
| 21 | + $this->composerPackageConstraintFilter = new ComposerPackageConstraintFilter($installedPackageResolver); |
| 22 | + } |
| 23 | + |
| 24 | + public function testRectorWithoutInterfaceIsIncluded(): void |
| 25 | + { |
| 26 | + $rector = new NoInterfaceRector(); |
| 27 | + $filtered = $this->composerPackageConstraintFilter->filter([$rector]); |
| 28 | + |
| 29 | + $this->assertCount(1, $filtered); |
| 30 | + $this->assertSame($rector, $filtered[0]); |
| 31 | + } |
| 32 | + |
| 33 | + public function testRectorWithSatisfiedConstraintIsIncluded(): void |
| 34 | + { |
| 35 | + $rector = new ComposerPackageConstraintRector('nikic/php-parser', '>=4.0.0'); |
| 36 | + $filtered = $this->composerPackageConstraintFilter->filter([$rector]); |
| 37 | + |
| 38 | + $this->assertCount(1, $filtered); |
| 39 | + $this->assertSame($rector, $filtered[0]); |
| 40 | + } |
| 41 | + |
| 42 | + public function testRectorWithUnsatisfiedConstraintIsExcluded(): void |
| 43 | + { |
| 44 | + $rector = new ComposerPackageConstraintRector('nikic/php-parser', '>=999.0.0'); |
| 45 | + $filtered = $this->composerPackageConstraintFilter->filter([$rector]); |
| 46 | + |
| 47 | + $this->assertCount(0, $filtered); |
| 48 | + } |
| 49 | + |
| 50 | + public function testRectorWithMissingPackageIsExcluded(): void |
| 51 | + { |
| 52 | + $rector = new ComposerPackageConstraintRector('non-existent/package', '>=1.0.0'); |
| 53 | + $filtered = $this->composerPackageConstraintFilter->filter([$rector]); |
| 54 | + |
| 55 | + $this->assertCount(0, $filtered); |
| 56 | + } |
| 57 | + |
| 58 | + public function testRectorWithCaretConstraint(): void |
| 59 | + { |
| 60 | + $rector = new ComposerPackageConstraintRector('nikic/php-parser', '^5.0'); |
| 61 | + $filtered = $this->composerPackageConstraintFilter->filter([$rector]); |
| 62 | + |
| 63 | + $this->assertCount(1, $filtered); |
| 64 | + $this->assertSame($rector, $filtered[0]); |
| 65 | + } |
| 66 | + |
| 67 | + public function testRectorWithLessThanConstraintExcludesNewerVersions(): void |
| 68 | + { |
| 69 | + $rector = new ComposerPackageConstraintRector('nikic/php-parser', '<1.0.0'); |
| 70 | + $filtered = $this->composerPackageConstraintFilter->filter([$rector]); |
| 71 | + |
| 72 | + $this->assertCount(0, $filtered); |
| 73 | + } |
| 74 | +} |
0 commit comments