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