ValidatorsTest.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603
  1. <?php declare(strict_types=1);
  2. namespace Inhere\ValidateTest;
  3. use Inhere\Validate\Validators;
  4. use PHPUnit\Framework\TestCase;
  5. use stdClass;
  6. /**
  7. * Class ValidatorsTest
  8. * @package Inhere\ValidateTest
  9. */
  10. class ValidatorsTest extends TestCase
  11. {
  12. public function testAliases(): void
  13. {
  14. $this->assertSame('neqField', Validators::realName('diff'));
  15. $this->assertSame('not-exist', Validators::realName('not-exist'));
  16. }
  17. public function testIsEmpty(): void
  18. {
  19. $this->assertFalse(Validators::isEmpty(1));
  20. $this->assertFalse(Validators::isEmpty(0));
  21. $this->assertFalse(Validators::isEmpty(false));
  22. $this->assertTrue(Validators::isEmpty(null));
  23. $this->assertTrue(Validators::isEmpty([]));
  24. $this->assertTrue(Validators::isEmpty(new stdClass()));
  25. $this->assertTrue(Validators::isEmpty(''));
  26. $this->assertTrue(Validators::isEmpty(' '));
  27. }
  28. public function testBool(): void
  29. {
  30. $this->assertFalse(Validators::bool(null));
  31. $this->assertFalse(Validators::bool([]));
  32. $this->assertTrue(Validators::bool('1'));
  33. $this->assertTrue(Validators::bool(1));
  34. $this->assertTrue(Validators::bool(''));
  35. }
  36. public function testFloat(): void
  37. {
  38. $this->assertFalse(Validators::float(null));
  39. $this->assertFalse(Validators::float(false));
  40. $this->assertFalse(Validators::float(''));
  41. $this->assertTrue(Validators::float('1'));
  42. $this->assertTrue(Validators::float('1.0'));
  43. $this->assertTrue(Validators::float(3.4));
  44. $this->assertTrue(Validators::float(-3.4));
  45. $this->assertTrue(Validators::float(3.4, 3.1));
  46. $this->assertTrue(Validators::float(3.4, 3.1, 5.4));
  47. $this->assertTrue(Validators::float(3.4, 4.1, 2.4));
  48. $this->assertTrue(Validators::float(3.4, null, 5.4));
  49. $this->assertTrue(Validators::float(0.8, 0, 4));
  50. $this->assertTrue(Validators::float(0.5, 0.3, 0.7));
  51. }
  52. public function testInteger(): void
  53. {
  54. $this->assertFalse(Validators::int(''));
  55. $this->assertFalse(Validators::integer(null));
  56. $this->assertFalse(Validators::integer(false));
  57. $this->assertFalse(Validators::integer(2, 5));
  58. $this->assertTrue(Validators::int(0));
  59. $this->assertTrue(Validators::integer(1));
  60. $this->assertTrue(Validators::integer(-1));
  61. $this->assertTrue(Validators::integer('1'));
  62. $this->assertTrue(Validators::integer(-2, -3, 1));
  63. $this->assertTrue(Validators::integer(2, 2, 5));
  64. $this->assertTrue(Validators::integer(2, null, 5));
  65. }
  66. public function testNumber(): void
  67. {
  68. $this->assertFalse(Validators::number(''));
  69. $this->assertFalse(Validators::number(-1));
  70. $this->assertFalse(Validators::number(0));
  71. $this->assertTrue(Validators::num(1));
  72. $this->assertTrue(Validators::number(10, 5, 12));
  73. $this->assertTrue(Validators::number(10, 12, 5));
  74. $this->assertTrue(Validators::number(10, null, 12));
  75. }
  76. public function testString(): void
  77. {
  78. $this->assertFalse(Validators::string(false));
  79. $this->assertFalse(Validators::string(null));
  80. $this->assertFalse(Validators::string(true));
  81. $this->assertFalse(Validators::string(0));
  82. $this->assertFalse(Validators::string('test', 2, 3));
  83. $this->assertFalse(Validators::string('test', 5));
  84. $this->assertTrue(Validators::string(''));
  85. $this->assertTrue(Validators::string('test', 2, 5));
  86. }
  87. public function testAlpha(): void
  88. {
  89. $this->assertFalse(Validators::alpha(5));
  90. $this->assertFalse(Validators::alpha('5'));
  91. $this->assertTrue(Validators::alpha('test'));
  92. }
  93. public function testAccepted(): void
  94. {
  95. $samples = [
  96. [5, false],
  97. ['5', false],
  98. ['no', false],
  99. ['off', false],
  100. ['OFF', false],
  101. [0, false],
  102. ['0', false],
  103. [false, false],
  104. ['false', false],
  105. [[], false],
  106. ['yes', true],
  107. ['Yes', true],
  108. ['YES', true],
  109. ['on', true],
  110. ['ON', true],
  111. ['1', true],
  112. [1, true],
  113. [true, true],
  114. ['true', true],
  115. ];
  116. foreach ($samples as [$val, $want]) {
  117. $this->assertSame($want, Validators::accepted($val));
  118. }
  119. }
  120. public function testAlphaNum(): void
  121. {
  122. $this->assertFalse(Validators::alphaNum('='));
  123. $this->assertFalse(Validators::alphaNum(null));
  124. $this->assertFalse(Validators::alphaNum(true));
  125. $this->assertFalse(Validators::alphaNum([]));
  126. $this->assertTrue(Validators::alphaNum(5));
  127. $this->assertTrue(Validators::alphaNum('5'));
  128. $this->assertTrue(Validators::alphaNum('6787test'));
  129. $this->assertTrue(Validators::alphaNum('test'));
  130. }
  131. public function testAlphaDash(): void
  132. {
  133. $this->assertFalse(Validators::alphaDash('='));
  134. // $this->assertFalse(Validators::alphaDash(null));
  135. $this->assertFalse(Validators::alphaDash('test='));
  136. $this->assertTrue(Validators::alphaDash('sdf56-_'));
  137. }
  138. public function testMin(): void
  139. {
  140. $this->assertFalse(Validators::min('test', 5));
  141. $this->assertFalse(Validators::min(56, 60));
  142. $this->assertTrue(Validators::min(56, 20));
  143. $this->assertTrue(Validators::min('test', 2));
  144. $this->assertTrue(Validators::min([3, 'test', 'hi'], 2));
  145. }
  146. public function testMax(): void
  147. {
  148. $this->assertFalse(Validators::max('test', 3));
  149. $this->assertFalse(Validators::max(56, 50));
  150. $this->assertTrue(Validators::max(56, 60));
  151. $this->assertTrue(Validators::max('test', 5));
  152. $this->assertTrue(Validators::max([3, 'test', 'hi'], 5));
  153. }
  154. // eq neq gt gte lt lte
  155. public function testValueCompare(): void
  156. {
  157. // eq
  158. $this->assertTrue(Validators::same(6, 6));
  159. $this->assertTrue(Validators::eq(true, true));
  160. $this->assertTrue(Validators::eq(null, null));
  161. $this->assertFalse(Validators::eq(false, null));
  162. $this->assertFalse(Validators::eq(5, '5'));
  163. $this->assertTrue(Validators::eq(5, '5', false));
  164. $this->assertFalse(Validators::eq(false, 0));
  165. $this->assertTrue(Validators::eq(false, 0, false));
  166. // neq
  167. $this->assertFalse(Validators::neq(5, '5', false));
  168. $this->assertTrue(Validators::neq(5, '5'));
  169. // gt
  170. $this->assertTrue(Validators::gt(6, 5));
  171. $this->assertTrue(Validators::gt('abc', 'ab'));
  172. $this->assertTrue(Validators::gt([1, 2], [2]));
  173. $this->assertFalse(Validators::gt(4, 4));
  174. $this->assertFalse(Validators::gt(3, 4));
  175. // gte
  176. $this->assertTrue(Validators::gte(6, 5));
  177. $this->assertTrue(Validators::gte('abc', 'ab'));
  178. $this->assertTrue(Validators::gte([1, 2], [2]));
  179. $this->assertTrue(Validators::gte(4, 4));
  180. $this->assertFalse(Validators::gte(2, 4));
  181. // lt
  182. $samples = [
  183. [5, 6, true],
  184. [[1], [1, 'a'], true],
  185. ['a', 'ab', true],
  186. [6, 6, false],
  187. [[1], [1], false],
  188. ['a', 'a', false],
  189. [1, 'a', false],
  190. ];
  191. foreach ($samples as $v) {
  192. $this->assertSame($v[2], Validators::lt($v[0], $v[1]));
  193. }
  194. // lte
  195. $samples = [
  196. [5, 6, true],
  197. [[1], [1, 'a'], true],
  198. ['a', 'ab', true],
  199. [6, 6, true],
  200. [[1], [1], true],
  201. ['a', 'a', true],
  202. [1, 'a', false],
  203. [6, 5, false],
  204. ];
  205. foreach ($samples as $v) {
  206. $this->assertSame($v[2], Validators::lte($v[0], $v[1]));
  207. }
  208. }
  209. public function testSize(): void
  210. {
  211. $this->assertFalse(Validators::size('test', 5));
  212. // $this->assertFalse(Validators::size(null, 5));
  213. $this->assertFalse(Validators::range('test', 5));
  214. $this->assertFalse(Validators::between(56, 20, 50));
  215. $this->assertTrue(Validators::size(56, 20, 100));
  216. $this->assertTrue(Validators::size('test', 2, 4));
  217. $this->assertTrue(Validators::size([3, 'test', 'hi'], 1, 4));
  218. $this->assertTrue(Validators::size(0.8, 0, 4));
  219. }
  220. public function testSize_float(): void
  221. {
  222. $this->assertTrue(Validators::size(0.8, 0, 4));
  223. $this->assertTrue(Validators::size(0.5, 0.3, 0.7));
  224. }
  225. public function testFixedSize(): void
  226. {
  227. $this->assertTrue(Validators::sizeEq([3, 'test', 'hi'], 3));
  228. $this->assertTrue(Validators::lengthEq('test', 4));
  229. }
  230. public function testLength(): void
  231. {
  232. $this->assertFalse(Validators::length('test', 5));
  233. $this->assertFalse(Validators::length('test', 0, 3));
  234. // $this->assertFalse(Validators::length(56, 60));
  235. $this->assertTrue(Validators::length('test', 3, 5));
  236. $this->assertTrue(Validators::length([3, 'test', 'hi'], 2, 5));
  237. }
  238. public function testRegexp(): void
  239. {
  240. $this->assertFalse(Validators::regexp('test', '/^\d+$/'));
  241. $this->assertFalse(Validators::regexp('test-dd', '/^\w+$/'));
  242. $this->assertTrue(Validators::regexp('compose启动服务', '/[\x{4e00}-\x{9fa5}]+/u'));
  243. $this->assertTrue(Validators::regexp('test56', '/^\w+$/'));
  244. }
  245. public function testUrl(): void
  246. {
  247. $this->assertFalse(Validators::url('test'));
  248. $this->assertFalse(Validators::url('/test56'));
  249. $this->assertTrue(Validators::url('http://a.com/test56'));
  250. }
  251. public function testEmail(): void
  252. {
  253. $this->assertFalse(Validators::email('test'));
  254. $this->assertFalse(Validators::email('/test56'));
  255. $this->assertTrue(Validators::email('abc@gmail.com'));
  256. }
  257. public function testIp(): void
  258. {
  259. $this->assertFalse(Validators::ip('test'));
  260. $this->assertFalse(Validators::ip('/test56'));
  261. $this->assertFalse(Validators::ipv4('/test56'));
  262. $this->assertFalse(Validators::ipv6('/test56'));
  263. $this->assertTrue(Validators::ip('0.0.0.0'));
  264. $this->assertTrue(Validators::ip('127.0.0.1'));
  265. $this->assertTrue(Validators::ipv4('127.0.0.1'));
  266. $this->assertTrue(Validators::ipv6('2400:3200::1'));
  267. $this->assertTrue(Validators::ipv6('0:0:0:0:0:0:0:0'));
  268. }
  269. public function testEnglish(): void
  270. {
  271. $this->assertFalse(Validators::english(123));
  272. $this->assertFalse(Validators::english('123'));
  273. $this->assertTrue(Validators::english('test'));
  274. }
  275. public function testIsArray(): void
  276. {
  277. $this->assertFalse(Validators::isArray('test'));
  278. $this->assertFalse(Validators::isArray(345));
  279. $this->assertTrue(Validators::isArray([]));
  280. $this->assertTrue(Validators::isArray(['a']));
  281. }
  282. public function testIsMap(): void
  283. {
  284. $this->assertFalse(Validators::isMap('test'));
  285. $this->assertFalse(Validators::isMap([]));
  286. $this->assertFalse(Validators::isMap(['abc']));
  287. $this->assertTrue(Validators::isMap(['a' => 'v']));
  288. $this->assertTrue(Validators::isMap(['value', 'a' => 'v']));
  289. }
  290. public function testIsList(): void
  291. {
  292. $this->assertFalse(Validators::isList('test'));
  293. $this->assertFalse(Validators::isList([]));
  294. $this->assertFalse(Validators::isList(['a' => 'v']));
  295. $this->assertFalse(Validators::isList(['value', 'a' => 'v']));
  296. $this->assertFalse(Validators::isList([3 => 'abc']));
  297. $this->assertFalse(Validators::isList(['abc', 3 => 45]));
  298. $this->assertTrue(Validators::isList(['abc']));
  299. $this->assertTrue(Validators::isList(['abc', 565, null]));
  300. }
  301. public function testIntList(): void
  302. {
  303. $this->assertFalse(Validators::intList('test'));
  304. $this->assertFalse(Validators::intList([]));
  305. $this->assertFalse(Validators::intList(['a', 'v']));
  306. $this->assertFalse(Validators::intList(['a', 456]));
  307. $this->assertFalse(Validators::intList(['a' => 'v']));
  308. $this->assertFalse(Validators::intList(['value', 'a' => 'v']));
  309. $this->assertFalse(Validators::intList([2 => '343', 45]));
  310. $this->assertFalse(Validators::intList([45, 2 => '343']));
  311. $this->assertTrue(Validators::intList(['343', 45]));
  312. $this->assertTrue(Validators::intList([565, 3234, -56]));
  313. }
  314. public function testNumList(): void
  315. {
  316. $this->assertFalse(Validators::numList('test'));
  317. $this->assertFalse(Validators::numList([]));
  318. $this->assertFalse(Validators::numList(['a', 'v']));
  319. $this->assertFalse(Validators::numList(['a' => 'v']));
  320. $this->assertFalse(Validators::numList(['value', 'a' => 'v']));
  321. $this->assertFalse(Validators::numList([565, 3234, -56]));
  322. $this->assertFalse(Validators::numList([2 => 56, 45]));
  323. $this->assertFalse(Validators::numList([45, 2 => 56]));
  324. $this->assertTrue(Validators::numList(['343', 45]));
  325. $this->assertTrue(Validators::numList([56, 45]));
  326. }
  327. public function testStrList(): void
  328. {
  329. $this->assertFalse(Validators::strList('test'));
  330. $this->assertFalse(Validators::strList([]));
  331. $this->assertFalse(Validators::strList(['a' => 'v']));
  332. $this->assertFalse(Validators::strList(['value', 'a' => 'v']));
  333. $this->assertFalse(Validators::strList(['abc', 565]));
  334. $this->assertFalse(Validators::strList(['abc', 565, null]));
  335. $this->assertTrue(Validators::strList(['abc', 'efg']));
  336. }
  337. public function testArrList(): void
  338. {
  339. $this->assertFalse(Validators::arrList('test'));
  340. $this->assertFalse(Validators::arrList([]));
  341. $this->assertFalse(Validators::arrList(['a' => 'v']));
  342. $this->assertFalse(Validators::arrList(['value', 'a' => 'v']));
  343. $this->assertFalse(Validators::arrList(['abc', 565]));
  344. $this->assertFalse(Validators::arrList([
  345. ['abc'],
  346. 'efg'
  347. ]));
  348. $this->assertTrue(Validators::arrList([
  349. ['abc'],
  350. ['efg']
  351. ]));
  352. }
  353. public function testHasKey(): void
  354. {
  355. $this->assertFalse(Validators::hasKey('hello, world', 'all'));
  356. $this->assertFalse(Validators::hasKey('hello, world', 'not'));
  357. $this->assertFalse(Validators::hasKey(['a' => 'v0', 'b' => 'v1', 'c' => 'v2'], 'd'));
  358. $this->assertFalse(Validators::hasKey(['a' => 'v0', 'b' => 'v1', 'c' => 'v2'], ['c', 'd']));
  359. $this->assertTrue(Validators::hasKey(['a' => 'v0', 'b' => 'v1', 'c' => 'v2'], 'b'));
  360. $this->assertTrue(Validators::hasKey(['a' => 'v0', 'b' => 'v1', 'c' => 'v2'], ['b', 'c']));
  361. }
  362. public function testDistinct(): void
  363. {
  364. $this->assertFalse(Validators::distinct('string'));
  365. $this->assertFalse(Validators::distinct([1, 2, 2]));
  366. $this->assertFalse(Validators::distinct([1, 2, '2']));
  367. $this->assertFalse(Validators::distinct(['a', 'b', 'b']));
  368. $this->assertTrue(Validators::distinct([1, 2, 3]));
  369. $this->assertTrue(Validators::distinct(['a', 'b', 'c']));
  370. }
  371. public function testInANDNotIn(): void
  372. {
  373. $samples = [
  374. [true, 1, [1, 2, 3], false],
  375. [true, 1, [1, 2, 3], true],
  376. [true, '1', [1, 2, 3], false],
  377. [false, '1', [1, 2, 3], true],
  378. [true, '1', '1,2,3', true],
  379. ];
  380. foreach ($samples as [$want, $val, $dict, $strict]) {
  381. $this->assertSame($want, Validators::in($val, $dict, $strict));
  382. $this->assertSame(!$want, Validators::notIn($val, $dict, $strict));
  383. }
  384. }
  385. public function testJson(): void
  386. {
  387. $this->assertFalse(Validators::json('test'));
  388. $this->assertFalse(Validators::json([]));
  389. $this->assertFalse(Validators::json(123));
  390. $this->assertFalse(Validators::json('123'));
  391. $this->assertTrue(Validators::json('123', false));
  392. $this->assertFalse(Validators::json('{aa: 34}'));
  393. $this->assertTrue(Validators::json('{}'));
  394. $this->assertTrue(Validators::json('[]'));
  395. $this->assertTrue(Validators::json('{"aa": 34}'));
  396. }
  397. public function testContains(): void
  398. {
  399. $this->assertFalse(Validators::contains('hello, world', 'all'));
  400. $this->assertFalse(Validators::contains(null, 'all'));
  401. $this->assertFalse(Validators::contains([], 'all'));
  402. // $this->assertFalse(Validators::contains('hello, world', false));
  403. $this->assertTrue(Validators::contains('123', 2));
  404. $this->assertTrue(Validators::contains('hello, world', 'llo'));
  405. $this->assertTrue(Validators::contains('hello, world', ['llo', 'wor']));
  406. }
  407. public function testStartWith(): void
  408. {
  409. $this->assertFalse(Validators::startWith(null, 'ell'));
  410. $this->assertFalse(Validators::startWith('hello, world', 'ell'));
  411. $this->assertFalse(Validators::startWith('hello, world', ''));
  412. $this->assertTrue(Validators::startWith('hello, world', 'hell'));
  413. $this->assertTrue(Validators::startWith(['hello', 'world'], 'hello'));
  414. }
  415. public function testEndWith(): void
  416. {
  417. $this->assertFalse(Validators::endWith('hello, world', 'ell'));
  418. $this->assertTrue(Validators::endWith('hello, world', 'world'));
  419. $this->assertTrue(Validators::endWith(['hello', 'world'], 'world'));
  420. }
  421. public function testDateCheck(): void
  422. {
  423. // date
  424. $this->assertFalse(Validators::date('hello'));
  425. $this->assertTrue(Validators::date(170526));
  426. $this->assertTrue(Validators::date('20170526'));
  427. // dateEquals
  428. $this->assertTrue(Validators::dateEquals('20170526', '20170526'));
  429. $this->assertTrue(Validators::dateEquals('2017-05-26', '20170526'));
  430. $this->assertFalse(Validators::dateEquals('20170525', '20170526'));
  431. // dateFormat
  432. $this->assertFalse(Validators::dateFormat('hello'));
  433. $this->assertFalse(Validators::dateFormat('170526', 'ymd'));
  434. $this->assertTrue(Validators::dateFormat('20170526', 'Ymd'));
  435. // beforeDate
  436. $this->assertTrue(Validators::beforeDate('20170524', '20170526'));
  437. $this->assertFalse(Validators::beforeDate('20170526', '20170526'));
  438. // beforeOrEqualDate
  439. $this->assertTrue(Validators::beforeOrEqualDate('20170524', '20170526'));
  440. $this->assertTrue(Validators::beforeOrEqualDate('20170526', '20170526'));
  441. $this->assertFalse(Validators::beforeOrEqualDate('20170527', '20170526'));
  442. // afterDate
  443. $this->assertTrue(Validators::afterDate('20170526', '20170524'));
  444. $this->assertFalse(Validators::afterDate('20170526', '20170526'));
  445. $this->assertFalse(Validators::afterDate('20170524', '20170526'));
  446. $this->assertFalse(Validators::afterDate([], '20170526'));
  447. // afterOrEqualDate
  448. $this->assertTrue(Validators::afterOrEqualDate('20170526', '20170526'));
  449. $this->assertTrue(Validators::afterOrEqualDate('20170526', '20170524'));
  450. $this->assertFalse(Validators::afterOrEqualDate('20170524', '20170526'));
  451. // isDate
  452. $this->assertTrue(Validators::isDate('2017-05-26'));
  453. $this->assertFalse(Validators::isDate('20170526'));
  454. // isDateFormat
  455. $this->assertTrue(Validators::isDateFormat('2017-05-26'));
  456. $this->assertFalse(Validators::isDateFormat('20170526'));
  457. }
  458. public function testPhone(): void
  459. {
  460. $this->assertTrue(Validators::phone('13555556666'));
  461. $this->assertFalse(Validators::phone('20170526'));
  462. }
  463. public function testPostCode(): void
  464. {
  465. $this->assertTrue(Validators::postCode('610000'));
  466. $this->assertFalse(Validators::postCode('20170526'));
  467. }
  468. public function testPrice(): void
  469. {
  470. $this->assertTrue(Validators::price('610.45'));
  471. $this->assertFalse(Validators::price('-201.26'));
  472. $this->assertFalse(Validators::price('abc'));
  473. $this->assertTrue(Validators::negativePrice('610.45'));
  474. $this->assertTrue(Validators::negativePrice('-201.26'));
  475. $this->assertFalse(Validators::negativePrice('abc'));
  476. }
  477. public function testOther(): void
  478. {
  479. // isFloat
  480. $this->assertFalse(Validators::isFloat([]));
  481. $this->assertFalse(Validators::isFloat('abc'));
  482. $this->assertTrue(Validators::isFloat('23.34'));
  483. $this->assertTrue(Validators::isFloat('-23.34'));
  484. // isUnsignedFloat
  485. $this->assertTrue(Validators::isUnsignedFloat('23.34'));
  486. $this->assertFalse(Validators::isUnsignedFloat('-23.34'));
  487. // isInt
  488. $this->assertTrue(Validators::isInt('23'));
  489. $this->assertTrue(Validators::isInt('-23'));
  490. $this->assertFalse(Validators::isInt('-23.34'));
  491. // isUnsignedInt
  492. $this->assertTrue(Validators::isUnsignedInt('23'));
  493. $this->assertFalse(Validators::isUnsignedInt('-23'));
  494. $this->assertFalse(Validators::isUnsignedInt('-23.34'));
  495. // macAddress
  496. $this->assertTrue(Validators::macAddress('01:23:45:67:89:ab'));
  497. $this->assertFalse(Validators::macAddress([]));
  498. $this->assertFalse(Validators::macAddress(null));
  499. $this->assertFalse(Validators::macAddress('123 abc'));
  500. // md5
  501. $this->assertFalse(Validators::md5('123 abc'));
  502. $this->assertFalse(Validators::md5(true));
  503. // sha1
  504. $this->assertFalse(Validators::sha1(true));
  505. $this->assertFalse(Validators::sha1('123 abc'));
  506. }
  507. }