From f0687f4fc132e7a9e8b58f030fbe621be27d36c0 Mon Sep 17 00:00:00 2001 From: Thierry Bugier Date: Fri, 10 Oct 2025 09:25:44 +0200 Subject: [PATCH 1/2] ci(lint): extend lint to test files --- phpstan.neon | 1 + rector.php | 1 + 2 files changed, 2 insertions(+) diff --git a/phpstan.neon b/phpstan.neon index c02769b3..14367437 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -12,6 +12,7 @@ parameters: - install - hook.php - setup.php + - tests scanDirectories: - ../../inc - ../../src diff --git a/rector.php b/rector.php index 5c4c3656..648c1e6e 100644 --- a/rector.php +++ b/rector.php @@ -44,6 +44,7 @@ __DIR__ . '/public', __DIR__ . '/src', __DIR__ . '/tools', + __DIR__ . '/tests', ]) ->withPhpVersion(PhpVersion::PHP_82) ->withCache( From baedbdc70c1d340744a816f3c47b129418e26bc6 Mon Sep 17 00:00:00 2001 From: Thierry Bugier Date: Fri, 10 Oct 2025 09:26:54 +0200 Subject: [PATCH 2/2] style(lint): fix unused vars in tests with Rector --- tests/src/CommonTestCase.php | 4 +- tests/src/Engine/V1/EngineTestCase.php | 2 +- tests/src/GlobalFixture.php | 4 +- tests/uninstall/PluginUninstallTest.php | 2 +- tests/units/CarbonIntensitySourceTest.php | 2 +- .../units/CarbonIntensitySource_ZoneTest.php | 4 +- tests/units/CarbonIntensityTest.php | 18 +++---- tests/units/ComputerUsageProfileTest.php | 2 +- tests/units/CronTaskTest.php | 2 +- tests/units/Dashboard/ProviderTest.php | 14 ++--- .../ElectricityMapClientTest.php | 2 +- tests/units/Engine/V1/ComputerTest.php | 2 +- tests/units/Engine/V1/MonitorTest.php | 10 ++-- tests/units/Impact/History/ComputerTest.php | 24 ++++----- tests/units/Impact/History/MonitorTest.php | 51 +++++++------------ .../Impact/History/NetworkEquipmentTest.php | 20 ++------ tests/units/LocationTest.php | 4 +- tests/units/ProfileTest.php | 2 +- tests/units/SearchTest.php | 1 - tests/units/ToolboxTest.php | 2 +- 20 files changed, 74 insertions(+), 98 deletions(-) diff --git a/tests/src/CommonTestCase.php b/tests/src/CommonTestCase.php index bc9c5666..b7f74472 100644 --- a/tests/src/CommonTestCase.php +++ b/tests/src/CommonTestCase.php @@ -241,7 +241,7 @@ protected function createComputerUsageProfile(array $usage_profile_params): Comp { $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(), @@ -254,7 +254,7 @@ protected function createComputerUsageProfilePower(array $usage_profile_params, { $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, ]); diff --git a/tests/src/Engine/V1/EngineTestCase.php b/tests/src/Engine/V1/EngineTestCase.php index 07583a0f..7f38f70d 100644 --- a/tests/src/Engine/V1/EngineTestCase.php +++ b/tests/src/Engine/V1/EngineTestCase.php @@ -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 ]); diff --git a/tests/src/GlobalFixture.php b/tests/src/GlobalFixture.php index cd6abbe1..684a15cc 100644 --- a/tests/src/GlobalFixture.php +++ b/tests/src/GlobalFixture.php @@ -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) { @@ -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); } diff --git a/tests/uninstall/PluginUninstallTest.php b/tests/uninstall/PluginUninstallTest.php index 718b1c04..c7cbf3d6 100644 --- a/tests/uninstall/PluginUninstallTest.php +++ b/tests/uninstall/PluginUninstallTest.php @@ -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)); diff --git a/tests/units/CarbonIntensitySourceTest.php b/tests/units/CarbonIntensitySourceTest.php index f7589969..9b9530d9 100644 --- a/tests/units/CarbonIntensitySourceTest.php +++ b/tests/units/CarbonIntensitySourceTest.php @@ -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() ]); diff --git a/tests/units/CarbonIntensitySource_ZoneTest.php b/tests/units/CarbonIntensitySource_ZoneTest.php index 3e4749be..724637f4 100644 --- a/tests/units/CarbonIntensitySource_ZoneTest.php +++ b/tests/units/CarbonIntensitySource_ZoneTest.php @@ -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); } @@ -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); } diff --git a/tests/units/CarbonIntensityTest.php b/tests/units/CarbonIntensityTest.php index 2c6a3793..983950eb 100644 --- a/tests/units/CarbonIntensityTest.php +++ b/tests/units/CarbonIntensityTest.php @@ -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() ]); @@ -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(), @@ -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() ]); @@ -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(), @@ -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(), ]); @@ -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', @@ -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(), @@ -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() ]); diff --git a/tests/units/ComputerUsageProfileTest.php b/tests/units/ComputerUsageProfileTest.php index c0150768..d6f4b8c7 100644 --- a/tests/units/ComputerUsageProfileTest.php +++ b/tests/units/ComputerUsageProfileTest.php @@ -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"]'); diff --git a/tests/units/CronTaskTest.php b/tests/units/CronTaskTest.php index 417e04e7..3f60adbc 100644 --- a/tests/units/CronTaskTest.php +++ b/tests/units/CronTaskTest.php @@ -137,7 +137,7 @@ public function testFillIncompleteLocations() ]); // Test a single - $glpi_locations = $this->getItems([ + $this->getItems([ GlpiLocation::class => [ [ 'name' => 'Valid Location', diff --git a/tests/units/Dashboard/ProviderTest.php b/tests/units/Dashboard/ProviderTest.php index fda3baa6..8f283efa 100644 --- a/tests/units/Dashboard/ProviderTest.php +++ b/tests/units/Dashboard/ProviderTest.php @@ -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, ]); @@ -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 @@ -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']); @@ -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 = [ @@ -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', diff --git a/tests/units/DataSource/CarbonIntensity/ElectricityMapClientTest.php b/tests/units/DataSource/CarbonIntensity/ElectricityMapClientTest.php index 358c0c40..c5817963 100644 --- a/tests/units/DataSource/CarbonIntensity/ElectricityMapClientTest.php +++ b/tests/units/DataSource/CarbonIntensity/ElectricityMapClientTest.php @@ -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' diff --git a/tests/units/Engine/V1/ComputerTest.php b/tests/units/Engine/V1/ComputerTest.php index 27491754..d18b0662 100644 --- a/tests/units/Engine/V1/ComputerTest.php +++ b/tests/units/Engine/V1/ComputerTest.php @@ -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, ]); diff --git a/tests/units/Engine/V1/MonitorTest.php b/tests/units/Engine/V1/MonitorTest.php index 21739859..7248752c 100644 --- a/tests/units/Engine/V1/MonitorTest.php +++ b/tests/units/Engine/V1/MonitorTest.php @@ -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(), @@ -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(), @@ -166,7 +166,7 @@ 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, ]); @@ -174,7 +174,7 @@ public function getCarbonEmissionPerDateProvider(): \Generator '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(), diff --git a/tests/units/Impact/History/ComputerTest.php b/tests/units/Impact/History/ComputerTest.php index 04b7b8bc..c60323ca 100644 --- a/tests/units/Impact/History/ComputerTest.php +++ b/tests/units/Impact/History/ComputerTest.php @@ -82,7 +82,7 @@ public function testEvaluateItem() } $this->login('glpi', 'glpi'); - $entities_id = $this->isolateInEntity('glpi', 'glpi'); + $this->isolateInEntity('glpi', 'glpi'); $model_power = 55; $location = $this->createItem(Location::class, [ @@ -90,7 +90,7 @@ public function testEvaluateItem() ]); $model = $this->createItem(GlpiComputerModel::class, ['power_consumption' => $model_power]); $glpi_type = $this->createItem(GlpiComputerType::class); - $type = $this->createItem(ComputerType::class, [ + $this->createItem(ComputerType::class, [ GlpiComputerType::getForeignKeyField() => $glpi_type->getID(), ]); $asset = $this->createItem(GlpiComputer::class, [ @@ -111,7 +111,7 @@ public function testEvaluateItem() 'day_6' => '0', 'day_7' => '0', ]); - $impact = $this->createItem(UsageInfo::class, [ + $this->createItem(UsageInfo::class, [ $usage_profile->getForeignKeyField() => $usage_profile->getID(), 'itemtype' => $asset->getType(), 'items_id' => $asset->getID(), @@ -220,7 +220,7 @@ public function testCanHistorize() // Add a usage profile $usage_profile = $this->createItem(ComputerUsageProfile::class); $this->assertFalse($history->canHistorize($id)); - $impact = $this->createItem(UsageInfo::class, [ + $this->createItem(UsageInfo::class, [ $usage_profile->getForeignKeyField() => $usage_profile->getID(), 'itemtype' => $computer->getType(), 'items_id' => $id, @@ -337,7 +337,7 @@ public function testComputerWithEmptyInfocomIsNotHistorizable() $history = new Computer(); $computer = $this->createItem(GlpiComputer::class); - $management = $this->createItem(Infocom::class, [ + $this->createItem(Infocom::class, [ 'itemtype' => $computer->getType(), 'items_id' => $computer->getID(), ]); @@ -365,7 +365,7 @@ public function testComputerWithEntryDateIsNotHistorizable() $history = new Computer(); $computer = $this->createItem(GlpiComputer::class); - $management = $this->createItem(Infocom::class, [ + $this->createItem(Infocom::class, [ 'itemtype' => $computer->getType(), 'items_id' => $computer->getID(), 'use_date' => '2020-01-01', @@ -481,7 +481,7 @@ public function testComputerWithUsageProfileIsNotHistorizable() $computer = $this->createItem(GlpiComputer::class); $usage_profile = $this->createItem(ComputerUsageProfile::class); - $impact = $this->createItem(UsageInfo::class, [ + $this->createItem(UsageInfo::class, [ $usage_profile->getForeignKeyField() => $usage_profile->getID(), 'itemtype' => $computer->getType(), 'items_id' => $computer->getID(), @@ -593,7 +593,7 @@ public function testComputerWithTypeIsNotHistorizable() $history = new Computer(); $glpi_computer_type = $this->createItem(GlpiComputerType::class); - $computer_type = $this->createItem(ComputerType::class, [ + $this->createItem(ComputerType::class, [ 'power_consumption' => 55, 'computertypes_id' => $glpi_computer_type->getID(), ]); @@ -624,7 +624,7 @@ public function testComputerWithCategoryIsNotHistorizable() $history = new Computer(); $glpi_computer_type = $this->createItem(GlpiComputerType::class); - $computer_type = $this->createItem(ComputerType::class, [ + $this->createItem(ComputerType::class, [ 'category' => ComputerType::CATEGORY_DESKTOP, 'computertypes_id' => $glpi_computer_type->getID(), ]); @@ -658,7 +658,7 @@ public function testComputerWithEverythingIsHistorizable() 'country' => 'France' ]); $glpi_computer_type = $this->createItem(GlpiComputerType::class); - $computer_type = $this->createItem(ComputerType::class, [ + $this->createItem(ComputerType::class, [ 'power_consumption' => 55, 'computertypes_id' => $glpi_computer_type->getID(), ]); @@ -666,13 +666,13 @@ public function testComputerWithEverythingIsHistorizable() 'locations_id' => $location->getID(), 'computertypes_id' => $glpi_computer_type->getID(), ]); - $management = $this->createItem(Infocom::class, [ + $this->createItem(Infocom::class, [ 'itemtype' => $computer->getType(), 'items_id' => $computer->getID(), 'use_date' => '2020-01-01', ]); $usage_profile = $this->createItem(ComputerUsageProfile::class); - $impact = $this->createItem(UsageInfo::class, [ + $this->createItem(UsageInfo::class, [ $usage_profile->getForeignKeyField() => $usage_profile->getID(), 'itemtype' => $computer->getType(), 'items_id' => $computer->getID(), diff --git a/tests/units/Impact/History/MonitorTest.php b/tests/units/Impact/History/MonitorTest.php index fac3fa82..42073ada 100644 --- a/tests/units/Impact/History/MonitorTest.php +++ b/tests/units/Impact/History/MonitorTest.php @@ -87,7 +87,7 @@ public function testEvaluateItem() } $this->login('glpi', 'glpi'); - $entities_id = $this->isolateInEntity('glpi', 'glpi'); + $this->isolateInEntity('glpi', 'glpi'); $model_power = 55; $location = $this->createItem(Location::class, [ @@ -97,7 +97,7 @@ public function testEvaluateItem() $computer_model_power = 80; $computer_model = $this->createItem(ComputerModel::class, ['power_consumption' => $computer_model_power]); $glpi_computer_type = $this->createItem(GlpiComputerType::class); - $computer_type = $this->createItem(ComputerType::class, [ + $this->createItem(ComputerType::class, [ GlpiComputerType::getForeignKeyField() => $glpi_computer_type->getID(), ]); $computer = $this->createItem(GlpiComputer::class, [ @@ -116,7 +116,7 @@ public function testEvaluateItem() 'day_6' => '0', 'day_7' => '0', ]); - $impact = $this->createItem(UsageInfo::class, [ + $this->createItem(UsageInfo::class, [ $usage_profile->getForeignKeyField() => $usage_profile->getID(), 'itemtype' => $computer->getType(), 'items_id' => $computer->getID(), @@ -124,7 +124,7 @@ public function testEvaluateItem() $model = $this->createItem(GlpiMonitorModel::class, ['power_consumption' => $model_power]); $glpi_type = $this->createItem(GlpiMonitorType::class); - $type = $this->createItem(MonitorType::class, [ + $this->createItem(MonitorType::class, [ GlpiMonitorType::getForeignKeyField() => $glpi_type->getID(), ]); $asset = $this->createItem(GlpiMonitor::class, [ @@ -134,7 +134,7 @@ public function testEvaluateItem() 'date_creation' => '2024-01-01', 'date_mod' => null, ]); - $computer_asset = $this->createItem(Computer_Item::class, [ + $this->createItem(Computer_Item::class, [ 'computers_id' => $computer->getID(), 'itemtype' => $asset->getType(), 'items_id' => $asset->getID(), @@ -211,7 +211,7 @@ private static function getMonitorLinkedToComputer(?GlpiComputer $computer = nul $item = $self->getItem(GlpiMonitor::class); - $computer_item = $self->getItem(Computer_Item::class, [ + $self->getItem(Computer_Item::class, [ 'computers_id' => $computer->getID(), 'itemtype' => $item->getType(), 'items_id' => $item->getID(), @@ -267,7 +267,6 @@ public function testEmptyMonitorIsNotHistorizable() 'has_inventory_entry_date' => false, ]; $this->assertEquals($expected, $result); - $expected = !in_array(false, $result, true); $result = $history->canHistorize($monitor->getID()); $this->assertFalse($result); } @@ -278,7 +277,7 @@ public function testMonitorLinkedToComputerIsNotHistorizable() $monitor = $this->createItem(GlpiMonitor::class); $computer = $this->createItem(GlpiComputer::class); - $computer_item = $this->createItem(Computer_Item::class, [ + $this->createItem(Computer_Item::class, [ 'computers_id' => $computer->getID(), 'itemtype' => $monitor->getType(), 'items_id' => $monitor->getID(), @@ -298,7 +297,6 @@ public function testMonitorLinkedToComputerIsNotHistorizable() 'has_inventory_entry_date' => false, ]; $this->assertEquals($expected, $result); - $expected = !in_array(false, $result, true); $result = $history->canHistorize($monitor->getID()); $this->assertFalse($result); } @@ -308,7 +306,7 @@ public function testMonitorWithEmptyInfocomIsNotHistorizable() $history = new Monitor(); $monitor = $this->createItem(GlpiMonitor::class); - $infocom = $this->createItem(Infocom::class, [ + $this->createItem(Infocom::class, [ 'itemtype' => $monitor->getType(), 'items_id' => $monitor->getID(), ]); @@ -327,7 +325,6 @@ public function testMonitorWithEmptyInfocomIsNotHistorizable() 'has_inventory_entry_date' => false, ]; $this->assertEquals($expected, $result); - $expected = !in_array(false, $result, true); $result = $history->canHistorize($monitor->getID()); $this->assertFalse($result); } @@ -337,7 +334,7 @@ public function testMonitorWithInfocomIsNotHistorizable() $history = new Monitor(); $monitor = $this->createItem(GlpiMonitor::class); - $infocom = $this->createItem(Infocom::class, [ + $this->createItem(Infocom::class, [ 'itemtype' => $monitor->getType(), 'items_id' => $monitor->getID(), 'buy_date' => '2024-01-01', @@ -357,7 +354,6 @@ public function testMonitorWithInfocomIsNotHistorizable() 'has_inventory_entry_date' => true, ]; $this->assertEquals($expected, $result); - $expected = !in_array(false, $result, true); $result = $history->canHistorize($monitor->getID()); $this->assertFalse($result); } @@ -371,7 +367,7 @@ public function testMonitorWithEmptyLocationIsNotHistorizable() $computer = $this->createItem(GlpiComputer::class, [ 'locations_id' => $location->getID(), ]); - $computer_item = $this->createItem(Computer_Item::class, [ + $this->createItem(Computer_Item::class, [ 'computers_id' => $computer->getID(), 'itemtype' => $monitor->getType(), 'items_id' => $monitor->getID(), @@ -391,7 +387,6 @@ public function testMonitorWithEmptyLocationIsNotHistorizable() 'has_inventory_entry_date' => false, ]; $this->assertEquals($expected, $result); - $expected = !in_array(false, $result, true); $result = $history->canHistorize($monitor->getID()); $this->assertFalse($result); } @@ -407,7 +402,7 @@ public function testMonitorWithLocationWithCountryIsNotHistorizable() $computer = $this->createItem(GlpiComputer::class, [ 'locations_id' => $location->getID(), ]); - $computer_item = $this->createItem(Computer_Item::class, [ + $this->createItem(Computer_Item::class, [ 'computers_id' => $computer->getID(), 'itemtype' => $monitor->getType(), 'items_id' => $monitor->getID(), @@ -428,7 +423,6 @@ public function testMonitorWithLocationWithCountryIsNotHistorizable() 'has_inventory_entry_date' => false, ]; $this->assertEquals($expected, $result); - $expected = !in_array(false, $result, true); $result = $history->canHistorize($monitor->getID()); $this->assertFalse($result); } @@ -444,7 +438,7 @@ public function testMonitorWithLocationWithStateIsNotHistorizable() $computer = $this->createItem(GlpiComputer::class, [ 'locations_id' => $location->getID(), ]); - $computer_item = $this->createItem(Computer_Item::class, [ + $this->createItem(Computer_Item::class, [ 'computers_id' => $computer->getID(), 'itemtype' => $monitor->getType(), 'items_id' => $monitor->getID(), @@ -464,7 +458,6 @@ public function testMonitorWithLocationWithStateIsNotHistorizable() 'has_inventory_entry_date' => false, ]; $this->assertEquals($expected, $result); - $expected = !in_array(false, $result, true); $result = $history->canHistorize($monitor->getID()); $this->assertFalse($result); } @@ -475,13 +468,13 @@ public function testMonitorWithUsageProfileIsNotHistorizable() $monitor = $this->createItem(GlpiMonitor::class); $computer = $this->createItem(GlpiComputer::class); - $computer_item = $this->createItem(Computer_Item::class, [ + $this->createItem(Computer_Item::class, [ 'computers_id' => $computer->getID(), 'itemtype' => $monitor->getType(), 'items_id' => $monitor->getID(), ]); $usage_profile = $this->createItem(ComputerUsageProfile::class); - $impact = $this->createItem(UsageInfo::class, [ + $this->createItem(UsageInfo::class, [ $usage_profile->getForeignKeyField() => $usage_profile->getID(), 'itemtype' => $computer->getType(), 'items_id' => $computer->getID(), @@ -501,7 +494,6 @@ public function testMonitorWithUsageProfileIsNotHistorizable() 'has_inventory_entry_date' => false, ]; $this->assertEquals($expected, $result); - $expected = !in_array(false, $result, true); $result = $history->canHistorize($monitor->getID()); $this->assertFalse($result); } @@ -529,7 +521,6 @@ public function testMonitorWithEmptyModelIsNotHistorizable() 'has_inventory_entry_date' => false, ]; $this->assertEquals($expected, $result); - $expected = !in_array(false, $result, true); $result = $history->canHistorize($monitor->getID()); $this->assertFalse($result); } @@ -559,7 +550,6 @@ public function testMonitorWithModelIsNotHistorizable() 'has_inventory_entry_date' => false, ]; $this->assertEquals($expected, $result); - $expected = !in_array(false, $result, true); $result = $history->canHistorize($monitor->getID()); $this->assertFalse($result); } @@ -569,7 +559,7 @@ public function testMonitorWithEmptyTypeIsNotHistorizable() $history = new Monitor(); $glpi_monitor_type = $this->createItem(GlpiMonitorType::class); - $monitor_type = $this->createItem(MonitorType::class, [ + $this->createItem(MonitorType::class, [ 'power_consumption' => 55, 'monitortypes_id' => $glpi_monitor_type->getID(), ]); @@ -591,7 +581,6 @@ public function testMonitorWithEmptyTypeIsNotHistorizable() 'has_inventory_entry_date' => false, ]; $this->assertEquals($expected, $result); - $expected = !in_array(false, $result, true); $result = $history->canHistorize($monitor->getID()); $this->assertFalse($result); } @@ -601,7 +590,7 @@ public function testMonitorWithTypeIsNotHistorizable() $history = new Monitor(); $glpi_monitor_type = $this->createItem(GlpiMonitorType::class); - $monitor_type = $this->createItem(MonitorType::class, [ + $this->createItem(MonitorType::class, [ 'monitortypes_id' => $glpi_monitor_type->getID(), 'power_consumption' => 55, ]); @@ -623,7 +612,6 @@ public function testMonitorWithTypeIsNotHistorizable() 'has_inventory_entry_date' => false, ]; $this->assertEquals($expected, $result); - $expected = !in_array(false, $result, true); $result = $history->canHistorize($monitor->getID()); $this->assertFalse($result); } @@ -645,12 +633,12 @@ public function testMonitorIsHistorizable() $computer = $this->createItem(GlpiComputer::class, [ 'locations_id' => $location->getID(), ]); - $computer_item = $this->createItem(Computer_Item::class, [ + $this->createItem(Computer_Item::class, [ 'computers_id' => $computer->getID(), 'itemtype' => $monitor->getType(), 'items_id' => $monitor->getID(), ]); - $infocom = $this->createItem(Infocom::class, [ + $this->createItem(Infocom::class, [ 'itemtype' => $monitor->getType(), 'items_id' => $monitor->getID(), 'buy_date' => '2024-01-01', @@ -666,7 +654,7 @@ public function testMonitorIsHistorizable() 'day_6' => '0', 'day_7' => '0', ]); - $impact = $this->createItem(UsageInfo::class, [ + $this->createItem(UsageInfo::class, [ $usage_profile->getForeignKeyField() => $usage_profile->getID(), 'itemtype' => $computer->getType(), 'items_id' => $computer->getID(), @@ -687,7 +675,6 @@ public function testMonitorIsHistorizable() 'has_inventory_entry_date' => true, ]; $this->assertEquals($expected, $result); - $expected = !in_array(false, $result, true); $result = $history->canHistorize($monitor->getID()); $this->assertTrue($result); } diff --git a/tests/units/Impact/History/NetworkEquipmentTest.php b/tests/units/Impact/History/NetworkEquipmentTest.php index e95d5c73..0e12cac0 100644 --- a/tests/units/Impact/History/NetworkEquipmentTest.php +++ b/tests/units/Impact/History/NetworkEquipmentTest.php @@ -77,7 +77,7 @@ public function testEvaluateItem() } $this->login('glpi', 'glpi'); - $entities_id = $this->isolateInEntity('glpi', 'glpi'); + $this->isolateInEntity('glpi', 'glpi'); $model_power = 100; $location = $this->createItem(Location::class, [ @@ -85,7 +85,7 @@ public function testEvaluateItem() ]); $model = $this->createItem(GlpiNetworkEquipmentModel::class, ['power_consumption' => $model_power]); $glpi_type = $this->createItem(GlpiNetworkEquipmentType::class); - $type = $this->createItem(NetworkEquipmentType::class, [ + $this->createItem(NetworkEquipmentType::class, [ GlpiNetworkEquipmentType::getForeignKeyField() => $glpi_type->getID(), ]); $asset = $this->createItem(GlpiNetworkEquipment::class, [ @@ -188,7 +188,6 @@ public function testEmptyItemIsNotHistorizable() 'has_inventory_entry_date' => false, ]; $this->assertEquals($expected, $result); - $expected = !in_array(false, $result, true); $result = $history->canHistorize($network_equipment->getID()); $this->assertFalse($result); } @@ -198,7 +197,7 @@ public function testNetDeviceWithEmptyInfocomIsNotHistorizable() $history = new NetworkEquipment(); $network_equipment = $this->createItem(GlpiNetworkEquipment::class); - $infocom = $this->createItem(Infocom::class, [ + $this->createItem(Infocom::class, [ 'itemtype' => $network_equipment->getType(), 'items_id' => $network_equipment->getID(), ]); @@ -215,7 +214,6 @@ public function testNetDeviceWithEmptyInfocomIsNotHistorizable() 'has_inventory_entry_date' => false, ]; $this->assertEquals($expected, $result); - $expected = !in_array(false, $result, true); $result = $history->canHistorize($network_equipment->getID()); $this->assertFalse($result); } @@ -225,7 +223,7 @@ public function testNetDeviceWithInfocomIsNotHistorizable() $history = new NetworkEquipment(); $network_equipment = $this->createItem(GlpiNetworkEquipment::class); - $infocom = $this->createItem(Infocom::class, [ + $this->createItem(Infocom::class, [ 'itemtype' => $network_equipment->getType(), 'items_id' => $network_equipment->getID(), 'buy_date' => '2024-01-01', @@ -243,7 +241,6 @@ public function testNetDeviceWithInfocomIsNotHistorizable() 'has_inventory_entry_date' => true, ]; $this->assertEquals($expected, $result); - $expected = !in_array(false, $result, true); $result = $history->canHistorize($network_equipment->getID()); $this->assertFalse($result); } @@ -269,7 +266,6 @@ public function testNetDeviceWithEmptyLocationIsNotHistorizable() 'has_inventory_entry_date' => false, ]; $this->assertEquals($expected, $result); - $expected = !in_array(false, $result, true); $result = $history->canHistorize($network_equipment->getID()); $this->assertFalse($result); } @@ -297,7 +293,6 @@ public function testNetDeviceWithLocationWithCountryIsNotHistorizable() 'has_inventory_entry_date' => false, ]; $this->assertEquals($expected, $result); - $expected = !in_array(false, $result, true); $result = $history->canHistorize($network_equipment->getID()); $this->assertFalse($result); } @@ -325,7 +320,6 @@ public function testNetDeviceWithLocationWithStateIsNotHistorizable() 'has_inventory_entry_date' => false, ]; $this->assertEquals($expected, $result); - $expected = !in_array(false, $result, true); $result = $history->canHistorize($network_equipment->getID()); $this->assertFalse($result); } @@ -351,7 +345,6 @@ public function testNetDeviceWithEmptyModelIsNotHistorizable() 'has_inventory_entry_date' => false, ]; $this->assertEquals($expected, $result); - $expected = !in_array(false, $result, true); $result = $history->canHistorize($network_equipment->getID()); $this->assertFalse($result); } @@ -379,7 +372,6 @@ public function testNetDeviceWithModelIsNotHistorizable() 'has_inventory_entry_date' => false, ]; $this->assertEquals($expected, $result); - $expected = !in_array(false, $result, true); $result = $history->canHistorize($network_equipment->getID()); $this->assertFalse($result); } @@ -405,7 +397,6 @@ public function testNetDeviceWithEmptyTypeIsNotHistorizable() 'has_inventory_entry_date' => false, ]; $this->assertEquals($expected, $result); - $expected = !in_array(false, $result, true); $result = $history->canHistorize($network_equipment->getID()); $this->assertFalse($result); } @@ -415,7 +406,7 @@ public function testNetDeviceWithTypeIsNotHistorizable() $history = new NetworkEquipment(); $glpi_type = $this->createItem(GlpiNetworkEquipmentType::class); - $network_equipment_type = $this->createItem(NetworkEquipmentType::class, [ + $this->createItem(NetworkEquipmentType::class, [ 'power_consumption' => 55, 'networkequipmenttypes_id' => $glpi_type->getID(), ]); @@ -435,7 +426,6 @@ public function testNetDeviceWithTypeIsNotHistorizable() 'has_inventory_entry_date' => false, ]; $this->assertEquals($expected, $result); - $expected = !in_array(false, $result, true); $result = $history->canHistorize($network_equipment->getID()); $this->assertFalse($result); } diff --git a/tests/units/LocationTest.php b/tests/units/LocationTest.php index a93d7935..daf1d2a2 100644 --- a/tests/units/LocationTest.php +++ b/tests/units/LocationTest.php @@ -205,7 +205,7 @@ public function testgetIncompleteLocations() $output = $iterator->count(); $this->assertEquals(1, $output); - $glpi_location = $this->createItem(GlpiLocation::class, [ + $this->createItem(GlpiLocation::class, [ '_boavizta_zone' => 'FRA', ]); $iterator = Location::getIncompleteLocations(); @@ -303,7 +303,7 @@ public function testEnableCarbonIntensityDownload() 'name' => 'baz', 'plugin_carbon_carbonintensitysources_id_historical' => $source->getID(), ]); - $source_zone = $this->createItem(CarbonIntensitySource_Zone::class, [ + $this->createItem(CarbonIntensitySource_Zone::class, [ $zone::getForeignKeyField() => $zone->getID(), $source::getForeignKeyField() => $source->getID(), 'is_download_enabled' => 0, diff --git a/tests/units/ProfileTest.php b/tests/units/ProfileTest.php index 765f045d..2b7e3662 100644 --- a/tests/units/ProfileTest.php +++ b/tests/units/ProfileTest.php @@ -60,7 +60,7 @@ public function testGetTabNameForItem() public function testShowForm() { $this->login('glpi', 'glpi'); - $glpi_profile = GlpiProfile::getById(4); // Super admin + GlpiProfile::getById(4); // Super admin $profile = new Profile(); $output = ''; ob_start(function ($buffer) use ($output) { diff --git a/tests/units/SearchTest.php b/tests/units/SearchTest.php index c2567451..eb915802 100644 --- a/tests/units/SearchTest.php +++ b/tests/units/SearchTest.php @@ -83,7 +83,6 @@ public function testSearchOptions() ]; $data = Search::getDatas(Monitor::class, $criterias); - $sql = $data['sql']['search']; $this->assertIsArray($data); } } diff --git a/tests/units/ToolboxTest.php b/tests/units/ToolboxTest.php index 7c4abd46..8d276f33 100644 --- a/tests/units/ToolboxTest.php +++ b/tests/units/ToolboxTest.php @@ -106,7 +106,7 @@ public function testGetLatestAssetDate() $expected = new DateTime('2024-06-15 00:00:00'); - $infocom = $this->createItem(Infocom::class, [ + $this->createItem(Infocom::class, [ 'itemtype' => $computer->getType(), 'items_id' => $computer->getID(), 'decommission_date' => $expected->format('Y-m-d H:i:s'),