AllowFileTest.php 816 B

1234567891011121314151617181920212223
  1. <?php
  2. namespace EasySwoole\Validate\tests;
  3. /**
  4. * @internal
  5. */
  6. class AllowFileTest extends BaseTestCase
  7. {
  8. public function testValidateClass()
  9. {
  10. $this->freeValidate();
  11. $this->validate->addColumn('file')->allowFile(['png']);
  12. $bool = $this->validate->validate(['file' => (new UploadFile(__DIR__ . '/../res/easyswoole.png', 1, 200, 'easyswoole.png'))]);
  13. $this->assertTrue($bool);
  14. $this->freeValidate();
  15. $this->validate->addColumn('file')->allowFile(['jpg', 'mp4']);
  16. $bool = $this->validate->validate(['file' => (new UploadFile(__DIR__ . '/../res/easyswoole.png', 1, 200, 'easyswoole.png'))]);
  17. $this->assertFalse($bool);
  18. $this->assertEquals('file文件扩展名必须在[jpg,mp4]内', $this->validate->getError()->__toString());
  19. }
  20. }