Passed
Push — master ( 4ed61c...14fd45 )
by Jakub
57s queued 13s
created

ClassNamespaceTest::must_have_method()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 0
dl 0
loc 10
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace Comquer\ReflectionTest;
4
5
use Comquer\Reflection\ClassName\ClassName;
6
use Comquer\Reflection\ClassName\ClassNameException;
7
use Comquer\ReflectionTest\Fixture\Animal\Animal;
8
use Comquer\ReflectionTest\Fixture\Animal\Cat;
9
use Comquer\ReflectionTest\Fixture\Animal\PersianCat;
10
use Comquer\ReflectionTest\Fixture\Sample\SampleClass;
11
use PHPUnit\Framework\TestCase;
12
13
class ClassNamespaceTest extends TestCase
14
{
15
    /** @test */
16
    function instantiate_with_valid_class_namespace()
1 ignored issue
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
17
    {
18
        self::assertInstanceOf(
19
            ClassName::class,
20
            new ClassName(SampleClass::class)
21
        );
22
    }
23
24
    /** @test */
25
    function cant_instantiate_with_interface_namespace()
26
    {
27
        $className = 'This\ClassDoes\Not\Exist';
28
29
        $exception = ClassNameException::classDoesNotExist($className);
30
        $this->expectException(get_class($exception));
31
        $this->expectExceptionMessage($exception->getMessage());
32
33
        new ClassName($className);
34
    }
35
36
    /** @test */
37
    function get_parents()
38
    {
39
        $persianCatClass = new ClassName(PersianCat::class);
40
        $parents = $persianCatClass->getParents();
41
42
        self::assertCount(2, $parents);
43
        self::assertTrue($parents->get(Cat::class)->equals(new ClassName(Cat::class)));
44
        self::assertTrue($parents->get(Animal::class)->equals(new ClassName(Animal::class)));
45
    }
46
47
    /** @test */
48
    function must_have_method()
49
    {
50
        $sampleClass = new ClassName(SampleClass::class);
51
        $sampleClass->mustHaveMethod('getSample');
52
53
        $exception = ClassNameException::missingMethod((string) $sampleClass, 'missingMethod');
54
        $this->expectException(get_class($exception));
55
        $this->expectExceptionMessage($exception->getMessage());
56
57
        $sampleClass->mustHaveMethod('missingMethod');
58
    }
59
}