diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..0ca66da --- /dev/null +++ b/.dockerignore @@ -0,0 +1,5 @@ +vendor/ +.git/ +.phpcs-cache +.idea/ +*.log diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ea5a247..af88f0d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -29,6 +29,7 @@ jobs: uses: elastic/elastic-github-actions/elasticsearch@master with: stack-version: ${{ matrix.elastic }} + security-enabled: false - name: Composer run: make composer @@ -43,3 +44,5 @@ jobs: - name: Tests run: make tests + env: + ELASTICSEARCH_HOST: http://localhost:9200 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..e6cb6b0 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,12 @@ +FROM php:8.2-cli + +RUN apt-get update && apt-get install -y \ + git \ + unzip \ + libcurl4-openssl-dev \ + && docker-php-ext-install curl \ + && rm -rf /var/lib/apt/lists/* + +COPY --from=composer:latest /usr/bin/composer /usr/bin/composer + +WORKDIR /app diff --git a/composer.json b/composer.json index 0d5a03a..d956f49 100644 --- a/composer.json +++ b/composer.json @@ -17,9 +17,9 @@ "require-dev": { "ext-curl": "*", "phpstan/phpstan": "^1.11.3", - "nette/tester": "v2.3.1", - "elasticsearch/elasticsearch": "^7", - "guzzlehttp/guzzle": "^6.3", + "nette/tester": "v2.5.7", + "elasticsearch/elasticsearch": "^9.0.0", + "guzzlehttp/guzzle": "^7.0", "slevomat/coding-standard": "^8.0" }, "autoload": { @@ -34,10 +34,11 @@ }, "config": { "allow-plugins": { - "dealerdirect/phpcodesniffer-composer-installer": true + "dealerdirect/phpcodesniffer-composer-installer": true, + "php-http/discovery": true } }, "brach-alias": { - "dev-master": "2.0.x-dev" + "dev-master": "2.0.0" } } diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..1479dbb --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,25 @@ +services: + php: + build: . + volumes: + - .:/app + environment: + - ELASTICSEARCH_HOST=elasticsearch:9200 + depends_on: + elasticsearch: + condition: service_healthy + + elasticsearch: + image: elasticsearch:9.2.2 + environment: + - discovery.type=single-node + - xpack.security.enabled=false + - xpack.security.enrollment.enabled=false + - ES_JAVA_OPTS=-Xms512m -Xmx512m + ports: + - "9202:9200" + healthcheck: + test: curl -s http://localhost:9200 >/dev/null || exit 1 + interval: 10s + timeout: 5s + retries: 10 diff --git a/src/Aggregation/Range.php b/src/Aggregation/Range.php index 5fd51f2..835bd8c 100644 --- a/src/Aggregation/Range.php +++ b/src/Aggregation/Range.php @@ -11,16 +11,12 @@ class Range implements LeafAggregationInterface { - private \Spameri\ElasticQuery\Aggregation\RangeValueCollection $ranges; - - public function __construct( private string $field, private bool $keyed = false, - \Spameri\ElasticQuery\Aggregation\RangeValueCollection $rangeValueCollection = null, + private \Spameri\ElasticQuery\Aggregation\RangeValueCollection $ranges = new \Spameri\ElasticQuery\Aggregation\RangeValueCollection(), ) { - $this->ranges = $rangeValueCollection ?: new \Spameri\ElasticQuery\Aggregation\RangeValueCollection(); } diff --git a/src/Exception/ResponseCouldNotBeMapped.php b/src/Exception/ResponseCouldNotBeMapped.php index d4a9fa4..75de6c0 100644 --- a/src/Exception/ResponseCouldNotBeMapped.php +++ b/src/Exception/ResponseCouldNotBeMapped.php @@ -11,7 +11,7 @@ class ResponseCouldNotBeMapped extends \InvalidArgumentException public function __construct( string $message, int $code = 0, - \Throwable $previous = null, + \Throwable|null $previous = null, ) { parent::__construct((string) \json_encode($message), $code, $previous); diff --git a/src/Mapping/Settings/Mapping/FieldSeparator.php b/src/Mapping/Settings/Mapping/FieldSeparator.php index 4d6cf63..e379bb1 100644 --- a/src/Mapping/Settings/Mapping/FieldSeparator.php +++ b/src/Mapping/Settings/Mapping/FieldSeparator.php @@ -1,7 +1,7 @@ index . '/_search'); + \curl_setopt($ch, \CURLOPT_URL, \ELASTICSEARCH_HOST . '/' . $document->index . '/_search'); \curl_setopt($ch, \CURLOPT_RETURNTRANSFER, 1); \curl_setopt($ch, \CURLOPT_CUSTOMREQUEST, 'GET'); \curl_setopt($ch, \CURLOPT_HTTPHEADER, ['Content-Type: application/json']); @@ -178,21 +177,18 @@ class AggregationCollection extends \Tester\TestCase $result = $resultMapper->map(\json_decode($response, true)); \Tester\Assert::type(\Spameri\ElasticQuery\Response\ResultSearch::class, $result); }); - - \curl_close($ch); } public function tearDown(): void { $ch = \curl_init(); - \curl_setopt($ch, \CURLOPT_URL, 'localhost:9200/' . self::INDEX); + \curl_setopt($ch, \CURLOPT_URL, \ELASTICSEARCH_HOST . '/' . self::INDEX); \curl_setopt($ch, \CURLOPT_RETURNTRANSFER, 1); \curl_setopt($ch, \CURLOPT_CUSTOMREQUEST, 'DELETE'); \curl_setopt($ch, \CURLOPT_HTTPHEADER, ['Content-Type: application/json']); \curl_exec($ch); - \curl_close($ch); } } diff --git a/tests/SpameriTests/ElasticQuery/Aggregation/Avg.phpt b/tests/SpameriTests/ElasticQuery/Aggregation/Avg.phpt index 24df7bc..f3ae24f 100644 --- a/tests/SpameriTests/ElasticQuery/Aggregation/Avg.phpt +++ b/tests/SpameriTests/ElasticQuery/Aggregation/Avg.phpt @@ -14,13 +14,12 @@ class Avg extends \Tester\TestCase public function setUp(): void { $ch = \curl_init(); - \curl_setopt($ch, \CURLOPT_URL, 'localhost:9200/' . self::INDEX); + \curl_setopt($ch, \CURLOPT_URL, \ELASTICSEARCH_HOST . '/' . self::INDEX); \curl_setopt($ch, \CURLOPT_RETURNTRANSFER, 1); \curl_setopt($ch, \CURLOPT_CUSTOMREQUEST, 'PUT'); \curl_setopt($ch, \CURLOPT_HTTPHEADER, ['Content-Type: application/json']); \curl_exec($ch); - \curl_close($ch); } @@ -64,7 +63,7 @@ class Avg extends \Tester\TestCase ); $ch = \curl_init(); - \curl_setopt($ch, \CURLOPT_URL, 'localhost:9200/' . $document->index . '/_search'); + \curl_setopt($ch, \CURLOPT_URL, \ELASTICSEARCH_HOST . '/' . $document->index . '/_search'); \curl_setopt($ch, \CURLOPT_RETURNTRANSFER, 1); \curl_setopt($ch, \CURLOPT_CUSTOMREQUEST, 'GET'); \curl_setopt($ch, \CURLOPT_HTTPHEADER, ['Content-Type: application/json']); @@ -81,21 +80,18 @@ class Avg extends \Tester\TestCase $result = $resultMapper->map(\json_decode($response, true)); \Tester\Assert::type(\Spameri\ElasticQuery\Response\ResultSearch::class, $result); }); - - \curl_close($ch); } public function tearDown(): void { $ch = \curl_init(); - \curl_setopt($ch, \CURLOPT_URL, 'localhost:9200/' . self::INDEX); + \curl_setopt($ch, \CURLOPT_URL, \ELASTICSEARCH_HOST . '/' . self::INDEX); \curl_setopt($ch, \CURLOPT_RETURNTRANSFER, 1); \curl_setopt($ch, \CURLOPT_CUSTOMREQUEST, 'DELETE'); \curl_setopt($ch, \CURLOPT_HTTPHEADER, ['Content-Type: application/json']); \curl_exec($ch); - \curl_close($ch); } } diff --git a/tests/SpameriTests/ElasticQuery/Aggregation/Filter.phpt b/tests/SpameriTests/ElasticQuery/Aggregation/Filter.phpt index dd640ed..0cea8ee 100644 --- a/tests/SpameriTests/ElasticQuery/Aggregation/Filter.phpt +++ b/tests/SpameriTests/ElasticQuery/Aggregation/Filter.phpt @@ -14,13 +14,12 @@ class Filter extends \Tester\TestCase public function setUp(): void { $ch = \curl_init(); - \curl_setopt($ch, \CURLOPT_URL, 'localhost:9200/' . self::INDEX); + \curl_setopt($ch, \CURLOPT_URL, \ELASTICSEARCH_HOST . '/' . self::INDEX); \curl_setopt($ch, \CURLOPT_RETURNTRANSFER, 1); \curl_setopt($ch, \CURLOPT_CUSTOMREQUEST, 'PUT'); \curl_setopt($ch, \CURLOPT_HTTPHEADER, ['Content-Type: application/json']); \curl_exec($ch); - \curl_close($ch); } @@ -76,7 +75,7 @@ class Filter extends \Tester\TestCase ); $ch = \curl_init(); - \curl_setopt($ch, \CURLOPT_URL, 'localhost:9200/' . $document->index . '/_search'); + \curl_setopt($ch, \CURLOPT_URL, \ELASTICSEARCH_HOST . '/' . $document->index . '/_search'); \curl_setopt($ch, \CURLOPT_RETURNTRANSFER, 1); \curl_setopt($ch, \CURLOPT_CUSTOMREQUEST, 'GET'); \curl_setopt($ch, \CURLOPT_HTTPHEADER, ['Content-Type: application/json']); @@ -93,21 +92,18 @@ class Filter extends \Tester\TestCase $result = $resultMapper->map(\json_decode($response, true)); \Tester\Assert::type(\Spameri\ElasticQuery\Response\ResultSearch::class, $result); }); - - \curl_close($ch); } public function tearDown(): void { $ch = \curl_init(); - \curl_setopt($ch, \CURLOPT_URL, 'localhost:9200/' . self::INDEX); + \curl_setopt($ch, \CURLOPT_URL, \ELASTICSEARCH_HOST . '/' . self::INDEX); \curl_setopt($ch, \CURLOPT_RETURNTRANSFER, 1); \curl_setopt($ch, \CURLOPT_CUSTOMREQUEST, 'DELETE'); \curl_setopt($ch, \CURLOPT_HTTPHEADER, ['Content-Type: application/json']); \curl_exec($ch); - \curl_close($ch); } } diff --git a/tests/SpameriTests/ElasticQuery/Aggregation/Histogram.phpt b/tests/SpameriTests/ElasticQuery/Aggregation/Histogram.phpt index 1a44991..2065824 100644 --- a/tests/SpameriTests/ElasticQuery/Aggregation/Histogram.phpt +++ b/tests/SpameriTests/ElasticQuery/Aggregation/Histogram.phpt @@ -14,13 +14,12 @@ class Histogram extends \Tester\TestCase public function setUp(): void { $ch = \curl_init(); - \curl_setopt($ch, \CURLOPT_URL, 'localhost:9200/' . self::INDEX); + \curl_setopt($ch, \CURLOPT_URL, \ELASTICSEARCH_HOST . '/' . self::INDEX); \curl_setopt($ch, \CURLOPT_RETURNTRANSFER, 1); \curl_setopt($ch, \CURLOPT_CUSTOMREQUEST, 'PUT'); \curl_setopt($ch, \CURLOPT_HTTPHEADER, ['Content-Type: application/json']); \curl_exec($ch); - \curl_close($ch); } @@ -65,7 +64,7 @@ class Histogram extends \Tester\TestCase ); $ch = \curl_init(); - \curl_setopt($ch, \CURLOPT_URL, 'localhost:9200/' . $document->index . '/_search'); + \curl_setopt($ch, \CURLOPT_URL, \ELASTICSEARCH_HOST . '/' . $document->index . '/_search'); \curl_setopt($ch, \CURLOPT_RETURNTRANSFER, 1); \curl_setopt($ch, \CURLOPT_CUSTOMREQUEST, 'GET'); \curl_setopt($ch, \CURLOPT_HTTPHEADER, ['Content-Type: application/json']); @@ -82,21 +81,18 @@ class Histogram extends \Tester\TestCase $result = $resultMapper->map(\json_decode($response, true)); \Tester\Assert::type(\Spameri\ElasticQuery\Response\ResultSearch::class, $result); }); - - \curl_close($ch); } public function tearDown(): void { $ch = \curl_init(); - \curl_setopt($ch, \CURLOPT_URL, 'localhost:9200/' . self::INDEX); + \curl_setopt($ch, \CURLOPT_URL, \ELASTICSEARCH_HOST . '/' . self::INDEX); \curl_setopt($ch, \CURLOPT_RETURNTRANSFER, 1); \curl_setopt($ch, \CURLOPT_CUSTOMREQUEST, 'DELETE'); \curl_setopt($ch, \CURLOPT_HTTPHEADER, ['Content-Type: application/json']); \curl_exec($ch); - \curl_close($ch); } } diff --git a/tests/SpameriTests/ElasticQuery/Aggregation/LeafAggregationCollection.phpt b/tests/SpameriTests/ElasticQuery/Aggregation/LeafAggregationCollection.phpt index 2ebf910..1cbe748 100644 --- a/tests/SpameriTests/ElasticQuery/Aggregation/LeafAggregationCollection.phpt +++ b/tests/SpameriTests/ElasticQuery/Aggregation/LeafAggregationCollection.phpt @@ -14,13 +14,12 @@ class LeafAggregationCollection extends \Tester\TestCase public function setUp(): void { $ch = \curl_init(); - \curl_setopt($ch, \CURLOPT_URL, 'localhost:9200/' . self::INDEX); + \curl_setopt($ch, \CURLOPT_URL, \ELASTICSEARCH_HOST . '/' . self::INDEX); \curl_setopt($ch, \CURLOPT_RETURNTRANSFER, 1); \curl_setopt($ch, \CURLOPT_CUSTOMREQUEST, 'PUT'); \curl_setopt($ch, \CURLOPT_HTTPHEADER, ['Content-Type: application/json']); \curl_exec($ch); - \curl_close($ch); } @@ -164,7 +163,7 @@ class LeafAggregationCollection extends \Tester\TestCase ); $ch = \curl_init(); - \curl_setopt($ch, \CURLOPT_URL, 'localhost:9200/' . $document->index . '/_search'); + \curl_setopt($ch, \CURLOPT_URL, \ELASTICSEARCH_HOST . '/' . $document->index . '/_search'); \curl_setopt($ch, \CURLOPT_RETURNTRANSFER, 1); \curl_setopt($ch, \CURLOPT_CUSTOMREQUEST, 'GET'); \curl_setopt($ch, \CURLOPT_HTTPHEADER, ['Content-Type: application/json']); @@ -181,21 +180,18 @@ class LeafAggregationCollection extends \Tester\TestCase $result = $resultMapper->map(\json_decode($response, true)); \Tester\Assert::type(\Spameri\ElasticQuery\Response\ResultSearch::class, $result); }); - - \curl_close($ch); } public function tearDown(): void { $ch = \curl_init(); - \curl_setopt($ch, \CURLOPT_URL, 'localhost:9200/' . self::INDEX); + \curl_setopt($ch, \CURLOPT_URL, \ELASTICSEARCH_HOST . '/' . self::INDEX); \curl_setopt($ch, \CURLOPT_RETURNTRANSFER, 1); \curl_setopt($ch, \CURLOPT_CUSTOMREQUEST, 'DELETE'); \curl_setopt($ch, \CURLOPT_HTTPHEADER, ['Content-Type: application/json']); \curl_exec($ch); - \curl_close($ch); } } diff --git a/tests/SpameriTests/ElasticQuery/Aggregation/Max.phpt b/tests/SpameriTests/ElasticQuery/Aggregation/Max.phpt index b03ac01..99aa685 100644 --- a/tests/SpameriTests/ElasticQuery/Aggregation/Max.phpt +++ b/tests/SpameriTests/ElasticQuery/Aggregation/Max.phpt @@ -14,13 +14,12 @@ class Max extends \Tester\TestCase public function setUp(): void { $ch = \curl_init(); - \curl_setopt($ch, \CURLOPT_URL, 'localhost:9200/' . self::INDEX); + \curl_setopt($ch, \CURLOPT_URL, \ELASTICSEARCH_HOST . '/' . self::INDEX); \curl_setopt($ch, \CURLOPT_RETURNTRANSFER, 1); \curl_setopt($ch, \CURLOPT_CUSTOMREQUEST, 'PUT'); \curl_setopt($ch, \CURLOPT_HTTPHEADER, ['Content-Type: application/json']); \curl_exec($ch); - \curl_close($ch); } @@ -64,7 +63,7 @@ class Max extends \Tester\TestCase ); $ch = \curl_init(); - \curl_setopt($ch, \CURLOPT_URL, 'localhost:9200/' . $document->index . '/_search'); + \curl_setopt($ch, \CURLOPT_URL, \ELASTICSEARCH_HOST . '/' . $document->index . '/_search'); \curl_setopt($ch, \CURLOPT_RETURNTRANSFER, 1); \curl_setopt($ch, \CURLOPT_CUSTOMREQUEST, 'GET'); \curl_setopt($ch, \CURLOPT_HTTPHEADER, ['Content-Type: application/json']); @@ -81,21 +80,18 @@ class Max extends \Tester\TestCase $result = $resultMapper->map(\json_decode($response, true)); \Tester\Assert::type(\Spameri\ElasticQuery\Response\ResultSearch::class, $result); }); - - \curl_close($ch); } public function tearDown(): void { $ch = \curl_init(); - \curl_setopt($ch, \CURLOPT_URL, 'localhost:9200/' . self::INDEX); + \curl_setopt($ch, \CURLOPT_URL, \ELASTICSEARCH_HOST . '/' . self::INDEX); \curl_setopt($ch, \CURLOPT_RETURNTRANSFER, 1); \curl_setopt($ch, \CURLOPT_CUSTOMREQUEST, 'DELETE'); \curl_setopt($ch, \CURLOPT_HTTPHEADER, ['Content-Type: application/json']); \curl_exec($ch); - \curl_close($ch); } } diff --git a/tests/SpameriTests/ElasticQuery/Aggregation/Min.phpt b/tests/SpameriTests/ElasticQuery/Aggregation/Min.phpt index 38668c1..d6d372e 100644 --- a/tests/SpameriTests/ElasticQuery/Aggregation/Min.phpt +++ b/tests/SpameriTests/ElasticQuery/Aggregation/Min.phpt @@ -14,13 +14,12 @@ class Min extends \Tester\TestCase public function setUp(): void { $ch = \curl_init(); - \curl_setopt($ch, \CURLOPT_URL, 'localhost:9200/' . self::INDEX); + \curl_setopt($ch, \CURLOPT_URL, \ELASTICSEARCH_HOST . '/' . self::INDEX); \curl_setopt($ch, \CURLOPT_RETURNTRANSFER, 1); \curl_setopt($ch, \CURLOPT_CUSTOMREQUEST, 'PUT'); \curl_setopt($ch, \CURLOPT_HTTPHEADER, ['Content-Type: application/json']); \curl_exec($ch); - \curl_close($ch); } @@ -64,7 +63,7 @@ class Min extends \Tester\TestCase ); $ch = \curl_init(); - \curl_setopt($ch, \CURLOPT_URL, 'localhost:9200/' . $document->index . '/_search'); + \curl_setopt($ch, \CURLOPT_URL, \ELASTICSEARCH_HOST . '/' . $document->index . '/_search'); \curl_setopt($ch, \CURLOPT_RETURNTRANSFER, 1); \curl_setopt($ch, \CURLOPT_CUSTOMREQUEST, 'GET'); \curl_setopt($ch, \CURLOPT_HTTPHEADER, ['Content-Type: application/json']); @@ -81,21 +80,18 @@ class Min extends \Tester\TestCase $result = $resultMapper->map(\json_decode($response, true)); \Tester\Assert::type(\Spameri\ElasticQuery\Response\ResultSearch::class, $result); }); - - \curl_close($ch); } public function tearDown(): void { $ch = \curl_init(); - \curl_setopt($ch, \CURLOPT_URL, 'localhost:9200/' . self::INDEX); + \curl_setopt($ch, \CURLOPT_URL, \ELASTICSEARCH_HOST . '/' . self::INDEX); \curl_setopt($ch, \CURLOPT_RETURNTRANSFER, 1); \curl_setopt($ch, \CURLOPT_CUSTOMREQUEST, 'DELETE'); \curl_setopt($ch, \CURLOPT_HTTPHEADER, ['Content-Type: application/json']); \curl_exec($ch); - \curl_close($ch); } } diff --git a/tests/SpameriTests/ElasticQuery/Aggregation/Nested.phpt b/tests/SpameriTests/ElasticQuery/Aggregation/Nested.phpt index fa49443..935c9bf 100644 --- a/tests/SpameriTests/ElasticQuery/Aggregation/Nested.phpt +++ b/tests/SpameriTests/ElasticQuery/Aggregation/Nested.phpt @@ -14,13 +14,12 @@ class Nested extends \Tester\TestCase public function setUp(): void { $ch = \curl_init(); - \curl_setopt($ch, \CURLOPT_URL, 'localhost:9200/' . self::INDEX); + \curl_setopt($ch, \CURLOPT_URL, \ELASTICSEARCH_HOST . '/' . self::INDEX); \curl_setopt($ch, \CURLOPT_RETURNTRANSFER, 1); \curl_setopt($ch, \CURLOPT_CUSTOMREQUEST, 'PUT'); \curl_setopt($ch, \CURLOPT_HTTPHEADER, ['Content-Type: application/json']); \curl_exec($ch); - \curl_close($ch); } @@ -64,7 +63,7 @@ class Nested extends \Tester\TestCase ); $ch = \curl_init(); - \curl_setopt($ch, \CURLOPT_URL, 'localhost:9200/' . $document->index . '/_search'); + \curl_setopt($ch, \CURLOPT_URL, \ELASTICSEARCH_HOST . '/' . $document->index . '/_search'); \curl_setopt($ch, \CURLOPT_RETURNTRANSFER, 1); \curl_setopt($ch, \CURLOPT_CUSTOMREQUEST, 'GET'); \curl_setopt($ch, \CURLOPT_HTTPHEADER, ['Content-Type: application/json']); @@ -81,21 +80,18 @@ class Nested extends \Tester\TestCase $result = $resultMapper->map(\json_decode($response, true)); \Tester\Assert::type(\Spameri\ElasticQuery\Response\ResultSearch::class, $result); }); - - \curl_close($ch); } public function tearDown(): void { $ch = \curl_init(); - \curl_setopt($ch, \CURLOPT_URL, 'localhost:9200/' . self::INDEX); + \curl_setopt($ch, \CURLOPT_URL, \ELASTICSEARCH_HOST . '/' . self::INDEX); \curl_setopt($ch, \CURLOPT_RETURNTRANSFER, 1); \curl_setopt($ch, \CURLOPT_CUSTOMREQUEST, 'DELETE'); \curl_setopt($ch, \CURLOPT_HTTPHEADER, ['Content-Type: application/json']); \curl_exec($ch); - \curl_close($ch); } } diff --git a/tests/SpameriTests/ElasticQuery/Aggregation/Range.phpt b/tests/SpameriTests/ElasticQuery/Aggregation/Range.phpt index 987bbef..65db983 100644 --- a/tests/SpameriTests/ElasticQuery/Aggregation/Range.phpt +++ b/tests/SpameriTests/ElasticQuery/Aggregation/Range.phpt @@ -14,13 +14,12 @@ class Range extends \Tester\TestCase public function setUp(): void { $ch = \curl_init(); - \curl_setopt($ch, \CURLOPT_URL, 'localhost:9200/' . self::INDEX); + \curl_setopt($ch, \CURLOPT_URL, \ELASTICSEARCH_HOST . '/' . self::INDEX); \curl_setopt($ch, \CURLOPT_RETURNTRANSFER, 1); \curl_setopt($ch, \CURLOPT_CUSTOMREQUEST, 'PUT'); \curl_setopt($ch, \CURLOPT_HTTPHEADER, ['Content-Type: application/json']); \curl_exec($ch); - \curl_close($ch); } @@ -110,7 +109,7 @@ class Range extends \Tester\TestCase ); $ch = \curl_init(); - \curl_setopt($ch, \CURLOPT_URL, 'localhost:9200/' . $document->index . '/_search'); + \curl_setopt($ch, \CURLOPT_URL, \ELASTICSEARCH_HOST . '/' . $document->index . '/_search'); \curl_setopt($ch, \CURLOPT_RETURNTRANSFER, 1); \curl_setopt($ch, \CURLOPT_CUSTOMREQUEST, 'GET'); \curl_setopt($ch, \CURLOPT_HTTPHEADER, ['Content-Type: application/json']); @@ -127,21 +126,18 @@ class Range extends \Tester\TestCase $result = $resultMapper->map(\json_decode($response, true)); \Tester\Assert::type(\Spameri\ElasticQuery\Response\ResultSearch::class, $result); }); - - \curl_close($ch); } public function tearDown(): void { $ch = \curl_init(); - \curl_setopt($ch, \CURLOPT_URL, 'localhost:9200/' . self::INDEX); + \curl_setopt($ch, \CURLOPT_URL, \ELASTICSEARCH_HOST . '/' . self::INDEX); \curl_setopt($ch, \CURLOPT_RETURNTRANSFER, 1); \curl_setopt($ch, \CURLOPT_CUSTOMREQUEST, 'DELETE'); \curl_setopt($ch, \CURLOPT_HTTPHEADER, ['Content-Type: application/json']); \curl_exec($ch); - \curl_close($ch); } } diff --git a/tests/SpameriTests/ElasticQuery/Aggregation/Term.phpt b/tests/SpameriTests/ElasticQuery/Aggregation/Term.phpt index 7b85d78..2cfe880 100644 --- a/tests/SpameriTests/ElasticQuery/Aggregation/Term.phpt +++ b/tests/SpameriTests/ElasticQuery/Aggregation/Term.phpt @@ -14,13 +14,12 @@ class Term extends \Tester\TestCase public function setUp(): void { $ch = \curl_init(); - \curl_setopt($ch, \CURLOPT_URL, 'localhost:9200/' . self::INDEX); + \curl_setopt($ch, \CURLOPT_URL, \ELASTICSEARCH_HOST . '/' . self::INDEX); \curl_setopt($ch, \CURLOPT_RETURNTRANSFER, 1); \curl_setopt($ch, \CURLOPT_CUSTOMREQUEST, 'PUT'); \curl_setopt($ch, \CURLOPT_HTTPHEADER, ['Content-Type: application/json']); \curl_exec($ch); - \curl_close($ch); } @@ -136,7 +135,7 @@ class Term extends \Tester\TestCase ); $ch = \curl_init(); - \curl_setopt($ch, \CURLOPT_URL, 'localhost:9200/' . $document->index . '/_search'); + \curl_setopt($ch, \CURLOPT_URL, \ELASTICSEARCH_HOST . '/' . $document->index . '/_search'); \curl_setopt($ch, \CURLOPT_RETURNTRANSFER, 1); \curl_setopt($ch, \CURLOPT_CUSTOMREQUEST, 'GET'); \curl_setopt($ch, \CURLOPT_HTTPHEADER, ['Content-Type: application/json']); @@ -153,21 +152,18 @@ class Term extends \Tester\TestCase $result = $resultMapper->map(\json_decode($response, true)); \Tester\Assert::type(\Spameri\ElasticQuery\Response\ResultSearch::class, $result); }); - - \curl_close($ch); } public function tearDown(): void { $ch = \curl_init(); - \curl_setopt($ch, \CURLOPT_URL, 'localhost:9200/' . self::INDEX); + \curl_setopt($ch, \CURLOPT_URL, \ELASTICSEARCH_HOST . '/' . self::INDEX); \curl_setopt($ch, \CURLOPT_RETURNTRANSFER, 1); \curl_setopt($ch, \CURLOPT_CUSTOMREQUEST, 'DELETE'); \curl_setopt($ch, \CURLOPT_HTTPHEADER, ['Content-Type: application/json']); \curl_exec($ch); - \curl_close($ch); } } diff --git a/tests/SpameriTests/ElasticQuery/Aggregation/TopHits.phpt b/tests/SpameriTests/ElasticQuery/Aggregation/TopHits.phpt index cdbb4d2..44d3028 100644 --- a/tests/SpameriTests/ElasticQuery/Aggregation/TopHits.phpt +++ b/tests/SpameriTests/ElasticQuery/Aggregation/TopHits.phpt @@ -14,13 +14,12 @@ class TopHits extends \Tester\TestCase public function setUp(): void { $ch = \curl_init(); - \curl_setopt($ch, \CURLOPT_URL, 'localhost:9200/' . self::INDEX); + \curl_setopt($ch, \CURLOPT_URL, \ELASTICSEARCH_HOST . '/' . self::INDEX); \curl_setopt($ch, \CURLOPT_RETURNTRANSFER, 1); \curl_setopt($ch, \CURLOPT_CUSTOMREQUEST, 'PUT'); \curl_setopt($ch, \CURLOPT_HTTPHEADER, ['Content-Type: application/json']); \curl_exec($ch); - \curl_close($ch); } @@ -64,7 +63,7 @@ class TopHits extends \Tester\TestCase ); $ch = \curl_init(); - \curl_setopt($ch, \CURLOPT_URL, 'localhost:9200/' . $document->index . '/_search'); + \curl_setopt($ch, \CURLOPT_URL, \ELASTICSEARCH_HOST . '/' . $document->index . '/_search'); \curl_setopt($ch, \CURLOPT_RETURNTRANSFER, 1); \curl_setopt($ch, \CURLOPT_CUSTOMREQUEST, 'GET'); \curl_setopt($ch, \CURLOPT_HTTPHEADER, ['Content-Type: application/json']); @@ -81,21 +80,18 @@ class TopHits extends \Tester\TestCase $result = $resultMapper->map(\json_decode($response, true)); \Tester\Assert::type(\Spameri\ElasticQuery\Response\ResultSearch::class, $result); }); - - \curl_close($ch); } public function tearDown(): void { $ch = \curl_init(); - \curl_setopt($ch, \CURLOPT_URL, 'localhost:9200/' . self::INDEX); + \curl_setopt($ch, \CURLOPT_URL, \ELASTICSEARCH_HOST . '/' . self::INDEX); \curl_setopt($ch, \CURLOPT_RETURNTRANSFER, 1); \curl_setopt($ch, \CURLOPT_CUSTOMREQUEST, 'DELETE'); \curl_setopt($ch, \CURLOPT_HTTPHEADER, ['Content-Type: application/json']); \curl_exec($ch); - \curl_close($ch); } } diff --git a/tests/SpameriTests/ElasticQuery/ElasticQuery.phpt b/tests/SpameriTests/ElasticQuery/ElasticQuery.phpt index 2f56ad5..ea2b364 100644 --- a/tests/SpameriTests/ElasticQuery/ElasticQuery.phpt +++ b/tests/SpameriTests/ElasticQuery/ElasticQuery.phpt @@ -13,18 +13,17 @@ class ElasticQuery extends \Tester\TestCase public function setUp() : void { $ch = \curl_init(); - \curl_setopt($ch, CURLOPT_URL, 'localhost:9200/' . self::INDEX); + \curl_setopt($ch, CURLOPT_URL, \ELASTICSEARCH_HOST . '/' . self::INDEX); \curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); \curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); \curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']); \curl_exec($ch); - \curl_close($ch); /// === $ch = \curl_init(); - \curl_setopt($ch, \CURLOPT_URL, 'localhost:9200/' . self::INDEX . '/_mapping'); + \curl_setopt($ch, \CURLOPT_URL, \ELASTICSEARCH_HOST . '/' . self::INDEX . '/_mapping'); \curl_setopt($ch, \CURLOPT_RETURNTRANSFER, 1); \curl_setopt($ch, \CURLOPT_CUSTOMREQUEST, 'PUT'); \curl_setopt($ch, \CURLOPT_HTTPHEADER, ['Content-Type: application/json']); @@ -43,7 +42,6 @@ class ElasticQuery extends \Tester\TestCase ); \curl_exec($ch); - \curl_close($ch); } @@ -113,7 +111,7 @@ class ElasticQuery extends \Tester\TestCase ); $ch = \curl_init(); - \curl_setopt($ch, \CURLOPT_URL, 'localhost:9200/' . $document->index . '/_search'); + \curl_setopt($ch, \CURLOPT_URL, \ELASTICSEARCH_HOST . '/' . $document->index . '/_search'); \curl_setopt($ch, \CURLOPT_RETURNTRANSFER, 1); \curl_setopt($ch, \CURLOPT_CUSTOMREQUEST, 'GET'); \curl_setopt($ch, \CURLOPT_HTTPHEADER, ['Content-Type: application/json']); @@ -129,21 +127,18 @@ class ElasticQuery extends \Tester\TestCase $result = $resultMapper->map(\json_decode($response, TRUE)); \Tester\Assert::type('int', $result->stats()->total()); }); - - \curl_close($ch); } public function tearDown() : void { $ch = \curl_init(); - \curl_setopt($ch, \CURLOPT_URL, 'localhost:9200/' . self::INDEX); + \curl_setopt($ch, \CURLOPT_URL, \ELASTICSEARCH_HOST . '/' . self::INDEX); \curl_setopt($ch, \CURLOPT_RETURNTRANSFER, 1); \curl_setopt($ch, \CURLOPT_CUSTOMREQUEST, 'DELETE'); \curl_setopt($ch, \CURLOPT_HTTPHEADER, ['Content-Type: application/json']); \curl_exec($ch); - \curl_close($ch); } } diff --git a/tests/SpameriTests/ElasticQuery/ElasticsearchTestCase.php b/tests/SpameriTests/ElasticQuery/ElasticsearchTestCase.php new file mode 100644 index 0000000..faa4cb7 --- /dev/null +++ b/tests/SpameriTests/ElasticQuery/ElasticsearchTestCase.php @@ -0,0 +1,21 @@ +index . '/'); + \curl_setopt($ch, CURLOPT_URL, \ELASTICSEARCH_HOST . '/' . $document->index . '/'); \curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); \curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); \curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']); @@ -44,7 +44,7 @@ class CzechDictionary extends \Tester\TestCase // Fetch settings and test if analyzer is configured - \curl_setopt($ch, CURLOPT_URL, 'localhost:9200/' . $document->index . '/_settings'); + \curl_setopt($ch, CURLOPT_URL, \ELASTICSEARCH_HOST . '/' . $document->index . '/_settings'); \curl_setopt($ch, CURLOPT_POSTFIELDS, []); \curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET'); @@ -66,7 +66,7 @@ class CzechDictionary extends \Tester\TestCase $text = 'Playstation 4 je nejlepší se SodaStream drinkem a kouskem GS-condro!'; - \curl_setopt($ch, CURLOPT_URL, 'localhost:9200/' . $document->index . '/_analyze'); + \curl_setopt($ch, CURLOPT_URL, \ELASTICSEARCH_HOST . '/' . $document->index . '/_analyze'); \curl_setopt($ch, CURLOPT_POSTFIELDS, \json_encode([ 'text' => $text, 'analyzer' => 'czechDictionary', @@ -84,22 +84,18 @@ class CzechDictionary extends \Tester\TestCase \Tester\Assert::same('lepsi', $responseAnalyzer['tokens'][2]['token']); \Tester\Assert::same('drink', $responseAnalyzer['tokens'][4]['token']); \Tester\Assert::same('kousek', $responseAnalyzer['tokens'][5]['token']); - - \curl_close($ch); } protected function tearDown(): void { $ch = \curl_init(); - \curl_setopt($ch, CURLOPT_URL, 'localhost:9200/' . self::INDEX); + \curl_setopt($ch, CURLOPT_URL, \ELASTICSEARCH_HOST . '/' . self::INDEX); \curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); \curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE'); \curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']); \curl_exec($ch); - - \curl_close($ch); } } diff --git a/tests/SpameriTests/ElasticQuery/Query/ElasticMatch.phpt b/tests/SpameriTests/ElasticQuery/Query/ElasticMatch.phpt index b27b764..39230cf 100644 --- a/tests/SpameriTests/ElasticQuery/Query/ElasticMatch.phpt +++ b/tests/SpameriTests/ElasticQuery/Query/ElasticMatch.phpt @@ -14,13 +14,12 @@ class ElasticMatch extends \Tester\TestCase public function setUp() : void { $ch = \curl_init(); - \curl_setopt($ch, CURLOPT_URL, 'localhost:9200/' . self::INDEX); + \curl_setopt($ch, CURLOPT_URL, \ELASTICSEARCH_HOST . '/' . self::INDEX); \curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); \curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); \curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']); \curl_exec($ch); - \curl_close($ch); } @@ -65,7 +64,7 @@ class ElasticMatch extends \Tester\TestCase ); $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, 'localhost:9200/' . $document->index . '/_search'); + curl_setopt($ch, CURLOPT_URL, \ELASTICSEARCH_HOST . '/' . $document->index . '/_search'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET'); curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']); @@ -81,21 +80,18 @@ class ElasticMatch extends \Tester\TestCase $result = $resultMapper->map(\json_decode($response, TRUE)); \Tester\Assert::type('int', $result->stats()->total()); }); - - curl_close($ch); } public function tearDown() : void { $ch = \curl_init(); - \curl_setopt($ch, CURLOPT_URL, 'localhost:9200/' . self::INDEX); + \curl_setopt($ch, CURLOPT_URL, \ELASTICSEARCH_HOST . '/' . self::INDEX); \curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); \curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE'); \curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']); \curl_exec($ch); - \curl_close($ch); } } diff --git a/tests/SpameriTests/ElasticQuery/Query/Exists.phpt b/tests/SpameriTests/ElasticQuery/Query/Exists.phpt index 52c782b..f0552dd 100644 --- a/tests/SpameriTests/ElasticQuery/Query/Exists.phpt +++ b/tests/SpameriTests/ElasticQuery/Query/Exists.phpt @@ -14,13 +14,12 @@ class Exists extends \Tester\TestCase public function setUp(): void { $ch = \curl_init(); - \curl_setopt($ch, \CURLOPT_URL, 'localhost:9200/' . self::INDEX); + \curl_setopt($ch, \CURLOPT_URL, \ELASTICSEARCH_HOST . '/' . self::INDEX); \curl_setopt($ch, \CURLOPT_RETURNTRANSFER, 1); \curl_setopt($ch, \CURLOPT_CUSTOMREQUEST, 'PUT'); \curl_setopt($ch, \CURLOPT_HTTPHEADER, ['Content-Type: application/json']); \curl_exec($ch); - \curl_close($ch); } @@ -74,7 +73,7 @@ class Exists extends \Tester\TestCase ); $ch = \curl_init(); - \curl_setopt($ch, \CURLOPT_URL, 'localhost:9200/' . $document->index . '/_search'); + \curl_setopt($ch, \CURLOPT_URL, \ELASTICSEARCH_HOST . '/' . $document->index . '/_search'); \curl_setopt($ch, \CURLOPT_RETURNTRANSFER, 1); \curl_setopt($ch, \CURLOPT_CUSTOMREQUEST, 'GET'); \curl_setopt($ch, \CURLOPT_HTTPHEADER, ['Content-Type: application/json']); @@ -91,21 +90,18 @@ class Exists extends \Tester\TestCase $result = $resultMapper->map(\json_decode($response, true)); \Tester\Assert::type('int', $result->stats()->total()); }); - - \curl_close($ch); } public function tearDown(): void { $ch = \curl_init(); - \curl_setopt($ch, \CURLOPT_URL, 'localhost:9200/' . self::INDEX); + \curl_setopt($ch, \CURLOPT_URL, \ELASTICSEARCH_HOST . '/' . self::INDEX); \curl_setopt($ch, \CURLOPT_RETURNTRANSFER, 1); \curl_setopt($ch, \CURLOPT_CUSTOMREQUEST, 'DELETE'); \curl_setopt($ch, \CURLOPT_HTTPHEADER, ['Content-Type: application/json']); \curl_exec($ch); - \curl_close($ch); } } diff --git a/tests/SpameriTests/ElasticQuery/Query/Fuzzy.phpt b/tests/SpameriTests/ElasticQuery/Query/Fuzzy.phpt index 1355435..0880bf9 100644 --- a/tests/SpameriTests/ElasticQuery/Query/Fuzzy.phpt +++ b/tests/SpameriTests/ElasticQuery/Query/Fuzzy.phpt @@ -14,13 +14,12 @@ class Fuzzy extends \Tester\TestCase public function setUp() : void { $ch = \curl_init(); - \curl_setopt($ch, CURLOPT_URL, 'localhost:9200/' . self::INDEX); + \curl_setopt($ch, CURLOPT_URL, \ELASTICSEARCH_HOST . '/' . self::INDEX); \curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); \curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); \curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']); \curl_exec($ch); - \curl_close($ch); } @@ -61,7 +60,7 @@ class Fuzzy extends \Tester\TestCase ); $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, 'localhost:9200/' . $document->index . '/_search'); + curl_setopt($ch, CURLOPT_URL, \ELASTICSEARCH_HOST . '/' . $document->index . '/_search'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET'); curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']); @@ -77,21 +76,18 @@ class Fuzzy extends \Tester\TestCase $result = $resultMapper->map(\json_decode($response, TRUE)); \Tester\Assert::type('int', $result->stats()->total()); }); - - curl_close($ch); } public function tearDown() : void { $ch = \curl_init(); - \curl_setopt($ch, CURLOPT_URL, 'localhost:9200/' . self::INDEX); + \curl_setopt($ch, CURLOPT_URL, \ELASTICSEARCH_HOST . '/' . self::INDEX); \curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); \curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE'); \curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']); \curl_exec($ch); - \curl_close($ch); } } diff --git a/tests/SpameriTests/ElasticQuery/Query/MatchPhrase.phpt b/tests/SpameriTests/ElasticQuery/Query/MatchPhrase.phpt index c1a92a0..e91013a 100644 --- a/tests/SpameriTests/ElasticQuery/Query/MatchPhrase.phpt +++ b/tests/SpameriTests/ElasticQuery/Query/MatchPhrase.phpt @@ -14,13 +14,12 @@ class MatchPhrase extends \Tester\TestCase public function setUp() : void { $ch = \curl_init(); - \curl_setopt($ch, CURLOPT_URL, 'localhost:9200/' . self::INDEX); + \curl_setopt($ch, CURLOPT_URL, \ELASTICSEARCH_HOST . '/' . self::INDEX); \curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); \curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); \curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']); \curl_exec($ch); - \curl_close($ch); } @@ -59,7 +58,7 @@ class MatchPhrase extends \Tester\TestCase ); $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, 'localhost:9200/' . $document->index . '/_search'); + curl_setopt($ch, CURLOPT_URL, \ELASTICSEARCH_HOST . '/' . $document->index . '/_search'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET'); curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']); @@ -75,21 +74,18 @@ class MatchPhrase extends \Tester\TestCase $result = $resultMapper->map(\json_decode($response, TRUE)); \Tester\Assert::type('int', $result->stats()->total()); }); - - curl_close($ch); } public function tearDown() : void { $ch = \curl_init(); - \curl_setopt($ch, CURLOPT_URL, 'localhost:9200/' . self::INDEX); + \curl_setopt($ch, CURLOPT_URL, \ELASTICSEARCH_HOST . '/' . self::INDEX); \curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); \curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE'); \curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']); \curl_exec($ch); - \curl_close($ch); } } diff --git a/tests/SpameriTests/ElasticQuery/Query/MultiMatch.phpt b/tests/SpameriTests/ElasticQuery/Query/MultiMatch.phpt index e2d3e6d..72e09e5 100644 --- a/tests/SpameriTests/ElasticQuery/Query/MultiMatch.phpt +++ b/tests/SpameriTests/ElasticQuery/Query/MultiMatch.phpt @@ -14,13 +14,12 @@ class MultiMatch extends \Tester\TestCase public function setUp(): void { $ch = \curl_init(); - \curl_setopt($ch, \CURLOPT_URL, 'localhost:9200/' . self::INDEX); + \curl_setopt($ch, \CURLOPT_URL, \ELASTICSEARCH_HOST . '/' . self::INDEX); \curl_setopt($ch, \CURLOPT_RETURNTRANSFER, 1); \curl_setopt($ch, \CURLOPT_CUSTOMREQUEST, 'PUT'); \curl_setopt($ch, \CURLOPT_HTTPHEADER, ['Content-Type: application/json']); \curl_exec($ch); - \curl_close($ch); } @@ -179,7 +178,7 @@ class MultiMatch extends \Tester\TestCase ); $ch = \curl_init(); - \curl_setopt($ch, \CURLOPT_URL, 'localhost:9200/' . $document->index . '/_search'); + \curl_setopt($ch, \CURLOPT_URL, \ELASTICSEARCH_HOST . '/' . $document->index . '/_search'); \curl_setopt($ch, \CURLOPT_RETURNTRANSFER, 1); \curl_setopt($ch, \CURLOPT_CUSTOMREQUEST, 'GET'); \curl_setopt($ch, \CURLOPT_HTTPHEADER, ['Content-Type: application/json']); @@ -196,21 +195,18 @@ class MultiMatch extends \Tester\TestCase $result = $resultMapper->map(\json_decode($response, true)); \Tester\Assert::type('int', $result->stats()->total()); }); - - \curl_close($ch); } public function tearDown(): void { $ch = \curl_init(); - \curl_setopt($ch, \CURLOPT_URL, 'localhost:9200/' . self::INDEX); + \curl_setopt($ch, \CURLOPT_URL, \ELASTICSEARCH_HOST . '/' . self::INDEX); \curl_setopt($ch, \CURLOPT_RETURNTRANSFER, 1); \curl_setopt($ch, \CURLOPT_CUSTOMREQUEST, 'DELETE'); \curl_setopt($ch, \CURLOPT_HTTPHEADER, ['Content-Type: application/json']); \curl_exec($ch); - \curl_close($ch); } } diff --git a/tests/SpameriTests/ElasticQuery/Query/Nested.phpt b/tests/SpameriTests/ElasticQuery/Query/Nested.phpt index 2244e1d..ff0debf 100644 --- a/tests/SpameriTests/ElasticQuery/Query/Nested.phpt +++ b/tests/SpameriTests/ElasticQuery/Query/Nested.phpt @@ -14,13 +14,12 @@ class Nested extends \Tester\TestCase public function setUp(): void { $ch = \curl_init(); - \curl_setopt($ch, \CURLOPT_URL, 'localhost:9200/' . self::INDEX); + \curl_setopt($ch, \CURLOPT_URL, \ELASTICSEARCH_HOST . '/' . self::INDEX); \curl_setopt($ch, \CURLOPT_RETURNTRANSFER, 1); \curl_setopt($ch, \CURLOPT_CUSTOMREQUEST, 'PUT'); \curl_setopt($ch, \CURLOPT_HTTPHEADER, ['Content-Type: application/json']); \curl_exec($ch); - \curl_close($ch); } @@ -126,13 +125,12 @@ class Nested extends \Tester\TestCase public function tearDown(): void { $ch = \curl_init(); - \curl_setopt($ch, \CURLOPT_URL, 'localhost:9200/' . self::INDEX); + \curl_setopt($ch, \CURLOPT_URL, \ELASTICSEARCH_HOST . '/' . self::INDEX); \curl_setopt($ch, \CURLOPT_RETURNTRANSFER, 1); \curl_setopt($ch, \CURLOPT_CUSTOMREQUEST, 'DELETE'); \curl_setopt($ch, \CURLOPT_HTTPHEADER, ['Content-Type: application/json']); \curl_exec($ch); - \curl_close($ch); } } diff --git a/tests/SpameriTests/ElasticQuery/Query/PhrasePrefix.phpt b/tests/SpameriTests/ElasticQuery/Query/PhrasePrefix.phpt index 10fba95..806797d 100644 --- a/tests/SpameriTests/ElasticQuery/Query/PhrasePrefix.phpt +++ b/tests/SpameriTests/ElasticQuery/Query/PhrasePrefix.phpt @@ -14,13 +14,12 @@ class PhrasePrefix extends \Tester\TestCase public function setUp(): void { $ch = \curl_init(); - \curl_setopt($ch, \CURLOPT_URL, 'localhost:9200/' . self::INDEX); + \curl_setopt($ch, \CURLOPT_URL, \ELASTICSEARCH_HOST . '/' . self::INDEX); \curl_setopt($ch, \CURLOPT_RETURNTRANSFER, 1); \curl_setopt($ch, \CURLOPT_CUSTOMREQUEST, 'PUT'); \curl_setopt($ch, \CURLOPT_HTTPHEADER, ['Content-Type: application/json']); \curl_exec($ch); - \curl_close($ch); } @@ -93,7 +92,7 @@ class PhrasePrefix extends \Tester\TestCase ); $ch = \curl_init(); - \curl_setopt($ch, \CURLOPT_URL, 'localhost:9200/' . $document->index . '/_search'); + \curl_setopt($ch, \CURLOPT_URL, \ELASTICSEARCH_HOST . '/' . $document->index . '/_search'); \curl_setopt($ch, \CURLOPT_RETURNTRANSFER, 1); \curl_setopt($ch, \CURLOPT_CUSTOMREQUEST, 'GET'); \curl_setopt($ch, \CURLOPT_HTTPHEADER, ['Content-Type: application/json']); @@ -110,21 +109,18 @@ class PhrasePrefix extends \Tester\TestCase $result = $resultMapper->map(\json_decode($response, true)); \Tester\Assert::type('int', $result->stats()->total()); }); - - \curl_close($ch); } public function tearDown(): void { $ch = \curl_init(); - \curl_setopt($ch, \CURLOPT_URL, 'localhost:9200/' . self::INDEX); + \curl_setopt($ch, \CURLOPT_URL, \ELASTICSEARCH_HOST . '/' . self::INDEX); \curl_setopt($ch, \CURLOPT_RETURNTRANSFER, 1); \curl_setopt($ch, \CURLOPT_CUSTOMREQUEST, 'DELETE'); \curl_setopt($ch, \CURLOPT_HTTPHEADER, ['Content-Type: application/json']); \curl_exec($ch); - \curl_close($ch); } } diff --git a/tests/SpameriTests/ElasticQuery/Query/Range.phpt b/tests/SpameriTests/ElasticQuery/Query/Range.phpt index ab5fbc9..3d969cc 100644 --- a/tests/SpameriTests/ElasticQuery/Query/Range.phpt +++ b/tests/SpameriTests/ElasticQuery/Query/Range.phpt @@ -14,13 +14,12 @@ class Range extends \Tester\TestCase public function setUp() : void { $ch = \curl_init(); - \curl_setopt($ch, CURLOPT_URL, 'localhost:9200/' . self::INDEX); + \curl_setopt($ch, CURLOPT_URL, \ELASTICSEARCH_HOST . '/' . self::INDEX); \curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); \curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); \curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']); \curl_exec($ch); - \curl_close($ch); } @@ -57,7 +56,7 @@ class Range extends \Tester\TestCase ); $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, 'localhost:9200/' . $document->index . '/_search'); + curl_setopt($ch, CURLOPT_URL, \ELASTICSEARCH_HOST . '/' . $document->index . '/_search'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET'); curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']); @@ -73,21 +72,18 @@ class Range extends \Tester\TestCase $result = $resultMapper->map(\json_decode($response, TRUE)); \Tester\Assert::type('int', $result->stats()->total()); }); - - curl_close($ch); } public function tearDown() : void { $ch = \curl_init(); - \curl_setopt($ch, CURLOPT_URL, 'localhost:9200/' . self::INDEX); + \curl_setopt($ch, CURLOPT_URL, \ELASTICSEARCH_HOST . '/' . self::INDEX); \curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); \curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE'); \curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']); \curl_exec($ch); - \curl_close($ch); } } diff --git a/tests/SpameriTests/ElasticQuery/Query/Term.phpt b/tests/SpameriTests/ElasticQuery/Query/Term.phpt index d8f7de0..b445579 100644 --- a/tests/SpameriTests/ElasticQuery/Query/Term.phpt +++ b/tests/SpameriTests/ElasticQuery/Query/Term.phpt @@ -14,13 +14,12 @@ class Term extends \Tester\TestCase public function setUp() : void { $ch = \curl_init(); - \curl_setopt($ch, CURLOPT_URL, 'localhost:9200/' . self::INDEX); + \curl_setopt($ch, CURLOPT_URL, \ELASTICSEARCH_HOST . '/' . self::INDEX); \curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); \curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); \curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']); \curl_exec($ch); - \curl_close($ch); } @@ -55,7 +54,7 @@ class Term extends \Tester\TestCase ); $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, 'localhost:9200/' . $document->index . '/_search'); + curl_setopt($ch, CURLOPT_URL, \ELASTICSEARCH_HOST . '/' . $document->index . '/_search'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET'); curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']); @@ -71,21 +70,18 @@ class Term extends \Tester\TestCase $result = $resultMapper->map(\json_decode($response, TRUE)); \Tester\Assert::type('int', $result->stats()->total()); }); - - curl_close($ch); } public function tearDown() : void { $ch = \curl_init(); - \curl_setopt($ch, CURLOPT_URL, 'localhost:9200/' . self::INDEX); + \curl_setopt($ch, CURLOPT_URL, \ELASTICSEARCH_HOST . '/' . self::INDEX); \curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); \curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE'); \curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']); \curl_exec($ch); - \curl_close($ch); } } diff --git a/tests/SpameriTests/ElasticQuery/Query/Terms.phpt b/tests/SpameriTests/ElasticQuery/Query/Terms.phpt index 0d6a2f0..edde1e6 100644 --- a/tests/SpameriTests/ElasticQuery/Query/Terms.phpt +++ b/tests/SpameriTests/ElasticQuery/Query/Terms.phpt @@ -14,13 +14,12 @@ class Terms extends \Tester\TestCase public function setUp() : void { $ch = \curl_init(); - \curl_setopt($ch, CURLOPT_URL, 'localhost:9200/' . self::INDEX); + \curl_setopt($ch, CURLOPT_URL, \ELASTICSEARCH_HOST . '/' . self::INDEX); \curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); \curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); \curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']); \curl_exec($ch); - \curl_close($ch); } public function testCreate() : void @@ -54,7 +53,7 @@ class Terms extends \Tester\TestCase ); $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, 'localhost:9200/' . $document->index . '/_search'); + curl_setopt($ch, CURLOPT_URL, \ELASTICSEARCH_HOST . '/' . $document->index . '/_search'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET'); curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']); @@ -70,21 +69,18 @@ class Terms extends \Tester\TestCase $result = $resultMapper->map(\json_decode($response, TRUE)); \Tester\Assert::type('int', $result->stats()->total()); }); - - curl_close($ch); } public function tearDown() : void { $ch = \curl_init(); - \curl_setopt($ch, CURLOPT_URL, 'localhost:9200/' . self::INDEX); + \curl_setopt($ch, CURLOPT_URL, \ELASTICSEARCH_HOST . '/' . self::INDEX); \curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); \curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE'); \curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']); \curl_exec($ch); - \curl_close($ch); } } diff --git a/tests/SpameriTests/ElasticQuery/Query/WildCard.phpt b/tests/SpameriTests/ElasticQuery/Query/WildCard.phpt index 68aafa0..f69290a 100644 --- a/tests/SpameriTests/ElasticQuery/Query/WildCard.phpt +++ b/tests/SpameriTests/ElasticQuery/Query/WildCard.phpt @@ -14,13 +14,12 @@ class WildCard extends \Tester\TestCase public function setUp() : void { $ch = \curl_init(); - \curl_setopt($ch, CURLOPT_URL, 'localhost:9200/' . self::INDEX); + \curl_setopt($ch, CURLOPT_URL, \ELASTICSEARCH_HOST . '/' . self::INDEX); \curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); \curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); \curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']); \curl_exec($ch); - \curl_close($ch); } @@ -55,7 +54,7 @@ class WildCard extends \Tester\TestCase ); $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, 'localhost:9200/' . $document->index . '/_search'); + curl_setopt($ch, CURLOPT_URL, \ELASTICSEARCH_HOST . '/' . $document->index . '/_search'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET'); curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']); @@ -65,27 +64,27 @@ class WildCard extends \Tester\TestCase ); \Tester\Assert::noError(static function () use ($ch) { - $response = curl_exec($ch); + $response = \curl_exec($ch); + if ($response === false) { + throw new \RuntimeException('Curl request failed: ' . \curl_error($ch)); + } $resultMapper = new \Spameri\ElasticQuery\Response\ResultMapper(); /** @var \Spameri\ElasticQuery\Response\ResultSearch $result */ - $result = $resultMapper->map(\json_decode($response, TRUE)); + $result = $resultMapper->map(\json_decode($response, true)); \Tester\Assert::type('int', $result->stats()->total()); }); - - curl_close($ch); } public function tearDown() : void { $ch = \curl_init(); - \curl_setopt($ch, CURLOPT_URL, 'localhost:9200/' . self::INDEX . '/'); + \curl_setopt($ch, CURLOPT_URL, \ELASTICSEARCH_HOST . '/' . self::INDEX . '/'); \curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); \curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE'); \curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']); \curl_exec($ch); - \curl_close($ch); } } diff --git a/tests/SpameriTests/ElasticQuery/Response/ResultVersion.phpt b/tests/SpameriTests/ElasticQuery/Response/ResultVersion.phpt index 6c30daa..4825066 100644 --- a/tests/SpameriTests/ElasticQuery/Response/ResultVersion.phpt +++ b/tests/SpameriTests/ElasticQuery/Response/ResultVersion.phpt @@ -13,13 +13,29 @@ class ResultVersion extends \Tester\TestCase { $resultMapper = new \Spameri\ElasticQuery\Response\ResultMapper(); /** @var \Spameri\ElasticQuery\Response\ResultVersion $resultObject */ - $resultObject = $resultMapper->map(\json_decode(\file_get_contents('http://127.0.0.1:9200'), TRUE)); + $resultObject = $resultMapper->map(\json_decode(\file_get_contents(\ELASTICSEARCH_HOST), TRUE)); \Tester\Assert::true($resultObject instanceof \Spameri\ElasticQuery\Response\ResultVersion); - if (\Spameri\ElasticQuery\Response\Result\Version::ELASTIC_VERSION_ID_7 <= $resultObject->version()->id()) { + if (\Spameri\ElasticQuery\Response\Result\Version::ELASTIC_VERSION_ID_9 <= $resultObject->version()->id()) { \Tester\Assert::true( - \Spameri\ElasticQuery\Response\Result\Version::ELASTIC_VERSION_ID_7 < $resultObject->version()->id() + \Spameri\ElasticQuery\Response\Result\Version::ELASTIC_VERSION_ID_9 <= $resultObject->version()->id() + ); + \Tester\Assert::true( + \Spameri\ElasticQuery\Response\Result\Version::ELASTIC_VERSION_ID_10 > $resultObject->version()->id() + ); + + } elseif (\Spameri\ElasticQuery\Response\Result\Version::ELASTIC_VERSION_ID_8 <= $resultObject->version()->id()) { + \Tester\Assert::true( + \Spameri\ElasticQuery\Response\Result\Version::ELASTIC_VERSION_ID_8 <= $resultObject->version()->id() + ); + \Tester\Assert::true( + \Spameri\ElasticQuery\Response\Result\Version::ELASTIC_VERSION_ID_9 > $resultObject->version()->id() + ); + + } elseif (\Spameri\ElasticQuery\Response\Result\Version::ELASTIC_VERSION_ID_7 <= $resultObject->version()->id()) { + \Tester\Assert::true( + \Spameri\ElasticQuery\Response\Result\Version::ELASTIC_VERSION_ID_7 <= $resultObject->version()->id() ); \Tester\Assert::true( \Spameri\ElasticQuery\Response\Result\Version::ELASTIC_VERSION_ID_8 > $resultObject->version()->id() diff --git a/tests/SpameriTests/ElasticQuery/VersionCheck.php b/tests/SpameriTests/ElasticQuery/VersionCheck.php index 8ae2373..21c0b8e 100644 --- a/tests/SpameriTests/ElasticQuery/VersionCheck.php +++ b/tests/SpameriTests/ElasticQuery/VersionCheck.php @@ -19,7 +19,7 @@ public static function check(): \Spameri\ElasticQuery\Response\ResultVersion /** @var \Spameri\ElasticQuery\Response\ResultVersion $resultObject */ $resultObject = self::$resultMapper->map( \json_decode( - (string) \file_get_contents('http://127.0.0.1:9200'), + (string) \file_get_contents(ElasticsearchTestCase::getBaseUrl()), true, ), ); diff --git a/tests/SpameriTests/bootstrap.php b/tests/SpameriTests/bootstrap.php index bdfc815..4ce5165 100644 --- a/tests/SpameriTests/bootstrap.php +++ b/tests/SpameriTests/bootstrap.php @@ -19,5 +19,7 @@ \Tester\Environment::setup(); \date_default_timezone_set('Europe/Prague'); +// Elasticsearch host configuration (can be overridden via environment variable) +\define('ELASTICSEARCH_HOST', \getenv('ELASTICSEARCH_HOST') ?: 'http://localhost:9200'); return $loader;