-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(IsText, IsMediumText): 增加
IsText
和 IsMediumText
校验规则
- Loading branch information
Showing
4 changed files
with
141 additions
and
0 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
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 16777215(16Mb-1) bytes or less | ||
* | ||
* @author Twin Huang <twinhuang@qq.com> | ||
*/ | ||
class IsMediumText extends IsString | ||
{ | ||
/** | ||
* @var int | ||
*/ | ||
protected $maxLength = 16777215; | ||
} |
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,25 @@ | ||
<?php | ||
/** | ||
* Wei Framework | ||
* | ||
* @copyright Copyright (c) 2008-2020 Twin Huang | ||
* @license http://opensource.org/licenses/mit-license.php MIT License | ||
*/ | ||
|
||
namespace Wei; | ||
|
||
use Wei\IsChar; | ||
use Wei\IsString; | ||
|
||
/** | ||
* Check if the input is a string of 65535(64Kb-1) bytes or less | ||
* | ||
* @author Twin Huang <twinhuang@qq.com> | ||
*/ | ||
class IsText extends IsString | ||
{ | ||
/** | ||
* @var int | ||
*/ | ||
protected $maxLength = 65535; | ||
} |
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,47 @@ | ||
<?php | ||
|
||
namespace WeiTest; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class IsMediumTextTest extends BaseValidatorTestCase | ||
{ | ||
/** | ||
* @dataProvider providerForMediumTextVal | ||
* @param mixed $input | ||
*/ | ||
public function testStringVal($input) | ||
{ | ||
$this->assertTrue($this->isMediumText($input)); | ||
} | ||
|
||
/** | ||
* @dataProvider providerForNotMediumTextVal | ||
* @param mixed $input | ||
*/ | ||
public function testNotStringVal($input) | ||
{ | ||
$this->assertFalse($this->isMediumText($input)); | ||
} | ||
|
||
public function providerForMediumTextVal() | ||
{ | ||
return [ | ||
[''], | ||
['123'], | ||
[str_repeat('1', 16777215)], | ||
[str_repeat('我', 16777215 / 3)], | ||
[str_repeat('🙂', 16777215 / 4)], | ||
]; | ||
} | ||
|
||
public function providerForNotMediumTextVal() | ||
{ | ||
return [ | ||
[str_repeat('1', 16777215 + 1)], | ||
[str_repeat('我', 16777215 / 3) . '1'], | ||
[str_repeat('🙂', 16777215 / 4) . '1234'], | ||
]; | ||
} | ||
} |
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,47 @@ | ||
<?php | ||
|
||
namespace WeiTest; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class IsTextTest extends BaseValidatorTestCase | ||
{ | ||
/** | ||
* @dataProvider providerForTextVal | ||
* @param mixed $input | ||
*/ | ||
public function testStringVal($input) | ||
{ | ||
$this->assertTrue($this->isText($input)); | ||
} | ||
|
||
/** | ||
* @dataProvider providerForNotTextVal | ||
* @param mixed $input | ||
*/ | ||
public function testNotStringVal($input) | ||
{ | ||
$this->assertFalse($this->isText($input)); | ||
} | ||
|
||
public function providerForTextVal() | ||
{ | ||
return [ | ||
[''], | ||
['123'], | ||
[str_repeat('1', 65535)], | ||
[str_repeat('我', 65535 / 3)], | ||
[str_repeat('🙂', 65535 / 4)], | ||
]; | ||
} | ||
|
||
public function providerForNotTextVal() | ||
{ | ||
return [ | ||
[str_repeat('1', 65535) . '1'], | ||
[str_repeat('我', 65535 / 3) . '1'], | ||
[str_repeat('🙂', 65535 / 4) . '1234'], | ||
]; | ||
} | ||
} |