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
34 changes: 1 addition & 33 deletions src/Elasticsearch/Tests/Filter/MatchFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function testApply(): void
);
}

public function testApplyWithNestedArrayProperty(): void
public function testApplyWithNestedProperty(): 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);
Expand Down Expand Up @@ -119,38 +119,6 @@ public function testApplyWithNestedArrayProperty(): void
);
}

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

$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();

$resourceClassResolverProphecy = $this->prophesize(ResourceClassResolverInterface::class);
$resourceClassResolverProphecy->isResourceClass(Foo::class)->willReturn(true)->shouldBeCalled();

$nameConverterProphecy = $this->prophesize(NameConverterInterface::class);
$nameConverterProphecy->normalize('foo.bar', Foo::class, null, Argument::type('array'))->willReturn('foo.bar')->shouldBeCalled();
$nameConverterProphecy->normalize('foo', Foo::class, null, Argument::type('array'))->willReturn('foo')->shouldBeCalled();

$matchFilter = new MatchFilter(
$this->prophesize(PropertyNameCollectionFactoryInterface::class)->reveal(),
$propertyMetadataFactoryProphecy->reveal(),
$resourceClassResolverProphecy->reveal(),
$this->prophesize(IriConverterInterface::class)->reveal(),
$this->prophesize(PropertyAccessorInterface::class)->reveal(),
$nameConverterProphecy->reveal(),
['foo.bar' => null]
);

self::assertSame(
['bool' => ['must' => [['nested' => ['path' => 'foo', 'query' => ['match' => ['foo.bar' => 'Krupicka']]]]]]],
$matchFilter->apply([], Foo::class, null, ['filters' => ['foo.bar' => 'Krupicka']])
);
}

public function testApplyWithInvalidFilters(): void
{
$propertyNameCollectionFactoryProphecy = $this->prophesize(PropertyNameCollectionFactoryInterface::class);
Expand Down
34 changes: 1 addition & 33 deletions src/Elasticsearch/Tests/Filter/TermFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function testApply(): void
);
}

public function testApplyWithNestedArrayProperty(): void
public function testApplyWithNestedProperty(): 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);
Expand Down Expand Up @@ -119,38 +119,6 @@ public function testApplyWithNestedArrayProperty(): void
);
}

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

$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();

$resourceClassResolverProphecy = $this->prophesize(ResourceClassResolverInterface::class);
$resourceClassResolverProphecy->isResourceClass(Foo::class)->willReturn(true)->shouldBeCalled();

$nameConverterProphecy = $this->prophesize(NameConverterInterface::class);
$nameConverterProphecy->normalize('foo.bar', Foo::class, null, Argument::type('array'))->willReturn('foo.bar')->shouldBeCalled();
$nameConverterProphecy->normalize('foo', Foo::class, null, Argument::type('array'))->willReturn('foo')->shouldBeCalled();

$termFilter = new TermFilter(
$this->prophesize(PropertyNameCollectionFactoryInterface::class)->reveal(),
$propertyMetadataFactoryProphecy->reveal(),
$resourceClassResolverProphecy->reveal(),
$this->prophesize(IriConverterInterface::class)->reveal(),
$this->prophesize(PropertyAccessorInterface::class)->reveal(),
$nameConverterProphecy->reveal(),
['foo.bar' => null]
);

self::assertSame(
['bool' => ['must' => [['nested' => ['path' => 'foo', 'query' => ['term' => ['foo.bar' => 'Krupicka']]]]]]],
$termFilter->apply([], Foo::class, null, ['filters' => ['foo.bar' => 'Krupicka']])
);
}

public function testApplyWithInvalidFilters(): void
{
$propertyNameCollectionFactoryProphecy = $this->prophesize(PropertyNameCollectionFactoryInterface::class);
Expand Down
13 changes: 0 additions & 13 deletions src/Elasticsearch/Tests/Util/FieldDatatypeTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,6 @@ public function testGetNestedFieldPath(): void
$fieldDatatype = $this->getValidFieldDatatype();

self::assertSame('foo.bar', $fieldDatatype->getNestedFieldPath(Foo::class, 'foo.bar.baz'));
self::assertSame('foo', $fieldDatatype->getNestedFieldPath(Foo::class, 'foo.baz'));
self::assertNull($fieldDatatype->getNestedFieldPath(Foo::class, 'baz'));
}

public function testGetNestedFieldInNestedCollection(): void
{
$fieldDatatype = $this->getValidFieldDatatype();

self::assertSame('bar.foo', $fieldDatatype->getNestedFieldPath(Foo::class, 'bar.foo.baz'));
self::assertSame('bar', $fieldDatatype->getNestedFieldPath(Foo::class, 'bar.foo'));
self::assertNull($fieldDatatype->getNestedFieldPath(Foo::class, 'baz'));
}

Expand Down Expand Up @@ -82,20 +72,17 @@ public function testIsNestedField(): void
$fieldDatatype = $this->getValidFieldDatatype();

self::assertTrue($fieldDatatype->isNestedField(Foo::class, 'foo.bar.baz'));
self::assertTrue($fieldDatatype->isNestedField(Foo::class, 'foo.baz'));
self::assertFalse($fieldDatatype->isNestedField(Foo::class, 'baz'));
}

private function getValidFieldDatatype()
{
$fooType = new Type(Type::BUILTIN_TYPE_OBJECT, false, Foo::class);
$barType = 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));
$bazType = new Type(Type::BUILTIN_TYPE_STRING, false, Foo::class);

$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, 'baz')->willReturn((new ApiProperty())->withBuiltinTypes([$bazType]));

$resourceClassResolverProphecy = $this->prophesize(ResourceClassResolverInterface::class);
$resourceClassResolverProphecy->isResourceClass(Foo::class)->willReturn(true)->shouldBeCalled();
Expand Down
6 changes: 2 additions & 4 deletions src/Elasticsearch/Util/FieldDatatypeTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ private function getNestedFieldPath(string $resourceClass, string $property): ?s
) {
$nestedPath = $this->getNestedFieldPath($nextResourceClass, implode('.', $properties));

return null === $nestedPath ? $currentProperty : "$currentProperty.$nestedPath";
return null === $nestedPath ? $nestedPath : "$currentProperty.$nestedPath";
}

if (
Expand All @@ -78,9 +78,7 @@ private function getNestedFieldPath(string $resourceClass, string $property): ?s
&& null !== ($className = $type->getClassName())
&& $this->resourceClassResolver->isResourceClass($className)
) {
$nestedPath = $this->getNestedFieldPath($className, implode('.', $properties));

return null === $nestedPath ? $currentProperty : "$currentProperty.$nestedPath";
return $currentProperty;
}
}

Expand Down