SecureTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 3

Importance

Changes 0
Metric Value
wmc 5
lcom 2
cbo 3
dl 0
loc 50
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setup() 0 23 1
A testAuthorizedUser() 0 5 1
A testUnauthorizedUser() 0 4 1
A testAuthorizedUserCollection() 0 5 1
A testUnauthorizedUserCollection() 0 4 1
1
<?php
2
/**
3
 * This file is part of the silex-annotation-provider package.
4
 * For the full copyright and license information, please view the LICENSE
5
 * file that was distributed with this source code.
6
 *
7
 * @license       MIT License
8
 * @copyright (c) 2018, Dana Desrosiers <[email protected]>
9
 */
10
11
namespace DDesrosiers\Test\SilexAnnotations\Annotations;
12
13
use DDesrosiers\Test\SilexAnnotations\AnnotationTestBase;
14
use Silex\Provider\SecurityServiceProvider;
15
16
class SecureTest extends AnnotationTestBase
17
{
18
    protected $authRequestOptions = array('PHP_AUTH_USER' => 'admin', 'PHP_AUTH_PW' => 'foo');
19
20
    public function setup()
21
    {
22
        parent::setup();
23
24
        $this->app->register(
25
                  new SecurityServiceProvider(),
26
                      array(
27
                          'security.firewalls' => array(
28
                              'admin' => array(
29
                                  'pattern' => '^/test',
30
                                  'http'    => true,
31
                                  'users'   => array(
32
                                      // raw password is foo
33
                                      'admin' => array(
34
                                          'ROLE_ADMIN',
35
                                          '$2y$15$lzUNsTegNXvZW3qtfucV0erYBcEqWVeyOmjolB7R1uodsAVJ95vvu'
36
                                      ),
37
                                  ),
38
                              ),
39
                          )
40
                      )
41
        );
42
    }
43
44
    public function testAuthorizedUser()
45
    {
46
        $this->requestOptions = $this->authRequestOptions;
47
        $this->assertEndPointStatus(self::GET_METHOD, "/test/secure", self::STATUS_OK);
48
    }
49
50
    public function testUnauthorizedUser()
51
    {
52
        $this->assertEndPointStatus(self::GET_METHOD, "/test/secure", self::STATUS_UNAUTHORIZED);
53
    }
54
55
    public function testAuthorizedUserCollection()
56
    {
57
        $this->requestOptions = $this->authRequestOptions;
58
        $this->assertEndPointStatus(self::GET_METHOD, "/testSecure/test", self::STATUS_OK);
59
    }
60
61
    public function testUnauthorizedUserCollection()
62
    {
63
        $this->assertEndPointStatus(self::GET_METHOD, "/testSecure/test", self::STATUS_UNAUTHORIZED);
64
    }
65
}
66