diff --git a/tests/ReturnTypeDeclarationSniffTest.php b/tests/Sniffs/ReturnTypeDeclarationSniffTest.php similarity index 59% rename from tests/ReturnTypeDeclarationSniffTest.php rename to tests/Sniffs/ReturnTypeDeclarationSniffTest.php index c3b81133..ad687918 100644 --- a/tests/ReturnTypeDeclarationSniffTest.php +++ b/tests/Sniffs/ReturnTypeDeclarationSniffTest.php @@ -12,40 +12,22 @@ * @since Class available since Release 5.4.0 */ -namespace Bartlett\Tests\CompatInfo; - -use Bartlett\CompatInfo\Analyser\CompatibilityAnalyser; -use Bartlett\Reflect\Client; +namespace Bartlett\Tests\CompatInfo\Sniffs; /** * @link https://wiki.php.net/rfc/return_types * @link https://www.php.net/manual/en/migration70.new-features.php#migration70.new-features.return-type-declarations */ -final class ReturnTypeDeclarationSniffTest extends \PHPUnit\Framework\TestCase +final class ReturnTypeDeclarationSniffTest extends SniffTestCase { - protected static $fixtures; - protected static $analyserId; - protected static $api; - /** - * Sets up the shared fixture. - * - * @return void + * {@inheritDoc} */ public static function setUpBeforeClass(): void { - self::$fixtures = __DIR__ . DIRECTORY_SEPARATOR - . 'fixtures' . DIRECTORY_SEPARATOR - . 'sniffs' . DIRECTORY_SEPARATOR - . 'functions' . DIRECTORY_SEPARATOR - ; + parent::setUpBeforeClass(); - self::$analyserId = CompatibilityAnalyser::class; - - $client = new Client(); - - // request for a Bartlett\Reflect\Api\Analyser - self::$api = $client->api('analyser'); + self::$fixtures .= 'functions' . DIRECTORY_SEPARATOR; } /** @@ -73,4 +55,30 @@ public function testReturnTypeHint() $versions ); } + + /** + * Regression test for nullable return type hint declaration detection GH#273 + * + * @link https://github.com/llaville/php-compat-info/issues/273 + * PHP 7.1 Nullable types not being detected + * @group features + * @group regression + * @return void + */ + public function testNullableReturnTypeHint() + { + $dataSource = self::$fixtures . 'gh273.php'; + $analysers = ['compatibility']; + $metrics = self::$api->run($dataSource, $analysers); + $versions = $metrics[self::$analyserId]['versions']; + + $this->assertEquals( + [ + 'php.min' => '7.1.0', + 'php.max' => '', + 'php.all' => '7.1.0', + ], + $versions + ); + } } diff --git a/tests/Sniffs/SniffTestCase.php b/tests/Sniffs/SniffTestCase.php new file mode 100644 index 00000000..3c7dc2ad --- /dev/null +++ b/tests/Sniffs/SniffTestCase.php @@ -0,0 +1,33 @@ +api('analyser'); + } +} diff --git a/tests/fixtures/gh273.php b/tests/fixtures/sniffs/functions/gh273.php similarity index 100% rename from tests/fixtures/gh273.php rename to tests/fixtures/sniffs/functions/gh273.php