| @@ 15-57 (lines=43) @@ | ||
| 12 | use JVal\Context; |
|
| 13 | use JVal\Testing\ConstraintTestCase; |
|
| 14 | ||
| 15 | class AllOfConstraintTest extends ConstraintTestCase |
|
| 16 | { |
|
| 17 | public function testNormalizeIfAllOfIsNotArray() |
|
| 18 | { |
|
| 19 | $this->expectConstraintException('InvalidTypeException', '/allOf'); |
|
| 20 | $schema = $this->loadSchema('invalid/allOf-not-array'); |
|
| 21 | $this->getConstraint()->normalize($schema, new Context(), $this->mockWalker()); |
|
| 22 | } |
|
| 23 | ||
| 24 | public function testNormalizeThrowsIfAllOfIsEmpty() |
|
| 25 | { |
|
| 26 | $this->expectConstraintException('EmptyArrayException', '/allOf'); |
|
| 27 | $schema = $this->loadSchema('invalid/allOf-empty'); |
|
| 28 | $this->getConstraint()->normalize($schema, new Context(), $this->mockWalker()); |
|
| 29 | } |
|
| 30 | ||
| 31 | public function testNormalizeThrowsIfAllOfElementIsNotObject() |
|
| 32 | { |
|
| 33 | $this->expectConstraintException('InvalidTypeException', '/allOf/1'); |
|
| 34 | $schema = $this->loadSchema('invalid/allOf-element-not-object'); |
|
| 35 | $this->getConstraint()->normalize($schema, new Context(), $this->mockWalker()); |
|
| 36 | } |
|
| 37 | ||
| 38 | public function testNormalizeEnsureEverySubSchemaIsValid() |
|
| 39 | { |
|
| 40 | $schema = $this->loadSchema('valid/allOf-valid-sub-schemas'); |
|
| 41 | $walker = $this->mockWalker(); |
|
| 42 | $walker->expects($this->exactly(2)) |
|
| 43 | ->method('parseSchema') |
|
| 44 | ->withConsecutive($schema->allOf[0], $schema->allOf[1]); |
|
| 45 | $this->getConstraint()->normalize($schema, new Context(), $walker); |
|
| 46 | } |
|
| 47 | ||
| 48 | protected function getConstraint() |
|
| 49 | { |
|
| 50 | return new AllOfConstraint(); |
|
| 51 | } |
|
| 52 | ||
| 53 | protected function getCaseFileNames() |
|
| 54 | { |
|
| 55 | return ['allOf']; |
|
| 56 | } |
|
| 57 | } |
|
| 58 | ||
| @@ 15-57 (lines=43) @@ | ||
| 12 | use JVal\Context; |
|
| 13 | use JVal\Testing\ConstraintTestCase; |
|
| 14 | ||
| 15 | class AnyOfConstraintTest extends ConstraintTestCase |
|
| 16 | { |
|
| 17 | public function testNormalizeIfAnyOfIsNotArray() |
|
| 18 | { |
|
| 19 | $this->expectConstraintException('InvalidTypeException', '/anyOf'); |
|
| 20 | $schema = $this->loadSchema('invalid/anyOf-not-array'); |
|
| 21 | $this->getConstraint()->normalize($schema, new Context(), $this->mockWalker()); |
|
| 22 | } |
|
| 23 | ||
| 24 | public function testNormalizeThrowsIfAnyOfIsEmpty() |
|
| 25 | { |
|
| 26 | $this->expectConstraintException('EmptyArrayException', '/anyOf'); |
|
| 27 | $schema = $this->loadSchema('invalid/anyOf-empty'); |
|
| 28 | $this->getConstraint()->normalize($schema, new Context(), $this->mockWalker()); |
|
| 29 | } |
|
| 30 | ||
| 31 | public function testNormalizeThrowsIfAnyOfElementIsNotObject() |
|
| 32 | { |
|
| 33 | $this->expectConstraintException('InvalidTypeException', '/anyOf/1'); |
|
| 34 | $schema = $this->loadSchema('invalid/anyOf-element-not-object'); |
|
| 35 | $this->getConstraint()->normalize($schema, new Context(), $this->mockWalker()); |
|
| 36 | } |
|
| 37 | ||
| 38 | public function testNormalizeEnsureEverySubSchemaIsValid() |
|
| 39 | { |
|
| 40 | $schema = $this->loadSchema('valid/anyOf-valid-sub-schemas'); |
|
| 41 | $walker = $this->mockWalker(); |
|
| 42 | $walker->expects($this->exactly(2)) |
|
| 43 | ->method('parseSchema') |
|
| 44 | ->withConsecutive($schema->anyOf[0], $schema->anyOf[1]); |
|
| 45 | $this->getConstraint()->normalize($schema, new Context(), $walker); |
|
| 46 | } |
|
| 47 | ||
| 48 | protected function getConstraint() |
|
| 49 | { |
|
| 50 | return new AnyOfConstraint(); |
|
| 51 | } |
|
| 52 | ||
| 53 | protected function getCaseFileNames() |
|
| 54 | { |
|
| 55 | return ['anyOf']; |
|
| 56 | } |
|
| 57 | } |
|
| 58 | ||
| @@ 15-57 (lines=43) @@ | ||
| 12 | use JVal\Context; |
|
| 13 | use JVal\Testing\ConstraintTestCase; |
|
| 14 | ||
| 15 | class OneOfConstraintTest extends ConstraintTestCase |
|
| 16 | { |
|
| 17 | public function testNormalizeIfOneOfIsNotArray() |
|
| 18 | { |
|
| 19 | $this->expectConstraintException('InvalidTypeException', '/oneOf'); |
|
| 20 | $schema = $this->loadSchema('invalid/oneOf-not-array'); |
|
| 21 | $this->getConstraint()->normalize($schema, new Context(), $this->mockWalker()); |
|
| 22 | } |
|
| 23 | ||
| 24 | public function testNormalizeThrowsIfOneOfIsEmpty() |
|
| 25 | { |
|
| 26 | $this->expectConstraintException('EmptyArrayException', '/oneOf'); |
|
| 27 | $schema = $this->loadSchema('invalid/oneOf-empty'); |
|
| 28 | $this->getConstraint()->normalize($schema, new Context(), $this->mockWalker()); |
|
| 29 | } |
|
| 30 | ||
| 31 | public function testNormalizeThrowsIfOneOfElementIsNotObject() |
|
| 32 | { |
|
| 33 | $this->expectConstraintException('InvalidTypeException', '/oneOf/1'); |
|
| 34 | $schema = $this->loadSchema('invalid/oneOf-element-not-object'); |
|
| 35 | $this->getConstraint()->normalize($schema, new Context(), $this->mockWalker()); |
|
| 36 | } |
|
| 37 | ||
| 38 | public function testNormalizeEnsureEverySubSchemaIsValid() |
|
| 39 | { |
|
| 40 | $schema = $this->loadSchema('valid/oneOf-valid-sub-schemas'); |
|
| 41 | $walker = $this->mockWalker(); |
|
| 42 | $walker->expects($this->exactly(2)) |
|
| 43 | ->method('parseSchema') |
|
| 44 | ->withConsecutive($schema->oneOf[0], $schema->oneOf[1]); |
|
| 45 | $this->getConstraint()->normalize($schema, new Context(), $walker); |
|
| 46 | } |
|
| 47 | ||
| 48 | protected function getConstraint() |
|
| 49 | { |
|
| 50 | return new OneOfConstraint(); |
|
| 51 | } |
|
| 52 | ||
| 53 | protected function getCaseFileNames() |
|
| 54 | { |
|
| 55 | return ['oneOf']; |
|
| 56 | } |
|
| 57 | } |
|
| 58 | ||