Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Changed - white space between first and second parameter is not required, if second parameter begins with `:`, e.g. `{{id:uint}}` * Changed preg_replace_callback to preg_match_all * Replaced `: class` with `: self` wherever it was possible
- Loading branch information
1 parent
09f7915
commit 3229e38
Showing
8 changed files
with
100 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the awesomite/chariot package. | ||
* (c) Bartłomiej Krukowski <bartlomiej@krukowski.me> | ||
* For the full copyright and license information, please view | ||
* the LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Awesomite\Chariot; | ||
|
||
use Awesomite\Chariot\Exceptions\InvalidArgumentException; | ||
use Awesomite\Chariot\Pattern\PatternRouter; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
class ShortNotationTest extends TestBase | ||
{ | ||
public function testShortNotation() | ||
{ | ||
$router = PatternRouter::createDefault(); | ||
$router->get('/category-{{id:uint}}', 'category'); | ||
$router->get('/item-{{ id:int }}', 'item'); | ||
|
||
$this->assertSame('/category-5', (string)$router->linkTo('category')->withParam('id', 5)); | ||
$this->assertSame('/item-27', (string)$router->linkTo('item')->withParam('id', 27)); | ||
} | ||
|
||
/** | ||
* @dataProvider providerInvalidShortNotation | ||
* | ||
* @param string $pattern | ||
* @param string $expectedMsg | ||
*/ | ||
public function testInvalidShortNotation(string $pattern, string $expectedMsg) | ||
{ | ||
$this->expectException(InvalidArgumentException::class); | ||
$this->expectExceptionMessage($expectedMsg); | ||
|
||
$router = PatternRouter::createDefault(); | ||
$router->get($pattern, 'category'); | ||
} | ||
|
||
public function providerInvalidShortNotation() | ||
{ | ||
return [ | ||
['/category-{{id[0-9]+}}', 'Invalid param name “id[0-9]+” (source: /category-{{id[0-9]+}})'], | ||
['/category-{{ id[0-9]+ }}', 'Invalid param name “id[0-9]+” (source: /category-{{ id[0-9]+ }})'], | ||
]; | ||
} | ||
} |