Skip to content

Commit

Permalink
Removed Travis CI in favor of Github action
Browse files Browse the repository at this point in the history
  • Loading branch information
ezimuel committed Aug 20, 2020
1 parent f729b18 commit 7dee03c
Show file tree
Hide file tree
Showing 19 changed files with 242 additions and 188 deletions.
2 changes: 1 addition & 1 deletion .ci/yaml-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
php util/RestSpecRunner.php

# Run YAML tests
vendor/bin/phpunit -c phpunit-integration.xml --group sync
vendor/bin/phpunit -c phpunit-yaml-tests.xml
74 changes: 74 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: PHP test

on: [push, pull_request]

jobs:
test:
name: Test
runs-on: ${{ matrix.os }}

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

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Use PHP ${{ matrix.php-version }}
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
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:
path: ${{ steps.composercache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-

- name: Install dependencies
run: |
composer install --prefer-dist
- name: PHP Coding Standards
run: |
composer run-script phpcs
- name: PHP Static Analysis Tool
run: |
composer run-script phpstan
- name: Unit tests
run: |
vendor/bin/phpunit -c phpunit.xml.dist
env:
TEST_SUITE: oss

- name: Configure sysctl limits
run: |
sudo swapoff -a
sudo sysctl -w vm.swappiness=1
sudo sysctl -w fs.file-max=262144
sudo sysctl -w vm.max_map_count=262144
- name: Runs Elasticsearch ${{ matrix.es-version }}
uses: elastic/elastic-github-actions/elasticsearch@master
with:
stack-version: ${{ matrix.es-version }}

- name: Integration tests
run: |
vendor/bin/phpunit -c phpunit-integration-tests.xml
env:
TEST_SUITE: oss

56 changes: 0 additions & 56 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ parameters:
reportUnmatchedIgnoredErrors:
false
ignoreErrors:
- '#Unsafe usage of new static()#'
- '#Unsafe usage of new static\(\)#'
- '#Call to static method performRequest\(\) on trait#'
- '#Constant JSON_THROW_ON_ERROR not found#'
- '#Caught class JsonException not found#'
Expand Down
27 changes: 27 additions & 0 deletions phpunit-integration-tests.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/6.3/phpunit.xsd"
bootstrap="tests/bootstrap.php"
colors="true"
failOnRisky="true"
verbose="true"
beStrictAboutChangesToGlobalState="true"
beStrictAboutOutputDuringTests="true"
>
<testsuites>
<testsuite name="Integration tests">
<directory>tests</directory>
<exclude>tests/Elasticsearch/Tests/YamlRunnerTest.php</exclude>
</testsuite>
</testsuites>
<groups>
<include>
<group>Integration</group>
</include>
</groups>
<filter>
<whitelist>
<directory suffix=".php">src</directory>
</whitelist>
</filter>
</phpunit>
33 changes: 33 additions & 0 deletions phpunit-yaml-tests.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/6.3/phpunit.xsd"
bootstrap="tests/bootstrap.php"
colors="true"
failOnRisky="true"
verbose="true"
beStrictAboutChangesToGlobalState="true"
beStrictAboutOutputDuringTests="true"
>
<php>
<!-- Disable E_USER_DEPRECATED setting E_ALL & ~E_USER_DEPRECATED-->
<ini name="error_reporting" value="16383"/>
</php>
<testsuites>
<testsuite name="Yaml tests">
<file>tests/Elasticsearch/Tests/YamlRunnerTest.php</file>
</testsuite>
</testsuites>
<groups>
<include>
<group>sync</group>
</include>
</groups>
<filter>
<whitelist>
<directory suffix=".php">src</directory>
</whitelist>
</filter>
<logging>
<log type="junit" target="tests/yaml-test-junit.xml"/>
</logging>
</phpunit>
10 changes: 6 additions & 4 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@
beStrictAboutChangesToGlobalState="true"
beStrictAboutOutputDuringTests="true"
>
<php>
<env name="ES_TEST_HOST" value=""/>
</php>
<testsuites>
<testsuite name="Tests">
<testsuite name="Unit tests">
<directory>tests</directory>
<exclude>tests/Elasticsearch/Tests/YamlRunnerTest.php</exclude>
</testsuite>
</testsuites>
<groups>
<exclude>
<group>Integration</group>
</exclude>
</groups>
<filter>
<whitelist>
<directory suffix=".php">src</directory>
Expand Down
1 change: 1 addition & 0 deletions ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
<ruleset name="Elasticsearch-PHP">
<rule ref="PSR2">
<exclude name="Generic.Files.LineLength.TooLong"/>
<exclude name="Squiz.WhiteSpace.SuperfluousWhitespace.EndLine"/>
</rule>
</ruleset>
83 changes: 72 additions & 11 deletions tests/Elasticsearch/Tests/ClientIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

use Elasticsearch\Client;
use Elasticsearch\ClientBuilder;
use Elasticsearch\Common\Exceptions\BadRequest400Exception;
use Elasticsearch\Common\Exceptions\ElasticsearchException;
use Elasticsearch\Common\Exceptions\Missing404Exception;
use Elasticsearch\Tests\ClientBuilder\ArrayLogger;
Expand All @@ -29,6 +30,7 @@
* Class ClientTest
*
* @subpackage Tests
* @group Integration
*/
class ClientIntegrationTest extends \PHPUnit\Framework\TestCase
{
Expand All @@ -51,12 +53,21 @@ public function setUp()
$this->logger = new ArrayLogger();
}

public function testLogRequestSuccessHasInfoNotEmpty()
private function getClient(): Client
{
$client = ClientBuilder::create()
->setHosts([$this->host])
->setLogger($this->logger)
->build();
->setLogger($this->logger);

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

public function testLogRequestSuccessHasInfoNotEmpty()
{
$client = $this->getClient();

$result = $client->info();

Expand All @@ -65,10 +76,7 @@ public function testLogRequestSuccessHasInfoNotEmpty()

public function testLogRequestSuccessHasPortInInfo()
{
$client = ClientBuilder::create()
->setHosts([$this->host])
->setLogger($this->logger)
->build();
$client = $this->getClient();

$result = $client->info();

Expand All @@ -77,10 +85,7 @@ public function testLogRequestSuccessHasPortInInfo()

public function testLogRequestFailHasWarning()
{
$client = ClientBuilder::create()
->setHosts([$this->host])
->setLogger($this->logger)
->build();
$client = $this->getClient();

try {
$result = $client->get([
Expand All @@ -92,6 +97,62 @@ public function testLogRequestFailHasWarning()
}
}

public function testIndexCannotBeEmptyStringForDelete()
{
$client = $this->getClient();

$this->expectException(Missing404Exception::class);

$client->delete(
[
'index' => '',
'id' => 'test'
]
);
}

public function testIdCannotBeEmptyStringForDelete()
{
$client = $this->getClient();

$this->expectException(BadRequest400Exception::class);

$client->delete(
[
'index' => 'test',
'id' => ''
]
);
}

public function testIndexCannotBeArrayOfEmptyStringsForDelete()
{
$client = $this->getClient();

$this->expectException(Missing404Exception::class);

$client->delete(
[
'index' => ['', '', ''],
'id' => 'test'
]
);
}

public function testIndexCannotBeArrayOfNullsForDelete()
{
$client = $this->getClient();

$this->expectException(Missing404Exception::class);

$client->delete(
[
'index' => [null, null, null],
'id' => 'test'
]
);
}

private function getLevelOutput(string $level, array $output): string
{
foreach ($output as $out) {
Expand Down
Loading

0 comments on commit 7dee03c

Please sign in to comment.