Skip to content
Merged
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
10 changes: 10 additions & 0 deletions src/GenericModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,16 @@ public static function enableRegistry(): void
static::$registry = true;
}

/**
* Check if the registry is enabled
*
* @return bool
*/
public static function isRegistryEnabled(): bool
{
return static::$registry;
}

/**
*
*
Expand Down
18 changes: 18 additions & 0 deletions test/tests/GenericModelTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace Aternos\Model\Test\Tests;

use Aternos\Model\GenericModel;
use PHPUnit\Framework\TestCase;

class GenericModelTest extends TestCase
{
public function testRegistry(): void
{
$this->assertTrue(GenericModel::isRegistryEnabled());
GenericModel::disableRegistry();
$this->assertFalse(GenericModel::isRegistryEnabled());
GenericModel::enableRegistry();
$this->assertTrue(GenericModel::isRegistryEnabled());
Comment on lines +12 to +16
Copy link

Copilot AI Mar 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test assumes the registry is enabled at the start and also risks leaving the global static registry state modified if an assertion fails after disableRegistry(). Since other tests in the suite call disableRegistry() without re-enabling it (e.g., TestDriverTest::testUpdate()), this can make the test order-dependent/flaky. Consider capturing the initial state with GenericModel::isRegistryEnabled() and restoring it in a try/finally (or tearDown()), and avoid asserting a hard-coded initial true unless you explicitly set it first.

Suggested change
$this->assertTrue(GenericModel::isRegistryEnabled());
GenericModel::disableRegistry();
$this->assertFalse(GenericModel::isRegistryEnabled());
GenericModel::enableRegistry();
$this->assertTrue(GenericModel::isRegistryEnabled());
$initialState = GenericModel::isRegistryEnabled();
try {
// Ensure registry is enabled so we can test disabling and re-enabling it
if (!$initialState) {
GenericModel::enableRegistry();
}
$this->assertTrue(GenericModel::isRegistryEnabled());
GenericModel::disableRegistry();
$this->assertFalse(GenericModel::isRegistryEnabled());
GenericModel::enableRegistry();
$this->assertTrue(GenericModel::isRegistryEnabled());
} finally {
// Restore original registry state to avoid leaking global changes
if ($initialState !== GenericModel::isRegistryEnabled()) {
if ($initialState) {
GenericModel::enableRegistry();
} else {
GenericModel::disableRegistry();
}
}
}

Copilot uses AI. Check for mistakes.
}
}
Loading