Geen omschrijving

ClosureTest.php 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. foreach (new PHP_Token_Stream(TEST_FILES_PATH . 'closure.php') as $token) {
  20. if ($token instanceof PHP_Token_FUNCTION) {
  21. $this->functions[] = $token;
  22. }
  23. }
  24. }
  25. public function testGetArguments()
  26. {
  27. $this->assertEquals(['$foo' => null, '$bar' => null], $this->functions[0]->getArguments());
  28. $this->assertEquals(['$foo' => 'Foo', '$bar' => null], $this->functions[1]->getArguments());
  29. $this->assertEquals(['$foo' => null, '$bar' => null, '$baz' => null], $this->functions[2]->getArguments());
  30. $this->assertEquals(['$foo' => 'Foo', '$bar' => null, '$baz' => null], $this->functions[3]->getArguments());
  31. $this->assertEquals([], $this->functions[4]->getArguments());
  32. $this->assertEquals([], $this->functions[5]->getArguments());
  33. }
  34. public function testGetName()
  35. {
  36. $this->assertEquals('anonymousFunction:2#5', $this->functions[0]->getName());
  37. $this->assertEquals('anonymousFunction:3#27', $this->functions[1]->getName());
  38. $this->assertEquals('anonymousFunction:4#51', $this->functions[2]->getName());
  39. $this->assertEquals('anonymousFunction:5#71', $this->functions[3]->getName());
  40. $this->assertEquals('anonymousFunction:6#93', $this->functions[4]->getName());
  41. $this->assertEquals('anonymousFunction:7#106', $this->functions[5]->getName());
  42. }
  43. public function testGetLine()
  44. {
  45. $this->assertEquals(2, $this->functions[0]->getLine());
  46. $this->assertEquals(3, $this->functions[1]->getLine());
  47. $this->assertEquals(4, $this->functions[2]->getLine());
  48. $this->assertEquals(5, $this->functions[3]->getLine());
  49. }
  50. public function testGetEndLine()
  51. {
  52. $this->assertEquals(2, $this->functions[0]->getLine());
  53. $this->assertEquals(3, $this->functions[1]->getLine());
  54. $this->assertEquals(4, $this->functions[2]->getLine());
  55. $this->assertEquals(5, $this->functions[3]->getLine());
  56. }
  57. }