| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- <?php declare(strict_types=1);
- /**
- * Created by PhpStorm.
- * User: inhere
- * Date: 2017-11-24
- * Time: 18:20
- */
- namespace Inhere\ValidateTest;
- use Inhere\Validate\Filter\Filtration;
- use PHPUnit\Framework\TestCase;
- /**
- * Class FiltrationTest
- *
- * @covers \Inhere\Validate\Filter\Filtration
- */
- class FiltrationTest extends TestCase
- {
- public function testFiltration(): void
- {
- $data = [
- 'name' => ' tom ',
- 'status' => ' 23 ',
- 'word' => 'word',
- 'toLower' => 'WORD',
- 'title' => 'helloWorld',
- ];
- $rules = [
- ['name', 'string|trim'],
- ['status', 'trim|int'],
- ['word', 'string|trim|upper'],
- ['toLower', 'lower'],
- [
- 'title',
- [
- 'string',
- 'snake' => ['-'],
- 'ucfirst',
- ]
- ],
- ];
- $cleaned = Filtration::make($data, $rules)->filtering();
- $this->assertSame($cleaned['name'], 'tom');
- $this->assertSame($cleaned['status'], 23);
- $this->assertSame($cleaned['word'], 'WORD');
- $this->assertSame($cleaned['toLower'], 'word');
- $this->assertSame($cleaned['title'], 'Hello-world');
- }
- }
|