/
ProgramWindowTest.php
166 lines (152 loc) · 4.61 KB
/
ProgramWindowTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
<?php
class ProgramWindowTest extends PHPUnit\Framework\TestCase
{
public static function setUpBeforeClass(): void
{
require_once 'ProgramWindow.php';
require_once 'Size.php';
require_once 'Position.php';
}
/**
* @testdox assert ProgramWindow has a $y property
* @task_id 1
*/
public function testHasPropertyY()
{
$reflector = new ReflectionClass(ProgramWindow::class);
$this->assertHasProperty($reflector, 'y', [
'has_type' => false,
'has_default' => false
]);
}
/**
* @testdox assert ProgramWindow has a $x property
* @task_id 1
*/
public function testHasPropertyX()
{
$reflector = new ReflectionClass(ProgramWindow::class);
$this->assertHasProperty($reflector, 'x', [
'has_type' => false,
'has_default' => false
]);
}
/**
* @testdox assert ProgramWindow has a $height property
* @task_id 1
*/
public function testHasPropertyHeight()
{
$reflector = new ReflectionClass(ProgramWindow::class);
$this->assertHasProperty($reflector, 'height', [
'has_type' => false,
'has_default' => false
]);
}
/**
* @testdox assert ProgramWindow has a $width property
* @task_id 1
*/
public function testHasPropertyWidth()
{
$reflector = new ReflectionClass(ProgramWindow::class);
$this->assertHasProperty($reflector, 'width', [
'has_type' => false,
'has_default' => false
]);
}
/**
* @testdox assert ProgramWindow has a constructor initial values
* @task_id 2
*/
public function testHasConstructorSettingInitialValues()
{
$window = new ProgramWindow();
$this->assertEquals(0, $window->y);
$this->assertEquals(0, $window->x);
$this->assertEquals(600, $window->height);
$this->assertEquals(800, $window->width);
}
/**
* @testdox assert Position class exists, with constructor, properties
* @task_id 3
*/
public function testPositionHasConstructorSettingInitialValues()
{
$position = new Position(30, 70);
$this->assertEquals(30, $position->y);
$this->assertEquals(70, $position->x);
}
/**
* @testdox assert Position class exists, with constructor, properties
* @task_id 3
*/
public function testSizeHasConstructorSettingInitialValues()
{
$size = new Size(300, 700);
$this->assertEquals(300, $size->height);
$this->assertEquals(700, $size->width);
}
/**
* @testdox assert ProgramWindow::resize function exists
* @task_id 3
*/
public function testProgramWindowResize()
{
$window = new ProgramWindow();
$size = new Size(430, 2135);
$window->resize($size);
$this->assertEquals(430, $window->height);
$this->assertEquals(2135, $window->width);
}
/**
* @testdox assert ProgramWindow::move function exists
* @task_id 4
*/
public function testProgramWindowMove()
{
$window = new ProgramWindow();
$position = new Position(40, 235);
$window->move($position);
$this->assertEquals(40, $window->y);
$this->assertEquals(235, $window->x);
}
private function assertHasProperty(
ReflectionClass $class,
string $name,
array $assertions = []
) {
$assertions = array_merge([
'has_type' => false,
'has_default_value' => false
], $assertions);
try {
$property = $class->getProperty($name);
} catch (ReflectionException) {
$this->fail(
"Property '$name' missing from class '{$class->getName()}'"
);
};
if ($assertions['has_type']) {
$this->assertTrue($property->hasType());
} else {
$this->assertFalse(
$property->hasType(),
"Property '$name' should not have a type declared"
);
}
if ($assertions['has_default_value']) {
$this->assertTrue($property->hasDefaultValue());
} else {
if ($assertions['has_type'] === false) {
$this->assertTrue($property->hasDefaultValue());
$this->assertNull($property->getDefaultValue());
} else {
$this->assertFalse(
$property->hasDefaultValue(),
"Property '$name' should not have a default value declared"
);
}
}
}
}