mirror of
https://github.com/opensourcepos/opensourcepos.git
synced 2026-11-08 23:43:32 -05:00
- Remove OsposConfigFixtureTrait usage across test suite; settings are now written through model(Appconfig::class)->batch_save() instead of mocking the OSPOS config object directly - OSPOSRulesTest keeps direct Config\OSPOS injection via Factories::injectMock since it tests config-object behavior directly - CashupControllerTest, ItemKitsControllerTest, GetItemDataRowTest, LocaleHelperTest, export_helperTest, tabular_helperTest switch to real DB-backed settings via Appconfig model - GetItemDataRowTest, LocaleHelperTest, export_helperTest, tabular_helperTest add DatabaseTestTrait/DatabaseBootstrapTrait and migrate/seed config plus resetDatabaseOnce() in setUp() - export_helperTest consolidates redundant parent::setUp() calls scattered across individual test methods into a single call This aligns tests with how settings are actually read at runtime (DB-backed Appconfig) rather than relying on a config-mocking fixture trait, reducing drift between test setup and production behavior. Signed-off-by: objecttothis <17935339+objecttothis@users.noreply.github.com>
51 lines
1.3 KiB
PHP
51 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace Tests\Support;
|
|
|
|
use CodeIgniter\Config\Factories;
|
|
use Config\OSPOS;
|
|
|
|
/**
|
|
* Shared helper for injecting a mocked OSPOS config into a test.
|
|
*
|
|
* Replaces the old per-file `$ospos = new OSPOS(); $ospos->settings = [...];
|
|
* Factories::injectMock(...)` block that was duplicated with slightly
|
|
* different settings arrays across many test files. Each test supplies the
|
|
* exact settings it depends on - OSPOS::getDefaultSettings() is private and
|
|
* only has a handful of keys, so it is not a usable base to merge onto.
|
|
*
|
|
* Usage:
|
|
*
|
|
* use Tests\Support\OsposConfigFixtureTrait;
|
|
*
|
|
* class FooTest extends CIUnitTestCase
|
|
* {
|
|
* use OsposConfigFixtureTrait;
|
|
*
|
|
* protected function setUp(): void
|
|
* {
|
|
* parent::setUp();
|
|
*
|
|
* $this->injectOsposSettings([
|
|
* 'invoice_enable' => false,
|
|
* 'number_locale' => 'en_US',
|
|
* ]);
|
|
* }
|
|
* }
|
|
*/
|
|
trait OsposConfigFixtureTrait
|
|
{
|
|
/**
|
|
* @param array<string, mixed> $settings
|
|
*/
|
|
protected function injectOsposSettings(array $settings): OSPOS
|
|
{
|
|
$ospos = new OSPOS();
|
|
$ospos->settings = $settings;
|
|
|
|
Factories::injectMock('config', OSPOS::class, $ospos);
|
|
|
|
return $ospos;
|
|
}
|
|
}
|