Skip to content

Commit e5a064d

Browse files
committed
test: add tests
1 parent b2e719a commit e5a064d

7 files changed

Lines changed: 154 additions & 6 deletions

File tree

src/Impact/Embodied/AbstractEmbodiedImpact.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ abstract protected function getVersion(): string;
8989
*/
9090
final public function getUnit(int $type, bool $short = true): ?string
9191
{
92+
// TODO: This methos is probably never called now. Check and drop.
9293
switch ($type) {
9394
case Type::IMPACT_GWP:
9495
return $short ? 'gCO2eq' : __('grams of carbon dioxyde equivalent', 'carbon');

tests/src/Impact/Embodied/AbstractEmbodiedImpactTest.php renamed to tests/src/Impact/Embodied/AbstractCommonEmbodiedImpactTest.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,22 @@
3939
use PHPUnit\Framework\Attributes\CoversClass;
4040

4141
#[CoversClass(AbstractEmbodiedImpact::class)]
42-
class AbstractEmbodiedImpactTest extends DbTestCase
42+
class AbstractCommonEmbodiedImpactTest extends DbTestCase
4343
{
4444
protected static string $itemtype = '';
4545
protected static string $itemtype_type = '';
4646
protected static string $itemtype_model = '';
4747

48-
public function testGetItemsToEvaluate()
48+
public static function setUpBeforeClass(): void
4949
{
5050
if (static::$itemtype === '' || static::$itemtype_type === '' || static::$itemtype_model === '') {
5151
// Ensure that the inherited test class is properly implemented for this test
52-
$this->fail('Itemtype properties not set in ' . static::class);
52+
self::fail('Itemtype properties not set in ' . static::class);
5353
}
54+
}
5455

56+
public function test_GetItemsToEvaluate_evaluates_asset_when_no_embodied_impact_exists()
57+
{
5558
// Test the asset is evaluable when no embodied impact is in the DB
5659
$glpi_asset_type = $this->createItem(static::$itemtype_type);
5760
$asset_type = $this->createItem('GlpiPlugin\\Carbon\\' . static::$itemtype_type, [
@@ -64,7 +67,10 @@ public function testGetItemsToEvaluate()
6467
$asset->getTableField('id') => $asset->getID(),
6568
]);
6669
$this->assertEquals(1, $iterator->count());
70+
}
6771

72+
public function test_GetItemsToEvaluate_does_not_evaluates_asset_when_embodied_impact_exists()
73+
{
6874
// Test the asset is no longer evaluable when there is embodied impact in the DB
6975
$glpi_asset_type = $this->createItem(static::$itemtype_type);
7076
$asset_type = $this->createItem('GlpiPlugin\\Carbon\\' . static::$itemtype_type, [
@@ -82,8 +88,11 @@ public function testGetItemsToEvaluate()
8288
$asset::getTableField('id') => $asset->getID(),
8389
]);
8490
$this->assertEquals(0, $iterator->count());
91+
}
8592

86-
// Test the asset is evaluable when there is embodied impact in the DB but recamculate is set
93+
public function test_GetItemsToEvaluate_evaluates_asset_when_embodied_impact_exists_and_marked_for_recalculation()
94+
{
95+
// Test the asset is evaluable when there is embodied impact in the DB but recalculate is set
8796
$glpi_asset_type = $this->createItem(static::$itemtype_type);
8897
$asset_type = $this->createItem('GlpiPlugin\\Carbon\\' . static::$itemtype_type, [
8998
getForeignKeyFieldForItemType(static::$itemtype_type) => $glpi_asset_type->getID(),
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
/**
4+
* -------------------------------------------------------------------------
5+
* Carbon plugin for GLPI
6+
*
7+
* @copyright Copyright (C) 2024-2025 Teclib' and contributors.
8+
* @license https://www.gnu.org/licenses/gpl-3.0.txt GPLv3+
9+
* @link https://github.com/pluginsGLPI/carbon
10+
*
11+
* -------------------------------------------------------------------------
12+
*
13+
* LICENSE
14+
*
15+
* This file is part of Carbon plugin for GLPI.
16+
*
17+
* This program is free software: you can redistribute it and/or modify
18+
* it under the terms of the GNU General Public License as published by
19+
* the Free Software Foundation, either version 3 of the License, or
20+
* (at your option) any later version.
21+
*
22+
* This program is distributed in the hope that it will be useful,
23+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
24+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25+
* GNU General Public License for more details.
26+
*
27+
* You should have received a copy of the GNU General Public License
28+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
29+
*
30+
* -------------------------------------------------------------------------
31+
*/
32+
33+
namespace GlpiPlugin\Carbon\Tests\Impact\Embodied\Boavizta;
34+
35+
use GlpiPlugin\Carbon\Impact\Embodied\AbstractEmbodiedImpact;
36+
use GlpiPlugin\Carbon\Tests\Impact\Embodied\AbstractCommonEmbodiedImpactTest;
37+
use PHPUnit\Framework\Attributes\CoversClass;
38+
39+
#[CoversClass(AbstractEmbodiedImpact::class)]
40+
class AbstractEmbodiedImpactTest extends AbstractCommonEmbodiedImpactTest
41+
{
42+
protected static string $itemtype = '';
43+
protected static string $itemtype_type = '';
44+
protected static string $itemtype_model = '';
45+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
/**
4+
* -------------------------------------------------------------------------
5+
* Carbon plugin for GLPI
6+
*
7+
* @copyright Copyright (C) 2024-2025 Teclib' and contributors.
8+
* @license https://www.gnu.org/licenses/gpl-3.0.txt GPLv3+
9+
* @link https://github.com/pluginsGLPI/carbon
10+
*
11+
* -------------------------------------------------------------------------
12+
*
13+
* LICENSE
14+
*
15+
* This file is part of Carbon plugin for GLPI.
16+
*
17+
* This program is free software: you can redistribute it and/or modify
18+
* it under the terms of the GNU General Public License as published by
19+
* the Free Software Foundation, either version 3 of the License, or
20+
* (at your option) any later version.
21+
*
22+
* This program is distributed in the hope that it will be useful,
23+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
24+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25+
* GNU General Public License for more details.
26+
*
27+
* You should have received a copy of the GNU General Public License
28+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
29+
*
30+
* -------------------------------------------------------------------------
31+
*/
32+
33+
namespace GlpiPlugin\Carbon\Tests\Impact\Embodied\Internal;
34+
35+
use GlpiPlugin\Carbon\Impact\Embodied\AbstractEmbodiedImpact;
36+
use GlpiPlugin\Carbon\Tests\Impact\Embodied\AbstractCommonEmbodiedImpactTest;
37+
use PHPUnit\Framework\Attributes\CoversClass;
38+
39+
#[CoversClass(AbstractEmbodiedImpact::class)]
40+
class AbstractEmbodiedImpactTest extends AbstractCommonEmbodiedImpactTest
41+
{
42+
protected static string $itemtype = '';
43+
protected static string $itemtype_type = '';
44+
protected static string $itemtype_model = '';
45+
}

tests/units/Impact/Embodied/Boavizta/ComputerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
use ComputerModel as GlpiComputerModel;
3737
use ComputerType as GlpiComputerType;
3838
use GlpiPlugin\Carbon\Impact\Embodied\Boavizta\Computer as BoaviztaComputer;
39-
use GlpiPlugin\Carbon\Tests\Impact\Embodied\AbstractEmbodiedImpactTest;
39+
use GlpiPlugin\Carbon\Tests\Impact\Embodied\Boavizta\AbstractEmbodiedImpactTest;
4040
use PHPUnit\Framework\Attributes\CoversClass;
4141

4242
#[CoversClass(BoaviztaComputer::class)]

tests/units/Impact/Embodied/Boavizta/MonitorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
namespace GlpiPlugin\Carbon\Impact\Embodied\Boavizta\Tests;
3434

3535
use GlpiPlugin\Carbon\Impact\Embodied\Boavizta\Monitor as BoaviztaMonitor;
36-
use GlpiPlugin\Carbon\Tests\Impact\Embodied\AbstractEmbodiedImpactTest;
36+
use GlpiPlugin\Carbon\Tests\Impact\Embodied\Boavizta\AbstractEmbodiedImpactTest;
3737
use Monitor as GlpiMonitor;
3838
use MonitorModel as glpiMonitorModel;
3939
use MonitorType as GlpiMonitorType;
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
/**
4+
* -------------------------------------------------------------------------
5+
* Carbon plugin for GLPI
6+
*
7+
* @copyright Copyright (C) 2024-2025 Teclib' and contributors.
8+
* @license https://www.gnu.org/licenses/gpl-3.0.txt GPLv3+
9+
* @link https://github.com/pluginsGLPI/carbon
10+
*
11+
* -------------------------------------------------------------------------
12+
*
13+
* LICENSE
14+
*
15+
* This file is part of Carbon plugin for GLPI.
16+
*
17+
* This program is free software: you can redistribute it and/or modify
18+
* it under the terms of the GNU General Public License as published by
19+
* the Free Software Foundation, either version 3 of the License, or
20+
* (at your option) any later version.
21+
*
22+
* This program is distributed in the hope that it will be useful,
23+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
24+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25+
* GNU General Public License for more details.
26+
*
27+
* You should have received a copy of the GNU General Public License
28+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
29+
*
30+
* -------------------------------------------------------------------------
31+
*/
32+
33+
namespace GlpiPlugin\Carbon\Impact\Embodied\Internal\Tests;
34+
35+
use Computer as GlpiComputer;
36+
use ComputerModel as GlpiComputerModel;
37+
use ComputerType as GlpiComputerType;
38+
use GlpiPlugin\Carbon\Impact\Embodied\Internal\Computer as InternalComputer;
39+
use GlpiPlugin\Carbon\Tests\Impact\Embodied\Internal\AbstractEmbodiedImpactTest;
40+
use PHPUnit\Framework\Attributes\CoversClass;
41+
42+
#[CoversClass(InternalComputer::class)]
43+
class ComputerTest extends AbstractEmbodiedImpactTest
44+
{
45+
protected static string $itemtype = GlpiComputer::class;
46+
protected static string $itemtype_type = GlpiComputerType::class;
47+
protected static string $itemtype_model = GlpiComputerModel::class;
48+
}

0 commit comments

Comments
 (0)