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

Integrating WP Unit Testing in windows #101

Closed
ronaksampat opened this issue Jul 24, 2017 · 4 comments
Closed

Integrating WP Unit Testing in windows #101

ronaksampat opened this issue Jul 24, 2017 · 4 comments

Comments

@ronaksampat
Copy link

ronaksampat commented Jul 24, 2017

This document assumes that you have already tried setting up WP Unit Testing environment for your project in windows but have stucked somewhere.

The purpose of this discussion is to perfectly set up WP Unit Testing environment in a local project. Followed through https://make.wordpress.org/cli/handbook/plugin-unit-tests/ but it lacks some points when it comes to windows with addition to some general points missing.

First, some commands in wp-cli doesnt work with windows, so use cygwin or alike command line utility.
Cygwin is preferred because its suggested even in Working With Patches – Make WordPress Core.

Before starting, let me suggest that if you fail with running wp scaffold command then update your wp-cli to stable version first (Ex : wp cli update --nightly)

For ease of understanding, I rewrite the points of above mentioned tutorial, such as ...

  1. Generate the plugin test files:

    wp scaffold plugin-tests my-plugin

It would work perfectly when you are running it on WordPress downloaded with wp core download but when you run this command in any local WordPress setup, which is not downloaded from above, it would generate error :

Error: This does not seem to be a WordPress install.
Pass --path=path/to/wordpress or run wp core download.

Which is valid cause its not installed from wp-cli, run the wp core download and it will create src with WordPress in it (The folder structure of core WordPress installation).

Running plugin-tests command can still generate error like ....

Error: 'wp-config.php' not found.
Either create one manually or use wp config create.

Now, running wp config create will create wp-config.php file in src installation.

  1. Initialize the testing environment locally: cd into the plugin directory and run the install script. (You’ll need to already have svn and wget installed.)

bash bin/install-wp-tests.sh wordpress_test root '' localhost latest

bash script does not work directly in windows. In windows10, they have introduced "Windows Subsystem for Linux" but in other versions of windows, you need to do separate work for running bash. Cygwin by default runs the bash scripts.

For running above bash script, not only svn and wget but svn and either wget or curl are required because of the following lines in install-wp-tests.sh script

download() { if [ which curl]; then curl -s "$1" > "$2"; elif [which wget ]; then wget -nv -O "$2" "$1" fi }

Again, which is a linux command not by default in windows, it can be installed as a package. All curl, svn and wget can be installed in windows as packages, but for running bash you need to be depending on third party tools, Cygwin in our case.

Bash script is bound to build wordpress over there right after wordpress-tests-lib because of mkdir -p $WP_CORE_DIR in install-wp-tests.sh file but it sometimes fails because its a tmp folder and so sometimes it depends on whether or not tmp folder is perfectly emptied or not. If in any case WordPress folder does not get created there, then you can set up one manually. The logic is, while running any tests, it runs them against this WordPress in /tmp/wordpress-tests-lib. So finally in your /tmp folder there should be structure like this ...

  1. data
  2. includes
  3. WordPress
  4. wp-tests-config.php file

Finally run phpunit and there you go.....

Hope, above mentioned tutorial helps.

@danielbachhuber
Copy link
Member

Thanks for submitting this issue, @ronaksampat.

Want to submit a pull request to the existing documentation with any improvements you'd suggest?

@ronaksampat
Copy link
Author

ronaksampat commented Jul 25, 2017

Hi @danielbachhuber, yes I would like to submit a pull request, with the points that I shared above but specifically ....

  1. If scaffold command fails, update to stable version (wp cli update --nightly)
  2. If testing locally, create a config file with wp config create
  3. Try using Cygwin or alike command line utility (Ex : vagrant can still be used)
  4. If bash script fails creating WordPress in /tmp then create one manually with wp-tests-config.php

@danielbachhuber
Copy link
Member

@ronaksampat Sounds good 👍

@danielbachhuber danielbachhuber added this to the 1.3.0 milestone Aug 7, 2017
@danielbachhuber
Copy link
Member

Landed in #103

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants