Skip to content

Commit

Permalink
Clean asset definitions after each test
Browse files Browse the repository at this point in the history
  • Loading branch information
cedric-anne committed Sep 16, 2024
1 parent a2e6a3a commit cbe52b2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 2 additions & 0 deletions phpunit/GLPITestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
* ---------------------------------------------------------------------
*/

use Glpi\Asset\AssetDefinitionManager;
use Glpi\Tests\Log\TestHandler;
use Monolog\Level;
use Monolog\Logger;
Expand Down Expand Up @@ -440,5 +441,6 @@ private function resetGlobalsAndStaticValues(): void
// Statics values
Log::$use_queue = false;
CommonDBTM::clearSearchOptionCache();
AssetDefinitionManager::unsetInstance();
}
}
14 changes: 12 additions & 2 deletions src/Glpi/Asset/AssetDefinitionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ final class AssetDefinitionManager
/**
* Definitions cache.
*/
private ?array $definitions_data;
private ?array $definitions_data = null;

/**
* List of available capacities.
Expand Down Expand Up @@ -99,6 +99,16 @@ public static function getInstance(): self
return self::$instance;
}

/**
* Unset the singleton instance
*
* @return void
*/
public static function unsetInstance(): void
{
self::$instance = null;
}

/**
* Returns the list of reserved system names
* @return array
Expand Down Expand Up @@ -339,7 +349,7 @@ private function getDefinition(string $system_name): ?AssetDefinition
*/
public function getDefinitions(bool $only_active = false): array
{
if (!isset($this->definitions_data)) {
if ($this->definitions_data === null) {
$this->definitions_data = getAllDataFromTable(AssetDefinition::getTable());
}

Expand Down

0 comments on commit cbe52b2

Please sign in to comment.