NamespaceTest.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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_NamespaceTest extends TestCase
  12. {
  13. /**
  14. * @covers PHP_Token_NAMESPACE::getName
  15. */
  16. public function testGetName()
  17. {
  18. $tokenStream = new PHP_Token_Stream(
  19. TEST_FILES_PATH . 'classInNamespace.php'
  20. );
  21. foreach ($tokenStream as $token) {
  22. if ($token instanceof PHP_Token_NAMESPACE) {
  23. $this->assertSame('Foo\\Bar', $token->getName());
  24. }
  25. }
  26. }
  27. public function testGetStartLineWithUnscopedNamespace()
  28. {
  29. $tokenStream = new PHP_Token_Stream(TEST_FILES_PATH . 'classInNamespace.php');
  30. foreach ($tokenStream as $token) {
  31. if ($token instanceof PHP_Token_NAMESPACE) {
  32. $this->assertSame(2, $token->getLine());
  33. }
  34. }
  35. }
  36. public function testGetEndLineWithUnscopedNamespace()
  37. {
  38. $tokenStream = new PHP_Token_Stream(TEST_FILES_PATH . 'classInNamespace.php');
  39. foreach ($tokenStream as $token) {
  40. if ($token instanceof PHP_Token_NAMESPACE) {
  41. $this->assertSame(2, $token->getEndLine());
  42. }
  43. }
  44. }
  45. public function testGetStartLineWithScopedNamespace()
  46. {
  47. $tokenStream = new PHP_Token_Stream(TEST_FILES_PATH . 'classInScopedNamespace.php');
  48. foreach ($tokenStream as $token) {
  49. if ($token instanceof PHP_Token_NAMESPACE) {
  50. $this->assertSame(2, $token->getLine());
  51. }
  52. }
  53. }
  54. public function testGetEndLineWithScopedNamespace()
  55. {
  56. $tokenStream = new PHP_Token_Stream(TEST_FILES_PATH . 'classInScopedNamespace.php');
  57. foreach ($tokenStream as $token) {
  58. if ($token instanceof PHP_Token_NAMESPACE) {
  59. $this->assertSame(8, $token->getEndLine());
  60. }
  61. }
  62. }
  63. }