Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Commit

Permalink
update check setParserProperty to check validity after closed
Browse files Browse the repository at this point in the history
  • Loading branch information
samsonasik authored and Ocramius committed Dec 31, 2014
1 parent f166278 commit 6460047
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 1 deletion.
14 changes: 13 additions & 1 deletion library/Zend/Config/Reader/Xml.php
Expand Up @@ -43,6 +43,19 @@ class Xml implements ReaderInterface
XMLReader::SIGNIFICANT_WHITESPACE
);

/**
* Get reader
*
* @return XMLReader
*/
public function getReader()
{
if ($this->reader === null) {
$this->reader = new XMLReader();
}
return $this->reader;
}

/**
* fromFile(): defined by Reader interface.
*
Expand All @@ -59,7 +72,6 @@ public function fromFile($filename)
$filename
));
}

$this->reader = new XMLReader();
$this->reader->open($filename, null, LIBXML_XINCLUDE);

Expand Down
51 changes: 51 additions & 0 deletions tests/ZendTest/Config/Reader/XmlTest.php
Expand Up @@ -9,6 +9,7 @@

namespace ZendTest\Config\Reader;

use XMLReader;
use Zend\Config\Reader\Xml;

/**
Expand Down Expand Up @@ -121,4 +122,54 @@ public function testElementWithBothAttributesAndAStringValueIsProcessedCorrectly
$this->assertArrayHasKey('_', $arrayXml['one'][1]);
$this->assertEquals('bazbat', $arrayXml['one'][1]['_']);
}

/**
* @group 6761
* @group 6730
*/
public function testCloseWhenCallFromFileReaderGetInvalid()
{
$configReader = new Xml();
$configReader->getReader()->open($this->getTestAssetPath('attributes'));
$configReader->getReader()->setParserProperty(XMLReader::VALIDATE, true);
$this->assertTrue($configReader->getReader()->isValid());

$configReader->fromFile($this->getTestAssetPath('attributes'));
$this->setExpectedException('PHPUnit_Framework_Error_Warning');
$configReader->getReader()->setParserProperty(XMLReader::VALIDATE, true);
}

/**
* @group 6761
* @group 6730
*/
public function testCloseWhenCallFromStringReaderGetInvalid()
{
$xml = <<<ECS
<?xml version="1.0" encoding="UTF-8"?>
<zend-config>
<test>foo</test>
<bar>baz</bar>
<bar>foo</bar>
</zend-config>
ECS;

$configReader = new Xml();
$configReader->getReader()->xml($xml, null, LIBXML_XINCLUDE);
$configReader->getReader()->setParserProperty(XMLReader::VALIDATE, true);
$this->assertTrue($configReader->getReader()->isValid());
$xml = <<<ECS
<?xml version="1.0" encoding="UTF-8"?>
<zend-config>
<test>foo</test>
<bar>baz</bar>
<bar>foo</bar>
</zend-config>
ECS;
$configReader->fromString($xml);
$this->setExpectedException('PHPUnit_Framework_Error_Warning');
$configReader->getReader()->setParserProperty(XMLReader::VALIDATE, true);
}
}

0 comments on commit 6460047

Please sign in to comment.