FiltrationTest.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php declare(strict_types=1);
  2. /**
  3. * Created by PhpStorm.
  4. * User: inhere
  5. * Date: 2017-11-24
  6. * Time: 18:20
  7. */
  8. namespace Inhere\ValidateTest;
  9. use Inhere\Validate\Filter\Filtration;
  10. use PHPUnit\Framework\TestCase;
  11. /**
  12. * Class FiltrationTest
  13. *
  14. * @covers \Inhere\Validate\Filter\Filtration
  15. */
  16. class FiltrationTest extends TestCase
  17. {
  18. public function testFiltration(): void
  19. {
  20. $data = [
  21. 'name' => ' tom ',
  22. 'status' => ' 23 ',
  23. 'word' => 'word',
  24. 'toLower' => 'WORD',
  25. 'title' => 'helloWorld',
  26. ];
  27. $rules = [
  28. ['name', 'string|trim'],
  29. ['status', 'trim|int'],
  30. ['word', 'string|trim|upper'],
  31. ['toLower', 'lower'],
  32. [
  33. 'title',
  34. [
  35. 'string',
  36. 'snake' => ['-'],
  37. 'ucfirst',
  38. ]
  39. ],
  40. ];
  41. $cleaned = Filtration::make($data, $rules)->filtering();
  42. $this->assertSame($cleaned['name'], 'tom');
  43. $this->assertSame($cleaned['status'], 23);
  44. $this->assertSame($cleaned['word'], 'WORD');
  45. $this->assertSame($cleaned['toLower'], 'word');
  46. $this->assertSame($cleaned['title'], 'Hello-world');
  47. }
  48. }