Completed
Pull Request — master (#33)
by Martijn
02:18
created

EmailTypeTest::testConstruct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 0
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
class EmailTypeTest extends SwaggerGen_TestCase
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
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');
0 ignored issues
show
Unused Code introduced by
$object 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...
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= ');
0 ignored issues
show
Unused Code introduced by
$object 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...
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]');
0 ignored issues
show
Unused Code introduced by
$object 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...
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]');
0 ignored issues
show
Unused Code introduced by
$object 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...
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