Skip to content

Commit e577032

Browse files
committed
Add type validation, integer exclusive validation and float exclusive validation tests
1 parent 3823f9a commit e577032

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

tests/Schemas/NumericSchemaTest.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use PHPUnit\Framework\Attributes\CoversClass;
66
use PHPUnit\Framework\TestCase;
7+
use stdClass;
78
use Webdevcave\SchemaValidator\Schemas\BaseSchema;
89
use Webdevcave\SchemaValidator\Schemas\NumericSchema;
910
use Webdevcave\SchemaValidator\Validator;
@@ -41,4 +42,34 @@ public function testRequirePositive(): void
4142
$this->assertTrue($schema->validate(1), "Failed asserting positive value");
4243
$this->assertFalse($schema->validate(-1), "Failed asserting negative value (positive required)");
4344
}
45+
46+
public function testTypeValidation(): void
47+
{
48+
$schema = new NumericSchema();
49+
50+
$this->assertFalse($schema->validate('str'), "Numeric schema should not validate strings");
51+
$this->assertFalse($schema->validate(new stdClass()), "Numeric schema should not validate objects");
52+
$this->assertFalse($schema->validate([1,2,3]), "Numeric schema should validate arrays");
53+
54+
$this->assertTrue($schema->validate(1), "Numeric schema should validate integers");
55+
$this->assertTrue($schema->validate(1.1), "Numeric schema should validate floats");
56+
}
57+
58+
public function testExclusiveIntegerValidation(): void
59+
{
60+
$schema = new NumericSchema();
61+
$schema->integer();
62+
63+
$this->assertTrue($schema->validate(1), "Numeric schema should validate integers (int only)");
64+
$this->assertFalse($schema->validate(1.1), "Numeric schema should not validate floats (int only)");
65+
}
66+
67+
public function testExclusiveFloatValidation(): void
68+
{
69+
$schema = new NumericSchema();
70+
$schema->float();
71+
72+
$this->assertFalse($schema->validate(1), "Numeric schema should not validate integers (floats only)");
73+
$this->assertTrue($schema->validate(1.1), "Numeric schema should validate floats (floats only)");
74+
}
4475
}

0 commit comments

Comments
 (0)