説明なし

ClosureTest.php 3.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. * Tests for the PHP_Token_FUNCTION class.
  12. *
  13. * @package PHP_TokenStream
  14. * @subpackage Tests
  15. * @author Sebastian Bergmann <sebastian@phpunit.de>
  16. * @copyright Sebastian Bergmann <sebastian@phpunit.de>
  17. * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
  18. * @version Release: @package_version@
  19. * @link http://github.com/sebastianbergmann/php-token-stream/
  20. * @since Class available since Release 1.0.0
  21. */
  22. class PHP_Token_ClosureTest extends PHPUnit_Framework_TestCase
  23. {
  24. protected $functions;
  25. protected function setUp()
  26. {
  27. $ts = new PHP_Token_Stream(TEST_FILES_PATH . 'closure.php');
  28. foreach ($ts as $token) {
  29. if ($token instanceof PHP_Token_FUNCTION) {
  30. $this->functions[] = $token;
  31. }
  32. }
  33. }
  34. /**
  35. * @covers PHP_Token_FUNCTION::getArguments
  36. */
  37. public function testGetArguments()
  38. {
  39. $this->assertEquals(array('$foo' => null, '$bar' => null), $this->functions[0]->getArguments());
  40. $this->assertEquals(array('$foo' => 'Foo', '$bar' => null), $this->functions[1]->getArguments());
  41. $this->assertEquals(array('$foo' => null, '$bar' => null, '$baz' => null), $this->functions[2]->getArguments());
  42. $this->assertEquals(array('$foo' => 'Foo', '$bar' => null, '$baz' => null), $this->functions[3]->getArguments());
  43. $this->assertEquals(array(), $this->functions[4]->getArguments());
  44. $this->assertEquals(array(), $this->functions[5]->getArguments());
  45. }
  46. /**
  47. * @covers PHP_Token_FUNCTION::getName
  48. */
  49. public function testGetName()
  50. {
  51. $this->assertEquals('anonymous function', $this->functions[0]->getName());
  52. $this->assertEquals('anonymous function', $this->functions[1]->getName());
  53. $this->assertEquals('anonymous function', $this->functions[2]->getName());
  54. $this->assertEquals('anonymous function', $this->functions[3]->getName());
  55. $this->assertEquals('anonymous function', $this->functions[4]->getName());
  56. $this->assertEquals('anonymous function', $this->functions[5]->getName());
  57. }
  58. /**
  59. * @covers PHP_Token::getLine
  60. */
  61. public function testGetLine()
  62. {
  63. $this->assertEquals(2, $this->functions[0]->getLine());
  64. $this->assertEquals(3, $this->functions[1]->getLine());
  65. $this->assertEquals(4, $this->functions[2]->getLine());
  66. $this->assertEquals(5, $this->functions[3]->getLine());
  67. }
  68. /**
  69. * @covers PHP_TokenWithScope::getEndLine
  70. */
  71. public function testGetEndLine()
  72. {
  73. $this->assertEquals(2, $this->functions[0]->getLine());
  74. $this->assertEquals(3, $this->functions[1]->getLine());
  75. $this->assertEquals(4, $this->functions[2]->getLine());
  76. $this->assertEquals(5, $this->functions[3]->getLine());
  77. }
  78. }