1
// comment
/** doc comment */
Test
XML;
$unserializer = new PHPParser_Unserializer_XML;
$this->assertEquals(
new PHPParser_Node_Scalar_String('Test', array(
'startLine' => 1,
'comments' => array(
new PHPParser_Comment('// comment' . "\n", 2),
new PHPParser_Comment_Doc('/** doc comment */', 3),
),
)),
$unserializer->unserialize($xml)
);
}
public function testEmptyNode() {
$xml = <<
XML;
$unserializer = new PHPParser_Unserializer_XML;
$this->assertEquals(
new PHPParser_Node_Scalar_ClassConst,
$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 or attribute, got node of type "foo:bar"'
),
array(
'',
'Expected node or scalar'
),
);
}
}