Skip to content

Commit 15b7578

Browse files
committed
Merge pull request #903
2 parents f9c1d89 + 392ee3d commit 15b7578

File tree

1 file changed

+69
-1
lines changed

1 file changed

+69
-1
lines changed

CONTRIBUTING.md

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,74 @@ make clean > /dev/null && make all > /dev/null && make install
2323

2424
## Testing
2525

26+
The extension's test use the PHPT format from PHP internals. This format is
27+
documented in the following links:
28+
29+
* [Introduction to PHPT Files](https://qa.php.net/write-test.php)
30+
* [PHPT - Test File Layout](https://qa.php.net/phpt_details.php)
31+
32+
Generally, most tests will be based on the following template:
33+
34+
```
35+
--TEST--
36+
Description of API or JIRA issue being tested
37+
--SKIPIF--
38+
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
39+
<?php /* One or more skip functions */ ?>
40+
--FILE--
41+
<?php
42+
require_once __DIR__ . "/../utils/basic.inc";
43+
44+
// Test code
45+
46+
?>
47+
===DONE===
48+
<?php exit(0); ?>
49+
--EXPECT--
50+
===DONE===
51+
```
52+
53+
The `basic-skipif.inc` and `basic.inc` files contain utility functions for the
54+
`SKIPIF` and `FILE` sections, respectively. If those functions are not needed
55+
(e.g. skip logic only depends on checking the `PHP_INT_SIZE` constant), the test
56+
should not include the file. When it doubt, keep it simple.
57+
58+
### Best Practices for `SKIPIF`
59+
60+
The [`skipif.php`](tests/utils/skipif.php) file defines various helper functions
61+
for use within a test's [`SKIPIF`](https://qa.php.net/phpt_details.php#skipif_section)
62+
section. When multiple functions are used in a single `SKIPIF` section, they
63+
should be logically ordered:
64+
65+
* Any PHP environment requirements should be checked first. For example, if a
66+
test requires a 64-bit architecture, start by checking `PHP_INT_SIZE` before
67+
anything else.
68+
* Any extension build requirements (e.g. `skip_if_not_libmongoc_crypto()`) or
69+
test environment requirements (e.g. `skip_if_auth()`) should then be checked.
70+
These functions only examine local information, such as `phpinfo()` output or
71+
the structure of the `URI` constant, and do not interact with a remote
72+
MongoDB server.
73+
* Any remote server requirements should then be checked. A general integration
74+
test that requires any type of remote server to be accessible might use
75+
`skip_if_not_live()` while a test requiring a replica set would prefer
76+
`skip_if_not_replica_set()`.
77+
* After requiring a remote server to be accessible (optionally with a specific
78+
type), you can enforce requirements about that server. This includes checking
79+
its server version, storage engine, availability of test commands, etc.
80+
* Finally, use `skip_if_not_clean()` if needed to ensure that the collection(s)
81+
under test are dropped before the test runs.
82+
83+
As a rule of thumb, your `SKIPIF` logic should be written to allow the test to
84+
run in as many environments as possible. To paraphrase the
85+
[robustness principal](https://en.wikipedia.org/wiki/Robustness_principle):
86+
87+
> Be conservative in what/how you test, and liberal in what environment you require
88+
89+
Consider that a well-crafted `EXPECTF` section may allow a `SKIPIF` section to
90+
be less restrictive.
91+
92+
### Local Mongo Orchestration (and Travis CI)
93+
2694
The test suite depends on [Mongo Orchestration](https://github.com/10gen/mongo-orchestration).
2795
Mongo Orchestration is an HTTP server that provides a REST API for maintaining
2896
MongoDB configurations. These configurations are located in ``scripts/presets``
@@ -58,7 +126,7 @@ export MONGODB_URI=`cat /tmp/uri.txt`
58126

59127
With this set-up, the tests can be run with `make test`.
60128

61-
### Legacy VM set-up
129+
### VM-based Mongo Orchestration (legacy set-up)
62130

63131
Alternative to the Travis CI set-up, our test suite also includes scripts to configure test environments
64132
with [Vagrant](https://www.vagrantup.com/) and

0 commit comments

Comments
 (0)