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

api-platform / core / 18343625207

08 Oct 2025 11:48AM UTC coverage: 24.542% (-0.02%) from 24.561%
18343625207

push

github

web-flow
fix(state): object mapper on delete operation (#7447)

fixes #7434

1 of 49 new or added lines in 2 files covered. (2.04%)

7084 existing lines in 207 files now uncovered.

14004 of 57061 relevant lines covered (24.54%)

26.01 hits per line

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

0.0
/src/State/Tests/Processor/ObjectMapperProcessorTest.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\Processor;
15

16
use ApiPlatform\Metadata\Get;
17
use ApiPlatform\Metadata\Post;
18
use ApiPlatform\State\Processor\ObjectMapperProcessor;
19
use ApiPlatform\State\ProcessorInterface;
20
use PHPUnit\Framework\TestCase;
21
use Symfony\Component\ObjectMapper\Attribute\Map;
22
use Symfony\Component\ObjectMapper\ObjectMapperInterface;
23

24
class ObjectMapperProcessorTest extends TestCase
25
{
26
    public function testProcessBypassesWhenNoObjectMapper(): void
27
    {
NEW
28
        $data = new DummyResourceWithoutMap();
×
NEW
29
        $operation = new Post(class: DummyResourceWithoutMap::class);
×
NEW
30
        $decorated = $this->createMock(ProcessorInterface::class);
×
NEW
31
        $decorated->expects($this->once())
×
NEW
32
            ->method('process')
×
NEW
33
            ->with($data, $operation, [], [])
×
NEW
34
            ->willReturn($data);
×
35

NEW
36
        $processor = new ObjectMapperProcessor(null, $decorated);
×
NEW
37
        $this->assertEquals($data, $processor->process($data, $operation));
×
38
    }
39

40
    public function testProcessBypassesOnNonWriteOperation(): void
41
    {
NEW
42
        $data = new DummyResourceWithoutMap();
×
NEW
43
        $operation = new Get(class: DummyResourceWithoutMap::class);
×
NEW
44
        $objectMapper = $this->createMock(ObjectMapperInterface::class);
×
NEW
45
        $decorated = $this->createMock(ProcessorInterface::class);
×
NEW
46
        $decorated->expects($this->once())
×
NEW
47
            ->method('process')
×
NEW
48
            ->with($data, $operation, [], [])
×
NEW
49
            ->willReturn($data);
×
50

NEW
51
        $processor = new ObjectMapperProcessor($objectMapper, $decorated);
×
NEW
52
        $this->assertEquals($data, $processor->process($data, $operation));
×
53
    }
54

55
    public function testProcessBypassesWithNullData(): void
56
    {
NEW
57
        $operation = new Post(class: DummyResourceWithoutMap::class);
×
NEW
58
        $objectMapper = $this->createMock(ObjectMapperInterface::class);
×
NEW
59
        $decorated = $this->createMock(ProcessorInterface::class);
×
NEW
60
        $decorated->expects($this->once())
×
NEW
61
            ->method('process')
×
NEW
62
            ->with(null, $operation, [], [])
×
NEW
63
            ->willReturn(null);
×
64

NEW
65
        $processor = new ObjectMapperProcessor($objectMapper, $decorated);
×
NEW
66
        $this->assertNull($processor->process(null, $operation));
×
67
    }
68

69
    public function testProcessBypassesWithMismatchedDataType(): void
70
    {
NEW
71
        $data = new \stdClass();
×
NEW
72
        $operation = new Post(class: DummyResourceWithMap::class);
×
NEW
73
        $objectMapper = $this->createMock(ObjectMapperInterface::class);
×
NEW
74
        $decorated = $this->createMock(ProcessorInterface::class);
×
NEW
75
        $decorated->expects($this->once())
×
NEW
76
            ->method('process')
×
NEW
77
            ->with($data, $operation, [], [])
×
NEW
78
            ->willReturn($data);
×
79

NEW
80
        $processor = new ObjectMapperProcessor($objectMapper, $decorated);
×
NEW
81
        $this->assertEquals($data, $processor->process($data, $operation));
×
82
    }
83

84
    public function testProcessBypassesWithoutMapAttribute(): void
85
    {
NEW
86
        $data = new DummyResourceWithoutMap();
×
NEW
87
        $operation = new Post(class: DummyResourceWithoutMap::class);
×
NEW
88
        $objectMapper = $this->createMock(ObjectMapperInterface::class);
×
NEW
89
        $decorated = $this->createMock(ProcessorInterface::class);
×
NEW
90
        $decorated->expects($this->once())
×
NEW
91
            ->method('process')
×
NEW
92
            ->with($data, $operation, [], [])
×
NEW
93
            ->willReturn($data);
×
94

NEW
95
        $processor = new ObjectMapperProcessor($objectMapper, $decorated);
×
NEW
96
        $this->assertEquals($data, $processor->process($data, $operation));
×
97
    }
98
}
99

100
class DummyResourceWithoutMap
101
{
102
}
103

104
#[Map]
105
class DummyResourceWithMap
106
{
107
}
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