Skip to content

Update #372

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

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
3e439c0
Fluent api on ParametersTrait (#304)
ilvalerione Feb 5, 2020
97136d3
change deprecated inline to the source
saimaz Feb 5, 2020
057642e
update to support the symfony serializer 5.0
saimaz Feb 19, 2020
1f9ce98
Merge remote-tracking branch 'remotes/origin/6.x' into 7.x
saimaz Feb 19, 2020
7aa5d65
fix phpunit to 7.0 major version
saimaz Feb 19, 2020
08c74ce
upgrade elasticsearch version in the travis to the 7.5.2
saimaz Feb 19, 2020
bb8d722
php 7.0 is not supported anymore with elasticsearch/elasticsearch
saimaz Feb 20, 2020
10b6193
prefer stable instead of dist in the travis composer install
saimaz Feb 20, 2020
bc7ee2f
rollback serializer to support v3 and v4
saimaz Feb 20, 2020
58bd293
make sure stable dependencies versions will be installed
saimaz Feb 20, 2020
1bfcd23
add elasticsearch/elasticsearch to the composer file
saimaz Feb 20, 2020
b7653ed
support serializer v5 and upgrade php minimum requirement to the 7.2
saimaz Feb 20, 2020
3b4424a
bump dev version up
saimaz Feb 20, 2020
8c75b81
Rename MatrixStatsAggregation.php to MaxAggregation.php
chrysanthos Mar 14, 2020
0db9dbb
Cleanup composer.json
jdreesen Oct 29, 2020
de0f077
Add Github Actions
shyim Feb 22, 2021
03f2af9
fix wrong namespace according to dev psr-4 for unit tests
84m Feb 23, 2021
2b1ec11
bump phpunit to ^8.0
84m Feb 23, 2021
f37eb40
remove phpunit 9.0 deprecations
84m Feb 23, 2021
41b9b52
bump phpunit to ^9.0 and php to ^7.3
84m Feb 23, 2021
b45d664
remove deprecated annotations of PHPUnit_Framework_MockObject_MockObject
84m Feb 23, 2021
95e06d5
reactivate unit test
84m Feb 23, 2021
c0789c3
Fixed for PHP 8 Compatibility
lernhart Feb 16, 2021
8a8ecf0
Merge branch '7.2'
chellem May 31, 2024
a4edd08
use serializer 8
chellem May 31, 2024
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
26 changes: 26 additions & 0 deletions .github/wait_for_es.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

use Elasticsearch\ClientBuilder;
use Elasticsearch\Common\Exceptions\NoNodesAvailableException;

require dirname(__DIR__) . '/vendor/autoload.php';

$retries = 0;
$maxRetries = 10;

while (true) {
try {
$client = ClientBuilder::create()->build();
$client->ping();
echo 'Is up and running' . PHP_EOL;
exit(0);
} catch (NoNodesAvailableException $e) {
if ($retries === $maxRetries) {
echo 'Cannot reach elasticsearch server' . PHP_EOL;
exit(1);
}

sleep(5);
$retries++;
}
}
48 changes: 48 additions & 0 deletions .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: PHPUnit

on:
push:
pull_request:

jobs:
build:
runs-on: ubuntu-latest
services:
elasticsearch:
image: elastic/elasticsearch:7.4.0
ports:
- 9200:9200
env:
discovery.type: single-node
strategy:
matrix:
php: ['7.4', '8.0']
steps:
- uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
tools: composer:v2
coverage: xdebug

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

- name: Install dependencies
run: composer install --prefer-dist --no-progress

- name: Wait for Elasticsearch
run: php ./.github/wait_for_es.php

- name: Run PHPUnit
run: vendor/bin/phpunit --coverage-clover=coverage.xml

- name: Run PHPCS
run: vendor/bin/phpcs -p --standard=PSR2 --ignore=vendor/ ./

- name: Upload Codecov
uses: codecov/codecov-action@v1
with:
file: ./coverage.xml
26 changes: 0 additions & 26 deletions .travis.yml

This file was deleted.

15 changes: 5 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,14 @@
}
],
"require": {
"php": "^7.0",
"symfony/serializer": "^3.0|^4.0",
"paragonie/random_compat": "*"
"php": "^7.4 || ^8.0",
"symfony/serializer": "^7.0",
"elasticsearch/elasticsearch": "^7.0"
},
"require-dev": {
"elasticsearch/elasticsearch": "^7.0",
"phpunit/phpunit": "~6.0",
"phpunit/phpunit": "^9.0",
"squizlabs/php_codesniffer": "^3.0"
},
"suggest": {
"elasticsearch/elasticsearch": "This library is for elasticsearch/elasticsearch client to enhance it with DSL functionality."
},
"autoload": {
"psr-4": {
"ONGR\\ElasticsearchDSL\\": "src/"
Expand All @@ -33,10 +29,9 @@
"ONGR\\ElasticsearchDSL\\Tests\\": "tests/"
}
},
"minimum-stability": "dev",
"extra": {
"branch-alias": {
"dev-master": "7.0-dev"
"dev-master": "7.2-dev"
}
}
}
25 changes: 13 additions & 12 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
Expand All @@ -8,7 +10,6 @@
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="vendor/autoload.php">

<testsuites>
Expand All @@ -23,16 +24,16 @@
</testsuite>
</testsuites>

<filter>
<whitelist>
<coverage>
<include>
<directory>./</directory>
<exclude>
<directory>./tests</directory>
<directory>./vendor</directory>
</exclude>
</whitelist>
</filter>
<logging>
<log type="coverage-text" target="php://stdout" showOnlySummary="true"/>
</logging>
</include>
<exclude>
<directory>./tests</directory>
<directory>./vendor</directory>
</exclude>
<report>
<text outputFile="php://stdout" showOnlySummary="true"/>
</report>
</coverage>
</phpunit>
6 changes: 6 additions & 0 deletions src/ParametersTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,15 @@ public function hasParameter($name)
* Removes parameter.
*
* @param string $name
* @return $this
*/
public function removeParameter($name)
{
if ($this->hasParameter($name)) {
unset($this->parameters[$name]);
}

return $this;
}

/**
Expand Down Expand Up @@ -70,10 +73,13 @@ public function getParameters()
/**
* @param string $name
* @param array|string|int|float|bool|\stdClass $value
* @return $this
*/
public function addParameter($name, $value)
{
$this->parameters[$name] = $value;

return $this;
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/Query/Compound/FunctionScoreQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,15 +181,15 @@ public function addRandomFunction($seed = null, BuilderInterface $query = null)
/**
* Adds script score function.
*
* @param string $inline
* @param string $source
* @param array $params
* @param array $options
* @param BuilderInterface $query
*
* @return $this
*/
public function addScriptScoreFunction(
$inline,
$source,
array $params = [],
array $options = [],
BuilderInterface $query = null
Expand All @@ -201,7 +201,7 @@ public function addScriptScoreFunction(
array_merge(
[
'lang' => 'painless',
'inline' => $inline,
'source' => $source,
'params' => $params
],
$options
Expand Down
2 changes: 1 addition & 1 deletion src/SearchEndpoint/AggregationsEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class AggregationsEndpoint extends AbstractSearchEndpoint
/**
* {@inheritdoc}
*/
public function normalize(NormalizerInterface $normalizer, $format = null, array $context = [])
public function normalize(NormalizerInterface $normalizer, string $format = null, array $context = [])
{
$output = [];
if (count($this->getAll()) > 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/SearchEndpoint/HighlightEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class HighlightEndpoint extends AbstractSearchEndpoint
/**
* {@inheritdoc}
*/
public function normalize(NormalizerInterface $normalizer, $format = null, array $context = [])
public function normalize(NormalizerInterface $normalizer, string $format = null, array $context = [])
{
if ($this->highlight) {
return $this->highlight->toArray();
Expand Down
2 changes: 1 addition & 1 deletion src/SearchEndpoint/InnerHitsEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class InnerHitsEndpoint extends AbstractSearchEndpoint
/**
* {@inheritdoc}
*/
public function normalize(NormalizerInterface $normalizer, $format = null, array $context = [])
public function normalize(NormalizerInterface $normalizer, string $format = null, array $context = [])
{
$output = [];
if (count($this->getAll()) > 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/SearchEndpoint/PostFilterEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class PostFilterEndpoint extends QueryEndpoint
/**
* {@inheritdoc}
*/
public function normalize(NormalizerInterface $normalizer, $format = null, array $context = [])
public function normalize(NormalizerInterface $normalizer, string $format = null, array $context = [])
{
if (!$this->getBool()) {
return null;
Expand Down
2 changes: 1 addition & 1 deletion src/SearchEndpoint/QueryEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class QueryEndpoint extends AbstractSearchEndpoint implements OrderedNormalizerI
/**
* {@inheritdoc}
*/
public function normalize(NormalizerInterface $normalizer, $format = null, array $context = [])
public function normalize(NormalizerInterface $normalizer, string $format = null, array $context = [])
{
if (!$this->filtersSet && $this->hasReference('filter_query')) {
/** @var BuilderInterface $filter */
Expand Down
2 changes: 1 addition & 1 deletion src/SearchEndpoint/SortEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class SortEndpoint extends AbstractSearchEndpoint
/**
* {@inheritdoc}
*/
public function normalize(NormalizerInterface $normalizer, $format = null, array $context = [])
public function normalize(NormalizerInterface $normalizer, string $format = null, array $context = [])
{
$output = [];

Expand Down
2 changes: 1 addition & 1 deletion src/SearchEndpoint/SuggestEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class SuggestEndpoint extends AbstractSearchEndpoint
/**
* {@inheritdoc}
*/
public function normalize(NormalizerInterface $normalizer, $format = null, array $context = [])
public function normalize(NormalizerInterface $normalizer, string $format = null, array $context = [])
{
$output = [];
if (count($this->getAll()) > 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/Serializer/Normalizer/CustomReferencedNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class CustomReferencedNormalizer extends CustomNormalizer
/**
* {@inheritdoc}
*/
public function normalize($object, $format = null, array $context = [])
public function normalize($object, string $format = null, array $context = [])
{
$object->setReferences($this->references);
$data = parent::normalize($object, $format, $context);
Expand Down
2 changes: 1 addition & 1 deletion src/Serializer/OrderedSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ private function order(array $data)
uasort(
$filteredData,
function (OrderedNormalizerInterface $a, OrderedNormalizerInterface $b) {
return $a->getOrder() > $b->getOrder();
return $a->getOrder() <=> $b->getOrder();
}
);

Expand Down
4 changes: 2 additions & 2 deletions tests/Functional/AbstractElasticsearchTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ abstract class AbstractElasticsearchTestCase extends TestCase
/**
* {@inheritdoc}
*/
protected function setUp()
protected function setUp(): void
{
parent::setUp();

Expand Down Expand Up @@ -109,7 +109,7 @@ protected function getDataArray()
/**
* {@inheritdoc}
*/
protected function tearDown()
protected function tearDown(): void
{
parent::tearDown();
$this->deleteIndex();
Expand Down
31 changes: 14 additions & 17 deletions tests/Unit/Aggregation/Bucketing/AdjacencyMatrixAggregationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,27 @@
* file that was distributed with this source code.
*/

namespace ONGR\ElasticsearchDSL\Tests\Unit\Bucketing\Aggregation;
namespace ONGR\ElasticsearchDSL\Tests\Unit\Aggregation\Bucketing;

use ONGR\ElasticsearchDSL\Aggregation\Bucketing\AdjacencyMatrixAggregation;
use ONGR\ElasticsearchDSL\BuilderInterface;
use ONGR\ElasticsearchDSL\Aggregation\Bucketing\FiltersAggregation;

/**
* Unit test for adjacency matrix aggregation.
*/
class AdjacencyMatrixAggregationTest extends \PHPUnit\Framework\TestCase
{
// /**
// * Test if exception is thrown when not anonymous filter is without name.
// *
// * @expectedException \LogicException
// * @expectedExceptionMessage In not anonymous filters filter name must be set.
// */
// public function testIfExceptionIsThrown()
// {
// $mock = $this->getMockBuilder('ONGR\ElasticsearchDSL\BuilderInterface')->getMock();
// $aggregation = new FiltersAggregation('test_agg');
// $aggregation->addFilter($mock);
// }
/**
* Test if exception is thrown when not anonymous filter is without name.
*/
public function testIfExceptionIsThrown()
{
$this->expectException(\LogicException::class);
$this->expectExceptionMessage("In not anonymous filters filter name must be set.");
$mock = $this->getMockBuilder('ONGR\ElasticsearchDSL\BuilderInterface')->getMock();
$aggregation = new FiltersAggregation('test_agg');
$aggregation->addFilter($mock);
}

/**
* Test GetArray method.
Expand Down Expand Up @@ -61,7 +60,7 @@ public function testToArray()
{
$aggregation = new AdjacencyMatrixAggregation('test_agg');
$filter = $this->getMockBuilder('ONGR\ElasticsearchDSL\BuilderInterface')
->setMethods(['toArray', 'getType'])
->onlyMethods(['toArray', 'getType'])
->getMockForAbstractClass();
$filter->expects($this->any())
->method('toArray')
Expand Down Expand Up @@ -95,9 +94,7 @@ public function testToArray()
*/
public function testFilterConstructor()
{
/** @var BuilderInterface|\PHPUnit_Framework_MockObject_MockObject $builderInterface1 */
$builderInterface1 = $this->getMockForAbstractClass('ONGR\ElasticsearchDSL\BuilderInterface');
/** @var BuilderInterface|\PHPUnit_Framework_MockObject_MockObject $builderInterface2 */
$builderInterface2 = $this->getMockForAbstractClass('ONGR\ElasticsearchDSL\BuilderInterface');

$aggregation = new AdjacencyMatrixAggregation(
Expand Down
Loading