File tree Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -28,4 +28,9 @@ public function __construct(
28
28
throw new InvalidArgumentException ('The content shall not be an empty string. ' );
29
29
}
30
30
}
31
+
32
+ public function withContent (string $ content ): self
33
+ {
34
+ return new self ($ this ->id , $ content , $ this ->metadata );
35
+ }
31
36
}
Original file line number Diff line number Diff line change @@ -247,4 +247,22 @@ public function testExceptionMessageIsCorrect()
247
247
248
248
new TextDocument (Uuid::v4 (), ' ' );
249
249
}
250
+
251
+ #[TestDox('withContent creates new instance with updated content ' )]
252
+ public function testWithContent ()
253
+ {
254
+ $ id = Uuid::v4 ();
255
+ $ originalContent = 'Original content ' ;
256
+ $ newContent = 'Updated content ' ;
257
+ $ metadata = new Metadata (['title ' => 'Test Document ' ]);
258
+
259
+ $ originalDocument = new TextDocument ($ id , $ originalContent , $ metadata );
260
+ $ updatedDocument = $ originalDocument ->withContent ($ newContent );
261
+
262
+ $ this ->assertNotSame ($ originalDocument , $ updatedDocument );
263
+ $ this ->assertSame ($ id , $ updatedDocument ->id );
264
+ $ this ->assertSame ($ newContent , $ updatedDocument ->content );
265
+ $ this ->assertSame ($ metadata , $ updatedDocument ->metadata );
266
+ $ this ->assertSame ($ originalContent , $ originalDocument ->content );
267
+ }
250
268
}
You can’t perform that action at this time.
0 commit comments