Skip to content

Commit ed41b59

Browse files
authored
Merge pull request #107 from PHPCSStandards/testutils/utilitymethodtestcase-add-phpcsversion-property
TestUtils\UtilityMethodTestCase: add new $phpcsVersion property
2 parents 816c1be + 788a52b commit ed41b59

File tree

6 files changed

+27
-21
lines changed

6 files changed

+27
-21
lines changed

PHPCSUtils/TestUtils/UtilityMethodTestCase.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,15 @@
9898
abstract class UtilityMethodTestCase extends TestCase
9999
{
100100

101+
/**
102+
* The PHPCS version the tests are being run on.
103+
*
104+
* @since 1.0.0
105+
*
106+
* @var string
107+
*/
108+
protected static $phpcsVersion = '0';
109+
101110
/**
102111
* The file extension of the test case file (without leading dot).
103112
*
@@ -173,6 +182,8 @@ public static function setUpTestFile()
173182
{
174183
parent::setUpBeforeClass();
175184

185+
self::$phpcsVersion = Helper::getVersion();
186+
176187
$caseFile = static::$caseFile;
177188
if (\is_string($caseFile) === false || $caseFile === '') {
178189
$testClass = \get_called_class();
@@ -186,7 +197,7 @@ public static function setUpTestFile()
186197

187198
$contents = \file_get_contents($caseFile);
188199

189-
if (\version_compare(Helper::getVersion(), '2.99.99', '>')) {
200+
if (\version_compare(self::$phpcsVersion, '2.99.99', '>')) {
190201
// PHPCS 3.x.
191202
$config = new \PHP_CodeSniffer\Config();
192203

Tests/BackCompat/BCFile/GetDeclarationNameJSTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
namespace PHPCSUtils\Tests\BackCompat\BCFile;
1212

1313
use PHPCSUtils\BackCompat\BCFile;
14-
use PHPCSUtils\BackCompat\Helper;
1514
use PHPCSUtils\TestUtils\UtilityMethodTestCase;
1615

1716
/**
@@ -135,7 +134,7 @@ public function dataGetDeclarationName()
135134
*/
136135
public function testGetDeclarationNameES6Method()
137136
{
138-
if (\version_compare(Helper::getVersion(), '3.0.0', '<') === true) {
137+
if (\version_compare(static::$phpcsVersion, '3.0.0', '<') === true) {
139138
$this->markTestSkipped('Support for JS ES6 method has not been backfilled for PHPCS 2.x (yet)');
140139
}
141140

Tests/BackCompat/Helper/GetCommandLineDataTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function testGetCommandLineData()
3434
{
3535
// Use the default values which are different across PHPCS versions.
3636
$expected = 'utf-8';
37-
if (\version_compare(Helper::getVersion(), '2.99.99', '<=') === true) {
37+
if (\version_compare(static::$phpcsVersion, '2.99.99', '<=') === true) {
3838
// Will effectively come down to `iso-8859-1`.
3939
$expected = null;
4040
}
@@ -68,7 +68,7 @@ public function testGetTabWidth()
6868
$result = Helper::getTabWidth(self::$phpcsFile);
6969
$this->assertSame(4, $result, 'Failed retrieving the default tab width');
7070

71-
if (\version_compare(Helper::getVersion(), '2.99.99', '>') === true) {
71+
if (\version_compare(static::$phpcsVersion, '2.99.99', '>') === true) {
7272
// PHPCS 3.x.
7373
self::$phpcsFile->config->tabWidth = 2;
7474
} else {
@@ -80,7 +80,7 @@ public function testGetTabWidth()
8080
$this->assertSame(2, $result, 'Failed retrieving the custom set tab width');
8181

8282
// Restore defaults before moving to the next test.
83-
if (\version_compare(Helper::getVersion(), '2.99.99', '>') === true) {
83+
if (\version_compare(static::$phpcsVersion, '2.99.99', '>') === true) {
8484
self::$phpcsFile->config->restoreDefaults();
8585
} else {
8686
self::$phpcsFile->phpcs->cli->setCommandLineValues(['--tab-width=4']);
@@ -96,7 +96,7 @@ public function testGetTabWidth()
9696
*/
9797
public function testIgnoreAnnotationsV2()
9898
{
99-
if (\version_compare(Helper::getVersion(), '2.99.99', '>') === true) {
99+
if (\version_compare(static::$phpcsVersion, '2.99.99', '>') === true) {
100100
$this->markTestSkipped('Test only applicable to PHPCS 2.x');
101101
}
102102

@@ -112,7 +112,7 @@ public function testIgnoreAnnotationsV2()
112112
*/
113113
public function testIgnoreAnnotationsV3Default()
114114
{
115-
if (\version_compare(Helper::getVersion(), '2.99.99', '<=') === true) {
115+
if (\version_compare(static::$phpcsVersion, '2.99.99', '<=') === true) {
116116
$this->markTestSkipped('Test only applicable to PHPCS 3.x');
117117
}
118118

@@ -135,7 +135,7 @@ public function testIgnoreAnnotationsV3Default()
135135
*/
136136
public function testIgnoreAnnotationsV3SetViaMethod()
137137
{
138-
if (\version_compare(Helper::getVersion(), '2.99.99', '<=') === true) {
138+
if (\version_compare(static::$phpcsVersion, '2.99.99', '<=') === true) {
139139
$this->markTestSkipped('Test only applicable to PHPCS 3.x');
140140
}
141141

@@ -157,7 +157,7 @@ public function testIgnoreAnnotationsV3SetViaMethod()
157157
*/
158158
public function testIgnoreAnnotationsV3SetViaProperty()
159159
{
160-
if (\version_compare(Helper::getVersion(), '2.99.99', '<=') === true) {
160+
if (\version_compare(static::$phpcsVersion, '2.99.99', '<=') === true) {
161161
$this->markTestSkipped('Test only applicable to PHPCS 3.x');
162162
}
163163

Tests/Utils/Numbers/GetCompleteNumberTest.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class GetCompleteNumberTest extends UtilityMethodTestCase
3131
*
3232
* @var string
3333
*/
34-
public static $phpcsVersion = null;
34+
public static $phpcsVersion = '0';
3535

3636
/**
3737
* Whether or not the tests are being run on PHP 7.4 or higher.
@@ -54,7 +54,7 @@ class GetCompleteNumberTest extends UtilityMethodTestCase
5454
*/
5555
public static function setUpStaticProperties()
5656
{
57-
if (isset(self::$phpcsVersion)) {
57+
if (self::$phpcsVersion !== '0') {
5858
return;
5959
}
6060

@@ -83,8 +83,7 @@ public function testNotANumberException()
8383
*/
8484
public function testUnsupportedPhpcsException()
8585
{
86-
self::setUpStaticProperties();
87-
if (\version_compare(self::$phpcsVersion, Numbers::UNSUPPORTED_PHPCS_VERSION, '!=') === true) {
86+
if (\version_compare(static::$phpcsVersion, Numbers::UNSUPPORTED_PHPCS_VERSION, '!=') === true) {
8887
$this->markTestSkipped('Test specific to a limited set of PHPCS versions');
8988
}
9089

@@ -109,10 +108,9 @@ public function testUnsupportedPhpcsException()
109108
public function testGetCompleteNumber($testMarker, $expected)
110109
{
111110
// Skip the test(s) on unsupported PHPCS versions.
112-
self::setUpStaticProperties();
113-
if (\version_compare(self::$phpcsVersion, Numbers::UNSUPPORTED_PHPCS_VERSION, '==') === true) {
111+
if (\version_compare(static::$phpcsVersion, Numbers::UNSUPPORTED_PHPCS_VERSION, '==') === true) {
114112
$this->markTestSkipped(
115-
'PHPCS ' . self::$phpcsVersion . ' is not supported due to buggy numeric string literal backfill.'
113+
'PHPCS ' . static::$phpcsVersion . ' is not supported due to buggy numeric string literal backfill.'
116114
);
117115
}
118116

Tests/Utils/ObjectDeclarations/GetNameJSTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
namespace PHPCSUtils\Tests\Utils\ObjectDeclarations;
1212

13-
use PHPCSUtils\BackCompat\Helper;
1413
use PHPCSUtils\Tests\BackCompat\BCFile\GetDeclarationNameJSTest as BCFile_GetDeclarationNameJSTest;
1514
use PHPCSUtils\Utils\ObjectDeclarations;
1615

@@ -113,7 +112,7 @@ public function testGetDeclarationName($testMarker, $expected, $targetType = nul
113112
*/
114113
public function testGetDeclarationNameES6Method()
115114
{
116-
if (\version_compare(Helper::getVersion(), '3.0.0', '<') === true) {
115+
if (\version_compare(static::$phpcsVersion, '3.0.0', '<') === true) {
117116
$this->markTestSkipped('Support for JS ES6 method has not been backfilled for PHPCS 2.x (yet)');
118117
}
119118

Tests/Utils/Operators/IsUnaryPlusMinusTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
namespace PHPCSUtils\Tests\Utils\Operators;
1212

13-
use PHPCSUtils\BackCompat\Helper;
1413
use PHPCSUtils\TestUtils\UtilityMethodTestCase;
1514
use PHPCSUtils\Utils\Numbers;
1615
use PHPCSUtils\Utils\Operators;
@@ -72,7 +71,7 @@ public function testIsUnaryPlusMinus($testMarker, $expected, $maybeSkip = false)
7271
$this->markTestSkipped($skipMessage);
7372
}
7473

75-
if (\version_compare(Helper::getVersion(), Numbers::UNSUPPORTED_PHPCS_VERSION, '>=') === true) {
74+
if (\version_compare(static::$phpcsVersion, Numbers::UNSUPPORTED_PHPCS_VERSION, '>=') === true) {
7675
$this->markTestSkipped($skipMessage);
7776
}
7877
}

0 commit comments

Comments
 (0)