Skip to content

Commit b7c5c55

Browse files
committed
UtilityMethodTestCase: implement use of the new PHPCSUtils\TestUtils\ConfigDouble class
Start using the new `ConfigDouble` class in the `UtilityMethodTestCase` class. Note: this includes deprecating the `UtilityMethodTestCase::setStaticConfigProperty()` method, which was introduced, but not publicized, in PHPCSUtils 1.0.9 in favour of handling the same in the `ConfigDouble` class.
1 parent bfa5acd commit b7c5c55

File tree

1 file changed

+7
-30
lines changed

1 file changed

+7
-30
lines changed

PHPCSUtils/TestUtils/UtilityMethodTestCase.php

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
namespace PHPCSUtils\TestUtils;
1212

13-
use PHP_CodeSniffer\Config;
1413
use PHP_CodeSniffer\Exceptions\TokenizerException;
1514
use PHP_CodeSniffer\Files\DummyFile;
1615
use PHP_CodeSniffer\Files\File;
@@ -19,6 +18,7 @@
1918
use PHPCSUtils\Exceptions\TestFileNotFound;
2019
use PHPCSUtils\Exceptions\TestMarkerNotFound;
2120
use PHPCSUtils\Exceptions\TestTargetNotFound;
21+
use PHPCSUtils\TestUtils\ConfigDouble;
2222
use PHPUnit\Framework\TestCase;
2323
use ReflectionClass;
2424
use ReflectionProperty;
@@ -212,31 +212,10 @@ public static function setUpTestFile()
212212

213213
$contents = \file_get_contents($caseFile);
214214

215-
/*
216-
* Set the static properties in the Config class to specific values for performance
217-
* and to clear out values from other tests.
218-
*/
219-
self::setStaticConfigProperty('executablePaths', []);
220-
221-
// Set to values which prevent the test-runner user's `CodeSniffer.conf` file
222-
// from being read and influencing the tests. Also prevent an `exec()` call to stty.
223-
self::setStaticConfigProperty('configData', ['report_width' => 80]);
224-
self::setStaticConfigProperty('configDataFile', '');
225-
226-
$config = new Config();
215+
$config = new ConfigDouble();
227216

228217
/*
229-
* Set to a usable value to circumvent Config trying to find a phpcs.xml config file.
230-
*
231-
* We just need to provide a standard so PHPCS will tokenize the file.
232-
* The standard itself doesn't actually matter for testing utility methods,
233-
* so use the smallest one to get the fastest results.
234-
*/
235-
$config->standards = ['PSR1'];
236-
237-
/*
238-
* Limiting the run to just one sniff will make it, yet again, slightly faster.
239-
* Picked the simplest/fastest sniff available which is registered in PSR1.
218+
* Limiting the run to just one (dummy) sniff will make it, yet again, slightly faster.
240219
*/
241220
$config->sniffs = static::$selectedSniff;
242221

@@ -315,17 +294,15 @@ public static function resetTestFile()
315294
self::$tabWidth = 4;
316295
self::$phpcsFile = null;
317296
self::$selectedSniff = ['Dummy.Dummy.Dummy'];
318-
319-
// Reset the static properties in the Config class to their defaults to prevent tests influencing each other.
320-
self::setStaticConfigProperty('executablePaths', []);
321-
self::setStaticConfigProperty('configData', null);
322-
self::setStaticConfigProperty('configDataFile', null);
323297
}
324298

325299
/**
326300
* Helper function to set the value of a private static property on the PHPCS Config class.
327301
*
328-
* @since 1.0.9
302+
* @since 1.0.9
303+
* @deprecated 1.1.0 Use the `PHPCSUtils\TestUtils\ConfigDouble::setStaticConfigProperty()` method instead.
304+
*
305+
* @codeCoverageIgnore
329306
*
330307
* @param string $name The name of the property to set.
331308
* @param mixed $value The value to set the property to.

0 commit comments

Comments
 (0)