20
20
use ApiPlatform \Metadata \Get ;
21
21
use ApiPlatform \Tests \Fixtures \TestBundle \Entity \Foo ;
22
22
use Elasticsearch \Client ;
23
- use Elasticsearch \Common \Exceptions \Missing404Exception ;
24
23
use PHPUnit \Framework \TestCase ;
25
24
use Prophecy \PhpUnit \ProphecyTrait ;
26
25
use Symfony \Component \Serializer \Normalizer \AbstractNormalizer ;
@@ -55,7 +54,6 @@ public function testGetItem(): void
55
54
'_index ' => 'foo ' ,
56
55
'_type ' => '_doc ' ,
57
56
'_id ' => '1 ' ,
58
- '_version ' => 1 ,
59
57
'found ' => true ,
60
58
'_source ' => [
61
59
'id ' => 1 ,
@@ -69,7 +67,7 @@ public function testGetItem(): void
69
67
$ foo ->setBar ('erèinissor ' );
70
68
71
69
$ clientProphecy = $ this ->prophesize (Client::class);
72
- $ clientProphecy ->get (['index ' => 'foo ' , 'id ' => '1 ' ])->willReturn ($ document )->shouldBeCalled ();
70
+ $ clientProphecy ->get (['client ' => [ ' ignore ' => 404 ], ' index ' => 'foo ' , 'id ' => '1 ' ])->willReturn ($ document )->shouldBeCalled ();
73
71
74
72
$ denormalizerProphecy = $ this ->prophesize (DenormalizerInterface::class);
75
73
$ denormalizerProphecy ->denormalize ($ document , Foo::class, DocumentNormalizer::FORMAT , [AbstractNormalizer::ALLOW_EXTRA_ATTRIBUTES => true ])->willReturn ($ foo )->shouldBeCalled ();
@@ -79,13 +77,18 @@ public function testGetItem(): void
79
77
self ::assertSame ($ foo , $ itemDataProvider ->provide ((new Get ())->withClass (Foo::class), ['id ' => 1 ]));
80
78
}
81
79
82
- public function testGetItemWithMissing404Exception (): void
80
+ public function testGetInexistantItem (): void
83
81
{
84
82
$ documentMetadataFactoryProphecy = $ this ->prophesize (DocumentMetadataFactoryInterface::class);
85
83
$ documentMetadataFactoryProphecy ->create (Foo::class)->willReturn (new DocumentMetadata ('foo ' ))->shouldBeCalled ();
86
84
87
85
$ clientProphecy = $ this ->prophesize (Client::class);
88
- $ clientProphecy ->get (['index ' => 'foo ' , 'id ' => '404 ' ])->willThrow (new Missing404Exception ())->shouldBeCalled ();
86
+ $ clientProphecy ->get (['client ' => ['ignore ' => 404 ], 'index ' => 'foo ' , 'id ' => '404 ' ])->willReturn ([
87
+ '_index ' => 'foo ' ,
88
+ '_type ' => '_doc ' ,
89
+ '_id ' => '404 ' ,
90
+ 'found ' => false ,
91
+ ])->shouldBeCalled ();
89
92
90
93
$ itemDataProvider = new ItemProvider ($ clientProphecy ->reveal (), $ documentMetadataFactoryProphecy ->reveal (), $ this ->prophesize (DenormalizerInterface::class)->reveal ());
91
94
0 commit comments