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

ClassNamespaceTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 20
dl 0
loc 45
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A must_have_method() 0 10 1
A get_parents() 0 8 1
A instantiate_with_valid_class_namespace() 0 5 1
A cant_instantiate_with_interface_namespace() 0 9 1
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
}