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

api-platform / core / 14955337251

11 May 2025 11:29AM UTC coverage: 7.202% (-1.3%) from 8.457%
14955337251

Pull #7135

github

web-flow
Merge 72523bb00 into 4dd0cdfc4
Pull Request #7135: fix(symfony,laravel): InvalidUriVariableException status code (e400)

1 of 65 new or added lines in 5 files covered. (1.54%)

503 existing lines in 14 files now uncovered.

10846 of 150592 relevant lines covered (7.2%)

3.29 hits per line

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

0.0
/tests/Functional/PullRequests/PullRequest7135Test.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\PullRequests;
15

16
use ApiPlatform\Symfony\Bundle\Test\ApiTestCase;
17
use ApiPlatform\Tests\Fixtures\TestBundle\Entity\PullRequest7135\Bar;
18
use ApiPlatform\Tests\Fixtures\TestBundle\Entity\PullRequest7135\Foo;
19
use ApiPlatform\Tests\RecreateSchemaTrait;
20
use ApiPlatform\Tests\SetupClassResourcesTrait;
21
use Doctrine\ORM\EntityManagerInterface;
22
use Doctrine\ORM\Tools\SchemaTool;
23
use Symfony\Component\Uid\Uuid;
24

25
class PullRequest7135Test extends ApiTestCase
26
{
27
    use RecreateSchemaTrait;
28
    use SetupClassResourcesTrait;
29

30
    protected static ?bool $alwaysBootKernel = false;
31

32
    /**
33
     * @return class-string[]
34
     */
35
    public static function getResources(): array
36
    {
NEW
37
        return [Bar::class, Foo::class];
×
38
    }
39

40
    public function testValidPostRequestWithIriWhenIdentifierIsUuid(): void
41
    {
NEW
42
        $container = static::getContainer();
×
NEW
43
        if ('mongodb' === $container->getParameter('kernel.environment')) {
×
NEW
44
            $this->markTestSkipped();
×
45
        }
46

NEW
47
        $this->recreateSchema(self::getResources());
×
NEW
48
        $bar = $this->loadBarFixture();
×
49

NEW
50
        $response = self::createClient()->request('POST', '/pull-request-7135/foo/', [
×
NEW
51
            'json' => [
×
NEW
52
                'bar' => 'pull-request-7135/bar/'.$bar->id,
×
NEW
53
            ],
×
NEW
54
        ]);
×
55

NEW
56
        self::assertEquals(201, $response->getStatusCode());
×
57
    }
58

59
    public function testInvalidPostRequestWithIriWhenIdentifierIsUuid(): void
60
    {
NEW
61
        $container = static::getContainer();
×
NEW
62
        if ('mongodb' === $container->getParameter('kernel.environment')) {
×
NEW
63
            $this->markTestSkipped();
×
64
        }
65

NEW
66
        $response = self::createClient()->request('POST', '/pull-request-7135/foo/', [
×
NEW
67
            'json' => [
×
NEW
68
                'bar' => 'pull-request-7135/bar/invalid-uuid',
×
NEW
69
            ],
×
NEW
70
        ]);
×
71

NEW
72
        self::assertEquals(400, $response->getStatusCode());
×
NEW
73
        self::assertJsonContains(['detail' => 'Identifier "id" could not be transformed.']);
×
74
    }
75

76
    public function testInvalidGetRequestWhenIdentifierIsUuid(): void
77
    {
NEW
78
        $container = static::getContainer();
×
NEW
79
        if ('mongodb' === $container->getParameter('kernel.environment')) {
×
NEW
80
            $this->markTestSkipped();
×
81
        }
82

NEW
83
        $response = self::createClient()->request('GET', '/pull-request-7135/bar/invalid-uuid');
×
84

NEW
85
        self::assertEquals(404, $response->getStatusCode());
×
86
    }
87

88
    protected function loadBarFixture(): Bar
89
    {
NEW
90
        $container = static::getContainer();
×
NEW
91
        $registry = $container->get('doctrine');
×
NEW
92
        $manager = $registry->getManager();
×
93

NEW
94
        $bar = new Bar(Uuid::fromString('0196b66f-66bd-780b-95fe-0ce987a32357'));
×
NEW
95
        $bar->title = 'Bar one';
×
NEW
96
        $manager->persist($bar);
×
97

NEW
98
        $manager->flush();
×
99

NEW
100
        return $bar;
×
101
    }
102

103
    protected function tearDown(): void
104
    {
NEW
105
        $container = static::getContainer();
×
NEW
106
        $registry = $container->get('doctrine');
×
NEW
107
        $manager = $registry->getManager();
×
NEW
108
        if (!$manager instanceof EntityManagerInterface) {
×
NEW
109
            return;
×
110
        }
111

NEW
112
        $classes = [];
×
NEW
113
        foreach (self::getResources() as $entityClass) {
×
NEW
114
            $classes[] = $manager->getClassMetadata($entityClass);
×
115
        }
116

NEW
117
        $schemaTool = new SchemaTool($manager);
×
NEW
118
        @$schemaTool->dropSchema($classes);
×
NEW
119
        parent::tearDown();
×
120
    }
121
}
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