• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

api-platform / core / 6198877116

15 Sep 2023 02:07PM UTC coverage: 36.999% (+0.08%) from 36.924%
6198877116

push

github

web-flow
Revert "feat(elasticsearch): filtering on nested fields (#5820)" (#5825)

This reverts commit d85884d53.

2 of 2 new or added lines in 1 file covered. (100.0%)

10101 of 27301 relevant lines covered (37.0%)

19.98 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/Elasticsearch/Tests/Util/FieldDatatypeTraitTest.php
1
<?php
2

3
/*
4
 * This file is part of the API Platform project.
5
 *
6
 * (c) Kévin Dunglas <dunglas@gmail.com>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11

12
declare(strict_types=1);
13

14
namespace ApiPlatform\Elasticsearch\Tests\Util;
15

16
use ApiPlatform\Elasticsearch\Tests\Fixtures\Foo;
17
use ApiPlatform\Elasticsearch\Util\FieldDatatypeTrait;
18
use ApiPlatform\Metadata\ApiProperty;
19
use ApiPlatform\Metadata\Exception\PropertyNotFoundException;
20
use ApiPlatform\Metadata\Property\Factory\PropertyMetadataFactoryInterface;
21
use ApiPlatform\Metadata\ResourceClassResolverInterface;
22
use PHPUnit\Framework\TestCase;
23
use Prophecy\PhpUnit\ProphecyTrait;
24
use Symfony\Component\PropertyInfo\Type;
25

26
class FieldDatatypeTraitTest extends TestCase
27
{
28
    use ProphecyTrait;
29

30
    public function testGetNestedFieldPath(): void
31
    {
32
        $fieldDatatype = $this->getValidFieldDatatype();
×
33

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

38
    public function testGetNestedFieldPathWithPropertyNotFound(): void
39
    {
40
        $propertyMetadataFactoryProphecy = $this->prophesize(PropertyMetadataFactoryInterface::class);
×
41
        $propertyMetadataFactoryProphecy->create(Foo::class, 'foo')->willThrow(new PropertyNotFoundException())->shouldBeCalled();
×
42

43
        $fieldDatatype = self::createFieldDatatypeInstance($propertyMetadataFactoryProphecy->reveal(), $this->prophesize(ResourceClassResolverInterface::class)->reveal());
×
44

45
        self::assertNull($fieldDatatype->getNestedFieldPath(Foo::class, 'foo.bar'));
×
46
    }
47

48
    public function testGetNestedFieldPathWithPropertyWithoutType(): void
49
    {
50
        $propertyMetadataFactoryProphecy = $this->prophesize(PropertyMetadataFactoryInterface::class);
×
51
        $propertyMetadataFactoryProphecy->create(Foo::class, 'foo')->willReturn(new ApiProperty())->shouldBeCalled();
×
52

53
        $fieldDatatype = self::createFieldDatatypeInstance($propertyMetadataFactoryProphecy->reveal(),
×
54
            $this->prophesize(ResourceClassResolverInterface::class)->reveal());
×
55

56
        self::assertNull($fieldDatatype->getNestedFieldPath(Foo::class, 'foo.bar'));
×
57
    }
58

59
    public function testGetNestedFieldPathWithInvalidCollectionType(): void
60
    {
61
        $propertyMetadataFactoryProphecy = $this->prophesize(PropertyMetadataFactoryInterface::class);
×
62
        $propertyMetadataFactoryProphecy->create(Foo::class, 'foo')->willReturn((new ApiProperty())->withBuiltinTypes([new Type(Type::BUILTIN_TYPE_STRING)]))->shouldBeCalled();
×
63

64
        $fieldDatatype = self::createFieldDatatypeInstance($propertyMetadataFactoryProphecy->reveal(),
×
65
            $this->prophesize(ResourceClassResolverInterface::class)->reveal());
×
66

67
        self::assertNull($fieldDatatype->getNestedFieldPath(Foo::class, 'foo.bar'));
×
68
    }
69

70
    public function testIsNestedField(): void
71
    {
72
        $fieldDatatype = $this->getValidFieldDatatype();
×
73

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

78
    private function getValidFieldDatatype()
79
    {
80
        $fooType = new Type(Type::BUILTIN_TYPE_OBJECT, false, Foo::class);
×
81
        $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));
×
82

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

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

90
        return self::createFieldDatatypeInstance($propertyMetadataFactoryProphecy->reveal(),
×
91
            $resourceClassResolverProphecy->reveal());
×
92
    }
93

94
    private static function createFieldDatatypeInstance(PropertyMetadataFactoryInterface $propertyMetadataFactory, ResourceClassResolverInterface $resourceClassResolver)
95
    {
96
        return new class($propertyMetadataFactory, $resourceClassResolver) {
×
97
            use FieldDatatypeTrait {
98
                isNestedField as public;
99
                getNestedFieldPath as public;
100
            }
101

102
            public function __construct(PropertyMetadataFactoryInterface $propertyMetadataFactory, ResourceClassResolverInterface $resourceClassResolver)
103
            {
104
                $this->propertyMetadataFactory = $propertyMetadataFactory;
×
105
                $this->resourceClassResolver = $resourceClassResolver;
×
106
            }
107
        };
×
108
    }
109
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc