Passed
Push — master ( 459b12...1ddf5f )
by Stephen
08:09 queued 05:53
created

InterfaceTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 46
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A interface_is_implemented() 0 4 2
A interface_exist() 0 3 1
A interface_methods_exist() 0 4 2
1
<?php
2
3
namespace Sfneal\Testing\Utils\Traits;
4
5
trait InterfaceTest
6
{
7
    // todo: add tests
8
9
    /** @test */
10
    public function interface_exist()
11
    {
12
        $this->assertTrue(interface_exists($this->interface()));
0 ignored issues
show
Bug introduced by
It seems like assertTrue() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

12
        $this->/** @scrutinizer ignore-call */ 
13
               assertTrue(interface_exists($this->interface()));
Loading history...
13
    }
14
15
    /** @test */
16
    public function interface_is_implemented()
17
    {
18
        foreach ($this->classes() as $class) {
19
            $this->assertArrayHasKey($this->interface(), class_implements($class));
0 ignored issues
show
Bug introduced by
It seems like assertArrayHasKey() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

19
            $this->/** @scrutinizer ignore-call */ 
20
                   assertArrayHasKey($this->interface(), class_implements($class));
Loading history...
20
        }
21
    }
22
23
    /** @test */
24
    public function interface_methods_exist()
25
    {
26
        foreach ($this->methods() as $method) {
27
            $this->assertTrue(method_exists($this->interface(), $method));
28
        }
29
    }
30
31
    /**
32
     * Retrieve the interface class that should be tested.
33
     *
34
     * @return string
35
     */
36
    abstract public function interface(): string;
37
38
    /**
39
     * Retrieve an array of classes that should implement the interface.
40
     *
41
     * @return array
42
     */
43
    abstract public function classes(): array;
44
45
    /**
46
     * Retrieve an array of method names that should exist in the interface.
47
     *
48
     * @return array
49
     */
50
    abstract public function methods(): array;
51
}
52