1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
class EmailTypeTest extends SwaggerGen_TestCase |
|
|
|
|
4
|
|
|
{ |
5
|
|
|
|
6
|
|
|
protected $parent; |
7
|
|
|
|
8
|
|
|
protected function setUp() |
9
|
|
|
{ |
10
|
|
|
$this->parent = $this->getMockForAbstractClass('\SwaggerGen\Swagger\AbstractObject'); |
11
|
|
|
} |
12
|
|
|
|
13
|
|
|
protected function assertPreConditions() |
14
|
|
|
{ |
15
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\AbstractObject', $this->parent); |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @covers \SwaggerGen\Swagger\Type\Custom\EmailType::__construct |
20
|
|
|
*/ |
21
|
|
|
public function testConstructNotAnEmail() |
22
|
|
|
{ |
23
|
|
|
$this->expectException('\SwaggerGen\Exception', "Not an email: 'wrong'"); |
24
|
|
|
|
25
|
|
|
$object = new SwaggerGen\Swagger\Type\Custom\EmailType($this->parent, 'wrong'); |
|
|
|
|
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @covers \SwaggerGen\Swagger\Type\Custom\EmailType::__construct |
30
|
|
|
*/ |
31
|
|
|
public function testConstruct() |
32
|
|
|
{ |
33
|
|
|
$object = new SwaggerGen\Swagger\Type\Custom\EmailType($this->parent, 'email'); |
34
|
|
|
|
35
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Type\Custom\EmailType', $object); |
36
|
|
|
|
37
|
|
|
$this->assertSame(array( |
38
|
|
|
'type' => 'string', |
39
|
|
|
'pattern' => \SwaggerGen\Swagger\Type\Custom\EmailType::PATTERN, |
40
|
|
|
), $object->toArray()); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @covers \SwaggerGen\Swagger\Type\Custom\EmailType::__construct |
45
|
|
|
*/ |
46
|
|
|
public function testConstructEmptyDefault() |
47
|
|
|
{ |
48
|
|
|
$this->expectException('\SwaggerGen\Exception', "Unparseable email definition: 'email='"); |
49
|
|
|
|
50
|
|
|
$object = new SwaggerGen\Swagger\Type\Custom\EmailType($this->parent, 'email= '); |
|
|
|
|
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @covers \SwaggerGen\Swagger\Type\Custom\EmailType::__construct |
55
|
|
|
*/ |
56
|
|
|
public function testConstructDefaultDoubleAt() |
57
|
|
|
{ |
58
|
|
|
$this->expectException('\SwaggerGen\Exception', "Invalid email default value: 'test@[email protected]'"); |
59
|
|
|
|
60
|
|
|
$object = new SwaggerGen\Swagger\Type\Custom\EmailType($this->parent, 'email=test@[email protected]'); |
|
|
|
|
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @covers \SwaggerGen\Swagger\Type\Custom\EmailType::__construct |
65
|
|
|
*/ |
66
|
|
|
public function testConstructDefaultUntrimmed() |
67
|
|
|
{ |
68
|
|
|
$this->expectException('\SwaggerGen\Exception', "Invalid email default value: ' [email protected]'"); |
69
|
|
|
|
70
|
|
|
$object = new SwaggerGen\Swagger\Type\Custom\EmailType($this->parent, 'email= [email protected]'); |
|
|
|
|
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @covers \SwaggerGen\Swagger\Type\Custom\EmailType::__construct |
75
|
|
|
*/ |
76
|
|
|
public function testConstructDefault() |
77
|
|
|
{ |
78
|
|
|
$object = new SwaggerGen\Swagger\Type\Custom\EmailType($this->parent, '[email protected]'); |
79
|
|
|
|
80
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Type\Custom\EmailType', $object); |
81
|
|
|
|
82
|
|
|
$this->assertSame(array( |
83
|
|
|
'type' => 'string', |
84
|
|
|
'pattern' => \SwaggerGen\Swagger\Type\Custom\EmailType::PATTERN, |
85
|
|
|
'default' => '[email protected]', |
86
|
|
|
), $object->toArray()); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @covers \SwaggerGen\Swagger\Type\Custom\EmailType->handleCommand |
91
|
|
|
*/ |
92
|
|
|
public function testCommandDefaultNoValue() |
93
|
|
|
{ |
94
|
|
|
$object = new SwaggerGen\Swagger\Type\Custom\EmailType($this->parent, 'email'); |
95
|
|
|
|
96
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Type\Custom\EmailType', $object); |
97
|
|
|
|
98
|
|
|
$this->expectException('\SwaggerGen\Exception', "Empty email default"); |
99
|
|
|
$object->handleCommand('default', ''); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @covers \SwaggerGen\Swagger\Type\Custom\EmailType->handleCommand |
104
|
|
|
*/ |
105
|
|
|
public function testCommandDefault() |
106
|
|
|
{ |
107
|
|
|
$object = new SwaggerGen\Swagger\Type\Custom\EmailType($this->parent, 'email'); |
108
|
|
|
|
109
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Type\Custom\EmailType', $object); |
110
|
|
|
|
111
|
|
|
$object->handleCommand('default', '[email protected]'); |
112
|
|
|
|
113
|
|
|
$this->assertSame(array( |
114
|
|
|
'type' => 'string', |
115
|
|
|
'pattern' => \SwaggerGen\Swagger\Type\Custom\EmailType::PATTERN, |
116
|
|
|
'default' => '[email protected]', |
117
|
|
|
), $object->toArray()); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
} |
121
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.