Skip to content

Commit

Permalink
Merge e9b5121 into d2ac6ac
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Nov 23, 2020
2 parents d2ac6ac + e9b5121 commit a7e55b3
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 8 deletions.
116 changes: 116 additions & 0 deletions .github/workflows/ci.yml
@@ -0,0 +1,116 @@
name: CI

on:
push:
branches:
- master
pull_request:
branches:
- '*'

jobs:
testsuite:
runs-on: ubuntu-18.04
strategy:
fail-fast: false
matrix:
php-version: ['7.2', '7.4']
prefer-lowest: ['']
include:
- php-version: '7.2'
prefer-lowest: 'prefer-lowest'

services:
elasticsearch:
image: elasticsearch:6.8.13
ports:
- 9200/tcp

steps:
- uses: actions/checkout@v1
with:
fetch-depth: 1

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
extensions: mbstring, intl, apcu
ini-values: apc.enable_cli = 1
coverage: pcov

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

- name: Get date part for cache key
id: key-date
run: echo "::set-output name=date::$(date +'%Y-%m')"

- name: Cache composer dependencies
uses: actions/cache@v1
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ steps.key-date.outputs.date }}-${{ hashFiles('composer.json') }}-${{ matrix.prefer-lowest }}

- name: composer install
run: |
if ${{ matrix.prefer-lowest == 'prefer-lowest' }}; then
composer update --prefer-lowest --prefer-stable
else
composer update
fi
- name: Setup problem matchers for PHPUnit
if: matrix.php-version == '7.4'
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"

- name: Run PHPUnit
env:
DB_URL: Cake\ElasticSearch\Datasource\Connection://127.0.0.1:${{ job.services.elasticsearch.ports['9200'] }}?driver=Cake\ElasticSearch\Datasource\Connection
run: |
if [[ ${{ matrix.php-version }} == '7.4' ]]; then
export CODECOVERAGE=1 && vendor/bin/phpunit --verbose --coverage-clover=coverage.xml
else
vendor/bin/phpunit
fi
- name: Submit code coverage
if: matrix.php-version == '7.4'
uses: codecov/codecov-action@v1

cs-stan:
name: Coding Standard & Static Analysis
runs-on: ubuntu-18.04

steps:
- uses: actions/checkout@v1
with:
fetch-depth: 1

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.2'
extensions: mbstring, intl, apcu
coverage: none

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

- name: Get date part for cache key
id: key-date
run: echo "::set-output name=date::$(date +'%Y-%m')"

- name: Cache composer dependencies
uses: actions/cache@v1
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ steps.key-date.outputs.date }}-${{ hashFiles('composer.json') }}-${{ matrix.prefer-lowest }}

- name: composer install
run: composer update

- name: Run PHP CodeSniffer
run: vendor/bin/phpcs --report=checkstyle src/ tests/
10 changes: 6 additions & 4 deletions tests/TestCase/QueryBuilderTest.php
Expand Up @@ -508,10 +508,12 @@ public function testScript()
{
$builder = new QueryBuilder();
$result = $builder->script("doc['foo'] > 2");
$expected = [
'script' => ['script' => ['source' => "doc['foo'] > 2"]],
];
$this->assertEquals($expected, $result->toArray());

$data = $result->toArray();
// The result varies a bit depending on the elasticsearch driver versions.
$this->assertArrayHasKey('script', $data);
$this->assertArrayHasKey('script', $data['script']);
$this->assertSame(["doc['foo'] > 2"], array_values($data['script']['script']));
}

/**
Expand Down
8 changes: 4 additions & 4 deletions tests/init.php
Expand Up @@ -55,11 +55,11 @@
'file' => 'debug',
]);

if (!getenv('db_dsn')) {
putenv('db_dsn=Cake\ElasticSearch\Datasource\Connection://127.0.0.1:9200?driver=Cake\ElasticSearch\Datasource\Connection');
if (!getenv('DB_URL')) {
putenv('DB_URL=Cake\ElasticSearch\Datasource\Connection://127.0.0.1:9200?driver=Cake\ElasticSearch\Datasource\Connection');
}

ConnectionManager::setConfig('test', ['url' => getenv('db_dsn')]);
ConnectionManager::setConfig('test_elastic', ['url' => getenv('db_dsn')]);
ConnectionManager::setConfig('test', ['url' => getenv('DB_URL')]);
ConnectionManager::setConfig('test_elastic', ['url' => getenv('DB_URL')]);

Router::reload();

0 comments on commit a7e55b3

Please sign in to comment.