1<?php
2
3declare(strict_types = 1);
4
5error_reporting(E_ALL | E_STRICT);
6
7// Set the default timezone. While this doesn't cause any tests to fail, PHP
8// complains if it is not set in 'date.timezone' of php.ini.
9date_default_timezone_set('UTC');
10
11// Ensure that composer has installed all dependencies
12if (!file_exists(dirname(__DIR__) . '/composer.lock')) {
13    die("Dependencies must be installed using composer:\n\nphp composer.phar install --dev\n\n"
14        . "See http://getcomposer.org for help with installing composer\n");
15}
16
17// Include the composer autoloader
18$autoloader = require_once dirname(__DIR__) . '/vendor/autoload.php';
19
20$client = \Elasticsearch\ClientBuilder::fromConfig([
21    'hosts' => [$_SERVER['ES_TEST_HOST']]
22]);
23
24$count = 0;
25while (!$client->ping()) {
26    $count += 1;
27
28    if ($count > 15) {
29        echo "Live cluster could not be found in 15s!\nContents of elasticsearch.log:\n\n";
30
31        $dir = new DirectoryIterator(dirname(__DIR__));
32
33        foreach ($dir as $fileinfo) {
34            if ($fileinfo->isDir() && !$fileinfo->isDot()) {
35                if (strpos($fileinfo->getFilename(), "elasticsearch") === 0) {
36                    $log = file_get_contents(dirname(__DIR__)."/$fileinfo/logs/elasticsearch.log");
37                    echo $log;
38                    break;
39                }
40
41            }
42        }
43
44        throw new \Exception();
45    }
46    sleep(1);
47}
48
49