Skip to content

Commit 8061824

Browse files
authored
Merge pull request #64 from Automattic/standardize/configs-and-ci
2 parents 2f13a4a + ae04abe commit 8061824

File tree

12 files changed

+315
-7
lines changed

12 files changed

+315
-7
lines changed

.distignore

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Directories
2+
/.git/
3+
/.github/
4+
/bin/
5+
/node_modules/
6+
/tests/
7+
/vendor/
8+
9+
# Files
10+
.distignore
11+
.editorconfig
12+
.gitattributes
13+
.gitignore
14+
.phpcs.xml.dist
15+
.wp-env.json
16+
.wp-env.override.json
17+
CHANGELOG.md
18+
composer.json
19+
composer.lock
20+
package.json
21+
package-lock.json
22+
phpunit.xml.dist

.github/dependabot.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Configuration for Dependabot version updates
2+
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file
3+
4+
version: 2
5+
updates:
6+
- package-ecosystem: "github-actions"
7+
directory: "/"
8+
schedule:
9+
interval: "weekly"
10+
day: "monday"
11+
groups:
12+
actions:
13+
patterns: ["*"]
14+
labels:
15+
- "dependencies"
16+
reviewers:
17+
- "Automattic/vip-plugins"
18+
commit-message:
19+
prefix: "Actions"
20+
include: "scope"
21+
open-pull-requests-limit: 5
22+
23+
- package-ecosystem: "composer"
24+
directory: "/"
25+
schedule:
26+
interval: "weekly"
27+
day: "tuesday"
28+
groups:
29+
dev-dependencies:
30+
patterns:
31+
- "automattic/*"
32+
- "dealerdirect/*"
33+
- "php-parallel-lint/*"
34+
- "phpcompatibility/*"
35+
- "phpunit/*"
36+
- "squizlabs/*"
37+
- "yoast/*"
38+
labels:
39+
- "dependencies"
40+
reviewers:
41+
- "Automattic/vip-plugins"
42+
commit-message:
43+
prefix: "Composer"
44+
include: "scope"
45+
open-pull-requests-limit: 5
46+
versioning-strategy: increase-if-necessary

.gitignore

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
1+
# Dependencies
2+
/node_modules/
13
/vendor/
2-
.phpcs.xml
3-
phpcs.xml
4-
composer.lock
4+
5+
# Composer
6+
/composer.lock
7+
8+
# Tests
9+
/.phpunit.cache/
10+
11+
# Local config overrides
12+
/.phpcs.xml
13+
/phpcs.xml
14+
/phpunit.xml
15+
/.wp-env.override.json

composer.json

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,17 @@
1919
"composer/installers": "^1.0 || ^2.0"
2020
},
2121
"require-dev": {
22-
"rector/rector": "^1.2",
2322
"automattic/vipwpcs": "^3.0",
24-
"phpcompatibility/phpcompatibility-wp": "^2.1"
23+
"php-parallel-lint/php-parallel-lint": "^1.0",
24+
"phpcompatibility/phpcompatibility-wp": "^2.1",
25+
"phpunit/phpunit": "^9",
26+
"rector/rector": "^1.2",
27+
"yoast/wp-test-utils": "^1.2"
28+
},
29+
"autoload-dev": {
30+
"psr-4": {
31+
"Automattic\\RewriteRulesInspector\\Tests\\": "tests/"
32+
}
2533
},
2634
"config": {
2735
"allow-plugins": {
@@ -31,9 +39,27 @@
3139
"sort-packages": true
3240
},
3341
"scripts": {
34-
"i18n": "@php wp i18n make-pot . ./languages/rewrite-rules-inspector.pot"
42+
"coverage": "@php ./vendor/bin/phpunit --coverage-html ./build/coverage-html",
43+
"coverage-ci": "@php ./vendor/bin/phpunit",
44+
"cs": "@php ./vendor/bin/phpcs -q",
45+
"cs-fix": "@php ./vendor/bin/phpcbf -q",
46+
"i18n": "@php wp i18n make-pot . ./languages/rewrite-rules-inspector.pot",
47+
"lint": "@php ./vendor/php-parallel-lint/php-parallel-lint/parallel-lint . -e php --exclude vendor --exclude .git",
48+
"lint-ci": "@php ./vendor/php-parallel-lint/php-parallel-lint/parallel-lint . -e php --exclude vendor --exclude .git --checkstyle",
49+
"test:unit": "@php ./vendor/bin/phpunit --testsuite Unit",
50+
"test:integration": "wp-env run tests-cli --env-cwd=wp-content/plugins/rewrite-rules-inspector ./vendor/bin/phpunit --testsuite WP_Tests",
51+
"test:integration-ms": "wp-env run tests-cli --env-cwd=wp-content/plugins/rewrite-rules-inspector /bin/bash -c 'WP_MULTISITE=1 ./vendor/bin/phpunit --testsuite WP_Tests'"
3552
},
3653
"scripts-descriptions": {
37-
"i18n": "Generate a POT file for translation."
54+
"coverage": "Run tests with code coverage reporting",
55+
"coverage-ci": "Run tests with code coverage reporting and send results to stdout",
56+
"cs": "Run PHP Code Sniffer",
57+
"cs-fix": "Run PHP Code Sniffer and fix violations",
58+
"i18n": "Generate a POT file for translation",
59+
"lint": "Run PHP linting",
60+
"lint-ci": "Run PHP linting and send results to stdout",
61+
"test:unit": "Run unit tests",
62+
"test:integration": "Run integration tests",
63+
"test:integration-ms": "Run integration tests in multisite mode"
3864
}
3965
}

phpunit.xml.dist

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.6/phpunit.xsd"
5+
bootstrap="tests/bootstrap.php"
6+
backupGlobals="false"
7+
colors="true"
8+
convertErrorsToExceptions="true"
9+
convertNoticesToExceptions="true"
10+
convertWarningsToExceptions="true"
11+
beStrictAboutTestsThatDoNotTestAnything="true"
12+
>
13+
<testsuites>
14+
<testsuite name="Unit">
15+
<directory suffix="Test.php">./tests/Unit</directory>
16+
</testsuite>
17+
<testsuite name="WP_Tests">
18+
<directory suffix="Test.php">./tests/Integration</directory>
19+
</testsuite>
20+
</testsuites>
21+
<coverage>
22+
<include>
23+
<directory suffix=".php">./src</directory>
24+
<file>./rewrite-rules-inspector.php</file>
25+
</include>
26+
<exclude>
27+
<directory>./vendor</directory>
28+
<directory>./tests</directory>
29+
</exclude>
30+
</coverage>
31+
</phpunit>

tests/Integration/PluginTest.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
/**
3+
* Integration tests for the plugin.
4+
*
5+
* @package Automattic\RewriteRulesInspector\Tests\Integration
6+
*/
7+
8+
namespace Automattic\RewriteRulesInspector\Tests\Integration;
9+
10+
/**
11+
* Test case for plugin integration.
12+
*/
13+
class PluginTest extends TestCase {
14+
15+
/**
16+
* Test that the plugin constant is defined.
17+
*/
18+
public function test_plugin_constant_defined(): void {
19+
$this->assertTrue( defined( 'REWRITE_RULES_INSPECTOR_VERSION' ) );
20+
}
21+
22+
/**
23+
* Test that the plugin file path constant is defined.
24+
*/
25+
public function test_plugin_file_path_constant_defined(): void {
26+
$this->assertTrue( defined( 'REWRITE_RULES_INSPECTOR_FILE_PATH' ) );
27+
}
28+
29+
/**
30+
* Test that the global plugin instance exists.
31+
*/
32+
public function test_global_plugin_instance_exists(): void {
33+
global $rewrite_rules_inspector;
34+
$this->assertInstanceOf( \Automattic\RewriteRulesInspector\Plugin::class, $rewrite_rules_inspector );
35+
}
36+
37+
/**
38+
* Test that the admin menu is registered.
39+
*/
40+
public function test_admin_menu_registered(): void {
41+
$this->assertGreaterThan(
42+
0,
43+
has_action( 'admin_menu', [ \Automattic\RewriteRulesInspector\Admin\AdminPage::class, 'register_page' ] )
44+
);
45+
}
46+
}

tests/Integration/TestCase.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
/**
3+
* Base test case for integration tests.
4+
*
5+
* @package Automattic\RewriteRulesInspector\Tests\Integration
6+
*/
7+
8+
namespace Automattic\RewriteRulesInspector\Tests\Integration;
9+
10+
use Yoast\WPTestUtils\WPIntegration\TestCase as WPIntegrationTestCase;
11+
12+
/**
13+
* Base test case for integration tests.
14+
*/
15+
abstract class TestCase extends WPIntegrationTestCase {
16+
// Extend as needed.
17+
}

tests/Integration/bootstrap.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
/**
3+
* Integration tests bootstrap file.
4+
*
5+
* @package Automattic\RewriteRulesInspector\Tests\Integration
6+
*/
7+
8+
use Yoast\WPTestUtils\WPIntegration;
9+
10+
// Load Composer autoloader.
11+
require_once dirname( __DIR__, 2 ) . '/vendor/autoload.php';
12+
13+
// Get access to tests_add_filter() function.
14+
require_once getenv( 'WP_PHPUNIT__DIR' ) . '/includes/functions.php';
15+
16+
/**
17+
* Manually load the plugin being tested.
18+
*/
19+
tests_add_filter(
20+
'muplugins_loaded',
21+
static function (): void {
22+
require dirname( __DIR__, 2 ) . '/rewrite-rules-inspector.php';
23+
}
24+
);
25+
26+
// Bootstrap WordPress.
27+
WPIntegration\bootstrap_it();
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
/**
3+
* Unit tests for the RewriteRules class.
4+
*
5+
* @package Automattic\RewriteRulesInspector\Tests\Unit\Core
6+
*/
7+
8+
namespace Automattic\RewriteRulesInspector\Tests\Unit\Core;
9+
10+
use Automattic\RewriteRulesInspector\Tests\Unit\TestCase;
11+
use Brain\Monkey\Functions;
12+
13+
/**
14+
* Test case for RewriteRules class.
15+
*/
16+
class RewriteRulesTest extends TestCase {
17+
18+
/**
19+
* Test that the class can be instantiated.
20+
*/
21+
public function test_class_exists(): void {
22+
$this->assertTrue( class_exists( \Automattic\RewriteRulesInspector\Core\RewriteRules::class ) );
23+
}
24+
}

tests/Unit/TestCase.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
/**
3+
* Base test case for unit tests.
4+
*
5+
* @package Automattic\RewriteRulesInspector\Tests\Unit
6+
*/
7+
8+
namespace Automattic\RewriteRulesInspector\Tests\Unit;
9+
10+
use Yoast\WPTestUtils\BrainMonkey\TestCase as BrainMonkeyTestCase;
11+
12+
/**
13+
* Base test case for unit tests.
14+
*/
15+
abstract class TestCase extends BrainMonkeyTestCase {
16+
// Extend as needed.
17+
}

0 commit comments

Comments
 (0)