|
| 1 | +--TEST-- |
| 2 | +Elasticsearch userland functions are supported |
| 3 | +--SKIPIF-- |
| 4 | +<?php |
| 5 | +if (!extension_loaded("scoutapm")) die("skip scoutapm extension required."); |
| 6 | +if (!extension_loaded("curl")) die("skip Elasticsearch needs the curl extension."); |
| 7 | +if (shell_exec("which composer") === null) die("skip composer not found in path."); |
| 8 | + |
| 9 | +$out = null; |
| 10 | +$result = null; |
| 11 | +exec("mkdir -p /tmp/scout_elastic_test && cd /tmp/scout_elastic_test && composer require -n elasticsearch/elasticsearch:^8.0", $out, $result); |
| 12 | + |
| 13 | +if ($result !== 0) { |
| 14 | + die("skip composer failed: " . implode(", ", $out)); |
| 15 | +} |
| 16 | + |
| 17 | +if (!getenv('CI')) { |
| 18 | + require "/tmp/scout_elastic_test/vendor/autoload.php"; |
| 19 | + |
| 20 | + // Check Elasticsearch is running & can connect to it |
| 21 | + /* Run with: |
| 22 | +docker run --rm --name elasticsearch \ |
| 23 | + -p 9200:9200 \ |
| 24 | + -e discovery.type=single-node \ |
| 25 | + -e xpack.security.enabled=false \ |
| 26 | + -e xpack.security.enrollment.enabled=false \ |
| 27 | + -e xpack.security.http.ssl.enabled=false \ |
| 28 | + -e xpack.security.transport.ssl.enabled=false \ |
| 29 | + elasticsearch:8.1.2 |
| 30 | + */ |
| 31 | + $client = \Elastic\Elasticsearch\ClientBuilder::create() |
| 32 | + ->setHosts(['localhost:9200']) |
| 33 | + ->build(); |
| 34 | + try { |
| 35 | + $client->search([]); |
| 36 | + } catch (\Elastic\Elasticsearch\Common\Exceptions\NoNodesAvailableException $e) { |
| 37 | + die("skip " . $e->getMessage()); |
| 38 | + } |
| 39 | +} |
| 40 | +?> |
| 41 | +--FILE-- |
| 42 | +<?php |
| 43 | + |
| 44 | +echo implode("\n", array_intersect( |
| 45 | + [ |
| 46 | + 'Elastic\Elasticsearch\Client->index', |
| 47 | + 'Elastic\Elasticsearch\Client->get', |
| 48 | + 'Elastic\Elasticsearch\Client->search', |
| 49 | + 'Elastic\Elasticsearch\Client->delete', |
| 50 | + ], |
| 51 | + scoutapm_list_instrumented_functions() |
| 52 | +)) . "\n"; |
| 53 | +scoutapm_enable_instrumentation(true); |
| 54 | + |
| 55 | +require "/tmp/scout_elastic_test/vendor/autoload.php"; |
| 56 | + |
| 57 | +$client = \Elastic\Elasticsearch\ClientBuilder::create() |
| 58 | + ->setHosts(['localhost:9200']) |
| 59 | + ->build(); |
| 60 | + |
| 61 | +$client->index(['index' => 'my_index', 'id' => 'my_id', 'body' => ['testField' => 'abc']]); |
| 62 | +$client->get(['index' => 'my_index', 'id' => 'my_id']); |
| 63 | +$client->search(['index' => 'my_index', 'body' => ['query' => ['match' => ['testField' => 'abc']]]]); |
| 64 | +$client->delete(['index' => 'my_index', 'id' => 'my_id']); |
| 65 | + |
| 66 | +$calls = scoutapm_get_calls(); |
| 67 | + |
| 68 | +var_dump(array_column($calls, 'function')); |
| 69 | + |
| 70 | +?> |
| 71 | +--CLEAN-- |
| 72 | +<?php |
| 73 | +shell_exec("rm -Rf /tmp/scout_elastic_test"); |
| 74 | +?> |
| 75 | +--EXPECTF-- |
| 76 | +Elastic\Elasticsearch\Client->index |
| 77 | +Elastic\Elasticsearch\Client->get |
| 78 | +Elastic\Elasticsearch\Client->search |
| 79 | +Elastic\Elasticsearch\Client->delete |
| 80 | +array(%d) { |
| 81 | + [%d]=> |
| 82 | + string(%d) "Elastic\Elasticsearch\Client->index" |
| 83 | + [%d]=> |
| 84 | + string(%d) "Elastic\Elasticsearch\Client->get" |
| 85 | + [%d]=> |
| 86 | + string(%d) "Elastic\Elasticsearch\Client->search" |
| 87 | + [%d]=> |
| 88 | + string(%d) "Elastic\Elasticsearch\Client->delete" |
| 89 | +} |
0 commit comments