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

api-platform / core / 16053734897

03 Jul 2025 02:52PM UTC coverage: 22.132% (-0.4%) from 22.566%
16053734897

Pull #7274

github

web-flow
Merge 459b4021a into 828b62a4e
Pull Request #7274: fix(symfony): restore graphql_playground option

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

3831 existing lines in 106 files now uncovered.

11560 of 52232 relevant lines covered (22.13%)

23.34 hits per line

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

0.0
/src/Elasticsearch/Tests/Extension/SortExtensionTest.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\Extension;
15

16
use ApiPlatform\Elasticsearch\Extension\RequestBodySearchCollectionExtensionInterface;
17
use ApiPlatform\Elasticsearch\Extension\SortExtension;
18
use ApiPlatform\Elasticsearch\Tests\Fixtures\Foo;
19
use ApiPlatform\Metadata\ApiProperty;
20
use ApiPlatform\Metadata\GetCollection;
21
use ApiPlatform\Metadata\Property\Factory\PropertyMetadataFactoryInterface;
22
use ApiPlatform\Metadata\ResourceClassResolverInterface;
23
use PHPUnit\Framework\Attributes\IgnoreDeprecations;
24
use PHPUnit\Framework\TestCase;
25
use Prophecy\PhpUnit\ProphecyTrait;
26
use Symfony\Component\Serializer\NameConverter\NameConverterInterface;
27
use Symfony\Component\TypeInfo\Type;
28

29
class SortExtensionTest extends TestCase
30
{
31
    use ProphecyTrait;
32

33
    public function testConstruct(): void
34
    {
35
        self::assertInstanceOf(
×
36
            RequestBodySearchCollectionExtensionInterface::class,
×
37
            new SortExtension(
×
38
                $this->prophesize(PropertyMetadataFactoryInterface::class)->reveal(),
×
39
                $this->prophesize(ResourceClassResolverInterface::class)->reveal(),
×
40
                $this->prophesize(NameConverterInterface::class)->reveal(),
×
41
                'asc'
×
42
            )
×
UNCOV
43
        );
×
44
    }
45

46
    public function testApplyToCollection(): void
47
    {
48
        $nameConverterProphecy = $this->prophesize(NameConverterInterface::class);
×
49
        $nameConverterProphecy->normalize('name', Foo::class)->willReturn('name')->shouldBeCalled();
×
UNCOV
50
        $nameConverterProphecy->normalize('bar', Foo::class)->willReturn('bar')->shouldBeCalled();
×
51

UNCOV
52
        $sortExtension = new SortExtension($this->prophesize(PropertyMetadataFactoryInterface::class)->reveal(), $this->prophesize(ResourceClassResolverInterface::class)->reveal(), $nameConverterProphecy->reveal(), 'asc');
×
53

UNCOV
54
        self::assertEquals(['sort' => [['name' => ['order' => 'asc']], ['bar' => ['order' => 'desc']]]], $sortExtension->applyToCollection([], Foo::class, (new GetCollection())->withOrder(['name', 'bar' => 'desc'])));
×
55
    }
56

57
    #[IgnoreDeprecations]
58
    public function testApplyToCollectionWithNestedProperty(): void
59
    {
60
        $fooType = Type::list(Type::object(Foo::class));
×
61

UNCOV
62
        $propertyMetadataFactoryProphecy = $this->prophesize(PropertyMetadataFactoryInterface::class);
×
63
        $propertyMetadataFactoryProphecy->create(Foo::class, 'foo')->willReturn((new ApiProperty())->withNativeType($fooType))->shouldBeCalled();
×
64

UNCOV
65
        $resourceClassResolverProphecy = $this->prophesize(ResourceClassResolverInterface::class);
×
66
        $resourceClassResolverProphecy->isResourceClass(Foo::class)->willReturn(true)->shouldBeCalled();
×
67

68
        $nameConverterProphecy = $this->prophesize(NameConverterInterface::class);
×
UNCOV
69
        $nameConverterProphecy->normalize('foo.bar', Foo::class)->willReturn('foo.bar')->shouldBeCalled();
×
70
        $nameConverterProphecy->normalize('foo', Foo::class)->willReturn('foo')->shouldBeCalled();
×
71

72
        $sortExtension = new SortExtension($propertyMetadataFactoryProphecy->reveal(), $resourceClassResolverProphecy->reveal(), $nameConverterProphecy->reveal(), 'asc');
×
73

UNCOV
74
        self::assertEquals(['sort' => [['foo.bar' => ['order' => 'desc', 'nested' => ['path' => 'foo']]]]], $sortExtension->applyToCollection([], Foo::class, (new GetCollection())->withOrder(['foo.bar' => 'desc'])));
×
75
    }
76

77
    public function testApplyToCollectionWithDefaultDirection(): void
78
    {
UNCOV
79
        $nameConverterProphecy = $this->prophesize(NameConverterInterface::class);
×
80
        $nameConverterProphecy->normalize('id', Foo::class)->willReturn('id')->shouldBeCalled();
×
81

82
        $sortExtension = new SortExtension($this->prophesize(PropertyMetadataFactoryInterface::class)->reveal(), $this->prophesize(ResourceClassResolverInterface::class)->reveal(), $nameConverterProphecy->reveal(), 'asc');
×
83

UNCOV
84
        self::assertEquals(['sort' => [['id' => ['order' => 'asc']]]], $sortExtension->applyToCollection([], Foo::class));
×
85
    }
86

87
    public function testApplyToCollectionWithNoOrdering(): void
88
    {
89
        $sortExtension = new SortExtension($this->prophesize(PropertyMetadataFactoryInterface::class)->reveal(), $this->prophesize(ResourceClassResolverInterface::class)->reveal(), $this->prophesize(NameConverterInterface::class)->reveal());
×
90

UNCOV
91
        self::assertEmpty($sortExtension->applyToCollection([], Foo::class));
×
92
    }
93
}
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