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_ClosureTest extends PHPUnit_Framework_TestCase
27 protected function setUp()
29 $ts = new PHP_Token_Stream(TEST_FILES_PATH . 'closure.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('$foo' => null, '$bar' => null), $this->functions[0]->getArguments());
44 $this->assertEquals(array('$foo' => 'Foo', '$bar' => null), $this->functions[1]->getArguments());
45 $this->assertEquals(array('$foo' => null, '$bar' => null, '$baz' => null), $this->functions[2]->getArguments());
46 $this->assertEquals(array('$foo' => 'Foo', '$bar' => null, '$baz' => null), $this->functions[3]->getArguments());
47 $this->assertEquals(array(), $this->functions[4]->getArguments());
48 $this->assertEquals(array(), $this->functions[5]->getArguments());
52 * @covers PHP_Token_FUNCTION::getName
54 public function testGetName()
56 $this->assertEquals('anonymous function', $this->functions[0]->getName());
57 $this->assertEquals('anonymous function', $this->functions[1]->getName());
58 $this->assertEquals('anonymous function', $this->functions[2]->getName());
59 $this->assertEquals('anonymous function', $this->functions[3]->getName());
60 $this->assertEquals('anonymous function', $this->functions[4]->getName());
61 $this->assertEquals('anonymous function', $this->functions[5]->getName());
65 * @covers PHP_Token::getLine
67 public function testGetLine()
69 $this->assertEquals(2, $this->functions[0]->getLine());
70 $this->assertEquals(3, $this->functions[1]->getLine());
71 $this->assertEquals(4, $this->functions[2]->getLine());
72 $this->assertEquals(5, $this->functions[3]->getLine());
76 * @covers PHP_TokenWithScope::getEndLine
78 public function testGetEndLine()
80 $this->assertEquals(2, $this->functions[0]->getLine());
81 $this->assertEquals(3, $this->functions[1]->getLine());
82 $this->assertEquals(4, $this->functions[2]->getLine());
83 $this->assertEquals(5, $this->functions[3]->getLine());