Automattic / Automattic/WP-Job-Manager

Unit tests fail in an unhelpful way when install-wp-tests.sh has not been run

Open
#1,526 0 comments 0 reactions 0 assignees View on GitHub
[Pri] Low [Status] Accepted [Type] Cleanup and Documentation
Dominant language
PHP
Stars
899
Forks
369
Avg merge
11h 37m
Merged PRs (30d)
12

Description

It would be much better if this failure had an error check to see if this file exists before it is required. If it doesn't then it would be great to have a helpful error message displayed instead that lets you know what you should do to fix the problem.

Instead, I had to dig through the README for instructions.

Note: There was a second layer to this problem.

The `bin/install-wp-tests.sh` script installs the files to the `/tmp/wordpress-tests-lib` directory... theoretically. Instead of going straight to `/tmp`, it will use the value in the `TMPDIR` environmental variable. In my case, this was set by vscode to be something other than /tmp which caused this script to install into another place.

It might be worthwhile to also make sure that the test bootstrap also checks the folder that is behind the TMPDIR env var if it is set, as well. Just in case the user is using the vscode terminal like I was.

#### Steps to Reproduce

1. Run `grunt test`

#### What I Expected

That unit tests would run

#### What Happened Instead

Unit tests failed to run because files were missing:

```
Warning: Uncaught Exception: Warning: require_once(/tmp/wordpress-tests-lib/includes/functions.php): failed to open stream: No such file or directory in .../wp-content/plugins/WP-Job-Manager/tests/php/bootstrap.php on line 42 in .../wp-content/plugins/WP-Job-Manager/tests/php/bootstrap.php:150
```

#### WordPress / WP Job Manager Version

master

#### Browser / OS Version

Mac OSX terminal

Contributor guide

Open the contributing guide

Research direction

Start with tests/php/bootstrap.php around the require_once failure at line 42, then inspect bin/install-wp-tests.sh and its handling of TMPDIR. Run grunt test without the test library installed to reproduce the failure. Done means missing files produce a helpful setup message and the bootstrap accounts for the script's installation path.

Written by the indexing model from the issue text.

Assessment

Tech stack
php, shell
Domain
testing, tooling
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.