Passed
Push — master ( 67253e...1a1f73 )
by Arthur
04:53 queued 11s
created

HelpersTest::testUnauthenticatedUserHelper()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: arthur
5
 * Date: 03.10.18
6
 * Time: 22:58.
7
 */
8
9
namespace Foundation\Tests;
10
11
use Foundation\Abstracts\Tests\CreatesApplication;
12
use Foundation\Abstracts\Tests\TestCase;
13
use Illuminate\Contracts\Auth\Authenticatable;
14
use Illuminate\Contracts\Filesystem\Filesystem;
15
use Illuminate\Foundation\Auth\Access\Authorizable;
16
use Modules\User\Entities\User;
17
use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException;
18
19
class HelpersTest extends TestCase
20
{
21
    public function testClassImplementsHelper()
22
    {
23
        $this->assertFalse(classImplementsInterface(self::class, Filesystem::class));
24
        $this->assertTrue(classImplementsInterface(self::class, \PHPUnit\Framework\Test::class));
25
        $this->assertFalse(classImplementsInterface(new HelpersTest(), Filesystem::class));
26
        $this->assertTrue(classImplementsInterface(new HelpersTest(), \PHPUnit\Framework\Test::class));
27
    }
28
29
    public function testUnauthenticatedUserHelper()
30
    {
31
        $this->expectException(UnauthorizedHttpException::class);
32
        getAuthenticatedUser();
33
    }
34
35
    public function testAuthenticatedUserHelper()
36
    {
37
        $this->actingAs(factory(User::class)->make());
0 ignored issues
show
Bug introduced by
It seems like factory(Modules\User\Ent...es\User::class)->make() can also be of type Illuminate\Database\Eloquent\Model; however, parameter $user of Illuminate\Foundation\Testing\TestCase::actingAs() does only seem to accept Illuminate\Contracts\Auth\Authenticatable, maybe add an additional type check? ( Ignorable by Annotation )

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

37
        $this->actingAs(/** @scrutinizer ignore-type */ factory(User::class)->make());
Loading history...
38
        $this->assertTrue(classImplementsInterface(getAuthenticatedUser(), Authenticatable::class));
39
    }
40
41
    public function testClassShortNameHelper()
42
    {
43
        $this->assertEquals('HelpersTest', getShortClassName(self::class));
44
    }
45
46
    public function testRandomArrayElementHelper()
47
    {
48
        $array = [
49
            "test",
50
            "x",
51
            "blabla",
52
            "hello",
53
            "hey"
54
        ];
55
56
        $randomArrayElement = getRandomArrayElement($array);
57
58
        $this->assertContains($randomArrayElement, $array);
59
    }
60
61
    public function testClassUsesTraitHelper()
62
    {
63
        $this->assertTrue(classUsesTrait(self::class, CreatesApplication::class));
64
        $this->assertFalse(classUsesTrait(self::class, Authorizable::class));
65
    }
66
}
67