/** * Test if quantify system works properly. * @covers Rentalhost\VanillaValidation\ValidationLocalize::translateFail */ public function testQuantify() { $defaultLocale = Validation::option('locale'); Validation::option('locale', 'pt-BR'); $validationFails = Validation::minLength(1)->validate('')->getFails(); static::assertSame('o campo deve possuir no mínimo um caractere', $validationFails[0]->getLocalized()); $validationFails = Validation::minLength(10)->validate('hello')->getFails(); static::assertSame('o campo deve possuir no mínimo 10 caracteres', $validationFails[0]->getLocalized()); Validation::option('locale', $defaultLocale); }
/** * Test nullable rule. * @covers Rentalhost\VanillaValidation\ValidationFieldRuleList::validate * @covers Rentalhost\VanillaValidation\Result\Nullable::__construct * @covers Rentalhost\VanillaValidation\Rule\NullableRule::validate */ public function testNullable() { // Both are invalid, because both is not nullable ('hello' != empty). $validation = Validation::nullable()->minLength(8)->validate('hello'); static::assertCount(1, $validation->getFails()); $validation = Validation::minLength(8)->nullable()->validate('hello'); static::assertCount(1, $validation->getFails()); // But here, one first will works, because it check by nullable first, // then the next rule is ignored ('' == empty). $validation = Validation::nullable()->minLength(8)->validate(''); static::assertCount(0, $validation->getFails()); $validation = Validation::minLength(8)->nullable()->validate(''); static::assertCount(1, $validation->getFails()); }
/** * Test rule directly. * @coversNothing */ public function testDirect() { static::assertInstanceOf(ValidationChain::class, Validation::minLength(5)); }