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'); |
|
|
|
|
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
|
|
View Code Duplication |
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'); |
|
|
|
|
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'); |
|
|
|
|
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
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: