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

api-platform / core / 14925420478

09 May 2025 09:03AM UTC coverage: 7.739% (+0.6%) from 7.179%
14925420478

Pull #7134

github

web-flow
Merge a0984c209 into 4ddce1f53
Pull Request #7134: refactor(metadata): type parameters to list<string>|string

48 of 134 new or added lines in 15 files covered. (35.82%)

2 existing lines in 2 files now uncovered.

12267 of 158510 relevant lines covered (7.74%)

15.54 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']),
×
55
            'baz' => (new QueryParameter(key: 'baz'))->withExtraProperties(['_api_values' => 'test1']),
×
56
            'fas' => (new QueryParameter(key: 'fas'))->withExtraProperties(['_api_values' => '42']),
×
57
        ]));
×
58
        $parameterProvider = new ParameterProvider(null, $locator);
×
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');
×
UNCOV
63
        $this->assertEquals('ok', $operation->getName());
×
64
        $this->assertEquals(['foo' => 'asc'], $operation->getParameters()->get('order', QueryParameter::class)->getValue());
×
65
        $this->assertEquals(['a' => 'bar'], $operation->getParameters()->get('search[:property]', QueryParameter::class)->getValue());
×
66
        $this->assertEquals('t42', $operation->getParameters()->get('baz', QueryParameter::class)->getValue());
×
67
        $this->assertEquals(new ParameterNotFound(), $operation->getParameters()->get('fas', QueryParameter::class)->getValue());
×
68
    }
69

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

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

© 2025 Coveralls, Inc