1
// comment
/** doc comment */
Test
XML;
$unserializer = new XML;
$this->assertEquals(
new Scalar\String('Test', array(
'startLine' => 1,
'comments' => array(
new Comment('// comment' . "\n", 2),
new Comment\Doc('/** doc comment */', 3),
),
)),
$unserializer->unserialize($xml)
);
}
public function testEmptyNode() {
$xml = <<
XML;
$unserializer = new XML;
$this->assertEquals(
new Scalar\MagicConst\Class_,
$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 XML;
$this->assertEquals($result, $unserializer->unserialize($xml));
}
/**
* @expectedException \DomainException
* @expectedExceptionMessage AST root element not found
*/
public function testWrongRootElementError() {
$xml = <<
XML;
$unserializer = new XML;
$unserializer->unserialize($xml);
}
/**
* @dataProvider provideTestErrors
*/
public function testErrors($xml, $errorMsg) {
$this->setExpectedException('DomainException', $errorMsg);
$xml = <<
$xml
XML;
$unserializer = new 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'
),
array(
'',
'Unknown node type "Foo"'
),
);
}
}