Server IP : 127.0.0.2 / Your IP : 3.148.252.90 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/Builder/ |
Upload File : |
<?php namespace PhpParser\Builder; use PhpParser\Comment; use PhpParser\Node; use PhpParser\Node\Expr\Print_; use PhpParser\Node\Scalar\String_; use PhpParser\Node\Stmt; class MethodTest extends \PHPUnit_Framework_TestCase { public function createMethodBuilder($name) { return new Method($name); } public function testModifiers() { $node = $this->createMethodBuilder('test') ->makePublic() ->makeAbstract() ->makeStatic() ->getNode() ; $this->assertEquals( new Stmt\ClassMethod('test', array( 'flags' => Stmt\Class_::MODIFIER_PUBLIC | Stmt\Class_::MODIFIER_ABSTRACT | Stmt\Class_::MODIFIER_STATIC, 'stmts' => null, )), $node ); $node = $this->createMethodBuilder('test') ->makeProtected() ->makeFinal() ->getNode() ; $this->assertEquals( new Stmt\ClassMethod('test', array( 'flags' => Stmt\Class_::MODIFIER_PROTECTED | Stmt\Class_::MODIFIER_FINAL )), $node ); $node = $this->createMethodBuilder('test') ->makePrivate() ->getNode() ; $this->assertEquals( new Stmt\ClassMethod('test', array( 'type' => Stmt\Class_::MODIFIER_PRIVATE )), $node ); } public function testReturnByRef() { $node = $this->createMethodBuilder('test') ->makeReturnByRef() ->getNode() ; $this->assertEquals( new Stmt\ClassMethod('test', array( 'byRef' => true )), $node ); } public function testParams() { $param1 = new Node\Param('test1'); $param2 = new Node\Param('test2'); $param3 = new Node\Param('test3'); $node = $this->createMethodBuilder('test') ->addParam($param1) ->addParams(array($param2, $param3)) ->getNode() ; $this->assertEquals( new Stmt\ClassMethod('test', array( 'params' => array($param1, $param2, $param3) )), $node ); } public function testStmts() { $stmt1 = new Print_(new String_('test1')); $stmt2 = new Print_(new String_('test2')); $stmt3 = new Print_(new String_('test3')); $node = $this->createMethodBuilder('test') ->addStmt($stmt1) ->addStmts(array($stmt2, $stmt3)) ->getNode() ; $this->assertEquals( new Stmt\ClassMethod('test', array( 'stmts' => array($stmt1, $stmt2, $stmt3) )), $node ); } public function testDocComment() { $node = $this->createMethodBuilder('test') ->setDocComment('/** Test */') ->getNode(); $this->assertEquals(new Stmt\ClassMethod('test', array(), array( 'comments' => array(new Comment\Doc('/** Test */')) )), $node); } public function testReturnType() { $node = $this->createMethodBuilder('test') ->setReturnType('bool') ->getNode(); $this->assertEquals(new Stmt\ClassMethod('test', array( 'returnType' => 'bool' ), array()), $node); } /** * @expectedException \LogicException * @expectedExceptionMessage Cannot add statements to an abstract method */ public function testAddStmtToAbstractMethodError() { $this->createMethodBuilder('test') ->makeAbstract() ->addStmt(new Print_(new String_('test'))) ; } /** * @expectedException \LogicException * @expectedExceptionMessage Cannot make method with statements abstract */ public function testMakeMethodWithStmtsAbstractError() { $this->createMethodBuilder('test') ->addStmt(new Print_(new String_('test'))) ->makeAbstract() ; } /** * @expectedException \LogicException * @expectedExceptionMessage Expected parameter node, got "Name" */ public function testInvalidParamError() { $this->createMethodBuilder('test') ->addParam(new Node\Name('foo')) ; } }