| 1 |
# Developing on Windows |
| 2 |
|
| 3 |
**Disclaimer:** We don't officially support or recommend development on Windows, as some of our tooling may not run well out of the box or may not support Windows in the future. |
| 4 |
|
| 5 |
Having said that, this document describes some workarounds that (as of the time of this writing) result in a fully functional development environment under Windows. |
| 6 |
|
| 7 |
## Making integration tests work |
| 8 |
|
| 9 |
In order to run the integration tests included in the plugin, you must first install the WP Tests Suite. |
| 10 |
|
| 11 |
### Prerequisites |
| 12 |
|
| 13 |
- The requirements described in [](CONTRIBUTING.md#minimum-requirementsCONTRIBUTING.md](CONTRIBUTING.md#minimum-requirements](CONTRIBUTING.md#minimum-requirements). |
| 14 |
- An SVN client. Most SVN clients should do, but we've had success using [](https://sliksvn.com/download/SlikSVN](https://sliksvn.com/download/](https://sliksvn.com/download/). |
| 15 |
|
| 16 |
Please note that: |
| 17 |
|
| 18 |
- Your SVN client directory should be added to your `Path` Environment Variable. Most installers do this automatically. |
| 19 |
- `curl.exe` and your SVN client will need internet access to download required files. |
| 20 |
|
| 21 |
### Assumptions |
| 22 |
|
| 23 |
For this section, we will assume that: |
| 24 |
|
| 25 |
- You want to download the WP Tests Suite in the directory `C:\my-custom-path\wp-tests\` (please make sure you have write access to your desired path). |
| 26 |
- Your database user is `root` and your password is empty. |
| 27 |
- You want to name your database table `wp_tests`. |
| 28 |
- Note that below, "terminal" refers to any command line program you might be using, such as CMD, PowerShell, VSCode terminal, Cmder, etc. |
| 29 |
|
| 30 |
### Setting up |
| 31 |
|
| 32 |
1. Create the database `wp_tests` using your preferred tool. |
| 33 |
2. In `bin\install-wp-tests.sh`, change the `TMPDIR` variable to the desired path. Note that a traditional Windows path won't work. Here's an example with our path: |
| 34 |
|
| 35 |
``` |
| 36 |
TMPDIR="/C/my-custom-path/wp-tests/" |
| 37 |
``` |
| 38 |
|
| 39 |
**Warning:** If you don't do this, the files will be downloaded in the Windows TEMP directory, meaning they could get deleted soon. |
| 40 |
3. Open the plugin's directory in Git Bash (or any other environment that can run `.sh` files) and issue this command to download all the WP Test Suite files: |
| 41 |
|
| 42 |
``` |
| 43 |
./bin/install-wp-tests.sh "wp_tests" "root" "" "localhost" "trunk" "true" |
| 44 |
``` |
| 45 |
|
| 46 |
4. Open the `C:\my-custom-path\wp-tests\wordpress-tests-lib\wp-tests-config.php` file, and update the `ABSPATH` constant (should be on line 3) so it can be understood by PHP on Windows. For our case, `C:/my-custom-path/wp-tests/wordpress/` should work. |
| 47 |
5. Add a new Environment Variable called `WP_TESTS_DIR` with the value of the WP Tests Suite path, appending `wordpress-tests-lib\` (in our case `C:\my-custom-path\wp-tests\wordpress-tests-lib\`). Note that any existing terminal windows won't be aware of the new variable, so it is recommended to close them. |
| 48 |
6. In a new terminal, you should be able to execute the integration tests by running: |
| 49 |
|
| 50 |
``` |
| 51 |
composer testwp |
| 52 |
``` |
| 53 |
|
| 54 |
**Note:** If you're issuing the command from PowerShell and it fails, please try another environment as PowerShell had some issues during our testing. |
| 55 |
7. You might want to revert your change in `install-wp-tests.sh` so you don't commit it accidentally. |
| 56 |
|
| 57 |
## Fixing composer issues when committing |
| 58 |
|
| 59 |
When trying to make your first commit, you might receive errors telling you that composer (the PHP package manager) is an unknown command. The issue is that the pre-commit process (outlined in `.husky\pre-commit`) may not recognize the `composer.phar` or `composer.bat` files in your composer installation. |
| 60 |
|
| 61 |
To make this work: |
| 62 |
|
| 63 |
- Verify that `composer` is in your `Path` Environment Variable. |
| 64 |
- In your composer installation directory, make a copy of `composer.phar` and rename it to `composer` (remove the extension). |
| 65 |
|
| 66 |
Now the pre-commit process should be able to pickup any `composer` commands normally. |
| 67 |
|