Skip to content

Commit

Permalink
tests: add missing coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
gskema committed Oct 25, 2023
1 parent 7522ea8 commit 6984ccb
Show file tree
Hide file tree
Showing 30 changed files with 355 additions and 6 deletions.
5 changes: 4 additions & 1 deletion src/Options.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@

use Attribute;

/**
* @see OptionsTest
*/
#[Attribute(Attribute::TARGET_CLASS)]
class Options
{
public function __construct(
/** @var array<string, mixed> */
public readonly array $options,
public readonly array $values,
) {
}
}
5 changes: 4 additions & 1 deletion src/Parameters.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@

use Attribute;

/**
* @see ParametersTest
*/
#[Attribute(Attribute::TARGET_CLASS)]
class Parameters
{
public function __construct(
/** @var array<string, mixed> */
public readonly array $parameters,
public readonly array $values,
) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
use Gskema\ElasticSearchQueryDSL\Model\Script\InlineScript;
use InvalidArgumentException;

final class AutoIntervalDateHistogramAggregationTest extends AbstractJsonSerializeTestCase
{
Expand Down Expand Up @@ -80,4 +81,34 @@ public static function dataTestJsonSerialize(): iterable

return $dataSets;
}

public function testMethods(): void
{
$obj1 = AutoIntervalDateHistogramAggregation::fromField(
'field1',
10,
['format' => 'yyyy-MM-dd']
)->setAgg('agg1', new GlobalAggregation());

self::assertInstanceOf(AutoIntervalDateHistogramAggregation::class, $obj1);

$obj2 = AutoIntervalDateHistogramAggregation::fromScript(
new InlineScript('script1'),
10,
['format' => 'yyyy-MM-dd'],
)->setAgg('agg1', new GlobalAggregation());

self::assertInstanceOf(AutoIntervalDateHistogramAggregation::class, $obj2);
}

public function testConstructorException(): void
{
$this->expectException(InvalidArgumentException::class);
new class extends AutoIntervalDateHistogramAggregation {
public function __construct()
{
parent::__construct(null, null, 10, []);
}
};
}
}
11 changes: 11 additions & 0 deletions tests/Aggregation/Bucket/CompositeAggregationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,15 @@ public static function dataTestJsonSerialize(): iterable

return $dataSets;
}

public function testMethods(): void
{
$obj = (new CompositeAggregation([
['agg1' => TermsAggregation::fromField('field1')],
['agg2' => TermsAggregation::fromField('field2')]
], ['size' => 10]))
->setAgg('agg1', new GlobalAggregation());

self::assertInstanceOf(CompositeAggregation::class, $obj);
}
}
12 changes: 12 additions & 0 deletions tests/Aggregation/Bucket/DateHistogramAggregationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
use Gskema\ElasticSearchQueryDSL\Model\Script\InlineScript;
use InvalidArgumentException;

final class DateHistogramAggregationTest extends AbstractJsonSerializeTestCase
{
Expand Down Expand Up @@ -66,4 +67,15 @@ public function testMethods(): void
$agg2 = DateHistogramAggregation::fromScript(new InlineScript('source1'), '1day');
self::assertInstanceOf(DateHistogramAggregation::class, $agg2);
}

public function testConstructorException(): void
{
$this->expectException(InvalidArgumentException::class);
new class extends DateHistogramAggregation {
public function __construct()
{
parent::__construct(null, null, 10);
}
};
}
}
29 changes: 29 additions & 0 deletions tests/Aggregation/Bucket/DiversifiedSamplerAggregationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
use Gskema\ElasticSearchQueryDSL\Model\Script\InlineScript;
use InvalidArgumentException;

final class DiversifiedSamplerAggregationTest extends AbstractJsonSerializeTestCase
{
Expand All @@ -28,6 +29,23 @@ public static function dataTestJsonSerialize(): iterable
->setAgg('key1', new GlobalAggregation()),
];

// #0
$dataSets[] = [
// language=JSON
'{
"diversified_sampler" : {
"script": "script1"
},
"aggs": {
"key1": {
"global": {}
}
}
}',
DiversifiedSamplerAggregation::fromScript(new InlineScript('script1'))
->setAgg('key1', new GlobalAggregation()),
];

return $dataSets;
}

Expand All @@ -39,4 +57,15 @@ public function testMethods(): void
$agg2 = DiversifiedSamplerAggregation::fromScript(new InlineScript('source1'));
self::assertInstanceOf(DiversifiedSamplerAggregation::class, $agg2);
}

public function testConstructorException(): void
{
$this->expectException(InvalidArgumentException::class);
new class extends DiversifiedSamplerAggregation {
public function __construct()
{
parent::__construct(null, null);
}
};
}
}
7 changes: 7 additions & 0 deletions tests/Aggregation/Bucket/ParentAggregationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,11 @@ public static function dataTestJsonSerialize(): iterable

return $dataSets;
}

public function testMethods(): void
{
$obj = (new ParentAggregation('type1'))->setAgg('agg1', new GlobalAggregation());

self::assertInstanceOf(ParentAggregation::class, $obj);
}
}
12 changes: 12 additions & 0 deletions tests/Aggregation/Bucket/RangeAggregationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
use Gskema\ElasticSearchQueryDSL\Model\Script\InlineScript;
use InvalidArgumentException;

final class RangeAggregationTest extends AbstractJsonSerializeTestCase
{
Expand Down Expand Up @@ -75,4 +76,15 @@ public function testMethods(): void
]);
self::assertInstanceOf(RangeAggregation::class, $agg);
}

public function testConstructorException(): void
{
$this->expectException(InvalidArgumentException::class);
new class extends RangeAggregation {
public function __construct()
{
parent::__construct(null, null, []);
}
};
}
}
14 changes: 14 additions & 0 deletions tests/Aggregation/Bucket/SignificantTextAggregationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Gskema\ElasticSearchQueryDSL\Aggregation\Bucket;

use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
use Gskema\ElasticSearchQueryDSL\Matcher\MatchNoneMatcher;

final class SignificantTextAggregationTest extends AbstractJsonSerializeTestCase
{
Expand Down Expand Up @@ -30,4 +31,17 @@ public static function dataTestJsonSerialize(): iterable

return $dataSets;
}

public function testMethods(): void
{
$obj = (new SignificantTextAggregation('field1', [
'size' => 3,
'background_filter' => new MatchNoneMatcher()
]))->setAgg('agg1', new GlobalAggregation());

$string = json_encode($obj->jsonSerialize());
self::assertIsString($string);

self::assertInstanceOf(SignificantTextAggregation::class, $obj);
}
}
12 changes: 12 additions & 0 deletions tests/Aggregation/Bucket/TermsAggregationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
use Gskema\ElasticSearchQueryDSL\Model\Script\InlineScript;
use InvalidArgumentException;

final class TermsAggregationTest extends AbstractJsonSerializeTestCase
{
Expand Down Expand Up @@ -57,4 +58,15 @@ public function testMethods(): void
$agg2 = TermsAggregation::fromScript(new InlineScript('source1'), ['order' => ['_count' => 'asc']]);
self::assertInstanceOf(TermsAggregation::class, $agg2);
}

public function testConstructorException(): void
{
$this->expectException(InvalidArgumentException::class);
new class extends TermsAggregation {
public function __construct()
{
parent::__construct(null, null);
}
};
}
}
12 changes: 12 additions & 0 deletions tests/Aggregation/Metric/AvgAggregationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
use Gskema\ElasticSearchQueryDSL\Model\Script\InlineScript;
use InvalidArgumentException;

final class AvgAggregationTest extends AbstractJsonSerializeTestCase
{
Expand Down Expand Up @@ -57,4 +58,15 @@ public function testMethods(): void
$agg2 = AvgAggregation::fromScript(new InlineScript('source1'));
self::assertInstanceOf(AvgAggregation::class, $agg2);
}

public function testConstructorException(): void
{
$this->expectException(InvalidArgumentException::class);
new class extends AvgAggregation {
public function __construct()
{
parent::__construct(null, null);
}
};
}
}
12 changes: 12 additions & 0 deletions tests/Aggregation/Metric/CardinalityAggregationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
use Gskema\ElasticSearchQueryDSL\Model\Script\InlineScript;
use InvalidArgumentException;

final class CardinalityAggregationTest extends AbstractJsonSerializeTestCase
{
Expand Down Expand Up @@ -44,4 +45,15 @@ public function testMethods(): void
$agg2 = CardinalityAggregation::fromScript(new InlineScript('source1'));
self::assertInstanceOf(CardinalityAggregation::class, $agg2);
}

public function testConstructorException(): void
{
$this->expectException(InvalidArgumentException::class);
new class extends CardinalityAggregation {
public function __construct()
{
parent::__construct(null, null);
}
};
}
}
12 changes: 12 additions & 0 deletions tests/Aggregation/Metric/ExtendedStatsAggregationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Gskema\ElasticSearchQueryDSL\Aggregation\Metric;

use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
use InvalidArgumentException;

final class ExtendedStatsAggregationTest extends AbstractJsonSerializeTestCase
{
Expand All @@ -23,4 +24,15 @@ public static function dataTestJsonSerialize(): iterable

return $dataSets;
}

public function testConstructorException(): void
{
$this->expectException(InvalidArgumentException::class);
new class extends ExtendedStatsAggregation {
public function __construct()
{
parent::__construct(null, null);
}
};
}
}
12 changes: 12 additions & 0 deletions tests/Aggregation/Metric/MaxAggregationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Gskema\ElasticSearchQueryDSL\Aggregation\Metric;

use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
use InvalidArgumentException;

final class MaxAggregationTest extends AbstractJsonSerializeTestCase
{
Expand All @@ -23,4 +24,15 @@ public static function dataTestJsonSerialize(): iterable

return $dataSets;
}

public function testConstructorException(): void
{
$this->expectException(InvalidArgumentException::class);
new class extends MaxAggregation {
public function __construct()
{
parent::__construct(null, null);
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,10 @@ public static function dataTestJsonSerialize(): iterable

return $dataSets;
}

public function testMethods(): void
{
$obj = new MedianAbsoluteDeviationAggregation(new InlineScript('script1'), ['missing' => 1]);
self::assertInstanceOf(MedianAbsoluteDeviationAggregation::class, $obj);
}
}
12 changes: 12 additions & 0 deletions tests/Aggregation/Metric/MinAggregationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Gskema\ElasticSearchQueryDSL\Aggregation\Metric;

use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
use InvalidArgumentException;

final class MinAggregationTest extends AbstractJsonSerializeTestCase
{
Expand All @@ -23,4 +24,15 @@ public static function dataTestJsonSerialize(): iterable

return $dataSets;
}

public function testConstructorException(): void
{
$this->expectException(InvalidArgumentException::class);
new class extends MinAggregation {
public function __construct()
{
parent::__construct(null, null);
}
};
}
}
Loading

0 comments on commit 6984ccb

Please sign in to comment.