55namespace Rector \Tests \VersionBonding ;
66
77use PHPUnit \Framework \TestCase ;
8+ use Rector \Configuration \Option ;
9+ use Rector \Configuration \Parameter \SimpleParameterProvider ;
810use Rector \Php \PhpVersionProvider ;
911use Rector \Php \PolyfillPackagesProvider ;
1012use Rector \Tests \VersionBonding \Fixture \NoInterfaceRector ;
13+ use Rector \Tests \VersionBonding \Fixture \PolyfillPhp83Rector ;
14+ use Rector \ValueObject \PhpVersion ;
15+ use Rector \ValueObject \PolyfillPackage ;
1116use Rector \VersionBonding \PhpVersionedFilter ;
1217
1318final class PhpVersionedFilterTest extends TestCase
@@ -20,6 +25,14 @@ protected function setUp(): void
2025 $ polyfillPackagesProvider = new PolyfillPackagesProvider ();
2126
2227 $ this ->phpVersionedFilter = new PhpVersionedFilter ($ phpVersionProvider , $ polyfillPackagesProvider );
28+
29+ SimpleParameterProvider ::setParameter (Option::POLYFILL_PACKAGES , [PolyfillPackage::PHP_83 ]);
30+ }
31+
32+ protected function tearDown (): void
33+ {
34+ SimpleParameterProvider ::setParameter (Option::POLYFILL_PACKAGES , []);
35+ SimpleParameterProvider ::setParameter (Option::POLYFILL_CEILING_PHP_VERSION , 0 );
2336 }
2437
2538 public function testRectorWithoutInterfaceIsIncluded (): void
@@ -30,4 +43,32 @@ public function testRectorWithoutInterfaceIsIncluded(): void
3043 $ this ->assertCount (1 , $ filtered );
3144 $ this ->assertSame ($ noInterfaceRector , $ filtered [0 ]);
3245 }
46+
47+ public function testPolyfilledRectorIsIncluded (): void
48+ {
49+ $ polyfillPhp83Rector = new PolyfillPhp83Rector ();
50+ $ filtered = $ this ->phpVersionedFilter ->filter ([$ polyfillPhp83Rector ]);
51+
52+ $ this ->assertCount (1 , $ filtered );
53+ $ this ->assertSame ($ polyfillPhp83Rector , $ filtered [0 ]);
54+ }
55+
56+ public function testPolyfilledRectorAbovePickedPhpSetsVersionIsSkipped (): void
57+ {
58+ SimpleParameterProvider ::setParameter (Option::POLYFILL_CEILING_PHP_VERSION , PhpVersion::PHP_82 );
59+
60+ $ filtered = $ this ->phpVersionedFilter ->filter ([new PolyfillPhp83Rector ()]);
61+ $ this ->assertCount (0 , $ filtered );
62+ }
63+
64+ public function testPolyfilledRectorBelowPickedPhpSetsVersionIsIncluded (): void
65+ {
66+ SimpleParameterProvider ::setParameter (Option::POLYFILL_CEILING_PHP_VERSION , PhpVersion::PHP_83 );
67+
68+ $ polyfillPhp83Rector = new PolyfillPhp83Rector ();
69+ $ filtered = $ this ->phpVersionedFilter ->filter ([$ polyfillPhp83Rector ]);
70+
71+ $ this ->assertCount (1 , $ filtered );
72+ $ this ->assertSame ($ polyfillPhp83Rector , $ filtered [0 ]);
73+ }
3374}
0 commit comments