UserValidatorsTest.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php declare(strict_types=1);
  2. /**
  3. * Created by PhpStorm.
  4. * User: inhere
  5. * Date: 2019-01-23
  6. * Time: 01:27
  7. */
  8. namespace Inhere\ValidateTest\Validator;
  9. use Inhere\Validate\Validator\UserValidators;
  10. use PHPUnit\Framework\TestCase;
  11. /**
  12. * Class UserValidatorsTest
  13. *
  14. * @package Inhere\ValidateTest\Validator
  15. */
  16. class UserValidatorsTest extends TestCase
  17. {
  18. public function testBasic(): void
  19. {
  20. UserValidators::removeAll();
  21. UserValidators::setValidators([
  22. 'name1' => static function () {
  23. },
  24. 'name2' => static function () {
  25. },
  26. '' => static function () {
  27. },
  28. ]);
  29. $this->assertCount(2, UserValidators::getValidators());
  30. $this->assertTrue(UserValidators::has('name1'));
  31. $this->assertFalse(UserValidators::has(''));
  32. $this->assertNotEmpty(UserValidators::get('name2'));
  33. $this->assertEmpty(UserValidators::get('name3'));
  34. UserValidators::remove('name1');
  35. $this->assertFalse(UserValidators::has('name1'));
  36. UserValidators::removeAll();
  37. $this->assertCount(0, UserValidators::getValidators());
  38. }
  39. }