| @@ 15-55 (lines=41) @@ | ||
| 12 | use JVal\Context; |
|
| 13 | use JVal\Testing\ConstraintTestCase; |
|
| 14 | ||
| 15 | class MaximumConstraintTest extends ConstraintTestCase |
|
| 16 | { |
|
| 17 | public function testNormalizeThrowsIfMaxNotPresent() |
|
| 18 | { |
|
| 19 | $this->expectConstraintException('MissingKeywordException', '', 'maximum'); |
|
| 20 | $schema = $this->loadSchema('invalid/maximum-not-present'); |
|
| 21 | $this->getConstraint()->normalize($schema, new Context(), $this->mockWalker()); |
|
| 22 | } |
|
| 23 | ||
| 24 | public function testNormalizeSetsExclusiveMaxToFalseIfNotPresent() |
|
| 25 | { |
|
| 26 | $schema = $this->loadSchema('valid/exclusiveMaximum-not-present'); |
|
| 27 | $this->getConstraint()->normalize($schema, new Context(), $this->mockWalker()); |
|
| 28 | $this->assertObjectHasAttribute('exclusiveMaximum', $schema); |
|
| 29 | $this->assertEquals(false, $schema->exclusiveMaximum); |
|
| 30 | } |
|
| 31 | ||
| 32 | public function testNormalizeThrowsIfMaximumIsNotANumber() |
|
| 33 | { |
|
| 34 | $this->expectConstraintException('InvalidTypeException', '/maximum'); |
|
| 35 | $schema = $this->loadSchema('invalid/maximum-not-number'); |
|
| 36 | $this->getConstraint()->normalize($schema, new Context(), $this->mockWalker()); |
|
| 37 | } |
|
| 38 | ||
| 39 | public function testNormalizeThrowsIfExclusiveMaximumIsNotABoolean() |
|
| 40 | { |
|
| 41 | $this->expectConstraintException('InvalidTypeException', '/exclusiveMaximum'); |
|
| 42 | $schema = $this->loadSchema('invalid/exclusiveMaximum-not-boolean'); |
|
| 43 | $this->getConstraint()->normalize($schema, new Context(), $this->mockWalker()); |
|
| 44 | } |
|
| 45 | ||
| 46 | protected function getConstraint() |
|
| 47 | { |
|
| 48 | return new MaximumConstraint(); |
|
| 49 | } |
|
| 50 | ||
| 51 | protected function getCaseFileNames() |
|
| 52 | { |
|
| 53 | return ['maximum']; |
|
| 54 | } |
|
| 55 | } |
|
| 56 | ||
| @@ 15-55 (lines=41) @@ | ||
| 12 | use JVal\Context; |
|
| 13 | use JVal\Testing\ConstraintTestCase; |
|
| 14 | ||
| 15 | class MinimumConstraintTest extends ConstraintTestCase |
|
| 16 | { |
|
| 17 | public function testNormalizeThrowsIfMaxNotPresent() |
|
| 18 | { |
|
| 19 | $this->expectConstraintException('MissingKeywordException', '', 'minimum'); |
|
| 20 | $schema = $this->loadSchema('invalid/minimum-not-present'); |
|
| 21 | $this->getConstraint()->normalize($schema, new Context(), $this->mockWalker()); |
|
| 22 | } |
|
| 23 | ||
| 24 | public function testNormalizeSetsExclusiveMaxToFalseIfNotPresent() |
|
| 25 | { |
|
| 26 | $schema = $this->loadSchema('valid/exclusiveMinimum-not-present'); |
|
| 27 | $this->getConstraint()->normalize($schema, new Context(), $this->mockWalker()); |
|
| 28 | $this->assertObjectHasAttribute('exclusiveMinimum', $schema); |
|
| 29 | $this->assertEquals(false, $schema->exclusiveMinimum); |
|
| 30 | } |
|
| 31 | ||
| 32 | public function testNormalizeThrowsIfMinimumIsNotANumber() |
|
| 33 | { |
|
| 34 | $this->expectConstraintException('InvalidTypeException', '/minimum'); |
|
| 35 | $schema = $this->loadSchema('invalid/minimum-not-number'); |
|
| 36 | $this->getConstraint()->normalize($schema, new Context(), $this->mockWalker()); |
|
| 37 | } |
|
| 38 | ||
| 39 | public function testNormalizeThrowsIfExclusiveMinimumIsNotABoolean() |
|
| 40 | { |
|
| 41 | $this->expectConstraintException('InvalidTypeException', '/exclusiveMinimum'); |
|
| 42 | $schema = $this->loadSchema('invalid/exclusiveMinimum-not-boolean'); |
|
| 43 | $this->getConstraint()->normalize($schema, new Context(), $this->mockWalker()); |
|
| 44 | } |
|
| 45 | ||
| 46 | protected function getConstraint() |
|
| 47 | { |
|
| 48 | return new MinimumConstraint(); |
|
| 49 | } |
|
| 50 | ||
| 51 | protected function getCaseFileNames() |
|
| 52 | { |
|
| 53 | return ['minimum']; |
|
| 54 | } |
|
| 55 | } |
|
| 56 | ||
| @@ 15-54 (lines=40) @@ | ||
| 12 | use JVal\Context; |
|
| 13 | use JVal\Testing\ConstraintTestCase; |
|
| 14 | ||
| 15 | class RequiredConstraintTest extends ConstraintTestCase |
|
| 16 | { |
|
| 17 | public function testNormalizeThrowsIfRequiredIsNotArray() |
|
| 18 | { |
|
| 19 | $this->expectConstraintException('InvalidTypeException', '/required'); |
|
| 20 | $schema = $this->loadSchema('invalid/required-not-array'); |
|
| 21 | $this->getConstraint()->normalize($schema, new Context(), $this->mockWalker()); |
|
| 22 | } |
|
| 23 | ||
| 24 | public function testNormalizeThrowsIfRequiredIsEmpty() |
|
| 25 | { |
|
| 26 | $this->expectConstraintException('EmptyArrayException', '/required'); |
|
| 27 | $schema = $this->loadSchema('invalid/required-empty'); |
|
| 28 | $this->getConstraint()->normalize($schema, new Context(), $this->mockWalker()); |
|
| 29 | } |
|
| 30 | ||
| 31 | public function testNormalizeThrowsIfRequiredPropertyIsNotString() |
|
| 32 | { |
|
| 33 | $this->expectConstraintException('InvalidTypeException', '/required/1'); |
|
| 34 | $schema = $this->loadSchema('invalid/required-property-not-string'); |
|
| 35 | $this->getConstraint()->normalize($schema, new Context(), $this->mockWalker()); |
|
| 36 | } |
|
| 37 | ||
| 38 | public function testNormalizeThrowsIfRequiredPropertyIsNotUnique() |
|
| 39 | { |
|
| 40 | $this->expectConstraintException('NotUniqueException', '/required'); |
|
| 41 | $schema = $this->loadSchema('invalid/required-property-not-unique'); |
|
| 42 | $this->getConstraint()->normalize($schema, new Context(), $this->mockWalker()); |
|
| 43 | } |
|
| 44 | ||
| 45 | protected function getConstraint() |
|
| 46 | { |
|
| 47 | return new RequiredConstraint(); |
|
| 48 | } |
|
| 49 | ||
| 50 | protected function getCaseFileNames() |
|
| 51 | { |
|
| 52 | return ['required']; |
|
| 53 | } |
|
| 54 | } |
|
| 55 | ||