验证器.是否整型数字

Testing Is Documentation

tests/Validate/Validator/IntegerTest.php验证器.是否整型数字 - 图1

Uses

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

验证通过的数据

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

  1. # Tests\Validate\Validator\IntegerTest::baseUseProvider
  2. public function baseUseProvider(): array
  3. {
  4. return [
  5. [true],
  6. [1],
  7. ['10002'],
  8. [' 1 '],
  9. ];
  10. }

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

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

未验证通过的数据

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

  1. # Tests\Validate\Validator\IntegerTest::badProvider
  2. public function badProvider(): array
  3. {
  4. return [
  5. [false],
  6. [1.1],
  7. ['0.0'],
  8. ['-0.0'],
  9. ];
  10. }

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

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