Completed
Push — master ( ba7c5d...c3b626 )
by Julián
02:08
created

tests/Janitor/Excluder/BasicAuthTest.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * Effortless maintenance management (http://juliangut.com/janitor)
4
 *
5
 * @link https://github.com/juliangut/janitor for the canonical source repository
6
 *
7
 * @license https://github.com/juliangut/janitor/blob/master/LICENSE
8
 */
9
10
namespace Janitor\Test\Excluder;
11
12
use Janitor\Excluder\BasicAuth;
13
use Zend\Diactoros\ServerRequestFactory;
14
15
/**
16
 * @covers \Janitor\Excluder\BasicAuth
17
 */
18
class BasicAuthTest extends \PHPUnit_Framework_TestCase
19
{
20
    protected $excludedUsers = [
21
        'root' => 'secret',
22
        'guest' => null,
23
    ];
24
25
    /**
26
     * @covers \Janitor\Excluder\BasicAuth::addUser
27
     * @covers \Janitor\Excluder\BasicAuth::isExcluded
28
     * @covers \Janitor\Excluder\BasicAuth::getAuth
29
     *
30
     * @dataProvider usersProvider
31
     */
32
    public function testIsExcluded($username, $password)
33
    {
34
        $authString = $username . ($password === null ? '' : ':' . $password);
35
36
        $request = ServerRequestFactory::fromGlobals();
37
        $request = $request->withHeader('Authorization', 'Basic ' . base64_encode($authString));
38
39
        $excluder = new BasicAuth();
40
        $excluder->addUser($username, $password);
41
42
        $this->assertTrue($excluder->isExcluded($request));
43
    }
44
45
    /**
46
     * Users provider.
47
     *
48
     * @return array
0 ignored issues
show
Consider making the return type a bit more specific; maybe use array<string|null>[].

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
49
     */
50
    public function usersProvider()
51
    {
52
        return [
53
            ['root', 'secret'],
54
            ['guest', null],
55
        ];
56
    }
57
58
    /**
59
     * @covers \Janitor\Excluder\BasicAuth::__construct
60
     * @covers \Janitor\Excluder\BasicAuth::isExcluded
61
     * @covers \Janitor\Excluder\BasicAuth::getAuth
62
     */
63
    public function testIsNotExcluded()
64
    {
65
        $request = ServerRequestFactory::fromGlobals();
66
        $excluder = new BasicAuth(['root' => 'secret']);
67
68
        $this->assertFalse($excluder->isExcluded($request));
69
    }
70
}
71