Skip to content

Commit

Permalink
refactor and begin to fix tests - add unit testcase for Nullable Retu…
Browse files Browse the repository at this point in the history
…rn Type (see GH-273)
  • Loading branch information
llaville committed Aug 6, 2020
1 parent 873dd49 commit bf55fd9
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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
);
}
}
33 changes: 33 additions & 0 deletions tests/Sniffs/SniffTestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php declare(strict_types=1);

namespace Bartlett\Tests\CompatInfo\Sniffs;

use Bartlett\CompatInfo\Analyser\CompatibilityAnalyser;
use Bartlett\CompatInfo\Client;

abstract class SniffTestCase extends \PHPUnit\Framework\TestCase
{
protected static $fixtures;
protected static $analyserId;
protected static $api;

/**
* Sets up the shared fixture.
*
* @return void
*/
public static function setUpBeforeClass(): void
{
self::$fixtures = dirname(__DIR__) . DIRECTORY_SEPARATOR
. 'fixtures' . DIRECTORY_SEPARATOR
. 'sniffs' . DIRECTORY_SEPARATOR
;

self::$analyserId = CompatibilityAnalyser::class;

$client = new Client();

// request for a Bartlett\CompatInfo\Api\Analyser
self::$api = $client->api('analyser');
}
}
File renamed without changes.

0 comments on commit bf55fd9

Please sign in to comment.