Skip to content

Commit 4a235f8

Browse files
committed
add contributor documentation
1 parent 53e4480 commit 4a235f8

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

CONTRIBUTING.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,51 @@ Using [robiningelbrecht/phpunit-coverage-tools](https://github.com/robiningelbre
106106
This percentage should be increased over time to just below whatever the current coverage is.
107107

108108
To run a code coverage test, use the same procedure for phpunit but add this argument: `--coverage-text=/dev/stdout`
109+
110+
### LDAP cleanliness
111+
112+
Any test that makes changes to LDAP must clean up after itself using `try`/`finally`.
113+
When a test fails to clean up after itself, it can cause other tests to fail or become otherwise un-useful.
114+
Because LDAP may not always be clean, any test that relies on a certain LDAP state should `assert` everything about that state.
115+
To reset LDAP to a clean slate, just re-run the `build.sh` script.
116+
117+
Note: `phpunit` can misbehave when using `expectException` and `try`/`finally`, see https://github.com/UnityHPC/unity-web-portal/issues/258.
118+
119+
### creating the conditions for a test
120+
121+
Selecting users for tests happens with the `get...User...` family of functions from `phpunit-bootstrap.php`.
122+
Since this family of functions is growing large and their names long and complicated, it is better to start with a simpler state and create the desired conditions manually.
123+
For example, rather than using `getUserWithOneKey`, use `getUserHasNoSSHKeys` and add one key for them.
124+
125+
The LDAP entries available in the dev environment are defined in `tools/docker-dev/identity/bootstrap.ldif`.
126+
These entries may be subject to change.
127+
Only `phpunit-bootstrap.php` should have hard-coded references to these entries.
128+
129+
### testing the HTTP API
130+
131+
When writing a test, it may be tempting to use the PHP API directly, but the HTTP API must also be tested.
132+
133+
Example:
134+
135+
using the PHP API:
136+
```php
137+
private function requestGroupCreation()
138+
{
139+
$USER->getPIGroup()->requestGroup();
140+
}
141+
```
142+
143+
using the HTTP API:
144+
```php
145+
private function requestGroupCreation()
146+
{
147+
http_post(
148+
__DIR__ . "/../../webroot/panel/new_account.php",
149+
["new_user_sel" => "pi", "eula" => "agree", "confirm_pi" => "agree"]
150+
);
151+
}
152+
```
153+
154+
`http_post` is defined in `phpunit-bootstrap.php`.
155+
156+
It is fine to use the PHP API when making assertions and doing cleanup.

0 commit comments

Comments
 (0)