Skip to content
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
116 changes: 112 additions & 4 deletions src/Elasticsearch/Filter/AbstractFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,14 @@
use ApiPlatform\Metadata\Property\Factory\PropertyMetadataFactoryInterface;
use ApiPlatform\Metadata\Property\Factory\PropertyNameCollectionFactoryInterface;
use ApiPlatform\Metadata\ResourceClassResolverInterface;
use Symfony\Component\PropertyInfo\Type;
use Symfony\Component\PropertyInfo\PropertyInfoExtractor;
use Symfony\Component\PropertyInfo\Type as LegacyType;
use Symfony\Component\Serializer\NameConverter\NameConverterInterface;
use Symfony\Component\TypeInfo\Type;
use Symfony\Component\TypeInfo\Type\CollectionType;
use Symfony\Component\TypeInfo\Type\CompositeTypeInterface;
use Symfony\Component\TypeInfo\Type\ObjectType;
use Symfony\Component\TypeInfo\Type\WrappingTypeInterface;

/**
* Abstract class with helpers for easing the implementation of a filter.
Expand All @@ -31,7 +37,9 @@
*/
abstract class AbstractFilter implements FilterInterface
{
use FieldDatatypeTrait { getNestedFieldPath as protected; }
use FieldDatatypeTrait {
getNestedFieldPath as protected;
}

public function __construct(protected PropertyNameCollectionFactoryInterface $propertyNameCollectionFactory, PropertyMetadataFactoryInterface $propertyMetadataFactory, ResourceClassResolverInterface $resourceClassResolver, protected ?NameConverterInterface $nameConverter = null, protected ?array $properties = null)
{
Expand Down Expand Up @@ -70,8 +78,108 @@
* - is the decomposed given property an association?
* - the resource class of the decomposed given property
* - the property name of the decomposed given property
*
* @return array{0: ?Type, 1: ?bool, 2: ?class-string, 3: ?string}
*/
protected function getMetadata(string $resourceClass, string $property): array
{
if (!method_exists(PropertyInfoExtractor::class, 'getType')) {
return $this->getLegacyMetadata($resourceClass, $property);

Check warning on line 87 in src/Elasticsearch/Filter/AbstractFilter.php

View check run for this annotation

Codecov / codecov/patch

src/Elasticsearch/Filter/AbstractFilter.php#L86-L87

Added lines #L86 - L87 were not covered by tests
}

$noop = [null, null, null, null];

Check warning on line 90 in src/Elasticsearch/Filter/AbstractFilter.php

View check run for this annotation

Codecov / codecov/patch

src/Elasticsearch/Filter/AbstractFilter.php#L90

Added line #L90 was not covered by tests

if (!$this->hasProperty($resourceClass, $property)) {
return $noop;

Check warning on line 93 in src/Elasticsearch/Filter/AbstractFilter.php

View check run for this annotation

Codecov / codecov/patch

src/Elasticsearch/Filter/AbstractFilter.php#L92-L93

Added lines #L92 - L93 were not covered by tests
}

$properties = explode('.', $property);
$totalProperties = \count($properties);
$currentResourceClass = $resourceClass;
$hasAssociation = false;
$currentProperty = null;
$type = null;

Check warning on line 101 in src/Elasticsearch/Filter/AbstractFilter.php

View check run for this annotation

Codecov / codecov/patch

src/Elasticsearch/Filter/AbstractFilter.php#L96-L101

Added lines #L96 - L101 were not covered by tests

foreach ($properties as $index => $currentProperty) {

Check warning on line 103 in src/Elasticsearch/Filter/AbstractFilter.php

View check run for this annotation

Codecov / codecov/patch

src/Elasticsearch/Filter/AbstractFilter.php#L103

Added line #L103 was not covered by tests
try {
$propertyMetadata = $this->propertyMetadataFactory->create($currentResourceClass, $currentProperty);
} catch (PropertyNotFoundException) {
return $noop;

Check warning on line 107 in src/Elasticsearch/Filter/AbstractFilter.php

View check run for this annotation

Codecov / codecov/patch

src/Elasticsearch/Filter/AbstractFilter.php#L105-L107

Added lines #L105 - L107 were not covered by tests
}

// check each type before deciding if it's noop or not
// e.g: maybe the first type is noop, but the second is valid
$isNoop = false;

Check warning on line 112 in src/Elasticsearch/Filter/AbstractFilter.php

View check run for this annotation

Codecov / codecov/patch

src/Elasticsearch/Filter/AbstractFilter.php#L112

Added line #L112 was not covered by tests

++$index;

Check warning on line 114 in src/Elasticsearch/Filter/AbstractFilter.php

View check run for this annotation

Codecov / codecov/patch

src/Elasticsearch/Filter/AbstractFilter.php#L114

Added line #L114 was not covered by tests

$type = $propertyMetadata->getNativeType();

Check warning on line 116 in src/Elasticsearch/Filter/AbstractFilter.php

View check run for this annotation

Codecov / codecov/patch

src/Elasticsearch/Filter/AbstractFilter.php#L116

Added line #L116 was not covered by tests

if (null === $type) {
return $noop;

Check warning on line 119 in src/Elasticsearch/Filter/AbstractFilter.php

View check run for this annotation

Codecov / codecov/patch

src/Elasticsearch/Filter/AbstractFilter.php#L118-L119

Added lines #L118 - L119 were not covered by tests
}

foreach ($type instanceof CompositeTypeInterface ? $type->getTypes() : [$type] as $t) {
$builtinType = $t;

Check warning on line 123 in src/Elasticsearch/Filter/AbstractFilter.php

View check run for this annotation

Codecov / codecov/patch

src/Elasticsearch/Filter/AbstractFilter.php#L122-L123

Added lines #L122 - L123 were not covered by tests

while ($builtinType instanceof WrappingTypeInterface) {
$builtinType = $builtinType->getWrappedType();

Check warning on line 126 in src/Elasticsearch/Filter/AbstractFilter.php

View check run for this annotation

Codecov / codecov/patch

src/Elasticsearch/Filter/AbstractFilter.php#L125-L126

Added lines #L125 - L126 were not covered by tests
}

if (!$builtinType instanceof ObjectType && !$t instanceof CollectionType) {
if ($totalProperties === $index) {
break 2;

Check warning on line 131 in src/Elasticsearch/Filter/AbstractFilter.php

View check run for this annotation

Codecov / codecov/patch

src/Elasticsearch/Filter/AbstractFilter.php#L129-L131

Added lines #L129 - L131 were not covered by tests
}

$isNoop = true;

Check warning on line 134 in src/Elasticsearch/Filter/AbstractFilter.php

View check run for this annotation

Codecov / codecov/patch

src/Elasticsearch/Filter/AbstractFilter.php#L134

Added line #L134 was not covered by tests

continue;

Check warning on line 136 in src/Elasticsearch/Filter/AbstractFilter.php

View check run for this annotation

Codecov / codecov/patch

src/Elasticsearch/Filter/AbstractFilter.php#L136

Added line #L136 was not covered by tests
}

if ($t instanceof CollectionType) {
$t = $t->getCollectionValueType();
$builtinType = $t;

Check warning on line 141 in src/Elasticsearch/Filter/AbstractFilter.php

View check run for this annotation

Codecov / codecov/patch

src/Elasticsearch/Filter/AbstractFilter.php#L139-L141

Added lines #L139 - L141 were not covered by tests

while ($builtinType instanceof WrappingTypeInterface) {
$builtinType = $builtinType->getWrappedType();

Check warning on line 144 in src/Elasticsearch/Filter/AbstractFilter.php

View check run for this annotation

Codecov / codecov/patch

src/Elasticsearch/Filter/AbstractFilter.php#L143-L144

Added lines #L143 - L144 were not covered by tests
}

if (!$builtinType instanceof ObjectType) {
if ($totalProperties === $index) {
break 2;

Check warning on line 149 in src/Elasticsearch/Filter/AbstractFilter.php

View check run for this annotation

Codecov / codecov/patch

src/Elasticsearch/Filter/AbstractFilter.php#L147-L149

Added lines #L147 - L149 were not covered by tests
}

$isNoop = true;

Check warning on line 152 in src/Elasticsearch/Filter/AbstractFilter.php

View check run for this annotation

Codecov / codecov/patch

src/Elasticsearch/Filter/AbstractFilter.php#L152

Added line #L152 was not covered by tests

continue;

Check warning on line 154 in src/Elasticsearch/Filter/AbstractFilter.php

View check run for this annotation

Codecov / codecov/patch

src/Elasticsearch/Filter/AbstractFilter.php#L154

Added line #L154 was not covered by tests
}
}

$className = $builtinType->getClassName();

Check warning on line 158 in src/Elasticsearch/Filter/AbstractFilter.php

View check run for this annotation

Codecov / codecov/patch

src/Elasticsearch/Filter/AbstractFilter.php#L158

Added line #L158 was not covered by tests

if ($isResourceClass = $this->resourceClassResolver->isResourceClass($className)) {
$currentResourceClass = $className;
} elseif ($totalProperties !== $index) {
$isNoop = true;

Check warning on line 163 in src/Elasticsearch/Filter/AbstractFilter.php

View check run for this annotation

Codecov / codecov/patch

src/Elasticsearch/Filter/AbstractFilter.php#L160-L163

Added lines #L160 - L163 were not covered by tests

continue;

Check warning on line 165 in src/Elasticsearch/Filter/AbstractFilter.php

View check run for this annotation

Codecov / codecov/patch

src/Elasticsearch/Filter/AbstractFilter.php#L165

Added line #L165 was not covered by tests
}

$hasAssociation = $totalProperties === $index && $isResourceClass;
$isNoop = false;

Check warning on line 169 in src/Elasticsearch/Filter/AbstractFilter.php

View check run for this annotation

Codecov / codecov/patch

src/Elasticsearch/Filter/AbstractFilter.php#L168-L169

Added lines #L168 - L169 were not covered by tests

break;

Check warning on line 171 in src/Elasticsearch/Filter/AbstractFilter.php

View check run for this annotation

Codecov / codecov/patch

src/Elasticsearch/Filter/AbstractFilter.php#L171

Added line #L171 was not covered by tests
}
}

if ($isNoop) {
return $noop;

Check warning on line 176 in src/Elasticsearch/Filter/AbstractFilter.php

View check run for this annotation

Codecov / codecov/patch

src/Elasticsearch/Filter/AbstractFilter.php#L175-L176

Added lines #L175 - L176 were not covered by tests
}

return [$type, $hasAssociation, $currentResourceClass, $currentProperty];

Check warning on line 179 in src/Elasticsearch/Filter/AbstractFilter.php

View check run for this annotation

Codecov / codecov/patch

src/Elasticsearch/Filter/AbstractFilter.php#L179

Added line #L179 was not covered by tests
}

protected function getLegacyMetadata(string $resourceClass, string $property): array

Check warning on line 182 in src/Elasticsearch/Filter/AbstractFilter.php

View check run for this annotation

Codecov / codecov/patch

src/Elasticsearch/Filter/AbstractFilter.php#L182

Added line #L182 was not covered by tests
{
$noop = [null, null, null, null];

Expand Down Expand Up @@ -108,7 +216,7 @@
foreach ($types as $type) {
$builtinType = $type->getBuiltinType();

if (Type::BUILTIN_TYPE_OBJECT !== $builtinType && Type::BUILTIN_TYPE_ARRAY !== $builtinType) {
if (LegacyType::BUILTIN_TYPE_OBJECT !== $builtinType && LegacyType::BUILTIN_TYPE_ARRAY !== $builtinType) {

Check warning on line 219 in src/Elasticsearch/Filter/AbstractFilter.php

View check run for this annotation

Codecov / codecov/patch

src/Elasticsearch/Filter/AbstractFilter.php#L219

Added line #L219 was not covered by tests
if ($totalProperties === $index) {
break 2;
}
Expand All @@ -124,7 +232,7 @@
continue;
}

if (Type::BUILTIN_TYPE_ARRAY === $builtinType && Type::BUILTIN_TYPE_OBJECT !== $type->getBuiltinType()) {
if (LegacyType::BUILTIN_TYPE_ARRAY === $builtinType && LegacyType::BUILTIN_TYPE_OBJECT !== $type->getBuiltinType()) {

Check warning on line 235 in src/Elasticsearch/Filter/AbstractFilter.php

View check run for this annotation

Codecov / codecov/patch

src/Elasticsearch/Filter/AbstractFilter.php#L235

Added line #L235 was not covered by tests
if ($totalProperties === $index) {
break 2;
}
Expand Down
75 changes: 51 additions & 24 deletions src/Elasticsearch/Filter/AbstractSearchFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@
use ApiPlatform\Metadata\Property\Factory\PropertyNameCollectionFactoryInterface;
use ApiPlatform\Metadata\ResourceClassResolverInterface;
use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
use Symfony\Component\PropertyInfo\Type;
use Symfony\Component\PropertyInfo\Type as LegacyType;
use Symfony\Component\Serializer\NameConverter\NameConverterInterface;
use Symfony\Component\TypeInfo\Type;
use Symfony\Component\TypeInfo\Type\WrappingTypeInterface;
use Symfony\Component\TypeInfo\TypeIdentifier;

/**
* Abstract class with helpers for easing the implementation of a search filter like a term filter or a match filter.
Expand Down Expand Up @@ -109,27 +112,40 @@
*/
abstract protected function getQuery(string $property, array $values, ?string $nestedPath): array;

/**
* Converts the given {@see Type} in PHP type.
*/
protected function getPhpType(Type $type): string
protected function getPhpType(LegacyType|Type $type): string

Check warning on line 115 in src/Elasticsearch/Filter/AbstractSearchFilter.php

View check run for this annotation

Codecov / codecov/patch

src/Elasticsearch/Filter/AbstractSearchFilter.php#L115

Added line #L115 was not covered by tests
{
switch ($builtinType = $type->getBuiltinType()) {
case Type::BUILTIN_TYPE_ARRAY:
case Type::BUILTIN_TYPE_INT:
case Type::BUILTIN_TYPE_FLOAT:
case Type::BUILTIN_TYPE_BOOL:
case Type::BUILTIN_TYPE_STRING:
return $builtinType;
case Type::BUILTIN_TYPE_OBJECT:
if (null !== ($className = $type->getClassName()) && is_a($className, \DateTimeInterface::class, true)) {
return \DateTimeInterface::class;
}
if ($type instanceof LegacyType) {
switch ($builtinType = $type->getBuiltinType()) {
case LegacyType::BUILTIN_TYPE_ARRAY:
case LegacyType::BUILTIN_TYPE_INT:
case LegacyType::BUILTIN_TYPE_FLOAT:
case LegacyType::BUILTIN_TYPE_BOOL:
case LegacyType::BUILTIN_TYPE_STRING:
return $builtinType;
case LegacyType::BUILTIN_TYPE_OBJECT:
if (null !== ($className = $type->getClassName()) && is_a($className, \DateTimeInterface::class, true)) {
return \DateTimeInterface::class;

Check warning on line 127 in src/Elasticsearch/Filter/AbstractSearchFilter.php

View check run for this annotation

Codecov / codecov/patch

src/Elasticsearch/Filter/AbstractSearchFilter.php#L117-L127

Added lines #L117 - L127 were not covered by tests
}

// no break
default:
return 'string';

Check warning on line 132 in src/Elasticsearch/Filter/AbstractSearchFilter.php

View check run for this annotation

Codecov / codecov/patch

src/Elasticsearch/Filter/AbstractSearchFilter.php#L132

Added line #L132 was not covered by tests
}
}

if ($type->isIdentifiedBy(TypeIdentifier::ARRAY, TypeIdentifier::INT, TypeIdentifier::FLOAT, TypeIdentifier::BOOL, TypeIdentifier::STRING)) {
while ($type instanceof WrappingTypeInterface) {
$type = $type->getWrappedType();

Check warning on line 138 in src/Elasticsearch/Filter/AbstractSearchFilter.php

View check run for this annotation

Codecov / codecov/patch

src/Elasticsearch/Filter/AbstractSearchFilter.php#L136-L138

Added lines #L136 - L138 were not covered by tests
}

return (string) $type;

Check warning on line 141 in src/Elasticsearch/Filter/AbstractSearchFilter.php

View check run for this annotation

Codecov / codecov/patch

src/Elasticsearch/Filter/AbstractSearchFilter.php#L141

Added line #L141 was not covered by tests
}

// no break
default:
return 'string';
if ($type->isIdentifiedBy(\DateTimeInterface::class)) {
return \DateTimeInterface::class;

Check warning on line 145 in src/Elasticsearch/Filter/AbstractSearchFilter.php

View check run for this annotation

Codecov / codecov/patch

src/Elasticsearch/Filter/AbstractSearchFilter.php#L144-L145

Added lines #L144 - L145 were not covered by tests
}

return 'string';

Check warning on line 148 in src/Elasticsearch/Filter/AbstractSearchFilter.php

View check run for this annotation

Codecov / codecov/patch

src/Elasticsearch/Filter/AbstractSearchFilter.php#L148

Added line #L148 was not covered by tests
}

/**
Expand Down Expand Up @@ -164,15 +180,26 @@
return $iri;
}

/**
* Are the given values valid according to the given {@see Type}?
*/
protected function hasValidValues(array $values, Type $type): bool
protected function hasValidValues(array $values, LegacyType|Type $type): bool

Check warning on line 183 in src/Elasticsearch/Filter/AbstractSearchFilter.php

View check run for this annotation

Codecov / codecov/patch

src/Elasticsearch/Filter/AbstractSearchFilter.php#L183

Added line #L183 was not covered by tests
{
if ($type instanceof LegacyType) {
foreach ($values as $value) {

Check warning on line 186 in src/Elasticsearch/Filter/AbstractSearchFilter.php

View check run for this annotation

Codecov / codecov/patch

src/Elasticsearch/Filter/AbstractSearchFilter.php#L185-L186

Added lines #L185 - L186 were not covered by tests
if (
null !== $value
&& LegacyType::BUILTIN_TYPE_INT === $type->getBuiltinType()
&& false === filter_var($value, \FILTER_VALIDATE_INT)

Check warning on line 190 in src/Elasticsearch/Filter/AbstractSearchFilter.php

View check run for this annotation

Codecov / codecov/patch

src/Elasticsearch/Filter/AbstractSearchFilter.php#L188-L190

Added lines #L188 - L190 were not covered by tests
) {
return false;

Check warning on line 192 in src/Elasticsearch/Filter/AbstractSearchFilter.php

View check run for this annotation

Codecov / codecov/patch

src/Elasticsearch/Filter/AbstractSearchFilter.php#L192

Added line #L192 was not covered by tests
}
}

return true;

Check warning on line 196 in src/Elasticsearch/Filter/AbstractSearchFilter.php

View check run for this annotation

Codecov / codecov/patch

src/Elasticsearch/Filter/AbstractSearchFilter.php#L196

Added line #L196 was not covered by tests
}

foreach ($values as $value) {
if (
null !== $value
&& Type::BUILTIN_TYPE_INT === $type->getBuiltinType()
&& $type->isIdentifiedBy(TypeIdentifier::INT)

Check warning on line 202 in src/Elasticsearch/Filter/AbstractSearchFilter.php

View check run for this annotation

Codecov / codecov/patch

src/Elasticsearch/Filter/AbstractSearchFilter.php#L202

Added line #L202 was not covered by tests
&& false === filter_var($value, \FILTER_VALIDATE_INT)
) {
return false;
Expand Down
6 changes: 3 additions & 3 deletions src/Elasticsearch/Tests/Extension/SortExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
use ApiPlatform\Metadata\ResourceClassResolverInterface;
use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;
use Symfony\Component\PropertyInfo\Type;
use Symfony\Component\Serializer\NameConverter\NameConverterInterface;
use Symfony\Component\TypeInfo\Type;

class SortExtensionTest extends TestCase
{
Expand Down Expand Up @@ -55,10 +55,10 @@

public function testApplyToCollectionWithNestedProperty(): void
{
$fooType = new Type(Type::BUILTIN_TYPE_ARRAY, false, Foo::class, true, new Type(Type::BUILTIN_TYPE_INT), new Type(Type::BUILTIN_TYPE_OBJECT, false, Foo::class));
$fooType = Type::list(Type::object(Foo::class));

Check warning on line 58 in src/Elasticsearch/Tests/Extension/SortExtensionTest.php

View check run for this annotation

Codecov / codecov/patch

src/Elasticsearch/Tests/Extension/SortExtensionTest.php#L58

Added line #L58 was not covered by tests

$propertyMetadataFactoryProphecy = $this->prophesize(PropertyMetadataFactoryInterface::class);
$propertyMetadataFactoryProphecy->create(Foo::class, 'foo')->willReturn((new ApiProperty())->withBuiltinTypes([$fooType]))->shouldBeCalled();
$propertyMetadataFactoryProphecy->create(Foo::class, 'foo')->willReturn((new ApiProperty())->withNativeType($fooType))->shouldBeCalled();

Check warning on line 61 in src/Elasticsearch/Tests/Extension/SortExtensionTest.php

View check run for this annotation

Codecov / codecov/patch

src/Elasticsearch/Tests/Extension/SortExtensionTest.php#L61

Added line #L61 was not covered by tests

$resourceClassResolverProphecy = $this->prophesize(ResourceClassResolverInterface::class);
$resourceClassResolverProphecy->isResourceClass(Foo::class)->willReturn(true)->shouldBeCalled();
Expand Down
32 changes: 16 additions & 16 deletions src/Elasticsearch/Tests/Filter/MatchFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
use Symfony\Component\PropertyInfo\Type;
use Symfony\Component\Serializer\NameConverter\NameConverterInterface;
use Symfony\Component\TypeInfo\Type;

class MatchFilterTest extends TestCase
{
Expand All @@ -55,8 +55,8 @@
$propertyNameCollectionFactoryProphecy->create(Foo::class)->willReturn(new PropertyNameCollection(['id', 'name', 'bar']))->shouldBeCalled();

$propertyMetadataFactoryProphecy = $this->prophesize(PropertyMetadataFactoryInterface::class);
$propertyMetadataFactoryProphecy->create(Foo::class, 'id')->willReturn((new ApiProperty())->withBuiltinTypes([new Type(Type::BUILTIN_TYPE_INT)]))->shouldBeCalled();
$propertyMetadataFactoryProphecy->create(Foo::class, 'name')->willReturn((new ApiProperty())->withBuiltinTypes([new Type(Type::BUILTIN_TYPE_STRING)]))->shouldBeCalled();
$propertyMetadataFactoryProphecy->create(Foo::class, 'id')->willReturn((new ApiProperty())->withNativeType(Type::int()))->shouldBeCalled();
$propertyMetadataFactoryProphecy->create(Foo::class, 'name')->willReturn((new ApiProperty())->withNativeType(Type::string()))->shouldBeCalled();

Check warning on line 59 in src/Elasticsearch/Tests/Filter/MatchFilterTest.php

View check run for this annotation

Codecov / codecov/patch

src/Elasticsearch/Tests/Filter/MatchFilterTest.php#L58-L59

Added lines #L58 - L59 were not covered by tests

$foo = new Foo();
$foo->setName('Xavier');
Expand Down Expand Up @@ -89,12 +89,12 @@

public function testApplyWithNestedArrayProperty(): void
{
$fooType = new Type(Type::BUILTIN_TYPE_ARRAY, false, Foo::class, true, new Type(Type::BUILTIN_TYPE_INT), new Type(Type::BUILTIN_TYPE_OBJECT, false, Foo::class));
$barType = new Type(Type::BUILTIN_TYPE_STRING);
$fooType = Type::list(Type::object(Foo::class));
$barType = Type::string();

Check warning on line 93 in src/Elasticsearch/Tests/Filter/MatchFilterTest.php

View check run for this annotation

Codecov / codecov/patch

src/Elasticsearch/Tests/Filter/MatchFilterTest.php#L92-L93

Added lines #L92 - L93 were not covered by tests

$propertyMetadataFactoryProphecy = $this->prophesize(PropertyMetadataFactoryInterface::class);
$propertyMetadataFactoryProphecy->create(Foo::class, 'foo')->willReturn((new ApiProperty())->withBuiltinTypes([$fooType]))->shouldBeCalled();
$propertyMetadataFactoryProphecy->create(Foo::class, 'bar')->willReturn((new ApiProperty())->withBuiltinTypes([$barType]))->shouldBeCalled();
$propertyMetadataFactoryProphecy->create(Foo::class, 'foo')->willReturn((new ApiProperty())->withNativeType($fooType))->shouldBeCalled();
$propertyMetadataFactoryProphecy->create(Foo::class, 'bar')->willReturn((new ApiProperty())->withNativeType($barType))->shouldBeCalled();

Check warning on line 97 in src/Elasticsearch/Tests/Filter/MatchFilterTest.php

View check run for this annotation

Codecov / codecov/patch

src/Elasticsearch/Tests/Filter/MatchFilterTest.php#L96-L97

Added lines #L96 - L97 were not covered by tests

$resourceClassResolverProphecy = $this->prophesize(ResourceClassResolverInterface::class);
$resourceClassResolverProphecy->isResourceClass(Foo::class)->willReturn(true)->shouldBeCalled();
Expand All @@ -121,12 +121,12 @@

public function testApplyWithNestedObjectProperty(): void
{
$fooType = new Type(Type::BUILTIN_TYPE_OBJECT, false, Foo::class);
$barType = new Type(Type::BUILTIN_TYPE_STRING);
$fooType = Type::object(Foo::class);
$barType = Type::string();

Check warning on line 125 in src/Elasticsearch/Tests/Filter/MatchFilterTest.php

View check run for this annotation

Codecov / codecov/patch

src/Elasticsearch/Tests/Filter/MatchFilterTest.php#L124-L125

Added lines #L124 - L125 were not covered by tests

$propertyMetadataFactoryProphecy = $this->prophesize(PropertyMetadataFactoryInterface::class);
$propertyMetadataFactoryProphecy->create(Foo::class, 'foo')->willReturn((new ApiProperty())->withBuiltinTypes([$fooType]))->shouldBeCalled();
$propertyMetadataFactoryProphecy->create(Foo::class, 'bar')->willReturn((new ApiProperty())->withBuiltinTypes([$barType]))->shouldBeCalled();
$propertyMetadataFactoryProphecy->create(Foo::class, 'foo')->willReturn((new ApiProperty())->withNativeType($fooType))->shouldBeCalled();
$propertyMetadataFactoryProphecy->create(Foo::class, 'bar')->willReturn((new ApiProperty())->withNativeType($barType))->shouldBeCalled();

Check warning on line 129 in src/Elasticsearch/Tests/Filter/MatchFilterTest.php

View check run for this annotation

Codecov / codecov/patch

src/Elasticsearch/Tests/Filter/MatchFilterTest.php#L128-L129

Added lines #L128 - L129 were not covered by tests

$resourceClassResolverProphecy = $this->prophesize(ResourceClassResolverInterface::class);
$resourceClassResolverProphecy->isResourceClass(Foo::class)->willReturn(true)->shouldBeCalled();
Expand Down Expand Up @@ -156,7 +156,7 @@
$propertyNameCollectionFactoryProphecy->create(Foo::class)->willReturn(new PropertyNameCollection(['id', 'bar']))->shouldBeCalled();

$propertyMetadataFactoryProphecy = $this->prophesize(PropertyMetadataFactoryInterface::class);
$propertyMetadataFactoryProphecy->create(Foo::class, 'id')->willReturn((new ApiProperty())->withBuiltinTypes([new Type(Type::BUILTIN_TYPE_INT)]))->shouldBeCalled();
$propertyMetadataFactoryProphecy->create(Foo::class, 'id')->willReturn((new ApiProperty())->withNativeType(Type::int()))->shouldBeCalled();

Check warning on line 159 in src/Elasticsearch/Tests/Filter/MatchFilterTest.php

View check run for this annotation

Codecov / codecov/patch

src/Elasticsearch/Tests/Filter/MatchFilterTest.php#L159

Added line #L159 was not covered by tests
$propertyMetadataFactoryProphecy->create(Foo::class, 'bar')->willReturn(new ApiProperty())->shouldBeCalled();

$iriConverterProphecy = $this->prophesize(IriConverterInterface::class);
Expand All @@ -183,11 +183,11 @@
$propertyNameCollectionFactoryProphecy->create(Foo::class)->willReturn(new PropertyNameCollection(['id', 'name', 'bar', 'date', 'weird']))->shouldBeCalled();

$propertyMetadataFactoryProphecy = $this->prophesize(PropertyMetadataFactoryInterface::class);
$propertyMetadataFactoryProphecy->create(Foo::class, 'id')->willReturn((new ApiProperty())->withBuiltinTypes([new Type(Type::BUILTIN_TYPE_INT)]))->shouldBeCalled();
$propertyMetadataFactoryProphecy->create(Foo::class, 'name')->willReturn((new ApiProperty())->withBuiltinTypes([new Type(Type::BUILTIN_TYPE_STRING)]))->shouldBeCalled();
$propertyMetadataFactoryProphecy->create(Foo::class, 'id')->willReturn((new ApiProperty())->withNativeType(Type::int()))->shouldBeCalled();
$propertyMetadataFactoryProphecy->create(Foo::class, 'name')->willReturn((new ApiProperty())->withNativeType(Type::string()))->shouldBeCalled();

Check warning on line 187 in src/Elasticsearch/Tests/Filter/MatchFilterTest.php

View check run for this annotation

Codecov / codecov/patch

src/Elasticsearch/Tests/Filter/MatchFilterTest.php#L186-L187

Added lines #L186 - L187 were not covered by tests
$propertyMetadataFactoryProphecy->create(Foo::class, 'bar')->willReturn(new ApiProperty())->shouldBeCalled();
$propertyMetadataFactoryProphecy->create(Foo::class, 'date')->willReturn((new ApiProperty())->withBuiltinTypes([new Type(Type::BUILTIN_TYPE_OBJECT, false, \DateTimeImmutable::class)]))->shouldBeCalled();
$propertyMetadataFactoryProphecy->create(Foo::class, 'weird')->willReturn((new ApiProperty())->withBuiltinTypes([new Type(Type::BUILTIN_TYPE_RESOURCE)]))->shouldBeCalled();
$propertyMetadataFactoryProphecy->create(Foo::class, 'date')->willReturn((new ApiProperty())->withNativeType(Type::object(\DateTimeImmutable::class)))->shouldBeCalled();
$propertyMetadataFactoryProphecy->create(Foo::class, 'weird')->willReturn((new ApiProperty())->withNativeType(Type::resource()))->shouldBeCalled();

Check warning on line 190 in src/Elasticsearch/Tests/Filter/MatchFilterTest.php

View check run for this annotation

Codecov / codecov/patch

src/Elasticsearch/Tests/Filter/MatchFilterTest.php#L189-L190

Added lines #L189 - L190 were not covered by tests

$resourceClassResolverProphecy = $this->prophesize(ResourceClassResolverInterface::class);
$resourceClassResolverProphecy->isResourceClass(\DateTimeImmutable::class)->willReturn(false)->shouldBeCalled();
Expand Down
Loading
Loading