No Description

NamespaceTest.php 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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_NAMESPACE 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_NamespaceTest extends PHPUnit_Framework_TestCase
  23. {
  24. /**
  25. * @covers PHP_Token_NAMESPACE::getName
  26. */
  27. public function testGetName()
  28. {
  29. $tokenStream = new PHP_Token_Stream(
  30. TEST_FILES_PATH . 'classInNamespace.php'
  31. );
  32. foreach ($tokenStream as $token) {
  33. if ($token instanceof PHP_Token_NAMESPACE) {
  34. $this->assertSame('Foo\\Bar', $token->getName());
  35. }
  36. }
  37. }
  38. public function testGetStartLineWithUnscopedNamespace()
  39. {
  40. $tokenStream = new PHP_Token_Stream(TEST_FILES_PATH . 'classInNamespace.php');
  41. foreach($tokenStream as $token) {
  42. if($token instanceOf PHP_Token_NAMESPACE) {
  43. $this->assertSame(2, $token->getLine());
  44. }
  45. }
  46. }
  47. public function testGetEndLineWithUnscopedNamespace()
  48. {
  49. $tokenStream = new PHP_Token_Stream(TEST_FILES_PATH . 'classInNamespace.php');
  50. foreach($tokenStream as $token) {
  51. if($token instanceOf PHP_Token_NAMESPACE) {
  52. $this->assertSame(2, $token->getEndLine());
  53. }
  54. }
  55. }
  56. public function testGetStartLineWithScopedNamespace()
  57. {
  58. $tokenStream = new PHP_Token_Stream(TEST_FILES_PATH . 'classInScopedNamespace.php');
  59. foreach($tokenStream as $token) {
  60. if($token instanceOf PHP_Token_NAMESPACE) {
  61. $this->assertSame(2, $token->getLine());
  62. }
  63. }
  64. }
  65. public function testGetEndLineWithScopedNamespace()
  66. {
  67. $tokenStream = new PHP_Token_Stream(TEST_FILES_PATH . 'classInScopedNamespace.php');
  68. foreach($tokenStream as $token) {
  69. if($token instanceOf PHP_Token_NAMESPACE) {
  70. $this->assertSame(8, $token->getEndLine());
  71. }
  72. }
  73. }
  74. }