gluon-web-remote

Web remote Administration for big size of gluon routers
git clone git://archive.git.mtrnord.blog/MTRNord/gluon-web-remote.git
Log | Files | Refs | README

FunctionTest.php (4466B)


      1 <?php
      2 /*
      3  * This file is part of the PHP_TokenStream package.
      4  *
      5  * (c) Sebastian Bergmann <sebastian@phpunit.de>
      6  *
      7  * For the full copyright and license information, please view the LICENSE
      8  * file that was distributed with this source code.
      9  */
     10 
     11 /**
     12  * Tests for the PHP_Token_FUNCTION class.
     13  *
     14  * @package    PHP_TokenStream
     15  * @subpackage Tests
     16  * @author     Sebastian Bergmann <sebastian@phpunit.de>
     17  * @copyright  Sebastian Bergmann <sebastian@phpunit.de>
     18  * @license    http://www.opensource.org/licenses/BSD-3-Clause  The BSD 3-Clause License
     19  * @version    Release: @package_version@
     20  * @link       http://github.com/sebastianbergmann/php-token-stream/
     21  * @since      Class available since Release 1.0.0
     22  */
     23 class PHP_Token_FunctionTest extends PHPUnit_Framework_TestCase
     24 {
     25     protected $functions;
     26 
     27     protected function setUp()
     28     {
     29         $ts = new PHP_Token_Stream(TEST_FILES_PATH . 'source.php');
     30 
     31         foreach ($ts as $token) {
     32             if ($token instanceof PHP_Token_FUNCTION) {
     33                 $this->functions[] = $token;
     34             }
     35         }
     36     }
     37 
     38     /**
     39      * @covers PHP_Token_FUNCTION::getArguments
     40      */
     41     public function testGetArguments()
     42     {
     43         $this->assertEquals(array(), $this->functions[0]->getArguments());
     44 
     45         $this->assertEquals(
     46           array('$baz' => 'Baz'), $this->functions[1]->getArguments()
     47         );
     48 
     49         $this->assertEquals(
     50           array('$foobar' => 'Foobar'), $this->functions[2]->getArguments()
     51         );
     52 
     53         $this->assertEquals(
     54           array('$barfoo' => 'Barfoo'), $this->functions[3]->getArguments()
     55         );
     56 
     57         $this->assertEquals(array(), $this->functions[4]->getArguments());
     58 
     59         $this->assertEquals(array('$x' => null, '$y' => null), $this->functions[5]->getArguments());
     60     }
     61 
     62     /**
     63      * @covers PHP_Token_FUNCTION::getName
     64      */
     65     public function testGetName()
     66     {
     67         $this->assertEquals('foo', $this->functions[0]->getName());
     68         $this->assertEquals('bar', $this->functions[1]->getName());
     69         $this->assertEquals('foobar', $this->functions[2]->getName());
     70         $this->assertEquals('barfoo', $this->functions[3]->getName());
     71         $this->assertEquals('baz', $this->functions[4]->getName());
     72     }
     73 
     74     /**
     75      * @covers PHP_Token::getLine
     76      */
     77     public function testGetLine()
     78     {
     79         $this->assertEquals(5, $this->functions[0]->getLine());
     80         $this->assertEquals(10, $this->functions[1]->getLine());
     81         $this->assertEquals(17, $this->functions[2]->getLine());
     82         $this->assertEquals(21, $this->functions[3]->getLine());
     83         $this->assertEquals(29, $this->functions[4]->getLine());
     84     }
     85 
     86     /**
     87      * @covers PHP_TokenWithScope::getEndLine
     88      */
     89     public function testGetEndLine()
     90     {
     91         $this->assertEquals(5, $this->functions[0]->getEndLine());
     92         $this->assertEquals(12, $this->functions[1]->getEndLine());
     93         $this->assertEquals(19, $this->functions[2]->getEndLine());
     94         $this->assertEquals(23, $this->functions[3]->getEndLine());
     95         $this->assertEquals(31, $this->functions[4]->getEndLine());
     96     }
     97 
     98     /**
     99      * @covers PHP_Token_FUNCTION::getDocblock
    100      */
    101     public function testGetDocblock()
    102     {
    103         $this->assertNull($this->functions[0]->getDocblock());
    104 
    105         $this->assertEquals(
    106           "/**\n     * @param Baz \$baz\n     */",
    107           $this->functions[1]->getDocblock()
    108         );
    109 
    110         $this->assertEquals(
    111           "/**\n     * @param Foobar \$foobar\n     */",
    112           $this->functions[2]->getDocblock()
    113         );
    114 
    115         $this->assertNull($this->functions[3]->getDocblock());
    116         $this->assertNull($this->functions[4]->getDocblock());
    117     }
    118 
    119     public function testSignature()
    120     {
    121         $ts = new PHP_Token_Stream(TEST_FILES_PATH . 'source5.php');
    122         $f  = $ts->getFunctions();
    123         $c  = $ts->getClasses();
    124         $i  = $ts->getInterfaces();
    125 
    126         $this->assertEquals(
    127           'foo($a, array $b, array $c = array())',
    128           $f['foo']['signature']
    129         );
    130 
    131         $this->assertEquals(
    132           'm($a, array $b, array $c = array())',
    133           $c['c']['methods']['m']['signature']
    134         );
    135 
    136         $this->assertEquals(
    137           'm($a, array $b, array $c = array())',
    138           $c['a']['methods']['m']['signature']
    139         );
    140 
    141         $this->assertEquals(
    142           'm($a, array $b, array $c = array())',
    143           $i['i']['methods']['m']['signature']
    144         );
    145     }
    146 }