File tree Expand file tree Collapse file tree 2 files changed +17
-2
lines changed
Expand file tree Collapse file tree 2 files changed +17
-2
lines changed Original file line number Diff line number Diff line change @@ -50,14 +50,17 @@ public function getResult(): ResultInterface
5050 $ this ->convertedResult ->setRawResult ($ this ->rawResult );
5151 }
5252
53- $ this ->convertedResult ->getMetadata ()->merge ($ this ->getMetadata ()->all ());
53+ $ metadata = $ this ->convertedResult ->getMetadata ();
54+ $ metadata ->merge ($ this ->getMetadata ()->all ());
5455
5556 if (null !== $ tokenUsageExtractor = $ this ->resultConverter ->getTokenUsageExtractor ()) {
5657 if (null !== $ tokenUsage = $ tokenUsageExtractor ->extract ($ this ->rawResult , $ this ->options )) {
57- $ this -> convertedResult -> getMetadata () ->add ('token_usage ' , $ tokenUsage );
58+ $ metadata ->add ('token_usage ' , $ tokenUsage );
5859 }
5960 }
6061
62+ $ this ->metadata ->set ($ metadata ->all ());
63+
6164 $ this ->isConverted = true ;
6265 }
6366
Original file line number Diff line number Diff line change @@ -136,6 +136,18 @@ public function testItKeepsResultMetadata()
136136 $ this ->assertSame ('value ' , $ unwrappedResult ->getMetadata ()->get ('key ' ));
137137 }
138138
139+ public function testMetadataGetsPromotedFromUnwrappedResult ()
140+ {
141+ $ result = new TextResult ('Hello World ' );
142+ $ result ->getMetadata ()->add ('foo ' , 'bar ' );
143+ $ converter = new PlainConverter ($ result );
144+
145+ $ deferredResult = new DeferredResult ($ converter , new InMemoryRawResult ());
146+ $ deferredResult ->getResult ();
147+
148+ $ this ->assertSame ('bar ' , $ deferredResult ->getMetadata ()->get ('foo ' ));
149+ }
150+
139151 /**
140152 * Workaround for low deps because mocking the ResponseInterface leads to an exception with
141153 * mock creation "Type Traversable|object|array|string|null contains both object and a class type"
You can’t perform that action at this time.
0 commit comments