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