Skip to content

Commit d48dd5e

Browse files
committed
Add core model preload helper for tests
1 parent 1c1ddc5 commit d48dd5e

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

Test/Traits/DefaultSettingsTrait.php

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
33
* This file is part of FacturaScripts
4-
* Copyright (C) 2021-2025 Carlos Garcia Gomez <carlos@facturascripts.com>
4+
* Copyright (C) 2021-2026 Carlos Garcia Gomez <carlos@facturascripts.com>
55
*
66
* This program is free software: you can redistribute it and/or modify
77
* it under the terms of the GNU Lesser General Public License as
@@ -19,15 +19,16 @@
1919

2020
namespace FacturaScripts\Test\Traits;
2121

22-
use FacturaScripts\Core\Base\DataBase\DataBaseWhere;
2322
use FacturaScripts\Core\DataSrc\Ejercicios;
2423
use FacturaScripts\Core\DataSrc\Paises;
2524
use FacturaScripts\Core\Lib\Accounting\AccountingPlanImport;
2625
use FacturaScripts\Core\Model\Almacen;
2726
use FacturaScripts\Core\Model\Cuenta;
2827
use FacturaScripts\Core\Model\Ejercicio;
2928
use FacturaScripts\Core\Model\RegularizacionImpuesto;
29+
use FacturaScripts\Core\Template\ModelClass;
3030
use FacturaScripts\Core\Tools;
31+
use FacturaScripts\Core\Where;
3132

3233
trait DefaultSettingsTrait
3334
{
@@ -40,7 +41,6 @@ protected static function installAccountingPlan(): void
4041
}
4142

4243
// recorremos todos los ejercicios
43-
$cuenta = new Cuenta();
4444
Ejercicios::clear();
4545
foreach (Ejercicios::all() as $exercise) {
4646
// si está cerrado, lo abrimos
@@ -49,8 +49,8 @@ protected static function installAccountingPlan(): void
4949
$exercise->save();
5050
}
5151

52-
$where = [new DataBaseWhere('codejercicio', $exercise->codejercicio)];
53-
if ($cuenta->count($where) > 0) {
52+
$where = [Where::eq('codejercicio', $exercise->codejercicio)];
53+
if (Cuenta::count($where) > 0) {
5454
// ya tiene plan contable
5555
continue;
5656
}
@@ -61,6 +61,22 @@ protected static function installAccountingPlan(): void
6161
}
6262
}
6363

64+
protected static function loadCoreModels(): void
65+
{
66+
foreach (Tools::folderScan(Tools::folder('Core', 'Model')) as $fileName) {
67+
if ('.php' !== substr($fileName, -4)) {
68+
continue;
69+
}
70+
71+
$className = '\\FacturaScripts\\Dinamic\\Model\\' . substr($fileName, 0, -4);
72+
if (false === is_subclass_of($className, ModelClass::class)) {
73+
continue;
74+
}
75+
76+
new $className();
77+
}
78+
}
79+
6480
protected static function removeTaxRegularization(): void
6581
{
6682
foreach (RegularizacionImpuesto::all() as $reg) {
@@ -78,7 +94,7 @@ protected static function setDefaultSettings(): void
7894
}
7995
}
8096

81-
$where = [new DataBaseWhere('idempresa', Tools::settings('default', 'idempresa', 1))];
97+
$where = [Where::eq('idempresa', Tools::settings('default', 'idempresa', 1))];
8298
foreach (Almacen::all($where) as $warehouse) {
8399
Tools::settingsSet('default', 'codalmacen', $warehouse->codalmacen);
84100
}

0 commit comments

Comments
 (0)