Repository navigation
Expand file tree
/
Copy pathMergePatchMapsTest.php
More file actions
63 lines (50 loc) · 2.04 KB
/
Copy pathMergePatchMapsTest.php
File metadata and controls
63 lines (50 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
/*
* This file is part of the API Platform project.
*
* (c) Kévin Dunglas <dunglas@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace ApiPlatform\Tests\Functional\Serializer;
use ApiPlatform\Test\ApiTestCase;
use ApiPlatform\Tests\Fixtures\TestBundle\ApiResource\Settings;
use ApiPlatform\Tests\SetupClassResourcesTrait;
final class MergePatchMapsTest extends ApiTestCase
{
use SetupClassResourcesTrait;
protected static ?bool $alwaysBootKernel = false;
public static function getResources(): array
{
return [Settings::class];
}
public function testMergePatchMergesMapWhenOptedIn(): void
{
$response = self::createClient()->request('PATCH', '/merge_patch_settings/1', [
'headers' => ['Content-Type' => 'application/merge-patch+json'],
'json' => ['settings' => ['b' => null, 'c' => ['d' => 1]]],
]);
$this->assertResponseStatusCodeSame(200);
$this->assertSame(['a' => 1, 'c' => ['e' => 2, 'd' => 1]], $response->toArray()['settings']);
}
public function testMergePatchValidatesMergedMap(): void
{
self::createClient()->request('PATCH', '/merge_patch_settings/1', [
'headers' => ['Content-Type' => 'application/merge-patch+json'],
'json' => ['settings' => ['x' => 1]],
]);
$this->assertResponseStatusCodeSame(422);
$this->assertJsonContains(['violations' => [['propertyPath' => 'settings']]]);
}
public function testMergePatchReplacesMapWithoutOptIn(): void
{
$response = self::createClient()->request('PATCH', '/merge_patch_settings/1/replace', [
'headers' => ['Content-Type' => 'application/merge-patch+json'],
'json' => ['settings' => ['b' => null, 'c' => ['d' => 1]]],
]);
$this->assertResponseStatusCodeSame(200);
$this->assertSame(['b' => null, 'c' => ['d' => 1]], $response->toArray()['settings']);
}
}