Fix PHPUnit tests and SonarCloud analysis
This commit is contained in:
2
.github/workflows/code-quality.yml
vendored
2
.github/workflows/code-quality.yml
vendored
@@ -110,7 +110,7 @@ jobs:
|
|||||||
restore-keys: ${{ runner.os }}-sonar
|
restore-keys: ${{ runner.os }}-sonar
|
||||||
|
|
||||||
- name: SonarCloud Scan
|
- name: SonarCloud Scan
|
||||||
uses: SonarSource/sonarcloud-github-action@master
|
uses: SonarSource/sonarqube-scan-action@master
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
|
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
|
||||||
|
|||||||
2
.github/workflows/sonarcloud.yml
vendored
2
.github/workflows/sonarcloud.yml
vendored
@@ -28,7 +28,7 @@ jobs:
|
|||||||
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
|
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
|
||||||
|
|
||||||
- name: SonarCloud Scan
|
- name: SonarCloud Scan
|
||||||
uses: SonarSource/sonarcloud-github-action@master
|
uses: SonarSource/sonarqube-scan-action@master
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
|
||||||
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
|
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0"?>
|
<?xml version="1.0"?>
|
||||||
<phpunit
|
<phpunit
|
||||||
bootstrap="tests/bootstrap.php"
|
bootstrap="tests/phpunit/bootstrap.php"
|
||||||
backupGlobals="false"
|
backupGlobals="false"
|
||||||
colors="true"
|
colors="true"
|
||||||
convertErrorsToExceptions="true"
|
convertErrorsToExceptions="true"
|
||||||
@@ -10,6 +10,7 @@
|
|||||||
<testsuites>
|
<testsuites>
|
||||||
<testsuite name="unit">
|
<testsuite name="unit">
|
||||||
<directory prefix="test-" suffix=".php">./tests/</directory>
|
<directory prefix="test-" suffix=".php">./tests/</directory>
|
||||||
|
<directory prefix="test-" suffix=".php">./tests/phpunit/</directory>
|
||||||
</testsuite>
|
</testsuite>
|
||||||
</testsuites>
|
</testsuites>
|
||||||
<filter>
|
<filter>
|
||||||
|
|||||||
@@ -8,20 +8,43 @@
|
|||||||
// Composer autoloader must be loaded before WP_PHPUNIT__DIR will be available.
|
// Composer autoloader must be loaded before WP_PHPUNIT__DIR will be available.
|
||||||
require_once dirname( dirname( __DIR__ ) ) . '/vendor/autoload.php';
|
require_once dirname( dirname( __DIR__ ) ) . '/vendor/autoload.php';
|
||||||
|
|
||||||
// Give access to tests_add_filter() function.
|
// Check if we're running the WordPress tests
|
||||||
require_once getenv( 'WP_PHPUNIT__DIR' ) . '/includes/functions.php';
|
if ( getenv( 'WP_PHPUNIT__DIR' ) ) {
|
||||||
|
// Give access to tests_add_filter() function.
|
||||||
|
require_once getenv( 'WP_PHPUNIT__DIR' ) . '/includes/functions.php';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manually load the plugin being tested.
|
* Manually load the plugin being tested.
|
||||||
*/
|
*/
|
||||||
function _manually_load_plugin() {
|
function _manually_load_plugin() {
|
||||||
require dirname( dirname( __DIR__ ) ) . '/wp-plugin-starter-template.php';
|
require dirname( dirname( __DIR__ ) ) . '/wp-plugin-starter-template.php';
|
||||||
// Load the multisite class for testing
|
// Load the multisite class for testing
|
||||||
$multisite_file = dirname( dirname( __DIR__ ) ) . '/includes/multisite/class-multisite.php';
|
$multisite_file = dirname( dirname( __DIR__ ) ) . '/includes/multisite/class-multisite.php';
|
||||||
if (file_exists($multisite_file)) {
|
if (file_exists($multisite_file)) {
|
||||||
require $multisite_file;
|
require $multisite_file;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Start up the WP testing environment.
|
||||||
|
require getenv( 'WP_PHPUNIT__DIR' ) . '/includes/bootstrap.php';
|
||||||
|
} else {
|
||||||
|
// We're running the WP_Mock tests
|
||||||
|
WP_Mock::bootstrap();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Now we define a few constants to help us with testing.
|
||||||
|
*/
|
||||||
|
define('WPST_PLUGIN_DIR', dirname(dirname(__DIR__)) . '/');
|
||||||
|
define('WPST_PLUGIN_URL', 'http://example.org/wp-content/plugins/wp-plugin-starter-template/');
|
||||||
|
define('WPST_VERSION', '0.1.0');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Now we include any plugin files that we need to be able to run the tests.
|
||||||
|
* This should be files that define the functions and classes you're going to test.
|
||||||
|
*/
|
||||||
|
require_once WPST_PLUGIN_DIR . 'includes/class-core.php';
|
||||||
|
require_once WPST_PLUGIN_DIR . 'includes/class-plugin.php';
|
||||||
|
if (file_exists(WPST_PLUGIN_DIR . 'admin/lib/admin.php')) {
|
||||||
|
require_once WPST_PLUGIN_DIR . 'admin/lib/admin.php';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start up the WP testing environment.
|
|
||||||
require getenv( 'WP_PHPUNIT__DIR' ) . '/includes/bootstrap.php';
|
|
||||||
|
|||||||
Reference in New Issue
Block a user