Test
XML;
$unserializer = new PHPParser_Unserializer_XML;
$this->assertEquals(
new PHPParser_Node_Scalar_String('Test', 1, '/** doc comment */'),
$unserializer->unserialize($xml)
);
}
public function testScalars() {
$xml = <<
test
1
1
1.5
XML;
$result = array(
array(), array(),
'test', '', '',
1,
1, 1.5,
true, false, null
);
$unserializer = new PHPParser_Unserializer_XML;
$this->assertEquals($result, $unserializer->unserialize($xml));
}
/**
* @expectedException DomainException
* @expectedExceptionMessage AST root element not found
*/
public function testWrongRootElementError() {
$xml = <<
XML;
$unserializer = new PHPParser_Unserializer_XML;
$unserializer->unserialize($xml);
}
/**
* @dataProvider provideTestErrors
*/
public function testErrors($xml, $errorMsg) {
$this->setExpectedException('DomainException', $errorMsg);
$xml = <<
$xml
XML;
$unserializer = new PHPParser_Unserializer_XML;
$unserializer->unserialize($xml);
}
public function provideTestErrors() {
return array(
array('test', '"true" scalar must be empty'),
array('test', '"false" scalar must be empty'),
array('test', '"null" scalar must be empty'),
array('bar', 'Unknown scalar type "foo"'),
array('x', '"x" is not a valid int'),
array('x', '"x" is not a valid float'),
array('', 'Expected node or scalar'),
array('test', 'Unexpected node of type "foo:bar"'),
array(
'test',
'Expected sub node, got node of type "foo:bar"'
),
array(
'',
'Expected node or scalar'
),
);
}
}