Skip to content

Commit 8fc7986

Browse files
authored
devops: composer-git-hooks added. CONTRIBUTING.md updated. (wp-graphql#904)
1 parent 594bc29 commit 8fc7986

File tree

4 files changed

+833
-17
lines changed

4 files changed

+833
-17
lines changed

.github/CONTRIBUTING.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,37 @@ When contributing please ensure you follow the guidelines below so that we can k
2323
* If possible, and if applicable, please also add/update unit tests for your changes
2424
* Push the changes to your fork and submit a pull request to the 'develop' branch of this repository
2525

26+
### Setting up an environment to run the WPUnit tests
27+
28+
1. Create a `.env` file from the provided `.env.testing` and update the following section.
29+
30+
```env
31+
# WordPress database configurations
32+
DB_NAME=wordpress
33+
DB_HOST=app_db
34+
DB_PORT=3306
35+
DB_USER=wordpress
36+
DB_PASSWORD=password
37+
ROOT_PASSWORD=password
38+
WP_TABLE_PREFIX=wp_
39+
SKIP_DB_CREATE=true
40+
SKIP_WP_SETUP=true
41+
42+
```
43+
44+
The variable should be point to a local instance of MySQL and `SKIP_DB_CREATE` and `SKIP_WP_SETUP` should be set to `false`.
45+
2. Run `composer installTestEnv` from the terminal in the plugin root directory. This will run the setup script and install all the required dependencies.
46+
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)
47+
48+
### Setting up a Docker environment to run the E2E tests
49+
50+
1. Run `composer installTestEnv` from the terminal in the plugin root directory to install all the required dependencies.
51+
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.
52+
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`.
53+
54+
> **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`.
55+
56+
2657
## Code Documentation
2758
2859
* We strive for full doc coverage and follow the standards set by phpDoc

bin/_lib.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ cleanup_local_files() {
130130
echo "Rebuilding lock file..."
131131
rm -rf $PROJECT_ROOT_DIR/vendor
132132

133-
composer install --no-dev
133+
composer install
134134
}
135135

136136
install_db() {

composer.json

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"require-dev": {
2828
"axepress/wp-graphql-cs": "^2.0.0-beta",
2929
"axepress/wp-graphql-stubs": "^1.27.1",
30+
"brainmaestro/composer-git-hooks": "^3.0",
3031
"php-stubs/woocommerce-stubs": "9.1.0",
3132
"phpstan/extension-installer": "^1.3",
3233
"phpstan/phpdoc-parser": "^1.22.0",
@@ -40,8 +41,7 @@
4041
"allow-plugins": {
4142
"johnpbloch/wordpress-core-installer": true,
4243
"dealerdirect/phpcodesniffer-composer-installer": true,
43-
"phpstan/extension-installer": true,
44-
"composer/installers": true
44+
"phpstan/extension-installer": true
4545
}
4646
},
4747
"autoload": {
@@ -81,11 +81,14 @@
8181
"@php bin/strauss.phar",
8282
"composer dump-autoload --optimize"
8383
],
84+
"cghooks": "vendor/bin/cghooks",
8485
"post-install-cmd": [
85-
"@strauss"
86+
"@strauss",
87+
"@cghooks add -i"
8688
],
8789
"post-update-cmd": [
88-
"@strauss"
90+
"@strauss",
91+
"@cghooks update"
8992
]
9093
},
9194
"support": {
@@ -128,6 +131,14 @@
128131
"exclude_from_prefix": {
129132
"file_patterns": []
130133
}
134+
},
135+
"hooks": {
136+
"pre-commit": [
137+
"composer runPreCommitCleanup"
138+
],
139+
"post-merge": [
140+
"composer install"
141+
]
131142
}
132143
}
133144
}

0 commit comments

Comments
 (0)