Skip to content

Commit

Permalink
Fix buffering
Browse files Browse the repository at this point in the history
  • Loading branch information
dmolineus committed Apr 16, 2024
1 parent 79feb82 commit 080ed27
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/WritableXliffDictionary.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ public function beginBuffering(): void
if ($this->buffering) {
throw new RuntimeException('Already buffering.');
}

$this->buffering = true;
}

/**
Expand Down
25 changes: 22 additions & 3 deletions tests/WritableXliffDictionaryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ public function testInstantiation(): void
self::assertSame('de', $dictionary->getTargetLanguage());
self::assertSame(
['test-string-with-only-source', 'test-string-with-source-and-target'],
iterator_to_array($dictionary->keys())
iterator_to_array($dictionary->keys()),
);
self::assertInstanceOf(
XliffTranslationValue::class,
$value = $dictionary->get('test-string-with-only-source')
$value = $dictionary->get('test-string-with-only-source'),
);
self::assertSame('test-string-with-only-source', $value->getKey());
self::assertSame('The source value', $value->getSource());
Expand All @@ -41,7 +41,7 @@ public function testInstantiation(): void

self::assertInstanceOf(
XliffTranslationValue::class,
$value = $dictionary->get('test-string-with-source-and-target')
$value = $dictionary->get('test-string-with-source-and-target'),
);
self::assertSame('test-string-with-source-and-target', $value->getKey());
self::assertSame('The source value', $value->getSource());
Expand Down Expand Up @@ -133,4 +133,23 @@ public function testWritingThrowsForUnknown(): void

$dictionary->getWritable('unknown-key');
}

public function testBuffering(): void
{
$dictionary = new WritableXliffDictionary($this->getTempFile());
$dictionary->beginBuffering();
self::assertTrue($dictionary->isBuffering());
}

public function commitBuffering(): void
{
$dictionary = new WritableXliffDictionary($this->getTempFile());
$dictionary->beginBuffering();
self::assertTrue($dictionary->isBuffering());

$dictionary->add('test');
$dictionary->commitBuffer();

self::assertFalse($dictionary->isBuffering());
}
}

0 comments on commit 080ed27

Please sign in to comment.