验证器.是否为中文、数字和字母

Testing Is Documentation

tests/Validate/Validator/ChineseAlphaNumTest.php验证器.是否为中文、数字和字母 - 图1

Uses

  1. <?php
  2. use Leevel\Validate\Validator;
  3. use stdClass;

验证通过的数据

以下是通过的校验数据示例。

  1. # Tests\Validate\Validator\ChineseAlphaNumTest::baseUseProvider
  2. public function baseUseProvider(): array
  3. {
  4. return [
  5. ['abc'],
  6. ['ABC'],
  7. ['123abc'],
  8. ['4ABC'],
  9. ['A4中国4bc'],
  10. ['ab1c'],
  11. ['AB成都2C'],
  12. ['Ab3c'],
  13. [123],
  14. ];
  15. }

上面的数据是测试的数据提供者。

  1. public function testBaseUse($value): void
  2. {
  3. $validate = new Validator(
  4. [
  5. 'name' => $value,
  6. ],
  7. [
  8. 'name' => 'chinese_alpha_num',
  9. ]
  10. );
  11. $this->assertTrue($validate->success());
  12. }

未验证通过的数据

以下是未通过的校验数据示例。

  1. # Tests\Validate\Validator\ChineseAlphaNumTest::badProvider
  2. public function badProvider(): array
  3. {
  4. return [
  5. [' '],
  6. ['not numeric'],
  7. [new stdClass()],
  8. [['foo', 'bar']],
  9. [[1, 2]],
  10. ['this is a string'],
  11. [true],
  12. [[[], []]],
  13. ];
  14. }

上面的数据是测试的数据提供者。

  1. public function testBad($value): void
  2. {
  3. $validate = new Validator(
  4. [
  5. 'name' => $value,
  6. ],
  7. [
  8. 'name' => 'chinese_alpha_num',
  9. ]
  10. );
  11. $this->assertFalse($validate->success());
  12. }