Authentication   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 13
c 0
b 0
f 0
dl 0
loc 51
rs 10
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A logout() 0 3 1
A loginAs() 0 7 1
A assertLoggedIn() 0 5 1
A assertNotLoggedIn() 0 5 1
A assertLoggedInAs() 0 5 1
1
<?php
2
3
namespace Zenstruck\Browser\Extension;
4
5
/**
6
 * This is a basic authentication extension more for an example. You will
7
 * likely need to create your own authentication extension or override
8
 * these methods.
9
 *
10
 * @author Kevin Bond <[email protected]>
11
 */
12
trait Authentication
13
{
14
    /**
15
     * @return static
16
     */
17
    public function loginAs(string $username, string $password): self
18
    {
19
        return $this
20
            ->visit('/login')
0 ignored issues
show
Bug introduced by
It seems like visit() 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

20
            ->/** @scrutinizer ignore-call */ visit('/login')
Loading history...
21
            ->fillField('email', $username)
22
            ->fillField('password', $password)
23
            ->click('Login')
24
        ;
25
    }
26
27
    /**
28
     * @return static
29
     */
30
    public function logout(): self
31
    {
32
        return $this->visit('/logout');
33
    }
34
35
    /**
36
     * @return static
37
     */
38
    public function assertLoggedIn(): self
39
    {
40
        $this->assertSee('Logout');
0 ignored issues
show
Bug introduced by
It seems like assertSee() 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

40
        $this->/** @scrutinizer ignore-call */ 
41
               assertSee('Logout');
Loading history...
41
42
        return $this;
43
    }
44
45
    /**
46
     * @return static
47
     */
48
    public function assertLoggedInAs(string $user): self
49
    {
50
        $this->assertSee($user);
51
52
        return $this;
53
    }
54
55
    /**
56
     * @return static
57
     */
58
    public function assertNotLoggedIn(): self
59
    {
60
        $this->assertSee('Login');
61
62
        return $this;
63
    }
64
}
65