Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement buffering #6

Merged
merged 1 commit into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/WritableXliffDictionary.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@
}

if (!file_exists($filename)) {
if ($sourceLanguage) {

Check failure on line 60 in src/WritableXliffDictionary.php

View workflow job for this annotation

GitHub Actions / PHP 8.1

RiskyTruthyFalsyComparison: Operand of type null|string contains type string, which can be falsy and truthy. This can cause possibly unexpected behavior. Use strict comparison instead. (reported by psalm)

Check failure on line 60 in src/WritableXliffDictionary.php

View workflow job for this annotation

GitHub Actions / PHP 8.1

RiskyTruthyFalsyComparison: Operand of type null|string contains type string, which can be falsy and truthy. This can cause possibly unexpected behavior. Use strict comparison instead. (reported by psalm)

Check failure on line 60 in src/WritableXliffDictionary.php

View workflow job for this annotation

GitHub Actions / PHP 8.2

RiskyTruthyFalsyComparison: Operand of type null|string contains type string, which can be falsy and truthy. This can cause possibly unexpected behavior. Use strict comparison instead. (reported by psalm)

Check failure on line 60 in src/WritableXliffDictionary.php

View workflow job for this annotation

GitHub Actions / PHP 8.3

RiskyTruthyFalsyComparison: Operand of type null|string contains type string, which can be falsy and truthy. This can cause possibly unexpected behavior. Use strict comparison instead. (reported by psalm)
$this->setSourceLanguage($sourceLanguage);
}
if ($targetLanguage) {

Check failure on line 63 in src/WritableXliffDictionary.php

View workflow job for this annotation

GitHub Actions / PHP 8.1

RiskyTruthyFalsyComparison: Operand of type null|string contains type string, which can be falsy and truthy. This can cause possibly unexpected behavior. Use strict comparison instead. (reported by psalm)

Check failure on line 63 in src/WritableXliffDictionary.php

View workflow job for this annotation

GitHub Actions / PHP 8.1

RiskyTruthyFalsyComparison: Operand of type null|string contains type string, which can be falsy and truthy. This can cause possibly unexpected behavior. Use strict comparison instead. (reported by psalm)

Check failure on line 63 in src/WritableXliffDictionary.php

View workflow job for this annotation

GitHub Actions / PHP 8.2

RiskyTruthyFalsyComparison: Operand of type null|string contains type string, which can be falsy and truthy. This can cause possibly unexpected behavior. Use strict comparison instead. (reported by psalm)

Check failure on line 63 in src/WritableXliffDictionary.php

View workflow job for this annotation

GitHub Actions / PHP 8.3

RiskyTruthyFalsyComparison: Operand of type null|string contains type string, which can be falsy and truthy. This can cause possibly unexpected behavior. Use strict comparison instead. (reported by psalm)
$this->setTargetLanguage($targetLanguage);
}
$this->markChanged();
Expand Down Expand Up @@ -117,6 +117,8 @@
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());
}
}
Loading