Exemplo n.º 1
0
 public function testNumberFloat()
 {
     V::validate(1.23, V::number()->float(), function ($err, $output) {
         $this->assertNull($err);
         $this->assertEquals(1.23, $output);
     });
     V::validate(123, V::number()->float(), function ($err, $output) {
         $this->assertEquals('value is not a float', $err);
         $this->assertNull($output);
     });
 }
 public function testNumberBetween()
 {
     V::validate(0, V::number()->between(5, 10), function ($err, $output) {
         $this->assertEquals('value must be >= 5', $err);
         $this->assertNull($output);
     });
     V::validate(4, V::number()->between(5, 10), function ($err, $output) {
         $this->assertEquals('value must be >= 5', $err);
         $this->assertNull($output);
     });
     V::validate(5, V::number()->between(5, 10), function ($err, $output) {
         $this->assertNull($err);
         $this->assertEquals(5, $output);
     });
     V::validate(7, V::number()->between(5, 10), function ($err, $output) {
         $this->assertNull($err);
         $this->assertEquals(7, $output);
     });
     V::validate(10, V::number()->between(5, 10), function ($err, $output) {
         $this->assertNull($err);
         $this->assertEquals(10, $output);
     });
     V::validate(11, V::number()->between(5, 10), function ($err, $output) {
         $this->assertEquals('value must be <= 10', $err);
         $this->assertNull($output);
     });
     V::validate(100, V::number()->between(5, 10), function ($err, $output) {
         $this->assertEquals('value must be <= 10', $err);
         $this->assertNull($output);
     });
 }
 public function testAnyCustomTransform()
 {
     $schema = V::number()->custom(function (InputValue $input) {
         $input->replace(function ($value) {
             return $value * 2;
         });
     });
     V::validate(2, $schema, function ($err, $output) {
         $this->assertNull($err);
         $this->assertEquals(4, $output);
     });
     V::validate(2.5, $schema, function ($err, $output) {
         $this->assertNull($err);
         $this->assertEquals(5, $output);
     });
 }
 public function testAssertNegative()
 {
     $this->setExpectedException('\\Validation\\ValidationException');
     V::assert('string', V::number());
 }