RegexParserTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 28
dl 0
loc 44
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testParse() 0 10 1
A setUp() 0 3 1
A parseDataProvider() 0 20 1
1
<?php
2
3
/*
4
 *
5
 * (c) Yaroslav Honcharuk <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Yarhon\RouteGuardBundle\Tests\Security\Http;
12
13
use PHPUnit\Framework\TestCase;
14
use Yarhon\RouteGuardBundle\Security\Http\RegexParser;
15
16
/**
17
 * @author Yaroslav Honcharuk <[email protected]>
18
 */
19
class RegexParserTest extends TestCase
20
{
21
    private $parser;
22
23
    public function setUp()
24
    {
25
        $this->parser = new RegexParser();
26
    }
27
28
    /**
29
     * @dataProvider parseDataProvider
30
     */
31
    public function testParse($pattern, $expected)
32
    {
33
        $expected = array_combine([
34
            'hasStringStartAssert',
35
            'hasStringEndAssert',
36
            'dynamicPartIsWildcard',
37
            'staticPrefix',
38
        ], $expected);
39
40
        $this->assertEquals($expected, $this->parser->parse($pattern));
41
    }
42
43
    public function parseDataProvider()
44
    {
45
        return [
46
            ['^foo$', [true, true, false, 'foo']],
47
            ['^foo\\$', [true, false, true, 'foo$']],
48
            ['foo', [false, false, true, 'foo']],
49
            ['\\\\', [false, false, true, '\\']],
50
            ['\\.\\+\\*\\?\\|\\^\\$\\[\\]\\(\\)\\{\\}\\d+', [false, false, false, '.+*?|^$[](){}']],
51
            ['foo(bar)', [false, false, false, 'foo']],
52
            ['foo[bar]', [false, false, false, 'foo']],
53
            ['foo.', [false, false, false, 'foo']],
54
            ['foo\\bar', [false, false, false, 'foo']],
55
            ['foob{1}', [false, false, false, 'foo']],
56
            ['foob+', [false, false, false, 'foo']],
57
            ['foob*', [false, false, false, 'foo']],
58
            ['foob?', [false, false, false, 'foo']],
59
            ['foob|c', [false, false, false, 'foo']],
60
            ['foo$a', [false, false, false, 'foo']],
61
            ['foo^a', [false, false, false, 'foo']],
62
            ['foo.*$', [false, true, true, 'foo']],
63
        ];
64
    }
65
}
66