From bf55fd9f3fe25ad927f4b9e72abaffa06a482c6f Mon Sep 17 00:00:00 2001 From: Laurent Laville Date: Thu, 6 Aug 2020 08:00:36 +0000 Subject: [PATCH] refactor and begin to fix tests - add unit testcase for Nullable Return Type (see GH-273) --- .../ReturnTypeDeclarationSniffTest.php | 54 +++++++++++-------- tests/Sniffs/SniffTestCase.php | 33 ++++++++++++ .../fixtures/{ => sniffs/functions}/gh273.php | 0 3 files changed, 64 insertions(+), 23 deletions(-) rename tests/{ => Sniffs}/ReturnTypeDeclarationSniffTest.php (59%) create mode 100644 tests/Sniffs/SniffTestCase.php rename tests/fixtures/{ => sniffs/functions}/gh273.php (100%) 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