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

api-platform / core / 13999305480

21 Mar 2025 07:18PM UTC coverage: 8.515% (+0.001%) from 8.514%
13999305480

push

github

soyuka
docs: changelog 4.1.2

13386 of 157201 relevant lines covered (8.52%)

22.91 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

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

24
    protected static ?bool $alwaysBootKernel = false;
25

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

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

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

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

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

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

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

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

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

91
        $this->assertNotContains('array', $keys);
×
92
    }
93

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

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

108
        self::createClient()->request('GET', 'header_required', ['headers' => []]);
×
109
        $this->assertResponseStatusCodeSame(422);
×
110
    }
111
}
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