| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,56 @@ |
| 1 |
+<?php |
|
| 2 |
+ |
|
| 3 |
+require_once(__DIR__ . '/TelnyxMock.php'); |
|
| 4 |
+ |
|
| 5 |
+define("MOCK_MINIMUM_VERSION", "0.1.0");
|
|
| 6 |
+ |
|
| 7 |
+if (\Telnyx\TelnyxMock::start()) {
|
|
| 8 |
+ register_shutdown_function('\Telnyx\TelnyxMock::stop');
|
|
| 9 |
+ |
|
| 10 |
+ define("MOCK_HOST", "localhost");
|
|
| 11 |
+ define("MOCK_PORT", \Telnyx\TelnyxMock::getPort());
|
|
| 12 |
+} else {
|
|
| 13 |
+ define("MOCK_HOST", getenv("TELNYX_MOCK_HOST") ?: "mock");
|
|
| 14 |
+ define("MOCK_PORT", getenv("TELNYX_MOCK_PORT") ?: 12111);
|
|
| 15 |
+} |
|
| 16 |
+ |
|
| 17 |
+define("MOCK_URL", "http://" . MOCK_HOST . ":" . MOCK_PORT);
|
|
| 18 |
+ |
|
| 19 |
+// Send a request to telnyx-mock |
|
| 20 |
+$ch = curl_init(MOCK_URL); |
|
| 21 |
+curl_setopt($ch, CURLOPT_HEADER, 1); |
|
| 22 |
+curl_setopt($ch, CURLOPT_NOBODY, 1); |
|
| 23 |
+curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
|
| 24 |
+$resp = curl_exec($ch); |
|
| 25 |
+ |
|
| 26 |
+if (curl_errno($ch)) {
|
|
| 27 |
+ echo "Couldn't reach telnyx-mock at `" . MOCK_HOST . ":" . MOCK_PORT . "`. Is " . |
|
| 28 |
+ "it running? Please see README for setup instructions.\n"; |
|
| 29 |
+ exit(1); |
|
| 30 |
+} |
|
| 31 |
+ |
|
| 32 |
+// Retrieve the Telnyx-Mock-Version header |
|
| 33 |
+$version = null; |
|
| 34 |
+$headers = explode("\n", $resp);
|
|
| 35 |
+foreach ($headers as $header) {
|
|
| 36 |
+ $pair = explode(":", $header, 2);
|
|
| 37 |
+ if ($pair[0] == "Telnyx-Mock-Version") {
|
|
| 38 |
+ $version = trim($pair[1]); |
|
| 39 |
+ } |
|
| 40 |
+} |
|
| 41 |
+ |
|
| 42 |
+if ($version === null) {
|
|
| 43 |
+ echo "Could not retrieve Telnyx-Mock-Version header. Are you sure " . |
|
| 44 |
+ "that the server at `" . MOCK_HOST . ":" . MOCK_PORT . "` is a telnyx-mock " . |
|
| 45 |
+ "instance?"; |
|
| 46 |
+ exit(1); |
|
| 47 |
+} |
|
| 48 |
+ |
|
| 49 |
+if ($version != "master" && version_compare($version, MOCK_MINIMUM_VERSION) == -1) {
|
|
| 50 |
+ echo "Your version of telnyx-mock (" . $version . ") is too old. The minimum " .
|
|
| 51 |
+ "version to run this test suite is " . MOCK_MINIMUM_VERSION . ". " . |
|
| 52 |
+ "Please see its repository for upgrade instructions.\n"; |
|
| 53 |
+ exit(1); |
|
| 54 |
+} |
|
| 55 |
+ |
|
| 56 |
+require_once __DIR__ . '/TestCase.php'; |