ClosureTest.php (3131B)
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_ClosureTest extends PHPUnit_Framework_TestCase 24 { 25 protected $functions; 26 27 protected function setUp() 28 { 29 $ts = new PHP_Token_Stream(TEST_FILES_PATH . 'closure.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('$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()); 49 } 50 51 /** 52 * @covers PHP_Token_FUNCTION::getName 53 */ 54 public function testGetName() 55 { 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()); 62 } 63 64 /** 65 * @covers PHP_Token::getLine 66 */ 67 public function testGetLine() 68 { 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()); 73 } 74 75 /** 76 * @covers PHP_TokenWithScope::getEndLine 77 */ 78 public function testGetEndLine() 79 { 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()); 84 } 85 }