Skip to content

Commit

Permalink
fix(IsTinyChar): 增加 IsTinyChar 校验规则
Browse files Browse the repository at this point in the history
  • Loading branch information
twinh committed Nov 24, 2020
1 parent 1094631 commit 4178fc9
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
22 changes: 22 additions & 0 deletions lib/IsTinyChar.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
/**
* Wei Framework
*
* @copyright Copyright (c) 2008-2020 Twin Huang
* @license http://opensource.org/licenses/mit-license.php MIT License
*/

namespace Wei;

/**
* Check if the input is a string of 255 characters or less
*
* @author Twin Huang <twinhuang@qq.com>
*/
class IsTinyChar extends IsChar
{
/**
* @var int
*/
protected $maxLength = 255;
}
44 changes: 44 additions & 0 deletions tests/unit/IsTinyCharTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace WeiTest;

/**
* @internal
*/
final class IsTinyCharTest extends BaseValidatorTestCase
{
/**
* @dataProvider providerForLength
* @param mixed $input
*/
public function testLength($input)
{
$this->assertTrue($this->isTinyChar($input));
}

/**
* @dataProvider providerForNotLength
* @param mixed $input
*/
public function testNotLength($input)
{
$this->assertFalse($this->isTinyChar($input));
}

public function providerForLength()
{
return [
['i♥u4'],
[str_repeat('1', 255)],
[str_repeat('😊', 255)],
];
}

public function providerForNotLength()
{
return [
[str_repeat('1', 256)],
[str_repeat('😊', 255) . '1'],
];
}
}

0 comments on commit 4178fc9

Please sign in to comment.