|
| 1 | +<?php declare(strict_types=1); |
| 2 | + |
| 3 | +require_once __DIR__ . '/utils.php'; |
| 4 | + |
| 5 | +function post(string $url, string $params) |
| 6 | +{ |
| 7 | + $ch = curl_init(); |
| 8 | + |
| 9 | + $jsonData = json_encode($params); |
| 10 | + |
| 11 | + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
| 12 | + curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json', 'Content-Length: ' . strlen($jsonData)]); |
| 13 | + curl_setopt($ch, CURLOPT_URL, $url); |
| 14 | + curl_setopt($ch, CURLOPT_POST, true); |
| 15 | + curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData); |
| 16 | + |
| 17 | + $response = curl_exec($ch); |
| 18 | + |
| 19 | + curl_close($ch); |
| 20 | + |
| 21 | + if ($response === false) { |
| 22 | + throw new Exception('Curl error: ' . curl_error($ch)); |
| 23 | + } |
| 24 | + |
| 25 | + return $response; |
| 26 | +} |
| 27 | + |
| 28 | +$body = 'list_extensions'; |
| 29 | + |
| 30 | +try { |
| 31 | + $response = post('http://127.0.0.1:8080/2015-03-31/functions/function/invocations', $body); |
| 32 | + $response = json_decode($response, true, 512, JSON_THROW_ON_ERROR); |
| 33 | +} catch (Throwable $e) { |
| 34 | + error($e->getMessage() . PHP_EOL . $e->getTraceAsString()); |
| 35 | +} |
| 36 | + |
| 37 | +if (! is_array($response)) { |
| 38 | + error('The response is not an array'); |
| 39 | +} |
| 40 | + |
| 41 | +// We changed PHP_INI_SCAN_DIR to `/var/task` to load `test_3_manual_extensions.ini` |
| 42 | +// We check one of the extensions was indeed loaded |
| 43 | +if (! in_array('intl', $response, true)) { |
| 44 | + error('Could not override PHP_INI_SCAN_DIR, test_3_manual_extensions.ini was not loaded'); |
| 45 | +} |
| 46 | + |
| 47 | +success('[Invoke] Function'); |
0 commit comments