File tree 2 files changed +37
-0
lines changed
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)
221
221
return $ this ->metadata [$ key ] ?? null ;
222
222
}
223
223
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
+
224
237
/**
225
238
* To array.
226
239
*
Original file line number Diff line number Diff line change @@ -121,4 +121,28 @@ public function testCreateValidIndex(): void
121
121
$ this ->assertEquals ([], $ index3 ->getMetadata ());
122
122
$ this ->assertEquals ([], $ index3 ->getFields ());
123
123
}
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
+ }
124
148
}
You can’t perform that action at this time.
0 commit comments