3 * This file is part of the PHP_TokenStream package.
5 * (c) Sebastian Bergmann <sebastian@phpunit.de>
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
12 * Tests for the PHP_Token_FUNCTION class.
14 * @package PHP_TokenStream
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
23 class PHP_Token_FunctionTest extends PHPUnit_Framework_TestCase
27 protected function setUp()
29 $ts = new PHP_Token_Stream(TEST_FILES_PATH . 'source.php');
31 foreach ($ts as $token) {
32 if ($token instanceof PHP_Token_FUNCTION) {
33 $this->functions[] = $token;
39 * @covers PHP_Token_FUNCTION::getArguments
41 public function testGetArguments()
43 $this->assertEquals(array(), $this->functions[0]->getArguments());
46 array('$baz' => 'Baz'), $this->functions[1]->getArguments()
50 array('$foobar' => 'Foobar'), $this->functions[2]->getArguments()
54 array('$barfoo' => 'Barfoo'), $this->functions[3]->getArguments()
57 $this->assertEquals(array(), $this->functions[4]->getArguments());
59 $this->assertEquals(array('$x' => null, '$y' => null), $this->functions[5]->getArguments());
63 * @covers PHP_Token_FUNCTION::getName
65 public function testGetName()
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());
75 * @covers PHP_Token::getLine
77 public function testGetLine()
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());
87 * @covers PHP_TokenWithScope::getEndLine
89 public function testGetEndLine()
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());
99 * @covers PHP_Token_FUNCTION::getDocblock
101 public function testGetDocblock()
103 $this->assertNull($this->functions[0]->getDocblock());
106 "/**\n * @param Baz \$baz\n */",
107 $this->functions[1]->getDocblock()
111 "/**\n * @param Foobar \$foobar\n */",
112 $this->functions[2]->getDocblock()
115 $this->assertNull($this->functions[3]->getDocblock());
116 $this->assertNull($this->functions[4]->getDocblock());
119 public function testSignature()
121 $ts = new PHP_Token_Stream(TEST_FILES_PATH . 'source5.php');
122 $f = $ts->getFunctions();
123 $c = $ts->getClasses();
124 $i = $ts->getInterfaces();
127 'foo($a, array $b, array $c = array())',
128 $f['foo']['signature']
132 'm($a, array $b, array $c = array())',
133 $c['c']['methods']['m']['signature']
137 'm($a, array $b, array $c = array())',
138 $c['a']['methods']['m']['signature']
142 'm($a, array $b, array $c = array())',
143 $i['i']['methods']['m']['signature']