Failed Conditions
Branch ignore-unknown-keywords (efa676)
by Stéphane
02:58
created

TypeConstraintTest   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3
Metric Value
wmc 7
lcom 1
cbo 3
dl 0
loc 47
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A testNormalizeThrowsIfTypeIsNotStringOrArray() 0 6 1
A testNormalizeThrowsIfTypeArrayElementIsNotAString() 0 6 1
A testNormalizeThrowsIfTypeArrayElementAreNotUnique() 0 6 1
A testNormalizeThrowsIfTypeIsNotADefinedPrimitiveType() 0 6 1
A testNormalizeThrowsIfTypeElementIsNotADefinedPrimitiveType() 0 6 1
A getConstraint() 0 4 1
A getCaseFileNames() 0 4 1
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