|
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; |
|
|
|
|
|
|
55
|
|
|
$this->fail($message); |
|
56
|
|
|
}catch(\Exception $e){} |
|
|
|
|
|
|
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
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.