• 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
/tests/Functional/Parameters/ParameterTest.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\Tests\Functional\Parameters;
15

16
use ApiPlatform\Symfony\Bundle\Test\ApiTestCase;
17
use ApiPlatform\Tests\Fixtures\TestBundle\ApiResource\WithParameter;
18
use ApiPlatform\Tests\SetupClassResourcesTrait;
19
use PHPUnit\Framework\Attributes\DataProvider;
20

21
final class ParameterTest extends ApiTestCase
22
{
23
    use SetupClassResourcesTrait;
24

25
    protected static ?bool $alwaysBootKernel = false;
26

27
    /**
28
     * @return class-string[]
29
     */
30
    public static function getResources(): array
31
    {
32
        return [WithParameter::class];
×
33
    }
34

35
    public function testWithGroupFilter(): void
36
    {
37
        $response = self::createClient()->request('GET', 'with_parameters/1?groups[]=b');
×
38
        $this->assertArrayNotHasKey('a', $response->toArray());
×
39
        $this->assertArraySubset(['b' => 'bar'], $response->toArray());
×
40
        $response = self::createClient()->request('GET', 'with_parameters/1?groups[]=b&groups[]=a');
×
41
        $this->assertArraySubset(['a' => 'foo', 'b' => 'bar'], $response->toArray());
×
42
    }
43

44
    public function testWithGroupProvider(): void
45
    {
46
        $response = self::createClient()->request('GET', 'with_parameters/1?group[]=b&group[]=a');
×
47
        $this->assertArraySubset(['a' => 'foo', 'b' => 'bar'], $response->toArray());
×
48
    }
49

50
    public function testWithServiceFilter(): void
51
    {
52
        $response = self::createClient()->request('GET', 'with_parameters/1?properties[]=a');
×
53
        $this->assertArraySubset(['a' => 'foo'], $response->toArray());
×
54
    }
55

56
    public function testWithServiceProvider(): void
57
    {
58
        $response = self::createClient()->request('GET', 'with_parameters/1?service=blabla');
×
59
        $this->assertArrayNotHasKey('a', $response->toArray());
×
60
    }
61

62
    public function testWithObjectProvider(): void
63
    {
64
        $response = self::createClient()->request('GET', 'with_parameters/1?service=blabla');
×
65
        $this->assertArrayNotHasKey('a', $response->toArray());
×
66
    }
67

68
    public function testWithHeader(): void
69
    {
70
        self::createClient()->request('GET', 'with_parameters/1?service=blabla', ['headers' => ['auth' => 'foo']]);
×
71
        $this->assertResponseStatusCodeSame(403);
×
72
    }
73

74
    public function testDisabled(): void
75
    {
76
        self::createClient()->request('GET', 'with_disabled_parameter_validation');
×
77
        $this->assertResponseStatusCodeSame(200);
×
78
    }
79

80
    /**
81
     * Because of the openapiContext deprecation.
82
     * TODO: only select a few classes to generate the docs for a faster test.
83
     */
84
    #[\PHPUnit\Framework\Attributes\Group('legacy')]
85
    public function testDisableOpenApi(): void
86
    {
87
        $response = self::createClient()->request('GET', 'docs', ['headers' => ['accept' => 'application/vnd.openapi+json']]);
×
88
        $keys = [];
×
89
        foreach ($response->toArray(false)['paths']['/with_parameters/{id}']['get']['parameters'] as $parameter) {
×
90
            $keys[] = $parameter['name'];
×
91
        }
92

93
        $this->assertNotContains('array', $keys);
×
94
    }
95

96
    public function testHeaderAndQuery(): void
97
    {
98
        $response = self::createClient()->request('GET', 'with_parameters_header_and_query?q=blabla', ['headers' => ['q' => '(complex stuff)']]);
×
99
        $this->assertEquals($response->toArray(), [
×
NEW
100
            '(complex stuff)',
×
101
            'blabla',
×
102
        ]);
×
103
    }
104

105
    public function testHeaderParameterRequired(): void
106
    {
107
        self::createClient()->request('GET', 'header_required', ['headers' => ['req' => 'blabla']]);
×
108
        $this->assertResponseStatusCodeSame(200);
×
109

110
        self::createClient()->request('GET', 'header_required', ['headers' => []]);
×
111
        $this->assertResponseStatusCodeSame(422);
×
112
    }
113

114
    #[DataProvider('provideHeaderValues')]
115
    public function testHeaderParameterInteger(string $value, int $expectedStatusCode): void
116
    {
NEW
117
        self::createClient()->request('GET', 'header_integer', ['headers' => ['Foo' => $value]]);
×
NEW
118
        $this->assertResponseStatusCodeSame($expectedStatusCode);
×
119
    }
120

121
    public static function provideHeaderValues(): iterable
122
    {
NEW
123
        yield 'valid integer' => ['3', 200];
×
NEW
124
        yield 'too high' => ['6', 422];
×
NEW
125
        yield 'too low' => ['0', 422];
×
NEW
126
        yield 'invalid integer' => ['string', 422];
×
127
    }
128
}
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