Skip to content

Commit a8a3268

Browse files
committed
Added github actions workflow and code style fixes
1 parent 2f48c5d commit a8a3268

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+569
-424
lines changed

.coveralls.yml

-3
This file was deleted.

.env

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Override for the ES port to use for the docker container
2+
ELASTICSEARCH_PORT=9201
3+
4+
# Override for the ES version to use for the docker container
5+
#ELASTICSEARCH_VERSION=8.8.0

.github/workflows/phpunit-tests.yml

+124
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
name: tests
2+
3+
concurrency:
4+
group: phpunit-tests-${{ github.ref_name }}
5+
cancel-in-progress: true
6+
7+
on: ['push', 'pull_request', 'workflow_dispatch']
8+
9+
env:
10+
ELASTICSEARCH_PORT: 9201
11+
12+
jobs:
13+
static_code_analysis:
14+
runs-on: 'ubuntu-20.04'
15+
name: 'Static code analysis'
16+
steps:
17+
- name: Setup PHP
18+
uses: shivammathur/setup-php@v2
19+
with:
20+
php-version: '8.1'
21+
22+
- name: Checkout
23+
uses: actions/checkout@v4
24+
25+
- name: 'Validate composer.json and composer.lock'
26+
run: composer validate
27+
28+
- name: 'Install dependencies with Composer'
29+
uses: 'ramsey/composer-install@v2'
30+
with:
31+
dependency-versions: 'highest'
32+
composer-options: '--prefer-dist'
33+
34+
- name: Check PHP coding standards
35+
run: php vendor/bin/php-cs-fixer fix --verbose --dry-run
36+
37+
phpunit:
38+
needs: [ static_code_analysis ]
39+
runs-on: 'ubuntu-20.04'
40+
name: 'PHPUnit (PHP ${{ matrix.php }}, Symfony ${{ matrix.symfony }}, ES ${{ matrix.elasticsearch }})'
41+
timeout-minutes: 30
42+
continue-on-error: ${{ matrix.experimental }}
43+
strategy:
44+
matrix:
45+
experimental:
46+
- false
47+
dependencies:
48+
- 'highest'
49+
php:
50+
- '8.1'
51+
- '8.2'
52+
elasticsearch:
53+
- '7.17.13'
54+
symfony:
55+
- '~5.0'
56+
include:
57+
- php: '8.1'
58+
symfony: '~5.0'
59+
elasticsearch: '8.0.1'
60+
experimental: false
61+
- php: '8.1'
62+
symfony: '~5.0'
63+
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
64+
experimental: false
65+
- php: '8.1'
66+
symfony: '~5.0'
67+
elasticsearch: '8.5.3' # there are some bc in minor version https://www.elastic.co/guide/en/elasticsearch/reference/current/migrating-8.5.html
68+
experimental: false
69+
- php: '8.1'
70+
symfony: '~5.0'
71+
elasticsearch: '8.6.2' # there are no bc in minor version https://www.elastic.co/guide/en/elasticsearch/reference/current/migrating-8.6.html
72+
experimental: false
73+
- php: '8.1'
74+
symfony: '~5.0'
75+
elasticsearch: '8.7.1' # there are no bc in minor version https://www.elastic.co/guide/en/elasticsearch/reference/current/migrating-8.7.html
76+
experimental: false
77+
- php: '8.1'
78+
symfony: '~5.0'
79+
elasticsearch: '8.8.0' # there are no bc in minor version https://www.elastic.co/guide/en/elasticsearch/reference/current/migrating-8.8.html
80+
experimental: false
81+
- php: '8.1'
82+
symfony: '~6.0'
83+
elasticsearch: '8.10.2' # newest version
84+
experimental: false
85+
fail-fast: false
86+
steps:
87+
- name: Checkout
88+
uses: actions/checkout@v4
89+
90+
- name: Setup PHP
91+
uses: shivammathur/setup-php@v2
92+
with:
93+
php-version: '${{ matrix.php }}'
94+
coverage: 'pcov'
95+
tools: 'composer:v2'
96+
extensions: 'curl, json, mbstring, openssl'
97+
ini-values: 'memory_limit=256M'
98+
99+
- name: 'Fix symfony/framework-bundle version'
100+
run: composer require --no-update symfony/framework-bundle:${{ matrix.symfony }}
101+
102+
- name: 'Install dependencies with Composer'
103+
uses: 'ramsey/composer-install@v2'
104+
with:
105+
dependency-versions: '${{ matrix.dependencies }}'
106+
composer-options: '--prefer-dist'
107+
108+
- name: 'Dump composer autoloader'
109+
run: composer dump-autoload --classmap-authoritative --no-ansi --no-interaction --no-scripts
110+
111+
- name: 'Setup Elasticsearch'
112+
env:
113+
ELASTICSEARCH_VERSION: ${{ matrix.elasticsearch }}
114+
run: docker compose up --detach --wait ; curl -XGET 'http://localhost:'"$ELASTICSEARCH_PORT"
115+
116+
- name: 'Run phpunit tests'
117+
run: |
118+
vendor/bin/simple-phpunit --coverage-clover=tests/App/build/clover.xml 2>/dev/null
119+
120+
- name: Upload coverage results to Coveralls
121+
env:
122+
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_TOKEN }}
123+
run: |
124+
vendor/bin/php-coveralls --coverage_clover=tests/App/build/clover.xml --json_path=tests/App/build/coveralls.json -v

.php-cs-fixer.dist.php

+8-24
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,15 @@
88
return (new PhpCsFixer\Config())
99
->setFinder($finder)
1010
->setRules([
11-
'@PHP73Migration' => true,
12-
'@PHPUnit75Migration:risky' => true,
13-
'@PSR2' => true,
1411
'@Symfony' => true,
15-
'@Symfony:risky' => true,
16-
'modernize_strpos' => true,
17-
'is_null' => true,
18-
'method_argument_space' => ['on_multiline' => 'ensure_fully_multiline'],
19-
'native_constant_invocation' => true,
20-
'native_function_invocation' => [
21-
'include' => ['@all'],
22-
],
23-
'no_alias_functions' => true,
24-
'no_useless_else' => true,
25-
'nullable_type_declaration_for_default_null_value' => true,
26-
'ordered_imports' => true,
27-
'php_unit_dedicate_assert' => ['target' => 'newest'],
28-
'static_lambda' => true,
29-
'ternary_to_null_coalescing' => true,
30-
'visibility_required' => ['elements' => ['property', 'method', 'const']],
31-
'void_return' => false,
32-
'protected_to_private' => false,
33-
'phpdoc_summary' => false,
12+
13+
// Exclude "phpdoc_summary" rule: "PHPDoc summary should end in either a full stop, exclamation mark, or question mark"
14+
'phpdoc_summary' => false,
3415
'phpdoc_annotation_without_dot' => false,
35-
'phpdoc_to_comment' => ['ignored_tags' => ['@var']]
16+
'no_superfluous_phpdoc_tags' => ['allow_mixed' => true, 'remove_inheritdoc' => false],
17+
// Indent '=>' operator
18+
'binary_operator_spaces' => ['operators' => ['=>' => 'align_single_space_minimal']],
19+
// PSR12 imports order
20+
'ordered_imports' => ['imports_order' => ['class', 'function', 'const']],
3621
])
3722
;
38-

.travis.yml

-31
This file was deleted.

README.md

+11-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

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

88
## Key points
99

@@ -31,3 +31,12 @@ Installation instructions and documentation of the bundle can be found [here](do
3131
## License
3232

3333
This bundle is licensed under the MIT license. Please, see the complete license in the [LICENSE](LICENSE) file.
34+
35+
## Running tests
36+
37+
```
38+
composer install
39+
docker compose up --detach --wait
40+
vendor/bin/simple-phpunit
41+
docker compose down --remove-orphans
42+
```

composer.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,12 @@
3232
"symfony/stopwatch": "^4.4 || ^5.0",
3333
"symfony/phpunit-bridge": "^4.4 || ^5.0",
3434
"symfony/browser-kit": "^4.4 || ^5.0",
35+
"symfony/dotenv": "^4.4 || ^5.0",
3536
"doctrine/orm": "^2.6.3",
3637

3738
"monolog/monolog": "^1.0|^2.0|^3.0",
3839
"knplabs/knp-paginator-bundle": "^4.0 || ^5.0",
39-
"squizlabs/php_codesniffer": "^3.0",
40+
"friendsofphp/php-cs-fixer": "^3.34",
4041
"php-coveralls/php-coveralls": "^2.1",
4142
"escapestudios/symfony2-coding-standard": "^3.0",
4243
"jchook/phpunit-assert-throws": "^1.0",
@@ -50,8 +51,7 @@
5051
"autoload": {
5152
"psr-4": {
5253
"Sineflow\\ElasticsearchBundle\\": "src/"
53-
},
54-
"exclude-from-classmap": ["/tests/"]
54+
}
5555
},
5656
"autoload-dev": {
5757
"psr-4": {

docker-compose.yml

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
services:
2+
elasticsearch:
3+
image: "docker.elastic.co/elasticsearch/elasticsearch:${ELASTICSEARCH_VERSION:-7.17.13}"
4+
container_name: sfes_elasticsearch
5+
environment:
6+
- discovery.type=single-node
7+
- bootstrap.memory_lock=true
8+
- "ES_JAVA_OPTS=-Xms${ELASTICSEARCH_JAVA_MEM:-2048m} -Xmx${ELASTICSEARCH_JAVA_MEM:-2048m}"
9+
- cluster.name=sfes
10+
- node.name=sfes1
11+
- xpack.security.enabled=false
12+
- 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)
13+
ulimits:
14+
memlock:
15+
soft: -1
16+
hard: -1
17+
volumes:
18+
- elasticsearch-data:/usr/share/elasticsearch/data
19+
ports:
20+
- "${ELASTICSEARCH_PORT:-9200}:9200"
21+
networks:
22+
- elastic
23+
healthcheck:
24+
test: curl -s http://sfes_elasticsearch:$${ELASTICSEARCH_PORT:-9200} > /dev/null || exit 1
25+
interval: 1s
26+
timeout: 5s
27+
retries: 120
28+
29+
volumes:
30+
elasticsearch-data:
31+
32+
networks:
33+
elastic:
34+
driver: bridge

phpunit.xml.dist

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
</testsuites>
2626

2727
<php>
28+
<server name="APP_ENV" value="test" force="true" />
2829
<server name="KERNEL_CLASS" value="Sineflow\ElasticsearchBundle\Tests\App\AppKernel" />
2930
<server name="SHELL_VERBOSITY" value="-1" />
3031
<env name="SYMFONY_PHPUNIT_VERSION" value="9" />

src/Annotation/DocObject.php

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* Annotation to mark a class as an object during the parsing process.
77
*
88
* @Annotation
9+
*
910
* @Target("CLASS")
1011
*/
1112
final class DocObject

src/Annotation/Id.php

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* Annotation used for the meta _id field
77
*
88
* @Annotation
9+
*
910
* @Target("PROPERTY")
1011
*/
1112
final class Id

src/Annotation/Score.php

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* Annotation used for the meta _score field, returned when searching
77
*
88
* @Annotation
9+
*
910
* @Target("PROPERTY")
1011
*/
1112
final class Score

src/Document/Provider/ElasticsearchProvider.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ public function getDocuments()
6666
['sort' => ['_doc']],
6767
Finder::RESULTS_RAW | Finder::ADAPTER_SCROLL,
6868
[
69-
'index' => $this->sourceIndexManager->getLiveIndex(),
70-
'size' => $this->chunkSize,
69+
'index' => $this->sourceIndexManager->getLiveIndex(),
70+
'size' => $this->chunkSize,
7171
'scroll' => $this->scrollTime,
7272
]
7373
);
@@ -90,7 +90,7 @@ public function getDocument($id): array
9090
{
9191
$params = [
9292
'index' => $this->sourceIndexManager->getLiveIndex(),
93-
'id' => $id,
93+
'id' => $id,
9494
];
9595
$doc = $this->sourceIndexManager->getConnection()->getClient()->get($params);
9696
$result = $doc['_source'];

src/Document/Repository/Repository.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function getById(string $id, int $resultType = Finder::RESULTS_OBJECT)
6565
*
6666
* @return mixed
6767
*/
68-
public function find(array $searchBody, int $resultsType = Finder::RESULTS_OBJECT, array $additionalRequestParams = [], ?int &$totalHits = null)
68+
public function find(array $searchBody, int $resultsType = Finder::RESULTS_OBJECT, array $additionalRequestParams = [], int &$totalHits = null)
6969
{
7070
return $this->finder->find([$this->documentClass], $searchBody, $resultsType, $additionalRequestParams, $totalHits);
7171
}

src/Exception/IndexOrAliasNotFoundException.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
namespace Sineflow\ElasticsearchBundle\Exception;
44

5-
use Throwable;
6-
75
/**
86
* Class IndexOrAliasNotFoundException
97
*/
@@ -19,7 +17,7 @@ class IndexOrAliasNotFoundException extends Exception
1917
*
2018
* @param int $code
2119
*/
22-
public function __construct(string $indexOrAlias, bool $isAlias = false, $code = 0, ?Throwable $previous = null)
20+
public function __construct(string $indexOrAlias, bool $isAlias = false, $code = 0, \Throwable $previous = null)
2321
{
2422
$this->indexOrAlias = $indexOrAlias;
2523

src/Exception/IndexRebuildingException.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class IndexRebuildingException extends Exception
1616
* @param array $indicesInProgress The physical indices, which are in the process of being built
1717
* @param int $code
1818
*/
19-
public function __construct(array $indicesInProgress, $code = 0, ?Exception $previous = null)
19+
public function __construct(array $indicesInProgress, $code = 0, Exception $previous = null)
2020
{
2121
parent::__construct(\sprintf('Index is currently being rebuilt as "%s"', \implode(', ', $indicesInProgress)), $code, $previous);
2222

src/Finder/Adapter/ScrollAdapter.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ class ScrollAdapter
3636
private $resultsType;
3737

3838
/**
39-
* @var int
39+
* @var int|null
4040
*/
41-
private $totalHits = null;
41+
private $totalHits;
4242

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

0 commit comments

Comments
 (0)