Skip to content

Commit a869bc3

Browse files
committed
AbstractMethodTestCase/AbstractTokenizerTestCase: use LocalFile instead of DummyFile
Should work just the same and just as well. Historical context: looks like the use of `DummyFile` is a left over from a time long, long ago, when the "test case code" was included in the same file as the unit test class. This was changed in 2016 for PHPCS 2.x via PR squizlabs/PHP_CodeSniffer 1193, but then the merge up into PHPCS 3.x (which introduced `DummyFile`) did not change the object instantiation.
1 parent 5dace4b commit a869bc3

File tree

2 files changed

+4
-12
lines changed

2 files changed

+4
-12
lines changed

tests/Core/AbstractMethodTestCase.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
namespace PHP_CodeSniffer\Tests\Core;
1111

1212
use Exception;
13-
use PHP_CodeSniffer\Files\DummyFile;
1413
use PHP_CodeSniffer\Files\File;
14+
use PHP_CodeSniffer\Files\LocalFile;
1515
use PHP_CodeSniffer\Ruleset;
1616
use PHP_CodeSniffer\Tests\ConfigDouble;
1717
use PHPUnit\Framework\TestCase;
@@ -58,11 +58,7 @@ public static function setUpBeforeClass(): void
5858
$relativePath = str_replace('\\', DIRECTORY_SEPARATOR, $relativeCN);
5959
$pathToTestFile = realpath(__DIR__).$relativePath.'.inc';
6060

61-
// Make sure the file gets parsed correctly based on the file type.
62-
$contents = 'phpcs_input_file: '.$pathToTestFile.PHP_EOL;
63-
$contents .= file_get_contents($pathToTestFile);
64-
65-
self::$phpcsFile = new DummyFile($contents, $ruleset, $config);
61+
self::$phpcsFile = new LocalFile($pathToTestFile, $ruleset, $config);
6662
self::$phpcsFile->parse();
6763

6864
}//end setUpBeforeClass()

tests/Core/Tokenizers/AbstractTokenizerTestCase.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
namespace PHP_CodeSniffer\Tests\Core\Tokenizers;
1414

15-
use PHP_CodeSniffer\Files\DummyFile;
15+
use PHP_CodeSniffer\Files\LocalFile;
1616
use PHP_CodeSniffer\Ruleset;
1717
use PHP_CodeSniffer\Tests\ConfigDouble;
1818
use PHP_CodeSniffer\Tests\Core\AbstractMethodTestCase;
@@ -63,11 +63,7 @@ protected function setUp(): void
6363
$relativePath = str_replace('\\', DIRECTORY_SEPARATOR, $relativeCN);
6464
$pathToTestFile = realpath(__DIR__).$relativePath.'.inc';
6565

66-
// Make sure the file gets parsed correctly based on the file type.
67-
$contents = 'phpcs_input_file: '.$pathToTestFile.PHP_EOL;
68-
$contents .= file_get_contents($pathToTestFile);
69-
70-
$this->phpcsFile = new DummyFile($contents, $ruleset, $config);
66+
$this->phpcsFile = new LocalFile($pathToTestFile, $ruleset, $config);
7167
$this->phpcsFile->parse();
7268
}//end if
7369

0 commit comments

Comments
 (0)