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 DependenciesConstraintTest extends ConstraintTestCase |
16
|
|
|
{ |
17
|
|
|
public function testNormalizeThrowsIfDependenciesIsNotObject() |
18
|
|
|
{ |
19
|
|
|
$this->expectConstraintException('InvalidTypeException', '/dependencies'); |
20
|
|
|
$schema = $this->loadSchema('invalid/dependencies-not-object'); |
21
|
|
|
$this->getConstraint()->normalize($schema, new Context(), $this->mockWalker()); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
public function testNormalizeThrowsIfDependenciesPropertyIsNotObjectOrArray() |
25
|
|
|
{ |
26
|
|
|
$this->expectConstraintException('InvalidTypeException', '/dependencies/bar'); |
27
|
|
|
$schema = $this->loadSchema('invalid/dependencies-property-not-object-or-array'); |
28
|
|
|
$this->getConstraint()->normalize($schema, new Context(), $this->mockWalker()); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function testNormalizeEnsuresSchemaDependenciesAreValid() |
32
|
|
|
{ |
33
|
|
|
$schema = $this->loadSchema('valid/dependencies-schema-dependencies'); |
34
|
|
|
$walker = $this->mockWalker(); |
35
|
|
|
$walker->expects($this->at(0)) |
36
|
|
|
->method('parseSchema') |
37
|
|
|
->with($schema->dependencies->foo); |
38
|
|
|
$walker->expects($this->at(1)) |
39
|
|
|
->method('parseSchema') |
40
|
|
|
->with($schema->dependencies->bar); |
41
|
|
|
$this->getConstraint()->normalize($schema, new Context(), $walker); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function testNormalizeThrowsIfPropertyDependenciesIsEmpty() |
45
|
|
|
{ |
46
|
|
|
$this->expectConstraintException('EmptyArrayException', '/dependencies/bar'); |
47
|
|
|
$schema = $this->loadSchema('invalid/dependencies-property-dependencies-empty'); |
48
|
|
|
$this->getConstraint()->normalize($schema, new Context(), $this->mockWalker()); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function testNormalizeThrowsIfPropertyDependencyIsNotString() |
52
|
|
|
{ |
53
|
|
|
$this->expectConstraintException('InvalidTypeException', '/dependencies/bar/1'); |
54
|
|
|
$schema = $this->loadSchema('invalid/dependencies-property-not-string'); |
55
|
|
|
$this->getConstraint()->normalize($schema, new Context(), $this->mockWalker()); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function testNormalizeThrowsIfPropertyDependencyIsNotUnique() |
59
|
|
|
{ |
60
|
|
|
$this->expectConstraintException('NotUniqueException', '/dependencies/bar'); |
61
|
|
|
$schema = $this->loadSchema('invalid/dependencies-property-dependencies-not-unique'); |
62
|
|
|
$this->getConstraint()->normalize($schema, new Context(), $this->mockWalker()); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
protected function getConstraint() |
66
|
|
|
{ |
67
|
|
|
return new DependenciesConstraint(); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
protected function getCaseFileNames() |
71
|
|
|
{ |
72
|
|
|
return ['dependencies']; |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|