File: TypeNameTest.php

package info (click to toggle)
phpunit-type 6.0.3-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 34,184 kB
  • sloc: php: 13,462; xml: 61; makefile: 16
file content (62 lines) | stat: -rw-r--r-- 2,256 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php declare(strict_types=1);
/*
 * This file is part of sebastian/type.
 *
 * (c) Sebastian Bergmann <sebastian@phpunit.de>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
namespace SebastianBergmann\Type;

use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Small;
use PHPUnit\Framework\TestCase;
use ReflectionClass;
use stdClass;

#[CoversClass(TypeName::class)]
#[Small]
final class TypeNameTest extends TestCase
{
    public function testFromReflection(): void
    {
        $class    = new ReflectionClass(TypeName::class);
        $typeName = TypeName::fromReflection($class);

        $this->assertTrue($typeName->isNamespaced());
        $this->assertSame('SebastianBergmann\\Type', $typeName->namespaceName());
        $this->assertSame(TypeName::class, $typeName->qualifiedName());
        $this->assertSame('TypeName', $typeName->simpleName());
    }

    public function testFromQualifiedName(): void
    {
        $typeName = TypeName::fromQualifiedName(self::class);

        $this->assertTrue($typeName->isNamespaced());
        $this->assertSame('SebastianBergmann\\Type', $typeName->namespaceName());
        $this->assertSame('SebastianBergmann\\Type\\TypeNameTest', $typeName->qualifiedName());
        $this->assertSame('TypeNameTest', $typeName->simpleName());
    }

    public function testFromQualifiedNameWithLeadingSeparator(): void
    {
        $typeName = TypeName::fromQualifiedName('\\' . self::class);

        $this->assertTrue($typeName->isNamespaced());
        $this->assertSame('SebastianBergmann\\Type', $typeName->namespaceName());
        $this->assertSame('SebastianBergmann\\Type\\TypeNameTest', $typeName->qualifiedName());
        $this->assertSame('TypeNameTest', $typeName->simpleName());
    }

    public function testFromQualifiedNameWithoutNamespace(): void
    {
        $typeName = TypeName::fromQualifiedName(stdClass::class);

        $this->assertFalse($typeName->isNamespaced());
        $this->assertNull($typeName->namespaceName());
        $this->assertSame(stdClass::class, $typeName->qualifiedName());
        $this->assertSame(stdClass::class, $typeName->simpleName());
    }
}