验证器.是否为中国邮政编码

Testing Is Documentation

tests/Validate/Validator/ZipCodeTest.php验证器.是否为中国邮政编码 - 图1

Uses

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

验证通过的数据

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

  1. # Tests\Validate\Validator\ZipCodeTest::baseUseProvider
  2. public function baseUseProvider(): array
  3. {
  4. return [
  5. ['610000'],
  6. ['610200'],
  7. ['611900'],
  8. ['611500'],
  9. [611900],
  10. [611500],
  11. ];
  12. }

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

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

未验证通过的数据

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

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

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

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