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

OneOfConstraintTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 43
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 5
Metric Value
wmc 6
lcom 1
cbo 5
dl 43
loc 43
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A testNormalizeIfOneOfIsNotArray() 6 6 1
A testNormalizeThrowsIfOneOfIsEmpty() 6 6 1
A testNormalizeThrowsIfOneOfElementIsNotObject() 6 6 1
A testNormalizeEnsureEverySubSchemaIsValid() 9 9 1
A getConstraint() 4 4 1
A getCaseFileNames() 4 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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 View Code Duplication
class OneOfConstraintTest extends ConstraintTestCase
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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