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: Generate an HTML coverage report when running tests locally. #525

Merged
merged 1 commit into from
Feb 21, 2023
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@
"scripts": {
"lint": "phpcs",
"lint-php8": "phpcs -p --standard=PHPCompatibilityWP --runtime-set testVersion 8.0- --extensions=php --ignore='vendor/,wordpress/,node_modules/' .",
"test": "phpunit",
"test": "php -d xdebug.mode=coverage vendor/bin/phpunit",
"test:watch": [
"Composer\\Config::disableProcessTimeout",
"phpunit-watcher watch"
"phpunit-watcher watch --no-coverage"
],
"format": "phpcbf"
}
Expand Down
1 change: 1 addition & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
</exclude>
<report>
<clover outputFile="tests/logs/clover.xml" />
<html outputDirectory="tests/logs/html" />
</report>
</coverage>
</phpunit>
21 changes: 21 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,27 @@ See `package.json` for other available scripts you might want to use during deve

When you're ready, open [a pull request](https://help.github.com/articles/creating-a-pull-request-from-a-fork/) with the suggested changes.

## 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`.

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`.

## Deployments

Deployments [to WP.org plugin repository](https://wordpress.org/plugins/two-factor/) are handled automatically by the GitHub action [.github/workflows/deploy.yml](.github/workflows/deploy.yml). All merges to the `master` branch are commited to the [`trunk` directory](https://plugins.trac.wordpress.org/browser/two-factor/trunk) while all [Git tags](https://github.com/WordPress/two-factor/tags) are pushed as versioned releases [under the `tags` directory](https://plugins.trac.wordpress.org/browser/two-factor/tags).
Expand Down