UriPatternsTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testItShouldBeARequestMatcher() 0 4 1
A testItShouldAllowUrisThatPassesOneOfTheExpressions() 0 5 1
A provideMatchingUris() 0 8 1
A testItShouldDenyUrisThatPassesNoneOfTheExpressions() 0 5 1
A provideNonMatchingUris() 0 7 1
1
<?php
2
namespace DkplusTest\CsrfApiUnprotectionBundle\UnprotectionRule;
3
4
use Dkplus\CsrfApiUnprotectionBundle\UnprotectionRule\UnprotectionRule;
5
use Dkplus\CsrfApiUnprotectionBundle\UnprotectionRule\UriPatterns;
6
use PHPUnit_Framework_TestCase as TestCase;
7
use Symfony\Component\HttpFoundation\Request;
8
9
/**
10
 * @covers Dkplus\CsrfApiUnprotectionBundle\UnprotectionRule\UriPatterns
11
 */
12
class UriPatternsTest extends TestCase
13
{
14
    public function testItShouldBeARequestMatcher()
15
    {
16
        $this->assertInstanceOf(UnprotectionRule::class, new UriPatterns([]));
17
    }
18
19
    /**
20
     * @dataProvider provideMatchingUris
21
     *
22
     * @param string $uri
23
     */
24
    public function testItShouldAllowUrisThatPassesOneOfTheExpressions($uri)
25
    {
26
        $rule = new UriPatterns(['/^\/api\/.*$/', '/^\/app_dev.php\/api\/.*$/']);
27
        $this->assertTrue($rule->matches(Request::create($uri)));
28
    }
29
30
    public static function provideMatchingUris()
31
    {
32
        return [
33
            ['/api/'],
34
            ['/app_dev.php/api/'],
35
            ['/api/foo/bar'],
36
        ];
37
    }
38
39
    /**
40
     * @dataProvider provideNonMatchingUris
41
     *
42
     * @param string $uri
43
     */
44
    public function testItShouldDenyUrisThatPassesNoneOfTheExpressions($uri)
45
    {
46
        $rule = new UriPatterns(['/^\/api\/.*$/', '/^\/app_dev.php\/api\/.*$/']);
47
        $this->assertFalse($rule->matches(Request::create($uri)));
48
    }
49
50
    public static function provideNonMatchingUris()
51
    {
52
        return [
53
            ['/app_test.php\/api/'],
54
            ['/apis/foo/bar'],
55
        ];
56
    }
57
}
58