15
15
16
16
use ApiPlatform \GraphQl \Serializer \SerializerContextBuilderInterface ;
17
17
use ApiPlatform \GraphQl \State \Provider \ReadProvider ;
18
+ use ApiPlatform \Metadata \Exception \ItemNotFoundException ;
18
19
use ApiPlatform \Metadata \GraphQl \Query ;
19
20
use ApiPlatform \Metadata \GraphQl \QueryCollection ;
20
21
use ApiPlatform \Metadata \IriConverterInterface ;
@@ -36,6 +37,26 @@ public function testProvide(): void
36
37
$ provider ->provide ($ operation , [], $ context );
37
38
}
38
39
40
+ /**
41
+ * Tests that provider returns null if resource is not found.
42
+ *
43
+ * @see https://github.com/api-platform/core/issues/6072
44
+ */
45
+ public function testProvideNotExistedResource (): void
46
+ {
47
+ $ context = ['args ' => ['id ' => '/dummy/1 ' ]];
48
+ $ operation = new Query (class: 'dummy ' );
49
+ $ decorated = $ this ->createMock (ProviderInterface::class);
50
+ $ iriConverter = $ this ->createMock (IriConverterInterface::class);
51
+ $ iriConverter ->expects ($ this ->once ())->method ('getResourceFromIri ' )->with ('/dummy/1 ' );
52
+ $ iriConverter ->method ('getResourceFromIri ' )->willThrowException (new ItemNotFoundException ());
53
+ $ serializerContextBuilder = $ this ->createMock (SerializerContextBuilderInterface::class);
54
+ $ provider = new ReadProvider ($ decorated , $ iriConverter , $ serializerContextBuilder , '. ' );
55
+ $ result = $ provider ->provide ($ operation , [], $ context );
56
+
57
+ $ this ->assertNull ($ result );
58
+ }
59
+
39
60
public function testProvideCollection (): void
40
61
{
41
62
$ info = $ this ->createMock (ResolveInfo::class);
0 commit comments