Skip to content

Commit 2676547

Browse files
committed
feature #479 [Store] Add with TextDocument::withContent method (OskarStark)
This PR was merged into the main branch. Discussion ---------- [Store] Add with `TextDocument::withContent` method | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | Docs? | no | Issues | Helpful for #465 | License | MIT Commits ------- 4a3014f [Store] Add withContent method to TextDocument with test
2 parents dcc4318 + 4a3014f commit 2676547

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/store/src/Document/TextDocument.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,9 @@ public function __construct(
2828
throw new InvalidArgumentException('The content shall not be an empty string.');
2929
}
3030
}
31+
32+
public function withContent(string $content): self
33+
{
34+
return new self($this->id, $content, $this->metadata);
35+
}
3136
}

src/store/tests/Document/TextDocumentTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,4 +247,22 @@ public function testExceptionMessageIsCorrect()
247247

248248
new TextDocument(Uuid::v4(), ' ');
249249
}
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+
}
250268
}

0 commit comments

Comments
 (0)