RegexTest::setUp()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Nip\Router\Tests\Parsers;
4
5
use Nip\Router\Parsers\Regex;
6
7
/**
8
 * Test class for Nip_Route_Abstract.
9
 * Generated by PHPUnit on 2010-11-17 at 15:16:44.
10
 */
11
class RegexTest extends \Nip\Router\Tests\AbstractTest
12
{
13
14
    /**
15
     * @var Regex
16
     */
17
    protected $object;
18
19
    /**
20
     * Sets up the fixture, for example, opens a network connection.
21
     * This method is called before a test is executed.
22
     */
23
    protected function setUp(): void
24
    {
25
        $this->object = new Regex();
26
    }
27
28
29
    public function testSetMap()
30
    {
31
        $this->object->setMap('shop/cart');
0 ignored issues
show
Bug introduced by
'shop/cart' of type string is incompatible with the type boolean expected by parameter $map of Nip\Router\Parsers\AbstractParser::setMap(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

31
        $this->object->setMap(/** @scrutinizer ignore-type */ 'shop/cart');
Loading history...
32
        static::assertEquals('shop/cart', $this->object->getRegex());
33
34
        $this->object->setMap('shop/:cart');
35
        static::assertEquals('shop/:cart', $this->object->getRegex());
36
37
        $this->object->setMap('shop/:cart');
38
        $this->object->setParams(['cart' => 'test']);
39
        static::assertEquals('shop/(test)', $this->object->getRegex());
40
41
        $this->object->setMap('shop/:cart/:url');
42
        $this->object->setParams(['cart' => 'test', 'url' => '[a-z0-9-]+']);
43
        static::assertEquals('shop/(test)/([a-z0-9-]+)', $this->object->getRegex());
44
    }
45
46
    public function testAssemble()
47
    {
48
        $params = [
49
            'url' => 'lorem',
50
            'name' => 'ipsum',
51
            'company' => 'dolo&rem',
52
        ];
53
        static::assertEquals('?url=lorem&name=ipsum&company=dolo%26rem', $this->object->assemble($params));
54
55
        $this->object->setMap('shop/:url');
0 ignored issues
show
Bug introduced by
'shop/:url' of type string is incompatible with the type boolean expected by parameter $map of Nip\Router\Parsers\AbstractParser::setMap(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

55
        $this->object->setMap(/** @scrutinizer ignore-type */ 'shop/:url');
Loading history...
56
        static::assertEquals('shop/lorem?name=ipsum&company=dolo%26rem', $this->object->assemble($params));
57
    }
58
59
    public function testMatch()
60
    {
61
        $this->object->setMap('shop/cart/:url');
0 ignored issues
show
Bug introduced by
'shop/cart/:url' of type string is incompatible with the type boolean expected by parameter $map of Nip\Router\Parsers\AbstractParser::setMap(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

61
        $this->object->setMap(/** @scrutinizer ignore-type */ 'shop/cart/:url');
Loading history...
62
        $this->object->setParams(array('url' => '[a-z0-9-]+'));
63
        static::assertTrue($this->object->match('shop/cart/test'));
64
        static::assertTrue($this->object->match('shop/cart/test-teas'));
65
        static::assertTrue($this->object->match('shop/cart/test123-teas123'));
66
        static::assertFalse($this->object->match('shop/cart/test123_teas123'));
67
    }
68
}
69