Skip to content

Commit

Permalink
devops: composer-git-hooks added. CONTRIBUTING.md updated. (#904)
Browse files Browse the repository at this point in the history
  • Loading branch information
kidunot89 authored Nov 6, 2024
1 parent 594bc29 commit 8fc7986
Show file tree
Hide file tree
Showing 4 changed files with 833 additions and 17 deletions.
31 changes: 31 additions & 0 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,37 @@ When contributing please ensure you follow the guidelines below so that we can k
* If possible, and if applicable, please also add/update unit tests for your changes
* Push the changes to your fork and submit a pull request to the 'develop' branch of this repository

### Setting up an environment to run the WPUnit tests

1. Create a `.env` file from the provided `.env.testing` and update the following section.

```env
# WordPress database configurations
DB_NAME=wordpress
DB_HOST=app_db
DB_PORT=3306
DB_USER=wordpress
DB_PASSWORD=password
ROOT_PASSWORD=password
WP_TABLE_PREFIX=wp_
SKIP_DB_CREATE=true
SKIP_WP_SETUP=true
```
The variable should be point to a local instance of MySQL and `SKIP_DB_CREATE` and `SKIP_WP_SETUP` should be set to `false`.
2. Run `composer installTestEnv` from the terminal in the plugin root directory. This will run the setup script and install all the required dependencies.
3. Run the tests by running `vendor/bin/codecept run wpunit` from the root directory. To learn about the libraries used to write the tests see [Codeception](https://codeception.com/), [WPBrowser](https://wpbrowser.wptestkit.dev/modules/WPBrowser/), and [WPGraphQL TestCase](https://github.com/wp-graphql/wp-graphql-testcase)
### Setting up a Docker environment to run the E2E tests
1. Run `composer installTestEnv` from the terminal in the plugin root directory to install all the required dependencies.
2. Next run `composer dRunApp`. This will build and start the docker network at http://localhost:8080 based off the configuration found in the `docker-compose.yml` in the project root.
3. Last run the test by running `composer dRunTest`. This runs the test suite by utilizing the `docker exec` command to run `vendor/bin/codecept run` from the project root within the docker container for wordpress site. You can pass further parameter to this comment by using the `FILTER` environment variable like so `FILTER="acceptance NewCustomerCheckingOutCept --debug" composer dRunTest`.
> **NOTE:** If you have no interest in the generated docker environment outside of automated test you can simply the process by just running the `dRunTestStandalone` command after the `installTestEnv` command combining steps 2 & 3, `composer dRunTestStandalone`. The command also reads the `FILTER` variables as well to so filter is possible `FILTER="acceptance NewCustomerCheckingOutCept --debug" composer dRunTestStandalone`.
## Code Documentation
* We strive for full doc coverage and follow the standards set by phpDoc
Expand Down
2 changes: 1 addition & 1 deletion bin/_lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ cleanup_local_files() {
echo "Rebuilding lock file..."
rm -rf $PROJECT_ROOT_DIR/vendor

composer install --no-dev
composer install
}

install_db() {
Expand Down
19 changes: 15 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"require-dev": {
"axepress/wp-graphql-cs": "^2.0.0-beta",
"axepress/wp-graphql-stubs": "^1.27.1",
"brainmaestro/composer-git-hooks": "^3.0",
"php-stubs/woocommerce-stubs": "9.1.0",
"phpstan/extension-installer": "^1.3",
"phpstan/phpdoc-parser": "^1.22.0",
Expand All @@ -40,8 +41,7 @@
"allow-plugins": {
"johnpbloch/wordpress-core-installer": true,
"dealerdirect/phpcodesniffer-composer-installer": true,
"phpstan/extension-installer": true,
"composer/installers": true
"phpstan/extension-installer": true
}
},
"autoload": {
Expand Down Expand Up @@ -81,11 +81,14 @@
"@php bin/strauss.phar",
"composer dump-autoload --optimize"
],
"cghooks": "vendor/bin/cghooks",
"post-install-cmd": [
"@strauss"
"@strauss",
"@cghooks add -i"
],
"post-update-cmd": [
"@strauss"
"@strauss",
"@cghooks update"
]
},
"support": {
Expand Down Expand Up @@ -128,6 +131,14 @@
"exclude_from_prefix": {
"file_patterns": []
}
},
"hooks": {
"pre-commit": [
"composer runPreCommitCleanup"
],
"post-merge": [
"composer install"
]
}
}
}
Loading

0 comments on commit 8fc7986

Please sign in to comment.