WebAssertTrait   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 45
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 2

3 Methods

Rating   Name   Duplication   Size   Complexity  
A assertView() 0 4 1
A assertTraitExists() 0 6 2
A callProtectedMethod() 0 7 1
1
<?php
2
3
namespace NwLaravel\Testing;
4
5
use Illuminate\Contracts\View;
6
use PHPUnit_Framework_TestCase as PHPUnit;
7
8
/**
9
  * @property object $response
10
  */
11
trait WebAssertTrait
12
{
13
    /**
14
     * Assert that the response view has name
15
     *
16
     * @param string $name
17
     * @param string $message
18
     */
19 2
    public function assertView($name, $message = '')
20
    {
21 2
        PHPUnit::assertThat($name, new ConstraintView($this->response), $message);
22 1
    }
23
24
    /**
25
     * Assert Trait Exists
26
     *
27
     * @param string $expected
28
     * @param Object $object
29
     * @param string $message
30
     *
31
     * @return void
32
     * @throws
33
     */
34 1
    public function assertTraitExists($expected, $object, $message = '')
35
    {
36 1
        $traits = class_uses($object);
37 1
        $message = $message ?: sprintf("Failed asserting not exists Trait instance of interface '%s'.", $expected);
38 1
        PHPUnit::assertArrayHasKey($expected, $traits, $message);
39 1
    }
40
41
    /**
42
     * Execute method protected
43
     *
44
     * @param object $object Object
45
     * @param string $method Method a Execute
46
     * @param array  $args   Params
47
     */
48 1
    public function callProtectedMethod($object, $method, array $args = array())
49
    {
50 1
        $class = new \ReflectionClass(get_class($object));
51 1
        $method = $class->getMethod($method);
52 1
        $method->setAccessible(true);
53 1
        return $method->invokeArgs($object, $args);
54
    }
55
}
56