Skip to content

Commit f30c28e

Browse files
committed
test(category): refactor class expressions
1 parent 238b4fc commit f30c28e

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

tests/3-unit/PluginFormcreatorCategory.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030
*/
3131
namespace tests\units;
3232
use GlpiPlugin\Formcreator\Tests\CommonTestCase;
33+
use Entity;
34+
use PluginFormcreatorForm;
35+
use Session;
3336

3437
class PluginFormcreatorCategory extends CommonTestCase {
3538
public function providerGetTypeName() {
@@ -80,15 +83,15 @@ public function testGetCategoryTree() {
8083

8184
// create a sub entity which will take in the forms and cateory for this test
8285
// and not conflict with previous data
83-
$entity = new \Entity();
86+
$entity = new Entity();
8487
$rand = mt_rand();
8588
$entities_id = $entity->add([
8689
'name' => "test formcreator sub entity $rand",
8790
'entities_id' => 0
8891
]);
8992

9093
// create some categories for forms
91-
$category = new \PluginFormcreatorCategory;
94+
$category = $this->newTestedInstance();
9295
$categories = [];
9396
for ($i = 0; $i < 5; $i++) {
9497
$root_cat = $category->add([
@@ -104,7 +107,7 @@ public function testGetCategoryTree() {
104107
}
105108

106109
// create some forms
107-
$form = new \PluginFormcreatorForm;
110+
$form = new PluginFormcreatorForm;
108111
for ($i = 0; $i < 10; $i++) {
109112
$form->add([
110113
'name' => "testgetCategoryTree form $i",
@@ -116,10 +119,11 @@ public function testGetCategoryTree() {
116119
}
117120

118121
// Set active entity
119-
\Session::changeActiveEntities($entities_id, true);
122+
Session::changeActiveEntities($entities_id, true);
120123

121124
//test method
122-
$tree = \PluginFormcreatorCategory::getCategoryTree();
125+
$testedClassName = $this->getTestedClassName();
126+
$tree = $testedClassName::getCategoryTree();
123127
$this->array($tree)
124128
->isNotEmpty()
125129
->child['subcategories'](function($child) {
@@ -132,6 +136,6 @@ public function testGetCategoryTree() {
132136
}
133137

134138
// return to root entity
135-
\Session::changeActiveEntities(0, true);
139+
Session::changeActiveEntities(0, true);
136140
}
137141
}

0 commit comments

Comments
 (0)