This repository was archived by the owner on Jun 25, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -221,6 +221,19 @@ public function getMetadataValue(string $key)
221221 return $ this ->metadata [$ key ] ?? null ;
222222 }
223223
224+ /**
225+ * With metadata value. Useful for metadata completion across layers.
226+ *
227+ * @param string $key
228+ * @param mixed $value
229+ */
230+ public function withMetadataValue (
231+ string $ key ,
232+ $ value
233+ ) {
234+ $ this ->metadata [$ key ] = $ value ;
235+ }
236+
224237 /**
225238 * To array.
226239 *
Original file line number Diff line number Diff line change @@ -121,4 +121,28 @@ public function testCreateValidIndex(): void
121121 $ this ->assertEquals ([], $ index3 ->getMetadata ());
122122 $ this ->assertEquals ([], $ index3 ->getFields ());
123123 }
124+
125+ /**
126+ * Test with metadata value.
127+ */
128+ public function testWithMetadataValue ()
129+ {
130+ $ index = Index::createFromArray ([
131+ 'uuid ' => [
132+ 'id ' => 'testId ' ,
133+ ],
134+ 'app_id ' => [
135+ 'id ' => 'testAppId ' ,
136+ ],
137+ 'is_ok ' => true ,
138+ 'doc_count ' => 10 ,
139+ 'size ' => '1kb ' ,
140+ ]);
141+
142+ $ this ->assertNull ($ index ->getMetadataValue ('key1 ' ));
143+ $ index ->withMetadataValue ('key1 ' , 'val1 ' );
144+ $ this ->assertEquals ('val1 ' , $ index ->getMetadataValue ('key1 ' ));
145+ $ index = Index::createFromArray ($ index ->toArray ());
146+ $ this ->assertEquals ('val1 ' , $ index ->getMetadataValue ('key1 ' ));
147+ }
124148}
You can’t perform that action at this time.
0 commit comments