@@ -55,6 +55,40 @@ The `basic-skipif.inc` and `basic.inc` files contain utility functions for the
55
55
(e.g. skip logic only depends on checking the ` PHP_INT_SIZE ` constant), the test
56
56
should not include the file. When it doubt, keep it simple.
57
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
+
58
92
### Local Mongo Orchestration (and Travis CI)
59
93
60
94
The test suite depends on [ Mongo Orchestration] ( https://github.com/10gen/mongo-orchestration ) .
0 commit comments