Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introducing PHP8 compliancy #1063

Merged
merged 4 commits into from
Dec 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .ci/packer_cache.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

source /usr/local/bin/bash_standard_lib.sh

DOCKER_IMAGES="php:7.4-cli
DOCKER_IMAGES="php:8.0-cli
php:7.4-cli
php:7.3-cli
php:7.2-cli
php:7.1-cli
giovannialbero1992 marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
1 change: 1 addition & 0 deletions .ci/test-matrix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ STACK_VERSION:
- 7.x-SNAPSHOT

PHP_VERSION:
- 8.0-cli
- 7.4-cli
- 7.3-cli
- 7.2-cli
Expand Down
13 changes: 9 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:

strategy:
matrix:
php-version: [7.1, 7.2, 7.3, 7.4]
php-version: [7.1, 7.2, 7.3, 7.4, 8.0]
os: [ubuntu-latest]
es-version: [7.x-SNAPSHOT]

Expand All @@ -24,11 +24,11 @@ jobs:
tools: prestissimo
env:
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Get composer cache directory
id: composercache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Cache dependencies
uses: actions/cache@v2
with:
Expand All @@ -37,9 +37,15 @@ jobs:
restore-keys: ${{ runner.os }}-composer-

- name: Install dependencies
if: ${{ matrix.php-version != '8.0' }}
run: |
composer install --prefer-dist

- name: ignore ignore-platform-reqs if it is using php 8
if: ${{ matrix.php-version == '8.0' }}
run: |
composer install --prefer-dist --ignore-platform-reqs

- name: PHP Coding Standards
run: |
composer run-script phpcs
Expand Down Expand Up @@ -71,4 +77,3 @@ jobs:
vendor/bin/phpunit -c phpunit-integration-tests.xml
env:
TEST_SUITE: oss

6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@
}
],
"require": {
"php": "^7.1",
"php": "^7.1 || ^8.0",
"ext-json": ">=1.3.7",
"ezimuel/ringphp": "^1.1.2",
"psr/log": "~1.0"
},
"require-dev": {
"ext-yaml": "*",
"ext-zip": "*",
"cpliakas/git-wrapper": "~2.0",
"cpliakas/git-wrapper": "~2.0 || ~3.0",
"doctrine/inflector": "^1.3",
"mockery/mockery": "^1.2",
"phpstan/phpstan": "^0.12",
"phpunit/phpunit": "^7.5",
"phpunit/phpunit": "^7.5 || ^8.5 || ^9.3",
"squizlabs/php_codesniffer": "^3.4",
"symfony/finder": "~4.0",
"symfony/yaml": "~4.0"
Expand Down
2 changes: 1 addition & 1 deletion tests/Elasticsearch/Tests/ClientBuilder/DummyLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@

class DummyLogger
{

giovannialbero1992 marked this conversation as resolved.
Show resolved Hide resolved
}
16 changes: 6 additions & 10 deletions tests/Elasticsearch/Tests/ClientBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,21 @@
use Elasticsearch\Client;
use Elasticsearch\ClientBuilder;
use Elasticsearch\Common\Exceptions\ElasticsearchException;
use Elasticsearch\Common\Exceptions\InvalidArgumentException;
use Elasticsearch\Common\Exceptions\RuntimeException;
use Elasticsearch\Tests\ClientBuilder\DummyLogger;
use GuzzleHttp\Ring\Client\MockHandler;
use PHPUnit\Framework\TestCase;

class ClientBuilderTest extends TestCase
{
/**
* @expectedException TypeError
*/
public function testClientBuilderThrowsExceptionForIncorrectLoggerClass()
{
$this->expectException(\TypeError::class);
ClientBuilder::create()->setLogger(new DummyLogger);
}

/**
* @expectedException TypeError
*/
public function testClientBuilderThrowsExceptionForIncorrectTracerClass()
{
$this->expectException(\TypeError::class);
ClientBuilder::create()->setTracer(new DummyLogger);
}

Expand All @@ -51,7 +46,7 @@ public function testGzipEnabledWhenElasticCloudId()
->build();

$this->assertInstanceOf(Client::class, $client);

try {
$result = $client->info();
} catch (ElasticsearchException $e) {
Expand All @@ -75,7 +70,7 @@ public function testElasticCloudIdNotOverrideCurlEncoding()
->build();

$this->assertInstanceOf(Client::class, $client);

try {
$result = $client->info();
} catch (ElasticsearchException $e) {
Expand Down Expand Up @@ -237,6 +232,7 @@ public function testFromConfigQuiteTrueWithUnknownKey()
*/
public function testFromConfigQuiteFalseWithUnknownKey()
{
$this->expectException(RuntimeException::class);
$client = ClientBuilder::fromConfig(
[
'hosts' => ['localhost:9200'],
Expand Down
8 changes: 4 additions & 4 deletions tests/Elasticsearch/Tests/ClientIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class ClientIntegrationTest extends \PHPUnit\Framework\TestCase
*/
private $host;

public function setUp()
public function setUp(): void
{
$this->host = Utility::getHost();
if (null == $this->host) {
Expand All @@ -58,10 +58,10 @@ private function getClient(): Client
$client = ClientBuilder::create()
->setHosts([$this->host])
->setLogger($this->logger);

if (getenv('TEST_SUITE') === 'xpack') {
$client->setSSLVerification(__DIR__ . '/../../../.ci/certs/ca.crt');
}
}
return $client->build();
}

Expand All @@ -80,7 +80,7 @@ public function testLogRequestSuccessHasPortInInfo()

$result = $client->info();

$this->assertContains('"port"', $this->getLevelOutput(LogLevel::INFO, $this->logger->output));
$this->assertStringContainsString('"port"', $this->getLevelOutput(LogLevel::INFO, $this->logger->output));
}

public function testLogRequestFailHasWarning()
Expand Down
2 changes: 1 addition & 1 deletion tests/Elasticsearch/Tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
*/
class ClientTest extends \PHPUnit\Framework\TestCase
{
public function tearDown()
public function tearDown(): void
{
m::close();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
*/
class StickyRoundRobinSelectorTest extends \PHPUnit\Framework\TestCase
{
public function tearDown()
public function tearDown(): void
{
m::close();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
*/
class SniffingConnectionPoolIntegrationTest extends \PHPUnit\Framework\TestCase
{
protected function setUp()
protected function setUp(): void
{
static::markTestSkipped("All of Sniffing unit tests use outdated cluster state format, need to redo");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@
*/
class SniffingConnectionPoolTest extends \PHPUnit\Framework\TestCase
{
protected function setUp()
protected function setUp(): void
{
static::markTestSkipped("All of Sniffing unit tests use outdated cluster state format, need to redo");
}


public function tearDown()
public function tearDown(): void
{
m::close();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class StaticConnectionPoolIntegrationTest extends \PHPUnit\Framework\TestCase
*/
private $host;

public function setUp()
public function setUp(): void
{
$this->host = Utility::getHost();
if (null == $this->host) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
*/
class StaticConnectionPoolTest extends \PHPUnit\Framework\TestCase
{
public function tearDown()
public function tearDown(): void
{
m::close();
}
Expand Down
18 changes: 9 additions & 9 deletions tests/Elasticsearch/Tests/Connections/ConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class ConnectionTest extends \PHPUnit\Framework\TestCase
*/
private $serializer;

protected function setUp()
protected function setUp(): void
{
$this->logger = $this->createMock(LoggerInterface::class);
$this->trace = $this->createMock(LoggerInterface::class);
Expand Down Expand Up @@ -96,7 +96,7 @@ function () {
$headers = $connection->getHeaders();

$this->assertArrayHasKey('User-Agent', $headers);
$this->assertContains('elasticsearch-php/'. Client::VERSION, $headers['User-Agent'][0]);
$this->assertStringContainsString('elasticsearch-php/'. Client::VERSION, $headers['User-Agent'][0]);
}

/**
Expand Down Expand Up @@ -125,7 +125,7 @@ public function testUserAgentHeaderIsSent()
$request = $connection->getLastRequestInfo()['request'];

$this->assertArrayHasKey('User-Agent', $request['headers']);
$this->assertContains('elasticsearch-php/'. Client::VERSION, $request['headers']['User-Agent'][0]);
$this->assertStringContainsString('elasticsearch-php/'. Client::VERSION, $request['headers']['User-Agent'][0]);
}

/**
Expand Down Expand Up @@ -157,7 +157,7 @@ public function testGetHeadersContainsHostArrayConfig()
$this->assertArrayHasKey(CURLOPT_HTTPAUTH, $request['client']['curl']);
$this->assertArrayHasKey(CURLOPT_USERPWD, $request['client']['curl']);
$this->assertArrayNotHasKey('Authorization', $request['headers']);
$this->assertContains('foo:bar', $request['client']['curl'][CURLOPT_USERPWD]);
$this->assertStringContainsString('foo:bar', $request['client']['curl'][CURLOPT_USERPWD]);
}

/**
Expand Down Expand Up @@ -191,7 +191,7 @@ public function testGetHeadersContainApiKeyAuth()

$this->assertArrayHasKey('Authorization', $request['headers']);
$this->assertArrayNotHasKey(CURLOPT_HTTPAUTH, $request['headers']);
$this->assertContains($params['client']['headers']['Authorization'][0], $request['headers']['Authorization'][0]);
$this->assertStringContainsString($params['client']['headers']['Authorization'][0], $request['headers']['Authorization'][0]);
}

/**
Expand Down Expand Up @@ -227,7 +227,7 @@ public function testGetHeadersContainApiKeyAuthOverHostArrayConfig()

$this->assertArrayHasKey('Authorization', $request['headers']);
$this->assertArrayNotHasKey(CURLOPT_HTTPAUTH, $request['headers']);
$this->assertContains($params['client']['headers']['Authorization'][0], $request['headers']['Authorization'][0]);
$this->assertStringContainsString($params['client']['headers']['Authorization'][0], $request['headers']['Authorization'][0]);
}

/**
Expand Down Expand Up @@ -261,7 +261,7 @@ public function testGetHeadersContainBasicAuth()
$this->assertArrayHasKey(CURLOPT_HTTPAUTH, $request['client']['curl']);
$this->assertArrayHasKey(CURLOPT_USERPWD, $request['client']['curl']);
$this->assertArrayNotHasKey('Authorization', $request['headers']);
$this->assertContains($params['client']['curl'][CURLOPT_USERPWD], $request['client']['curl'][CURLOPT_USERPWD]);
$this->assertStringContainsString($params['client']['curl'][CURLOPT_USERPWD], $request['client']['curl'][CURLOPT_USERPWD]);
}

/**
Expand Down Expand Up @@ -297,7 +297,7 @@ public function testGetHeadersContainBasicAuthOverHostArrayConfig()
$this->assertArrayHasKey(CURLOPT_HTTPAUTH, $request['client']['curl']);
$this->assertArrayHasKey(CURLOPT_USERPWD, $request['client']['curl']);
$this->assertArrayNotHasKey('Authorization', $request['headers']);
$this->assertContains('username:password', $request['client']['curl'][CURLOPT_USERPWD]);
$this->assertStringContainsString('username:password', $request['client']['curl'][CURLOPT_USERPWD]);
}

/**
Expand Down Expand Up @@ -332,7 +332,7 @@ function () {

$result = $tryDeserializeError->invoke($connection, $response, ServerErrorResponseException::class);
$this->assertInstanceOf(ServerErrorResponseException::class, $result);
$this->assertContains('master_not_discovered_exception', $result->getMessage());
$this->assertStringContainsString('master_not_discovered_exception', $result->getMessage());
}

public function testHeaderClientParamIsResetAfterSent()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class AbstractEndpointTest extends \PHPUnit\Framework\TestCase
*/
private $endpoint;

protected function setUp()
protected function setUp(): void
{
$this->endpoint = $this->getMockForAbstractClass(AbstractEndpoint::class);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Elasticsearch/Tests/Endpoints/StatusEndpointTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class StatusEndpointTest extends \PHPUnit\Framework\TestCase
*/
private $endpoint;

protected function setUp()
protected function setUp(): void
{
$this->endpoint = new Status();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ class SearchHitIteratorTest extends \PHPUnit\Framework\TestCase
*/
private $searchResponse;

public function setUp()
public function setUp(): void
{
$this->searchResponse = Mockery::mock(SearchResponseIterator::class);
}

public function tearDown()
public function tearDown(): void
{
Mockery::close();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
class SearchResponseIteratorTest extends \PHPUnit\Framework\TestCase
{

public function tearDown()
public function tearDown(): void
{
m::close();
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Elasticsearch/Tests/RegisteredNamespaceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
*/
class RegisteredNamespaceTest extends \PHPUnit\Framework\TestCase
{
public function tearDown()
public function tearDown(): void
{
m::close();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
*/
class ArrayToJSONSerializerTest extends \PHPUnit\Framework\TestCase
{
public function tearDown()
public function tearDown(): void
{
m::close();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
*/
class EverythingToJSONSerializerTest extends \PHPUnit\Framework\TestCase
{
public function tearDown()
public function tearDown(): void
{
m::close();
}
Expand Down
Loading