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

GitHub actions #19

Merged
merged 1 commit into from
Oct 10, 2023
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: 0 additions & 3 deletions .coveralls.yml

This file was deleted.

5 changes: 5 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Override for the ES port to use for the docker container
ELASTICSEARCH_PORT=9201

# Override for the ES version to use for the docker container
#ELASTICSEARCH_VERSION=8.8.0
124 changes: 124 additions & 0 deletions .github/workflows/phpunit-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
name: tests

concurrency:
group: phpunit-tests-${{ github.ref_name }}
cancel-in-progress: true

on: ['push', 'pull_request', 'workflow_dispatch']

env:
ELASTICSEARCH_PORT: 9201

jobs:
static_code_analysis:
runs-on: 'ubuntu-20.04'
name: 'Static code analysis'
steps:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'

- name: Checkout
uses: actions/checkout@v4

- name: 'Validate composer.json and composer.lock'
run: composer validate

- name: 'Install dependencies with Composer'
uses: 'ramsey/composer-install@v2'
with:
dependency-versions: 'highest'
composer-options: '--prefer-dist'

- name: Check PHP coding standards
run: php vendor/bin/php-cs-fixer fix --verbose --dry-run

phpunit:
needs: [ static_code_analysis ]
runs-on: 'ubuntu-20.04'
name: 'PHPUnit (PHP ${{ matrix.php }}, Symfony ${{ matrix.symfony }}, ES ${{ matrix.elasticsearch }})'
timeout-minutes: 30
continue-on-error: ${{ matrix.experimental }}
strategy:
matrix:
experimental:
- false
dependencies:
- 'highest'
php:
- '8.1'
- '8.2'
elasticsearch:
- '7.17.13'
symfony:
- '~5.0'
include:
- php: '8.1'
symfony: '~5.0'
elasticsearch: '8.0.1'
experimental: false
- php: '8.1'
symfony: '~5.0'
elasticsearch: '8.1.3' # there are some bc in minor version https://www.elastic.co/guide/en/elasticsearch/reference/current/migrating-8.1.html#breaking-changes-8.1
experimental: false
- php: '8.1'
symfony: '~5.0'
elasticsearch: '8.5.3' # there are some bc in minor version https://www.elastic.co/guide/en/elasticsearch/reference/current/migrating-8.5.html
experimental: false
- php: '8.1'
symfony: '~5.0'
elasticsearch: '8.6.2' # there are no bc in minor version https://www.elastic.co/guide/en/elasticsearch/reference/current/migrating-8.6.html
experimental: false
- php: '8.1'
symfony: '~5.0'
elasticsearch: '8.7.1' # there are no bc in minor version https://www.elastic.co/guide/en/elasticsearch/reference/current/migrating-8.7.html
experimental: false
- php: '8.1'
symfony: '~5.0'
elasticsearch: '8.8.0' # there are no bc in minor version https://www.elastic.co/guide/en/elasticsearch/reference/current/migrating-8.8.html
experimental: false
- php: '8.1'
symfony: '~6.0'
elasticsearch: '8.10.2' # newest version
experimental: false
fail-fast: false
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '${{ matrix.php }}'
coverage: 'pcov'
tools: 'composer:v2'
extensions: 'curl, json, mbstring, openssl'
ini-values: 'memory_limit=256M'

- name: 'Fix symfony/framework-bundle version'
run: composer require --no-update symfony/framework-bundle:${{ matrix.symfony }}

- name: 'Install dependencies with Composer'
uses: 'ramsey/composer-install@v2'
with:
dependency-versions: '${{ matrix.dependencies }}'
composer-options: '--prefer-dist'

- name: 'Dump composer autoloader'
run: composer dump-autoload --classmap-authoritative --no-ansi --no-interaction --no-scripts

- name: 'Setup Elasticsearch'
env:
ELASTICSEARCH_VERSION: ${{ matrix.elasticsearch }}
run: docker compose up --detach --wait ; curl -XGET 'http://localhost:'"$ELASTICSEARCH_PORT"

- name: 'Run phpunit tests'
run: |
vendor/bin/simple-phpunit --coverage-clover=tests/App/build/clover.xml 2>/dev/null

- name: Upload coverage results to Coveralls
env:
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_TOKEN }}
run: |
vendor/bin/php-coveralls --coverage_clover=tests/App/build/clover.xml --json_path=tests/App/build/coveralls.json -v
32 changes: 8 additions & 24 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,15 @@
return (new PhpCsFixer\Config())
->setFinder($finder)
->setRules([
'@PHP73Migration' => true,
'@PHPUnit75Migration:risky' => true,
'@PSR2' => true,
'@Symfony' => true,
'@Symfony:risky' => true,
'modernize_strpos' => true,
'is_null' => true,
'method_argument_space' => ['on_multiline' => 'ensure_fully_multiline'],
'native_constant_invocation' => true,
'native_function_invocation' => [
'include' => ['@all'],
],
'no_alias_functions' => true,
'no_useless_else' => true,
'nullable_type_declaration_for_default_null_value' => true,
'ordered_imports' => true,
'php_unit_dedicate_assert' => ['target' => 'newest'],
'static_lambda' => true,
'ternary_to_null_coalescing' => true,
'visibility_required' => ['elements' => ['property', 'method', 'const']],
'void_return' => false,
'protected_to_private' => false,
'phpdoc_summary' => false,

// Exclude "phpdoc_summary" rule: "PHPDoc summary should end in either a full stop, exclamation mark, or question mark"
'phpdoc_summary' => false,
'phpdoc_annotation_without_dot' => false,
'phpdoc_to_comment' => ['ignored_tags' => ['@var']]
'no_superfluous_phpdoc_tags' => ['allow_mixed' => true, 'remove_inheritdoc' => false],
// Indent '=>' operator
'binary_operator_spaces' => ['operators' => ['=>' => 'align_single_space_minimal']],
// PSR12 imports order
'ordered_imports' => ['imports_order' => ['class', 'function', 'const']],
])
;

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

This file was deleted.

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

![License](https://img.shields.io/github/license/sineflow/elasticsearchbundle.svg)
[![Latest Stable Version](https://img.shields.io/github/release/sineflow/elasticsearchbundle.svg)](https://packagist.org/packages/sineflow/elasticsearch-bundle)
[![Build Status](https://travis-ci.com/sineflow/ElasticsearchBundle.svg?branch=main)](https://app.travis-ci.com/github/sineflow/ElasticsearchBundle)
[![Coverage Status](https://coveralls.io/repos/sineflow/ElasticsearchBundle/badge.svg?branch=master&service=github)](https://coveralls.io/github/sineflow/ElasticsearchBundle?branch=master)
![Tests Workflow](https://github.com/sineflow/ElasticsearchBundle/actions/workflows/phpunit-tests.yml/badge.svg)
[![Coverage Status](https://coveralls.io/repos/github/sineflow/ElasticsearchBundle/badge.svg?branch=main)](https://coveralls.io/github/sineflow/ElasticsearchBundle?branch=main)

## Key points

Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@
"symfony/stopwatch": "^4.4 || ^5.0",
"symfony/phpunit-bridge": "^4.4 || ^5.0",
"symfony/browser-kit": "^4.4 || ^5.0",
"symfony/dotenv": "^4.4 || ^5.0",
"doctrine/orm": "^2.6.3",

"monolog/monolog": "^1.0|^2.0|^3.0",
"knplabs/knp-paginator-bundle": "^4.0 || ^5.0",
"squizlabs/php_codesniffer": "^3.0",
"friendsofphp/php-cs-fixer": "^3.34",
"php-coveralls/php-coveralls": "^2.1",
"escapestudios/symfony2-coding-standard": "^3.0",
"jchook/phpunit-assert-throws": "^1.0",
Expand All @@ -50,8 +51,7 @@
"autoload": {
"psr-4": {
"Sineflow\\ElasticsearchBundle\\": "src/"
},
"exclude-from-classmap": ["/tests/"]
}
},
"autoload-dev": {
"psr-4": {
Expand Down
34 changes: 34 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
services:
elasticsearch:
image: "docker.elastic.co/elasticsearch/elasticsearch:${ELASTICSEARCH_VERSION:-7.17.13}"
container_name: sfes_elasticsearch
environment:
- discovery.type=single-node
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms${ELASTICSEARCH_JAVA_MEM:-2048m} -Xmx${ELASTICSEARCH_JAVA_MEM:-2048m}"
- cluster.name=sfes
- node.name=sfes1
- xpack.security.enabled=false
- indices.id_field_data.enabled=true # TODO: temporary requirement for ES8 until tests are fixed to not do sorting/aggregations on _id (https://github.com/elastic/elasticsearch/issues/43599)
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- elasticsearch-data:/usr/share/elasticsearch/data
ports:
- "${ELASTICSEARCH_PORT:-9200}:9200"
networks:
- elastic
healthcheck:
test: curl -s http://sfes_elasticsearch:$${ELASTICSEARCH_PORT:-9200} > /dev/null || exit 1
interval: 1s
timeout: 5s
retries: 120

volumes:
elasticsearch-data:

networks:
elastic:
driver: bridge
1 change: 1 addition & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
</testsuites>

<php>
<server name="APP_ENV" value="test" force="true" />
<server name="KERNEL_CLASS" value="Sineflow\ElasticsearchBundle\Tests\App\AppKernel" />
<server name="SHELL_VERBOSITY" value="-1" />
<env name="SYMFONY_PHPUNIT_VERSION" value="9" />
Expand Down
1 change: 1 addition & 0 deletions src/Annotation/DocObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Annotation to mark a class as an object during the parsing process.
*
* @Annotation
*
* @Target("CLASS")
*/
final class DocObject
Expand Down
1 change: 1 addition & 0 deletions src/Annotation/Id.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Annotation used for the meta _id field
*
* @Annotation
*
* @Target("PROPERTY")
*/
final class Id
Expand Down
1 change: 1 addition & 0 deletions src/Annotation/Score.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Annotation used for the meta _score field, returned when searching
*
* @Annotation
*
* @Target("PROPERTY")
*/
final class Score
Expand Down
6 changes: 3 additions & 3 deletions src/Document/Provider/ElasticsearchProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ public function getDocuments()
['sort' => ['_doc']],
Finder::RESULTS_RAW | Finder::ADAPTER_SCROLL,
[
'index' => $this->sourceIndexManager->getLiveIndex(),
'size' => $this->chunkSize,
'index' => $this->sourceIndexManager->getLiveIndex(),
'size' => $this->chunkSize,
'scroll' => $this->scrollTime,
]
);
Expand All @@ -90,7 +90,7 @@ public function getDocument($id): array
{
$params = [
'index' => $this->sourceIndexManager->getLiveIndex(),
'id' => $id,
'id' => $id,
];
$doc = $this->sourceIndexManager->getConnection()->getClient()->get($params);
$result = $doc['_source'];
Expand Down
2 changes: 1 addition & 1 deletion src/Document/Repository/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function getById(string $id, int $resultType = Finder::RESULTS_OBJECT)
*
* @return mixed
*/
public function find(array $searchBody, int $resultsType = Finder::RESULTS_OBJECT, array $additionalRequestParams = [], ?int &$totalHits = null)
public function find(array $searchBody, int $resultsType = Finder::RESULTS_OBJECT, array $additionalRequestParams = [], int &$totalHits = null)
{
return $this->finder->find([$this->documentClass], $searchBody, $resultsType, $additionalRequestParams, $totalHits);
}
Expand Down
4 changes: 1 addition & 3 deletions src/Exception/IndexOrAliasNotFoundException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace Sineflow\ElasticsearchBundle\Exception;

use Throwable;

/**
* Class IndexOrAliasNotFoundException
*/
Expand All @@ -19,7 +17,7 @@ class IndexOrAliasNotFoundException extends Exception
*
* @param int $code
*/
public function __construct(string $indexOrAlias, bool $isAlias = false, $code = 0, ?Throwable $previous = null)
public function __construct(string $indexOrAlias, bool $isAlias = false, $code = 0, \Throwable $previous = null)
{
$this->indexOrAlias = $indexOrAlias;

Expand Down
2 changes: 1 addition & 1 deletion src/Exception/IndexRebuildingException.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class IndexRebuildingException extends Exception
* @param array $indicesInProgress The physical indices, which are in the process of being built
* @param int $code
*/
public function __construct(array $indicesInProgress, $code = 0, ?Exception $previous = null)
public function __construct(array $indicesInProgress, $code = 0, Exception $previous = null)
{
parent::__construct(\sprintf('Index is currently being rebuilt as "%s"', \implode(', ', $indicesInProgress)), $code, $previous);

Expand Down
4 changes: 2 additions & 2 deletions src/Finder/Adapter/ScrollAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ class ScrollAdapter
private $resultsType;

/**
* @var int
* @var int|null
*/
private $totalHits = null;
private $totalHits;

/**
* When a search query with a 'scroll' param is performed, not only the scroll id is returned, but also the
Expand Down
Loading