Completed
Push — master ( 3f171e...dc1984 )
by Renato
09:39
created

WebAssertTrait::assertTraitExists()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 2
nop 3
dl 0
loc 6
ccs 5
cts 5
cp 1
crap 2
rs 9.4285
1
<?php
2
3
namespace NwLaravel\Testing;
4
5
use Illuminate\Contracts\View;
6
use PHPUnit_Framework_TestCase as PHPUnit;
7
8
trait WebAssertTrait
9
{
10
    /**
11
     * Assert that the response view has name
12
     *
13
     * @param string $name
14
     * @param string $message
15
     */
16 2
    public function assertView($name, $message = '')
17
    {
18 2
        PHPUnit::assertThat($name, new ConstraintView($this->response), $message);
0 ignored issues
show
Bug introduced by
The property response does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
19 1
    }
20
21
    /**
22
     * Assert Trait Exists
23
     *
24
     * @param  string $expected
25
     * @param  Object $object
26
     * @param  string $message
27
     *
28
     * @return void
29
     * @throws
30
     */
31 1
    public function assertTraitExists($expected, $object, $message = '')
32
    {
33 1
        $traits = class_uses($object);
34 1
        $message = $message ?: sprintf("Failed asserting not exists Trait instance of interface '%s'.", $expected);
35 1
        PHPUnit::assertArrayHasKey($expected, $traits, $message);
36 1
    }
37
38
    /**
39
     * Execute method protected
40
     *
41
     * @param object $object Object
42
     * @param string $method Method a Execute
43
     * @param array  $args   Params
44
     */
45 2
    public function callProtectedMethod($object, $method, array $args = array())
46
    {
47 1
        $class = new \ReflectionClass(get_class($object));
48 2
        $method = $class->getMethod($method);
49 1
        $method->setAccessible(true);
50 1
        return $method->invokeArgs($object, $args);
51
    }
52
}
53