Nessuna descrizione

NamespaceTest.php 1.8KB

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