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