You are here

public function PoStreamWriterTest::testWriteItem in Drupal 9

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/Component/Gettext/PoStreamWriterTest.php \Drupal\Tests\Component\Gettext\PoStreamWriterTest::testWriteItem()

@covers ::writeItem @dataProvider providerWriteData

File

core/tests/Drupal/Tests/Component/Gettext/PoStreamWriterTest.php, line 60

Class

PoStreamWriterTest
@coversDefaultClass \Drupal\Component\Gettext\PoStreamWriter @group Gettext

Namespace

Drupal\Tests\Component\Gettext

Code

public function testWriteItem($poContent, $expected, $long) {
  if ($long) {
    $this
      ->expectException(\Exception::class, 'Unable to write data:');
  }

  // Limit the file system quota to make the write fail on long strings.
  vfsStream::setQuota(10);
  $this->poWriter
    ->setURI($this->poFile
    ->url());
  $this->poWriter
    ->open();
  $poItem = $this
    ->prophesize(PoItem::class);
  $poItem
    ->__toString()
    ->willReturn($poContent);
  $this->poWriter
    ->writeItem($poItem
    ->reveal());
  $this->poWriter
    ->close();
  $this
    ->assertEquals(file_get_contents($this->poFile
    ->url()), $expected);
}