-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #328 from Yoast/JRF/yoastcs-tests-add-nonsnifftest…
…case Tests: add abstract `NonSniffTestCase` class
- Loading branch information
Showing
1 changed file
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
namespace YoastCS\Yoast\Tests; | ||
|
||
use PHP_CodeSniffer\Config; | ||
use PHP_CodeSniffer\Files\File; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* Base TestCase for non-sniff, non-code related tests, which still need a PHPCS File object. | ||
* | ||
* Note: this class will likely be moved to PHPCSUtils at some point in the future (once PHPCSUtils drops PHP < 7.0). | ||
* | ||
* @since 3.0.0 | ||
*/ | ||
abstract class NonSniffTestCase extends TestCase { | ||
|
||
/** | ||
* Create a mocked PHPCS File object. | ||
* | ||
* @return File | ||
*/ | ||
protected function get_mock_file() { | ||
$config = new class() extends Config { | ||
|
||
/** | ||
* Disable the original class constructor. | ||
*/ | ||
public function __construct() {} | ||
}; | ||
|
||
$phpcsFile = new class() extends File { | ||
|
||
/** | ||
* Disable the original class constructor. | ||
*/ | ||
public function __construct() {} | ||
}; | ||
|
||
$phpcsFile->config = $config; | ||
|
||
return $phpcsFile; | ||
} | ||
} |