Skip to content

Commit 5401479

Browse files
committed
Fix tests for PHP 7 with ES 6.7 + updated versions req in docs
1 parent d771be7 commit 5401479

File tree

3 files changed

+30
-8
lines changed

3 files changed

+30
-8
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ Version Matrix
2929

3030
| Elasticsearch Version | Elasticsearch-PHP Branch |
3131
| --------------------- | ------------------------ |
32-
| >= 6.0, < 7.0 | 6.0 |
32+
| >= 6.6, < 7.0 | 6.7 |
33+
| >= 6.0, < 6.6 | 6.5 |
3334
| >= 5.0, < 6.0 | 5.0 |
3435
| >= 2.0, < 5.0 | 1.0 or 2.0 |
3536
| >= 1.0, < 2.0 | 1.0 or 2.0 |
@@ -49,12 +50,12 @@ Installation via Composer
4950
-------------------------
5051
The recommended method to install _Elasticsearch-PHP_ is through [Composer](http://getcomposer.org).
5152

52-
1. Add `elasticsearch/elasticsearch` as a dependency in your project's `composer.json` file (change version to suit your version of Elasticsearch, for instance this is for ES 6.0 to 6.5):
53+
1. Add `elasticsearch/elasticsearch` as a dependency in your project's `composer.json` file (change version to suit your version of Elasticsearch, for instance for ES 6.7):
5354

5455
```json
5556
{
5657
"require": {
57-
"elasticsearch/elasticsearch": "^6.5"
58+
"elasticsearch/elasticsearch": "^6.7"
5859
}
5960
}
6061
```

docs/installation.asciidoc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ The master branch will always track Elasticsearch master, but it is not recommen
2727
[width="40%",options="header",frame="topbot"]
2828
|============================
2929
|Elasticsearch Version | Elasticsearch-PHP Branch
30-
| >= 6.0 | `6.0`
30+
| >= 6.6, <= 6.7 | `6.7`
31+
| >= 6.0, <= 6.5 | `6.5`
3132
| >= 5.0, <= 6.0 | `5.0`
3233
| >= 1.0, <= 5.0 | `1.0`, `2.0`
3334
| <= 0.90.* | `0.4`
@@ -41,7 +42,7 @@ The master branch will always track Elasticsearch master, but it is not recommen
4142
--------------------------
4243
{
4344
"require": {
44-
"elasticsearch/elasticsearch": "~6.0"
45+
"elasticsearch/elasticsearch": "~6.7.0"
4546
}
4647
}
4748
--------------------------

tests/Elasticsearch/Tests/YamlRunnerTest.php

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,17 @@ class YamlRunnerTest extends \PHPUnit\Framework\TestCase
6868
private static $skippedTests = [
6969
'nodes.stats/30_discovery.yml#Discovery stats' => 'Failing on ES 6.1+: nodes.$master.discovery is an empty array, expected to have cluster_state_queue field in it',
7070
'indices.stats/20_translog.yml#Translog retention' => 'Failing on ES 6.3+: Failed asserting that 495 is equal to <string:$creation_size> or is less than \'$creation_size\'',
71-
'indices.shrink/30_copy_settings.yml#Copy settings during shrink index' => 'Failing on ES 6.4+: Failed to match in test "Copy settings during shrink index". Expected [\'4\'] does not match [false] '
71+
'indices.shrink/30_copy_settings.yml#Copy settings during shrink index' => 'Failing on ES 6.4+: Failed to match in test "Copy settings during shrink index". Expected [\'4\'] does not match [false] ',
7272
];
7373

74+
private static $skippedTestsIfPhpLessThan = [
75+
// Failing on ES 6.7+ only with PHP 7.0: Cannot access empty property
76+
'indices.put_mapping/11_basic_with_types.yml#Create index with invalid mappings' => '7.1.0',
77+
'indices.put_mapping/10_basic.yml#Create index with invalid mappings' => '7.1.0',
78+
'indices.create/11_basic_with_types.yml#Create index with invalid mappings' => '7.1.0',
79+
'indices.create/11_basic_with_types.yml#Create index with no type mappings' => '7.1.0',
80+
'indices.create/10_basic.yml#Create index with invalid mappings' => '7.1.0',
81+
];
7482
/**
7583
* @var array A list of skipped test with their reasons
7684
*/
@@ -814,8 +822,8 @@ public function yamlProvider(): array
814822
$filter = getenv('TEST_CASE') !== false ? getenv('TEST_CASE') : null;
815823

816824
/**
817-
* @var SplFileInfo $file
818-
*/
825+
* @var SplFileInfo $file
826+
*/
819827
foreach ($finder as $file) {
820828
$files = array_merge($files, $this->splitDocument($file, $path, $filter));
821829
}
@@ -944,6 +952,7 @@ private function formatRegex(string $regex): string
944952
*/
945953
private function splitDocument(SplFileInfo $file, string $path, string $filter = null): array
946954
{
955+
947956
$fileContent = $file->getContents();
948957
// cleanup some bad comments
949958
$fileContent = str_replace('"#', '" #', $fileContent);
@@ -973,6 +982,17 @@ function ($item) {
973982
$skip = false;
974983
$documentParsed = null;
975984
foreach ($documents as $documentString) {
985+
// Extract test name
986+
if (preg_match('/"([^"]+)"/', $documentString, $matches)) {
987+
$testName = $matches[1];
988+
// Skip YAML parsing if test is signed to be skipped and if PHP is < version specified
989+
// To prevent YAML parse error, e.g. empty property
990+
if (array_key_exists("$fileName#$testName", static::$skippedTestsIfPhpLessThan)) {
991+
if (version_compare(PHP_VERSION, static::$skippedTestsIfPhpLessThan["$fileName#$testName"], '<')) {
992+
continue;
993+
}
994+
}
995+
}
976996
// TODO few bad instances of teardown, should be fixed in upstream but this is a quick fix locally
977997
$documentString = str_replace(" teardown:", "teardown:", $documentString);
978998
try {

0 commit comments

Comments
 (0)