Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ parameters:
- install
- hook.php
- setup.php
- tests
scanDirectories:
- ../../inc
- ../../src
Expand Down
1 change: 1 addition & 0 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
__DIR__ . '/public',
__DIR__ . '/src',
__DIR__ . '/tools',
__DIR__ . '/tests',
])
->withPhpVersion(PhpVersion::PHP_82)
->withCache(
Expand Down
4 changes: 2 additions & 2 deletions tests/src/CommonTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@
*/
protected function createItem(string $itemtype, array $input = []): CommonDBTM
{
global $DB;

Check failure on line 164 in tests/src/CommonTestCase.php

View workflow job for this annotation

GitHub Actions / GLPI 11.0.x - php:8.2 - mariadb:10.6 / Continuous integration

Missing PHPDoc tag `@var` for global variable $DB

Check failure on line 164 in tests/src/CommonTestCase.php

View workflow job for this annotation

GitHub Actions / GLPI 11.0.x - php:8.4 - mariadb:11.4 / Continuous integration

Missing PHPDoc tag `@var` for global variable $DB

$this->handleDeprecations($itemtype, $input);

Expand Down Expand Up @@ -241,20 +241,20 @@
{
$usage_profile = $this->createItem(ComputerUsageProfile::class, $usage_profile_params);
$glpi_computer = $this->createItem(Computer::class);
$impact = $this->createItem(UsageInfo::class, [
$this->createItem(UsageInfo::class, [
'itemtype' => Computer::class,
'items_id' => $glpi_computer->getId(),
ComputerUsageProfile::getForeignKeyField() => $usage_profile->getID(),
]);

return $glpi_computer;

Check failure on line 250 in tests/src/CommonTestCase.php

View workflow job for this annotation

GitHub Actions / GLPI 11.0.x - php:8.2 - mariadb:10.6 / Continuous integration

Method GlpiPlugin\Carbon\Tests\CommonTestCase::createComputerUsageProfile() should return Computer but returns CommonDBTM.

Check failure on line 250 in tests/src/CommonTestCase.php

View workflow job for this annotation

GitHub Actions / GLPI 11.0.x - php:8.4 - mariadb:11.4 / Continuous integration

Method GlpiPlugin\Carbon\Tests\CommonTestCase::createComputerUsageProfile() should return Computer but returns CommonDBTM.
}

protected function createComputerUsageProfilePower(array $usage_profile_params, int $type_power): Computer
{
$glpi_computer = $this->createComputerUsageProfile($usage_profile_params);
$glpiComputerType = $this->createItem(GlpiComputerType::class);
$carbonComputerType = $this->createItem(ComputerType::class, [
$this->createItem(ComputerType::class, [
GlpiComputerType::getForeignKeyField() => $glpiComputerType->getID(),
'power_consumption' => $type_power,
]);
Expand Down
2 changes: 1 addition & 1 deletion tests/src/Engine/V1/EngineTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public function getPowerProvider(): \Generator

$model = $this->createItem(static::$model_class);
$glpi_type = $this->createItem(static::$glpi_type_class);
$type = $this->createItem(static::$type_class, [
$this->createItem(static::$type_class, [
static::$glpi_type_class::getForeignKeyField() => $glpi_type->getID(),
'power_consumption' => 40
]);
Expand Down
4 changes: 2 additions & 2 deletions tests/src/GlobalFixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public static function loadDataset()
// ini_set('auto_detect_line_endings', true);
$file = dirname(__DIR__) . '/fixtures/carbon_intensity.csv';
if (($handle = fopen($file, 'r')) === false) {
fwrite(STDOUT, sprintf('Failed to open carbon intensity dataset CSV file' . PHP_EOL));
fwrite(STDOUT, 'Failed to open carbon intensity dataset CSV file' . PHP_EOL);
exit(1);
}
while (($row = fgetcsv($handle, 256, ',', '"', '\\')) !== false) {
Expand All @@ -148,7 +148,7 @@ public static function loadDataset()
];
$count = (new DbUtils())->countElementsInTable($intensity_table, $condition);
if ($count !== 3648) {
fwrite(STDOUT, sprintf('Failed to load carbon intensity dataset' . PHP_EOL));
fwrite(STDOUT, 'Failed to load carbon intensity dataset' . PHP_EOL);
exit(1);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/uninstall/PluginUninstallTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function testUninstallPlugin()
// Uninstall the plugin
ob_start();
$plugin->uninstall($plugin->getID());
$log = ob_get_clean();
ob_get_clean();

// Check the plugin is not installed
$plugin->getFromDBbyDir(strtolower($pluginName));
Expand Down
2 changes: 1 addition & 1 deletion tests/units/CarbonIntensitySourceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public function testDisplayTabContentForItem()

$item = $this->createItem(Zone::class);
$source = $this->createItem(CarbonIntensitySource::class);
$source_zone = $this->createItem(CarbonIntensitySource_Zone::class, [
$this->createItem(CarbonIntensitySource_Zone::class, [
$item::getForeignKeyField() => $item->getID(),
$source::getForeignKeyField() => $source->getID()
]);
Expand Down
4 changes: 2 additions & 2 deletions tests/units/CarbonIntensitySource_ZoneTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function testShowForSource()

$this->login('glpi', 'glpi');
ob_start();
$result = $instance->showForSource($source);
$instance->showForSource($source);
$output = ob_get_clean();
$this->assertNotEmpty($output);
}
Expand Down Expand Up @@ -97,7 +97,7 @@ public function testShowForZone()

$this->login('glpi', 'glpi');
ob_start();
$result = $instance->showForZone($zone);
$instance->showForZone($zone);
$output = ob_get_clean();
$this->assertNotEmpty($output);
}
Expand Down
18 changes: 9 additions & 9 deletions tests/units/CarbonIntensityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function testGetLastKnownDate()
$source = $this->createItem(CarbonIntensitySource::class, [
'name' => 'bar'
]);
$source_zone = $this->createItem(CarbonIntensitySource_Zone::class, [
$this->createItem(CarbonIntensitySource_Zone::class, [
$source::getForeignKeyField() => $source->getID(),
$zone::getForeignKeyField() => $zone->getID()
]);
Expand All @@ -78,7 +78,7 @@ public function testGetLastKnownDate()
'data_quality' => 2,
]);
$expected = '2024-02-01 00:00:00';
$intensity = $this->createItem(CarbonIntensity::class, [
$this->createItem(CarbonIntensity::class, [
'date' => $expected,
$source::getForeignKeyField() => $source->getID(),
$zone::getForeignKeyField() => $zone->getID(),
Expand All @@ -101,7 +101,7 @@ public function testGetFirstKnownDate()
$source = $this->createItem(CarbonIntensitySource::class, [
'name' => 'bar'
]);
$source_zone = $this->createItem(CarbonIntensitySource_Zone::class, [
$this->createItem(CarbonIntensitySource_Zone::class, [
$source::getForeignKeyField() => $source->getID(),
$zone::getForeignKeyField() => $zone->getID()
]);
Expand All @@ -116,7 +116,7 @@ public function testGetFirstKnownDate()
'data_quality' => 2,
]);
$expected = '2024-02-01 00:00:00';
$intensity = $this->createItem(CarbonIntensity::class, [
$this->createItem(CarbonIntensity::class, [
'date' => $expected,
$source::getForeignKeyField() => $source->getID(),
$zone::getForeignKeyField() => $zone->getID(),
Expand Down Expand Up @@ -154,7 +154,7 @@ public function testFindGaps()
'name' => 'test_zone',
'plugin_carbon_carbonintensitysources_id_historical' => $source->getID(),
]);
$source_zone = $this->createItem(CarbonIntensitySource_Zone::class, [
$this->createItem(CarbonIntensitySource_Zone::class, [
'plugin_carbon_carbonintensitysources_id' => $source->getID(),
'plugin_carbon_zones_id' => $zone->getID(),
]);
Expand Down Expand Up @@ -296,7 +296,7 @@ public function testGetDownloadStartDate()
$this->assertEquals($expected, $result);

$computer = $this->createItem(Computer::class);
$infocom = $this->createItem(Infocom::class, [
$this->createItem(Infocom::class, [
'itemtype' => $computer->getType(),
'items_id' => $computer->getID(),
'buy_date' => '2022-02-01',
Expand Down Expand Up @@ -328,11 +328,11 @@ public function testGetDownloadStopDate()
'name' => 'bar'
]);
$expected = new DateTimeImmutable('2019-01-31 23:00:00');
$source_zone = $this->createItem(CarbonIntensitySource_Zone::class, [
$this->createItem(CarbonIntensitySource_Zone::class, [
$source::getForeignKeyField() => $source->getID(),
$zone::getForeignKeyField() => $zone->getID(),
]);
$intensity = $this->createItem(CarbonIntensity::class, [
$this->createItem(CarbonIntensity::class, [
'date' => '2019-02-01',
$source::getForeignKeyField() => $source->getID(),
$zone::getForeignKeyField() => $zone->getID(),
Expand All @@ -355,7 +355,7 @@ public function testDownloadOneZone()
$source = $this->createItem(CarbonIntensitySource::class, [
'name' => 'bar'
]);
$source_zone = $this->createItem(CarbonIntensitySource_Zone::class, [
$this->createItem(CarbonIntensitySource_Zone::class, [
$source::getForeignKeyField() => $source->getID(),
$zone::getForeignKeyField() => $zone->getID()
]);
Expand Down
2 changes: 1 addition & 1 deletion tests/units/ComputerUsageProfileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public function testShowMassiveActionsSubForm()
ob_start(function ($buffer) {
return $buffer;
});
$result = ComputerUsageProfile::showMassiveActionsSubForm($massive_action);
ComputerUsageProfile::showMassiveActionsSubForm($massive_action);
$output = ob_get_clean();
$crawler = new Crawler($output);
$selector = $crawler->filter('select[name="plugin_carbon_computerusageprofiles_id"]');
Expand Down
2 changes: 1 addition & 1 deletion tests/units/CronTaskTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public function testFillIncompleteLocations()
]);

// Test a single
$glpi_locations = $this->getItems([
$this->getItems([
GlpiLocation::class => [
[
'name' => 'Valid Location',
Expand Down
14 changes: 7 additions & 7 deletions tests/units/Dashboard/ProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,18 @@ public function setUp(): void
protected function handledComputersCountFixture(): int
{
// Switch to an empty entity
$entities_id = $this->isolateInEntity('glpi', 'glpi');
$this->isolateInEntity('glpi', 'glpi');

$glpi_computer_type_empty = $this->createItem(GlpiComputerType::class);

$glpi_computer_type = $this->createItem(GlpiComputerType::class);

$computer_type_empty = $this->createItem(ComputerType::class, [
$this->createItem(ComputerType::class, [
'computertypes_id' => $glpi_computer_type_empty->getID(),
'power_consumption' => 0,
]);

$computer_type = $this->createItem(ComputerType::class, [
$this->createItem(ComputerType::class, [
'computertypes_id' => $glpi_computer_type->getID(),
'power_consumption' => 90,
]);
Expand Down Expand Up @@ -166,7 +166,7 @@ protected function handledComputersCountFixture(): int

public function testGetHandledComputersCount()
{
$total_count = $this->handledComputersCountFixture();
$this->handledComputersCountFixture();

// 3 computers are complete
// 1 having both power_consumption from computer type and computer model
Expand All @@ -186,7 +186,7 @@ public function testGetUnhandledComputersCount()

public function testGetHandledAssetsRatio()
{
$total_count = $this->handledComputersCountFixture();
$this->handledComputersCountFixture();
$result = Provider::getHandledAssetsRatio([Computer::class]);
$expected = 19; // This is a percentage
$this->assertEquals($expected, $result['data'][0]['number']);
Expand Down Expand Up @@ -265,7 +265,7 @@ public function testGetSumUsageEmissionsPerModel()

public function testGetSumPowerPerModel()
{
$entities_id = $this->isolateInEntity('glpi', 'glpi');
$this->isolateInEntity('glpi', 'glpi');

$country = $this->getUniqueString();
$usage_profile = [
Expand Down Expand Up @@ -339,7 +339,7 @@ public function testGetUsageCarbonEmissionPerMonth()
'day_7' => 1,
];
$computer_1 = $this->createComputerUsageProfilePowerLocation($usage_profile, 60, PLUGIN_CARBON_TEST_FAKE_ZONE_NAME);
$infocom = $this->createItem(Infocom::class, [
$this->createItem(Infocom::class, [
'itemtype' => $computer_1->getType(),
'items_id' => $computer_1->getID(),
'buy_date' => '2024-01-01',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function testFetchDay()
$zone = new Zone();
$zone->getFromDbByCrit(['name' => 'France']);
$this->assertFalse($zone->isNewItem());
$source_zone = $this->createItem(CarbonIntensitySource_Zone::class, [
$this->createItem(CarbonIntensitySource_Zone::class, [
CarbonIntensitySource::getForeignKeyField() => $source->getID(),
Zone::getForeignKeyField() => $zone->getID(),
'code' => 'FR'
Expand Down
2 changes: 1 addition & 1 deletion tests/units/Engine/V1/ComputerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ private function computerSetModelWithPower(GlpiComputer $computer, int $power)
private function computerSetTypeWithPower(GlpiComputer $computer, int $power)
{
$glpi_computer_type = $this->createItem(GlpiComputerType::class);
$carbonComputerType = $this->createItem(ComputerType::class, [
$this->createItem(ComputerType::class, [
GlpiComputerType::getForeignKeyField() => $glpi_computer_type->getID(),
'power_consumption' => $power,
]);
Expand Down
10 changes: 5 additions & 5 deletions tests/units/Engine/V1/MonitorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ public function testGetUsageProfile()
{
$computer = $this->createItem(GlpiComputer::class);
$profile = $this->createItem(ComputerUsageProfile::class);
$impact = $this->createItem(UsageInfo::class, [
$this->createItem(UsageInfo::class, [
'itemtype' => GlpiComputer::class,
'items_id' => $computer->getID(),
'plugin_carbon_computerusageprofiles_id' => $profile->getID(),
]);
$monitor = $this->createItem(GlpiMonitor::class);
$computer_item = $this->createItem(Computer_Item::class, [
$this->createItem(Computer_Item::class, [
'computers_id' => $computer->getID(),
'itemtype' => $monitor->getType(),
'items_id' => $monitor->getID(),
Expand Down Expand Up @@ -130,7 +130,7 @@ public function getEnergyPerDayProvider(): \Generator
$item = $this->createItem(static::$itemtype_class, [
static::$model_class::getForeignKeyField() => $model->getID(),
]);
$computer_item = $this->createItem(Computer_Item::class, [
$this->createItem(Computer_Item::class, [
'computers_id' => $computer->getID(),
'itemtype' => $item->getType(),
'items_id' => $item->getID(),
Expand Down Expand Up @@ -166,15 +166,15 @@ public function getCarbonEmissionPerDateProvider(): \Generator
];
$computer = $this->createComputerUsageProfilePowerLocation($usage_profile, 40, $country);
$glpi_monitor_type = $this->createItem(GlpiMonitorType::class);
$monitory_type = $this->createItem(MonitorType::class, [
$this->createItem(MonitorType::class, [
'monitortypes_id' => $glpi_monitor_type->getID(),
'power_consumption' => 31,
]);
$monitor = $this->createItem(GlpiMonitor::class, [
'locations_id' => $computer->fields['locations_id'],
'monitortypes_id' => $glpi_monitor_type->getID(),
]);
$computer_item = $this->createItem(Computer_Item::class, [
$this->createItem(Computer_Item::class, [
'computers_id' => $computer->getID(),
'itemtype' => $monitor->getType(),
'items_id' => $monitor->getID(),
Expand Down
Loading
Loading