Test Failed
Pull Request — master (#26)
by Christopher
02:40
created

xsYearMonthDurationTest   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 7
c 4
b 0
f 0
lcom 0
cbo 2
dl 0
loc 65
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
A tearDown() 0 4 1
A testXsYearMonthDurationValid() 0 6 1
A testXsYearMonthDurationInvalid() 0 7 2
A testXsYearMonthDurationInvalidDataProvider() 0 14 1
A testXsYearMonthDurationValidDataProvider() 0 9 1
1
<?php
2
namespace AlgoWeb\xsdTypes;
3
4
use AlgoWeb\xsdTypes\xsYearMonthDuration;
5
6
/**
7
 * Generated Test Class.
8
 */
9
class xsYearMonthDurationTest extends \PHPUnit_Framework_TestCase
10
{
11
    /**
12
     * Sets up the fixture, for example, opens a network connection.
13
     * This method is called before a test is executed.
14
     */
15
    protected function setUp()
16
    {
17
        parent::setUp();
18
    }
19
20
    /**
21
     * Tears down the fixture, for example, closes a network connection.
22
     * This method is called after a test is executed.
23
     */
24
    protected function tearDown()
25
    {
26
        parent::tearDown();
27
    }
28
29
    /**
30
         * @dataProvider testXsYearMonthDurationValidDataProvider
31
     */
32
    public function testXsYearMonthDurationValid($duration, $message) {
33
        $d = new xsYearMonthDuration($duration);
34
        $e = (string)$d;
35
        $this->assertEquals($duration,$e,$message);
36
37
    }
38
39
    public function testXsYearMonthDurationValidDataProvider() {
40
        return array(
41
            array('P2Y6M', '2 years, 6 months'),
42
            array('P20M', '20 months (the number of months can be more than 12)'),
43
            array('P0Y20M', '20 months (0 is permitted as a number, but is not required)'),
44
            array('P0Y', '0 years'),
45
            array('-P60Y', 'minus 60 years'),
46
        );
47
    }
48
    /**
49
     * @dataProvider testXsYearMonthDurationInvalidDataProvider
50
     */
51
    public function testXsYearMonthDurationInvalid($duration, $message) {
52
        try {
53
            $d = new xsYearMonthDuration($duration);
54
            $e = (string)$d;
0 ignored issues
show
Unused Code introduced by
$e is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
55
            $this->fail($message);
56
        }catch(\Exception $e){}
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
57
    }
58
59
    public function testXsYearMonthDurationInvalidDataProvider() {
60
        return array(
61
            array('P2Y6M5DT12H35M30S', 'components other than years or months are not allowed'),
62
            array('P-20M', 'the minus sign must appear first'),
63
            array('P20MT', '"T" must not be present'),
64
            array('P1YM', 'no value is specified for months, so "M" must not be present'),
65
            array('-P15.5Y', 'numbers cannot be expressed as a decimal'),
66
            array('1Y2M', '"P" must always be present'),
67
            array('P2M1Y', 'years must appear before months'),
68
            array('P', 'at least one number and designator are required'),
69
            array('', 'an empty value is not valid, unless xsi:nil is used'),
70
71
        );
72
    }
73
}
74