Chris@0: poWriter = new PoStreamWriter(); Chris@0: Chris@0: $root = vfsStream::setup(); Chris@0: $this->poFile = new vfsStreamFile('powriter.po'); Chris@0: $root->addChild($this->poFile); Chris@0: } Chris@0: Chris@0: /** Chris@0: * @covers ::getURI Chris@0: */ Chris@0: public function testGetUriException() { Chris@0: if (method_exists($this, 'expectException')) { Chris@0: $this->expectException(\Exception::class, 'No URI set.'); Chris@0: } Chris@0: else { Chris@0: $this->setExpectedException(\Exception::class, 'No URI set.'); Chris@0: } Chris@0: Chris@0: $this->poWriter->getURI(); Chris@0: } Chris@0: Chris@0: /** Chris@0: * @covers ::writeItem Chris@0: * @dataProvider providerWriteData Chris@0: */ Chris@0: public function testWriteItem($poContent, $expected, $long) { Chris@0: if ($long) { Chris@0: if (method_exists($this, 'expectException')) { Chris@0: $this->expectException(\Exception::class, 'Unable to write data:'); Chris@0: } Chris@0: else { Chris@0: $this->setExpectedException(\Exception::class, 'Unable to write data:'); Chris@0: } Chris@0: } Chris@0: Chris@0: // Limit the file system quota to make the write fail on long strings. Chris@0: vfsStream::setQuota(10); Chris@0: Chris@0: $this->poWriter->setURI($this->poFile->url()); Chris@0: $this->poWriter->open(); Chris@0: Chris@0: $poItem = $this->prophesize(PoItem::class); Chris@0: $poItem->__toString()->willReturn($poContent); Chris@0: Chris@0: $this->poWriter->writeItem($poItem->reveal()); Chris@0: $this->poWriter->close(); Chris@0: $this->assertEquals(file_get_contents($this->poFile->url()), $expected); Chris@0: } Chris@0: Chris@0: /** Chris@0: * @return array Chris@0: * - Content to write. Chris@0: * - Written content. Chris@0: * - Content longer than 10 bytes. Chris@0: */ Chris@0: public function providerWriteData() { Chris@0: return [ Chris@0: ['', '', FALSE], Chris@0: ["\r\n", "\r\n", FALSE], Chris@0: ['write this if you can', 'write this', TRUE], Chris@0: ['éáíó>&', 'éáíó>&', FALSE], Chris@0: ['éáíó>&<', 'éáíó>&', TRUE], Chris@0: ['中文 890', '中文 890', FALSE], Chris@0: ['中文 89012', '中文 890', TRUE], Chris@0: ]; Chris@0: } Chris@0: Chris@0: /** Chris@0: * @covers ::close Chris@0: */ Chris@0: public function testCloseException() { Chris@0: if (method_exists($this, 'expectException')) { Chris@0: $this->expectException(\Exception::class, 'Cannot close stream that is not open.'); Chris@0: } Chris@0: else { Chris@0: $this->setExpectedException(\Exception::class, 'Cannot close stream that is not open.'); Chris@0: } Chris@0: Chris@0: $this->poWriter->close(); Chris@0: } Chris@0: Chris@0: }