Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests: add abstract NonSniffTestCase class #328

Merged
merged 1 commit into from
Nov 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions Yoast/Tests/NonSniffTestCase.php
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;
}
}