Skip to content

Commit

Permalink
Run tests on the tests container, such as not to affect the WordPress…
Browse files Browse the repository at this point in the history
… env
  • Loading branch information
dd32 committed Aug 20, 2024
1 parent 9287c24 commit 1aa4fb3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 19 deletions.
11 changes: 10 additions & 1 deletion class-two-factor-core.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ public static function get_providers() {
* @return array
*/
public static function enable_dummy_method_for_debug( $methods ) {
if ( ! self::is_wp_debug() ) {
if ( ! self::is_wp_debug() && ! self::is_tests() ) {
unset( $methods['Two_Factor_Dummy'] );
}

Expand All @@ -225,6 +225,15 @@ protected static function is_wp_debug() {
return ( defined( 'WP_DEBUG' ) && WP_DEBUG );
}

/**
* Check if we're running within Unit Tests.
*
* @return boolean
*/
protected static function is_tests() {
return defined( 'DIR_TESTDATA' ) && function_exists( 'tests_add_filter' );
}

/**
* Get the user settings page URL.
*
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"private": true,
"engineStrict": true,
"engines": {
"node": ">=16"
"node": ">=20"
},
"homepage": "https://github.com/wordpress/two-factor",
"scripts": {
Expand All @@ -21,7 +21,7 @@
"format:css": "npm run lint:css -- --fix",
"test": "npm run composer test",
"test:watch": "npm run composer test:watch",
"composer": "wp-env run cli --env-cwd=wp-content/plugins/two-factor composer",
"composer": "wp-env run tests-cli --env-cwd=wp-content/plugins/two-factor composer",
"preinstall": "composer install"
},
"repository": {
Expand Down
17 changes: 1 addition & 16 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,7 @@ When you're ready, open [a pull request](https://help.github.com/articles/creati

## Testing

### Running tests in Docker

1. Run `npm run env start`
1. Run `npm run test` or `npm run test:watch`.

### Running tests locally

1. Create a MySQL database for the tests. Don't reuse an existing database, because all of the data will be deleted every time the tests are run.
1. Add the following to your `~/.bashrc`, with the values for the database you created above:
```
export WORDPRESS_DB_NAME=wp_tests
export WORDPRESS_DB_USER=wp_tests
export WORDPRESS_DB_PASSWORD=wp_tests
```
1. `source ~/.bashrc`
1. Run `composer run test` or `composer run test:watch`.
1. Run `npm test` or `npm run test:watch`.

To view the code coverage report, you can open a web browser, go to `File > Open file...`, and then select `{path to two-factor}/tests/logs/html/index.html`.

Expand Down

0 comments on commit 1aa4fb3

Please sign in to comment.