ClosureTest.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. /*
  3. * This file is part of php-token-stream.
  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. use PHPUnit\Framework\TestCase;
  11. class PHP_Token_ClosureTest extends TestCase
  12. {
  13. /**
  14. * @var PHP_Token_FUNCTION[]
  15. */
  16. private $functions;
  17. protected function setUp()
  18. {
  19. $ts = new PHP_Token_Stream(TEST_FILES_PATH . 'closure.php');
  20. foreach ($ts as $token) {
  21. if ($token instanceof PHP_Token_FUNCTION) {
  22. $this->functions[] = $token;
  23. }
  24. }
  25. }
  26. /**
  27. * @covers PHP_Token_FUNCTION::getArguments
  28. */
  29. public function testGetArguments()
  30. {
  31. $this->assertEquals(['$foo' => null, '$bar' => null], $this->functions[0]->getArguments());
  32. $this->assertEquals(['$foo' => 'Foo', '$bar' => null], $this->functions[1]->getArguments());
  33. $this->assertEquals(['$foo' => null, '$bar' => null, '$baz' => null], $this->functions[2]->getArguments());
  34. $this->assertEquals(['$foo' => 'Foo', '$bar' => null, '$baz' => null], $this->functions[3]->getArguments());
  35. $this->assertEquals([], $this->functions[4]->getArguments());
  36. $this->assertEquals([], $this->functions[5]->getArguments());
  37. }
  38. /**
  39. * @covers PHP_Token_FUNCTION::getName
  40. */
  41. public function testGetName()
  42. {
  43. $this->assertEquals('anonymousFunction:2#5', $this->functions[0]->getName());
  44. $this->assertEquals('anonymousFunction:3#27', $this->functions[1]->getName());
  45. $this->assertEquals('anonymousFunction:4#51', $this->functions[2]->getName());
  46. $this->assertEquals('anonymousFunction:5#71', $this->functions[3]->getName());
  47. $this->assertEquals('anonymousFunction:6#93', $this->functions[4]->getName());
  48. $this->assertEquals('anonymousFunction:7#106', $this->functions[5]->getName());
  49. }
  50. /**
  51. * @covers PHP_Token::getLine
  52. */
  53. public function testGetLine()
  54. {
  55. $this->assertEquals(2, $this->functions[0]->getLine());
  56. $this->assertEquals(3, $this->functions[1]->getLine());
  57. $this->assertEquals(4, $this->functions[2]->getLine());
  58. $this->assertEquals(5, $this->functions[3]->getLine());
  59. }
  60. /**
  61. * @covers PHP_TokenWithScope::getEndLine
  62. */
  63. public function testGetEndLine()
  64. {
  65. $this->assertEquals(2, $this->functions[0]->getLine());
  66. $this->assertEquals(3, $this->functions[1]->getLine());
  67. $this->assertEquals(4, $this->functions[2]->getLine());
  68. $this->assertEquals(5, $this->functions[3]->getLine());
  69. }
  70. }