Skip to content

Commit e1a770a

Browse files
committed
adds test
1 parent 9714c00 commit e1a770a

1 file changed

Lines changed: 57 additions & 0 deletions

File tree

tests/Application/ApplicationTest.php

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,5 +534,62 @@ public function testInitSettingsUsesEnvVariable()
534534

535535
$this->assertNotNull($app->getSettingManager());
536536
}
537+
538+
public function testInitSettingsWithSettingManagerUsesItDirectly()
539+
{
540+
// Clear registry
541+
Registry::getInstance()->set('Settings', null);
542+
543+
// Create a SettingManager with a raw source
544+
$rawSource = new Ini('examples/config/application.ini');
545+
$settingManager = new \Neuron\Data\Settings\SettingManager($rawSource);
546+
547+
// Pass the SettingManager to the app
548+
$app = new AppMock("2.0", $settingManager);
549+
550+
// The app should use the SettingManager directly (not wrap it again)
551+
$appSettings = $app->getSettingManager();
552+
$this->assertSame($settingManager, $appSettings);
553+
554+
// Verify we don't have double-wrapping by checking the internal source
555+
// If double-wrapped, getSource() would return a SettingManager instead of the raw Ini
556+
$this->assertInstanceOf(Ini::class, $appSettings->getSource());
557+
$this->assertNotInstanceOf(\Neuron\Data\Settings\SettingManager::class, $appSettings->getSource());
558+
}
559+
560+
public function testInitSettingsWithRawSourceWrapsIt()
561+
{
562+
// Clear registry
563+
Registry::getInstance()->set('Settings', null);
564+
565+
// Pass a raw source (not a SettingManager)
566+
$rawSource = new Ini('examples/config/application.ini');
567+
$app = new AppMock("2.0", $rawSource);
568+
569+
// The app should wrap it in a SettingManager
570+
$appSettings = $app->getSettingManager();
571+
$this->assertInstanceOf(\Neuron\Data\Settings\SettingManager::class, $appSettings);
572+
573+
// Verify the raw source is wrapped
574+
$this->assertInstanceOf(Ini::class, $appSettings->getSource());
575+
}
576+
577+
public function testInitSettingsWithSettingManagerPreservesFallback()
578+
{
579+
// Clear registry
580+
Registry::getInstance()->set('Settings', null);
581+
582+
// Create a SettingManager with custom fallback
583+
$rawSource = new Ini('examples/config/application.ini');
584+
$settingManager = new \Neuron\Data\Settings\SettingManager($rawSource);
585+
586+
// Pass the SettingManager to the app
587+
$app = new AppMock("2.0", $settingManager);
588+
589+
// The app should set a fallback (env variables)
590+
$appSettings = $app->getSettingManager();
591+
$this->assertNotNull($appSettings->getFallback());
592+
$this->assertInstanceOf(\Neuron\Data\Settings\Source\Env::class, $appSettings->getFallback());
593+
}
537594
}
538595

0 commit comments

Comments
 (0)