Skip to content

Commit b56a78b

Browse files
authored
Migrations to phpunit
1 parent 543b61e commit b56a78b

13 files changed

+360
-395
lines changed

tests/functional/CommonITILSatisfaction.php renamed to phpunit/abstracts/CommonITILSatisfaction.php

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ abstract class CommonITILSatisfaction extends DbTestCase
4646
*/
4747
protected function getTestedClass(): string
4848
{
49-
$test_class = static::class;
49+
$test_class = str_replace('Test', '', static::class);
5050
// Rule class has the same name as the test class but in the global namespace
5151
return substr(strrchr($test_class, '\\'), 1);
5252
}
@@ -57,7 +57,7 @@ public function testGetItemtype()
5757
$tested_class = $this->getTestedClass();
5858
$itemtype = $tested_class::getItemtype();
5959
// Verify the itemtype is a subclass of CommonITILObject
60-
$this->boolean(is_a($itemtype, \CommonITILObject::class, true))->isTrue();
60+
$this->assertTrue(is_a($itemtype, \CommonITILObject::class, true));
6161
}
6262

6363
public function testGetSurveyUrl()
@@ -75,7 +75,7 @@ public function testGetSurveyUrl()
7575
'entities_id' => $root_entity_id,
7676
'solvedate' => $_SESSION['glpi_currenttime'],
7777
]);
78-
$this->integer($items_id)->isGreaterThan(0);
78+
$this->assertGreaterThan(0, $items_id);
7979

8080
$this->login(); // Authorized user required to update entity config
8181

@@ -84,25 +84,25 @@ public function testGetSurveyUrl()
8484
$config_suffix = $itemtype === 'Ticket' ? '' : ('_' . strtolower($itemtype));
8585
$inquest_url = "[ITEMTYPE],[ITEMTYPE_NAME],[{$tag_prefix}_ID],[{$tag_prefix}_NAME],[{$tag_prefix}_CREATEDATE],
8686
[{$tag_prefix}_SOLVEDATE],[{$tag_prefix}_PRIORITY]";
87-
$this->boolean(
87+
$this->assertTrue(
8888
$entity->update([
8989
'id' => $root_entity_id,
9090
'inquest_URL' . $config_suffix => $inquest_url,
9191
'inquest_config' . $config_suffix => \CommonITILSatisfaction::TYPE_EXTERNAL,
9292
])
93-
)->isTrue();
93+
);
9494

9595
$expected = "{$itemtype},{$item->getTypeName(1)},{$items_id},{$item->fields['name']},{$item->getField('date')},
9696
{$item->getField('solvedate')},{$item->getField('priority')}";
9797
$generated = \Entity::generateLinkSatisfaction($item);
98-
$this->string($generated)->isEqualTo($expected);
98+
$this->assertEquals($expected, $generated);
9999
}
100100

101101
public function testGetIndexName()
102102
{
103103
$index_name = $this->getTestedClass()::getIndexName();
104-
$this->boolean(is_string($index_name))->isTrue();
105-
$this->string($index_name)->isNotEmpty();
104+
$this->assertTrue(is_string($index_name));
105+
$this->assertNotEmpty($index_name);
106106
}
107107

108108
public function testGetLogTypeID()
@@ -118,7 +118,7 @@ public function testGetLogTypeID()
118118
'entities_id' => getItemByTypeName('Entity', '_test_root_entity', true),
119119
'solvedate' => $_SESSION['glpi_currenttime'],
120120
]);
121-
$this->integer($items_id)->isGreaterThan(0);
121+
$this->assertGreaterThan(0, $items_id);
122122

123123
// Add a satisfaction
124124
/** @var \CommonITILSatisfaction $satisfaction */
@@ -131,14 +131,14 @@ public function testGetLogTypeID()
131131
'type' => \CommonITILSatisfaction::TYPE_INTERNAL,
132132
'date' => $_SESSION['glpi_currenttime'],
133133
]);
134-
$this->integer($satisfaction_id)->isGreaterThan(0);
134+
$this->assertGreaterThan(0, $satisfaction_id);
135135

136136
$log_type = $satisfaction->getLogTypeID();
137-
$this->boolean(is_array($log_type))->isTrue();
138-
$this->array($log_type)->size->isEqualTo(2);
139-
$this->string($log_type[0])->isEqualTo($itilobject_type);
137+
$this->assertIsArray($log_type);
138+
$this->assertCount(2, $log_type);
139+
$this->assertEquals($itilobject_type, $log_type[0]);
140140

141-
$this->integer($log_type[1])->isEqualTo($items_id);
141+
$this->assertEquals($items_id, $log_type[1]);
142142
}
143143

144144
public function testDateAnsweredSetOnAnswer()
@@ -156,11 +156,11 @@ public function testDateAnsweredSetOnAnswer()
156156
'solvedate' => $_SESSION['glpi_currenttime'],
157157
'users_id_recipient' => getItemByTypeName('User', TU_USER, true),
158158
]);
159-
$this->integer($items_id)->isGreaterThan(0);
159+
$this->assertGreaterThan(0, $items_id);
160160

161-
$this->boolean($item->addTeamMember('User', getItemByTypeName('User', TU_USER, true), [
161+
$this->assertTrue($item->addTeamMember('User', getItemByTypeName('User', TU_USER, true), [
162162
'role' => Team::ROLE_REQUESTER,
163-
]))->isTrue();
163+
]));
164164

165165
// Add a satisfaction
166166
/** @var \CommonITILSatisfaction $satisfaction */
@@ -173,17 +173,17 @@ public function testDateAnsweredSetOnAnswer()
173173
'type' => \CommonITILSatisfaction::TYPE_INTERNAL,
174174
'date' => $_SESSION['glpi_currenttime'],
175175
]);
176-
$this->integer($satisfaction_id)->isGreaterThan(0);
177-
$this->variable($satisfaction->fields['date_answered'])->isNull();
176+
$this->assertGreaterThan(0, $satisfaction_id);
177+
$this->assertNull($satisfaction->fields['date_answered']);
178178

179179
$this->login();
180180

181-
$this->boolean($satisfaction->update([
181+
$this->assertTrue($satisfaction->update([
182182
$itilobject_type::getForeignKeyField() => $items_id, // These items don't use `id` as the index field...
183183
'satisfaction' => 5
184-
]))->isTrue();
184+
]));
185185

186-
$this->variable($satisfaction->fields['date_answered'])->isNotNull();
187-
$this->string($satisfaction->fields['date_answered'])->isEqualTo($_SESSION['glpi_currenttime']);
186+
$this->assertNotNull($satisfaction->fields['date_answered']);
187+
$this->assertEquals($_SESSION['glpi_currenttime'], $satisfaction->fields['date_answered']);
188188
}
189189
}

tests/functional/ChangeSatisfaction.php renamed to phpunit/functional/ChangeSatisfactionTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@
3636
namespace tests\units;
3737

3838
// Force import because of atoum autoloader not working
39-
require_once 'CommonITILSatisfaction.php';
39+
require_once __DIR__ . '/../abstracts/CommonITILSatisfaction.php';
4040

41-
class ChangeSatisfaction extends CommonITILSatisfaction
41+
class ChangeSatisfactionTest extends CommonITILSatisfaction
4242
{
4343
}

tests/functional/Cluster.php renamed to phpunit/functional/ClusterTest.php

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
use Item_Cluster;
4141
use NetworkEquipment;
4242

43-
class Cluster extends DbTestCase
43+
class ClusterTest extends DbTestCase
4444
{
4545
protected function getClusterByItemProvider(): iterable
4646
{
@@ -129,17 +129,19 @@ protected function getClusterByItemProvider(): iterable
129129
];
130130
}
131131

132-
/**
133-
* @dataProvider getClusterByItemProvider
134-
*/
135-
public function testgetClusterByItem(CommonDBTM $item, ?int $expected): void
132+
public function testgetClusterByItem(): void
136133
{
137-
$result = \Cluster::getClusterByItem($item);
138-
if ($result === null) {
139-
$this->variable($result)->isNull();
140-
} else {
141-
$this->object($result)->isInstanceOf(\Cluster::class);
142-
$this->integer($result->getID())->isEqualTo($expected);
134+
foreach ($this->getClusterByItemProvider() as $row) {
135+
$item = $row["item"];
136+
$expected = $row["expected"];
137+
138+
$result = \Cluster::getClusterByItem($item);
139+
if ($result === null) {
140+
$this->assertNull($result);
141+
} else {
142+
$this->assertInstanceOf(\Cluster::class, $result);
143+
$this->assertEquals($expected, $result->getID());
144+
}
143145
}
144146
}
145147
}

0 commit comments

Comments
 (0)