|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the JVal package. |
|
5
|
|
|
* |
|
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
7
|
|
|
* file that was distributed with this source code. |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace JVal\Constraint; |
|
11
|
|
|
|
|
12
|
|
|
use JVal\Context; |
|
13
|
|
|
use JVal\Testing\ConstraintTestCase; |
|
14
|
|
|
|
|
15
|
|
|
class TypeConstraintTest extends ConstraintTestCase |
|
16
|
|
|
{ |
|
17
|
|
|
public function testNormalizeThrowsIfTypeIsNotStringOrArray() |
|
18
|
|
|
{ |
|
19
|
|
|
$this->expectConstraintException('InvalidTypeException', '/type'); |
|
20
|
|
|
$schema = $this->loadSchema('invalid/type-not-string-or-array'); |
|
21
|
|
|
$this->getConstraint()->normalize($schema, new Context(), $this->mockWalker()); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
public function testNormalizeThrowsIfTypeArrayElementIsNotAString() |
|
25
|
|
|
{ |
|
26
|
|
|
$this->expectConstraintException('InvalidTypeException', '/type/1'); |
|
27
|
|
|
$schema = $this->loadSchema('invalid/type-element-not-string'); |
|
28
|
|
|
$this->getConstraint()->normalize($schema, new Context(), $this->mockWalker()); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
public function testNormalizeThrowsIfTypeArrayElementAreNotUnique() |
|
32
|
|
|
{ |
|
33
|
|
|
$this->expectConstraintException('NotUniqueException', '/type'); |
|
34
|
|
|
$schema = $this->loadSchema('invalid/type-element-not-unique'); |
|
35
|
|
|
$this->getConstraint()->normalize($schema, new Context(), $this->mockWalker()); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function testNormalizeThrowsIfTypeIsNotADefinedPrimitiveType() |
|
39
|
|
|
{ |
|
40
|
|
|
$this->expectConstraintException('NotPrimitiveTypeException', '/type'); |
|
41
|
|
|
$schema = $this->loadSchema('invalid/type-not-primitive'); |
|
42
|
|
|
$this->getConstraint()->normalize($schema, new Context(), $this->mockWalker()); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function testNormalizeThrowsIfTypeElementIsNotADefinedPrimitiveType() |
|
46
|
|
|
{ |
|
47
|
|
|
$this->expectConstraintException('NotPrimitiveTypeException', '/type/1'); |
|
48
|
|
|
$schema = $this->loadSchema('invalid/type-element-not-primitive'); |
|
49
|
|
|
$this->getConstraint()->normalize($schema, new Context(), $this->mockWalker()); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
protected function getConstraint() |
|
53
|
|
|
{ |
|
54
|
|
|
return new TypeConstraint(); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
protected function getCaseFileNames() |
|
58
|
|
|
{ |
|
59
|
|
|
return ['type']; |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
|