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

api-platform / core / 10315659289

09 Aug 2024 07:49AM UTC coverage: 7.841% (-0.006%) from 7.847%
10315659289

push

github

soyuka
style: cs fixes

70 of 529 new or added lines in 176 files covered. (13.23%)

160 existing lines in 58 files now uncovered.

12688 of 161818 relevant lines covered (7.84%)

26.86 hits per line

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

0.0
/src/State/Tests/ParameterProviderTest.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\State\Tests;
15

16
use ApiPlatform\Metadata\Get;
17
use ApiPlatform\Metadata\Operation;
18
use ApiPlatform\Metadata\Parameter;
19
use ApiPlatform\Metadata\Parameters;
20
use ApiPlatform\Metadata\QueryParameter;
21
use ApiPlatform\State\ParameterProviderInterface;
22
use ApiPlatform\State\Provider\ParameterProvider;
23
use PHPUnit\Framework\TestCase;
24
use Psr\Container\ContainerInterface;
25
use Symfony\Component\HttpFoundation\Request;
26

27
final class ParameterProviderTest extends TestCase
28
{
29
    public function testExtractValues(): void
30
    {
NEW
31
        $locator = new class implements ContainerInterface {
×
32
            public function get(string $id)
33
            {
34
                if ('test' === $id) {
×
NEW
35
                    return new class implements ParameterProviderInterface {
×
36
                        public function provide(Parameter $parameter, array $parameters = [], array $context = []): ?Operation
37
                        {
38
                            return new Get(name: 'ok');
×
39
                        }
40
                    };
×
41
                }
42
            }
43

44
            public function has(string $id): bool
45
            {
46
                return 'test' === $id;
×
47
            }
48
        };
×
49

50
        $operation = new Get(parameters: new Parameters([
×
51
            'order' => new QueryParameter(key: 'order', provider: 'test'),
×
52
            'search[:property]' => new QueryParameter(key: 'search[:property]', provider: [self::class, 'provide']),
×
53
            'foo' => new QueryParameter(key: 'foo', provider: [self::class, 'shouldNotBeCalled']),
×
54
        ]));
×
55
        $parameterProvider = new ParameterProvider(null, $locator);
×
56
        $request = new Request(server: ['QUERY_STRING' => 'order[foo]=asc&search[a]=bar']);
×
57
        $context = ['request' => $request, 'operation' => $operation];
×
58
        $parameterProvider->provide($operation, [], $context);
×
59
        $operation = $request->attributes->get('_api_operation');
×
60

61
        $this->assertEquals('ok', $operation->getName());
×
62
        $this->assertEquals(['foo' => 'asc'], $operation->getParameters()->get('order', QueryParameter::class)->getValue());
×
63
        $this->assertEquals(['a' => 'bar'], $operation->getParameters()->get('search[:property]', QueryParameter::class)->getValue());
×
64
    }
65

66
    public static function provide(): void
67
    {
68
        static::assertTrue(true);
×
69
    }
70

71
    public static function shouldNotBeCalled(): void
72
    {
73
        static::assertTrue(false); // @phpstan-ignore-line
×
74
    }
75
}
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