/** * Test collect method. * @covers Rentalhost\VanillaValidation\Validation::collect */ public function testCollect() { Validation::collect($beforeAction)->trim()->collect($afterAction)->validate(' hello '); static::assertSame(' hello ', $beforeAction); static::assertSame('hello', $afterAction); // Pre-definition of values. $validation = new Validation(); $validation->field('name1', ' hello ')->collect($beforeAction1)->trim()->collect($afterAction1); $validation->field('name2', ' hello ')->collect($beforeAction2)->trim()->collect($afterAction2); static::assertNull($beforeAction1); static::assertNull($beforeAction2); static::assertNull($afterAction1); static::assertNull($afterAction2); $validation->validate(); static::assertSame(' hello ', $beforeAction1); static::assertSame(' hello ', $beforeAction2); static::assertSame('hello', $afterAction1); static::assertSame('hello', $afterAction2); unset($beforeAction1, $beforeAction2, $afterAction1, $afterAction2); // Post-definition of values. $validation = new Validation(); $validation->field('name1')->collect($beforeAction1)->trim()->collect($afterAction1); $validation->field('name2')->collect($beforeAction2)->trim()->collect($afterAction2); static::assertNull($beforeAction1); static::assertNull($beforeAction2); static::assertNull($afterAction1); static::assertNull($afterAction2); $validation->validate(['name1' => ' hello ', 'name2' => ' hello ']); static::assertSame(' hello ', $beforeAction1); static::assertSame(' hello ', $beforeAction2); static::assertSame('hello', $afterAction1); static::assertSame('hello', $afterAction2); }
/** * Test collect method. * @covers Rentalhost\VanillaValidation\ValidationChain::collect */ public function testCollect() { Validation::collect($beforeAction)->trim()->collect($afterAction)->validate(' hello '); static::assertSame(' hello ', $beforeAction); static::assertSame('hello', $afterAction); }