Merge pull request #26345 from woocommerce/refactor/phpunit-suite
Restructure PHPUnit Suite
This commit is contained in:
commit
c0ecb79ba2
|
@ -43,6 +43,11 @@
|
|||
"Automattic\\WooCommerce\\": "src/"
|
||||
}
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"Automattic\\WooCommerce\\Tests\\": "tests/php/"
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"post-install-cmd": [
|
||||
"sh ./bin/package-update.sh"
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
<!-- Exclude paths -->
|
||||
<exclude-pattern>tests/cli/</exclude-pattern>
|
||||
<exclude-pattern>tests/legacy/</exclude-pattern>
|
||||
<exclude-pattern>includes/libraries/</exclude-pattern>
|
||||
<exclude-pattern>includes/legacy/</exclude-pattern>
|
||||
<exclude-pattern>includes/api/legacy/</exclude-pattern>
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<phpunit
|
||||
bootstrap="tests/bootstrap.php"
|
||||
bootstrap="tests/legacy/bootstrap.php"
|
||||
backupGlobals="false"
|
||||
colors="true"
|
||||
convertErrorsToExceptions="true"
|
||||
|
@ -10,7 +10,8 @@
|
|||
>
|
||||
<testsuites>
|
||||
<testsuite name="WooCommerce Test Suite">
|
||||
<directory suffix=".php">./tests/unit-tests</directory>
|
||||
<directory suffix=".php">./tests/legacy/unit-tests</directory>
|
||||
<directory suffix=".php">./tests/php</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
<filter>
|
||||
|
@ -46,6 +47,6 @@
|
|||
</whitelist>
|
||||
</filter>
|
||||
<listeners>
|
||||
<listener class="SpeedTrapListener" file="tests/includes/listener-loader.php" />
|
||||
<listener class="SpeedTrapListener" file="tests/legacy/includes/listener-loader.php" />
|
||||
</listeners>
|
||||
</phpunit>
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
# Prevent anyone from accidentally adding code to these directories.
|
||||
# This will break any PRs that do, revealing ths mistake they made.
|
||||
*
|
||||
!.gitignore
|
||||
!README.md
|
|
@ -0,0 +1,3 @@
|
|||
# WARNING
|
||||
|
||||
The namespace of this folder belongs to the [WC-Admin Plugin](https://github.com/woocommerce/woocommerce-admin) that is included in Core via composer. Any contributions to this namespace should be made in the corresponding repository to prevent conflicts.
|
|
@ -0,0 +1,5 @@
|
|||
# Prevent anyone from accidentally adding code to these directories.
|
||||
# This will break any PRs that do, revealing ths mistake they made.
|
||||
*
|
||||
!.gitignore
|
||||
!README.md
|
|
@ -0,0 +1,3 @@
|
|||
# WARNING
|
||||
|
||||
The namespace of this folder belongs to the [Product Blocks Plugin](https://github.com/woocommerce/woocommerce-gutenberg-products-block) that is included in Core via composer. Any contributions to this namespace should be made in the corresponding repository to prevent conflicts.
|
|
@ -46,7 +46,7 @@ The tests will execute and you'll be presented with a summary.
|
|||
|
||||
You can run specific tests by providing the path and filename to the test class:
|
||||
|
||||
$ vendor/bin/phpunit tests/unit-tests/importer/product.php
|
||||
$ vendor/bin/phpunit tests/legacy/unit-tests/importer/product.php
|
||||
|
||||
A text code coverage summary can be displayed using the `--coverage-text` option:
|
||||
|
||||
|
@ -54,6 +54,7 @@ A text code coverage summary can be displayed using the `--coverage-text` option
|
|||
|
||||
### Writing Tests
|
||||
|
||||
* There are two different PHPUnit directories, `tests/legacy` and `tests/php`. The `tests/legacy` directory contains all of the tests for code in the `includes` directory, and the `tests/php` directory is a PSR-4 namespaced directory for tests of code in the `src` directory.
|
||||
* Each test file should roughly correspond to an associated source file, e.g. the `formatting/functions.php` test file covers code in the `wc-formatting-functions.php` file
|
||||
* Each test method should cover a single method or function with one or more assertions
|
||||
* A single method or function can have multiple associated test methods if it's a large or complex method
|
||||
|
|
|
@ -41,7 +41,7 @@ class WC_Unit_Tests_Bootstrap {
|
|||
// phpcs:enable WordPress.VIP.SuperGlobalInputUsage.AccessDetected
|
||||
|
||||
$this->tests_dir = dirname( __FILE__ );
|
||||
$this->plugin_dir = dirname( $this->tests_dir );
|
||||
$this->plugin_dir = dirname( dirname( $this->tests_dir ) );
|
||||
$this->wp_tests_dir = getenv( 'WP_TESTS_DIR' ) ? getenv( 'WP_TESTS_DIR' ) : sys_get_temp_dir() . '/wordpress-tests-lib';
|
||||
|
||||
// load test function so tests_add_filter() is available.
|
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 10 KiB |
|
@ -41,7 +41,7 @@ class WC_Test_WooCommerce extends WC_Unit_Test_Case {
|
|||
* @since 2.2
|
||||
*/
|
||||
public function test_constants() {
|
||||
$this->assertEquals( str_replace( 'tests/unit-tests/core/', '', plugin_dir_path( __FILE__ ) ) . 'woocommerce.php', WC_PLUGIN_FILE );
|
||||
$this->assertEquals( str_replace( 'tests/legacy/unit-tests/core/', '', plugin_dir_path( __FILE__ ) ) . 'woocommerce.php', WC_PLUGIN_FILE );
|
||||
$this->assertEquals( $this->wc->version, Constants::get_constant( 'WC_VERSION' ) );
|
||||
$this->assertEquals( WC_VERSION, WOOCOMMERCE_VERSION );
|
||||
$this->assertEquals( 6, WC_ROUNDING_PRECISION );
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue