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

api-platform / core / 11174994628

04 Oct 2024 06:16AM UTC coverage: 7.441% (+0.005%) from 7.436%
11174994628

push

github

soyuka
Merge 3.4

14 of 36 new or added lines in 4 files covered. (38.89%)

18 existing lines in 1 file now uncovered.

12276 of 164979 relevant lines covered (7.44%)

13.57 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\ParameterNotFound;
22
use ApiPlatform\State\ParameterProviderInterface;
23
use ApiPlatform\State\Provider\ParameterProvider;
24
use PHPUnit\Framework\TestCase;
25
use Psr\Container\ContainerInterface;
26
use Symfony\Component\HttpFoundation\Request;
27

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

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

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

64
        $this->assertEquals('ok', $operation->getName());
×
65
        $this->assertEquals(['foo' => 'asc'], $operation->getParameters()->get('order', QueryParameter::class)->getValue());
×
66
        $this->assertEquals(['a' => 'bar'], $operation->getParameters()->get('search[:property]', QueryParameter::class)->getValue());
×
NEW
67
        $this->assertEquals('t42', $operation->getParameters()->get('baz', QueryParameter::class)->getValue());
×
NEW
68
        $this->assertEquals(new ParameterNotFound(), $operation->getParameters()->get('fas', QueryParameter::class)->getValue());
×
69
    }
70

71
    public static function provide(): void
72
    {
73
        static::assertTrue(true);
×
74
    }
75

76
    public static function shouldNotBeCalled(): void
77
    {
78
        static::assertTrue(false); // @phpstan-ignore-line
×
79
    }
80
}
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