Skip to content

Commit 1b8f08f

Browse files
author
Carlos Garcia
committed
Ahora cuando falla un test se guarda un archivo de log en MyFiles con las consultas sql ejecutadas.
1 parent c43324b commit 1b8f08f

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

Test/Traits/LogErrorsTrait.php

Lines changed: 11 additions & 1 deletion
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-2022 Carlos Garcia Gomez <carlos@facturascripts.com>
4+
* Copyright (C) 2021-2025 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
@@ -20,6 +20,7 @@
2020
namespace FacturaScripts\Test\Traits;
2121

2222
use FacturaScripts\Core\Base\MiniLog;
23+
use FacturaScripts\Core\Tools;
2324

2425
trait LogErrorsTrait
2526
{
@@ -32,6 +33,15 @@ protected function logErrors(bool $force = false): void
3233
error_log(print_r($item['context'], true));
3334
}
3435
}
36+
37+
// guardamos la lista de consultas sql en un archivo
38+
$queries = [];
39+
foreach (MiniLog::read('database', ['debug']) as $item) {
40+
$queries[] = $item['message'];
41+
}
42+
$file_path = Tools::folder('MyFiles', 'test_error_' . date('Y-m-d_H-i-s_') . rand(0, 1000) . '.log');
43+
file_put_contents($file_path, implode(PHP_EOL, $queries) . PHP_EOL, FILE_APPEND);
44+
error_log('Database queries in ' . $file_path . PHP_EOL);
3545
}
3646

3747
MiniLog::clear();

0 commit comments

Comments
 (0)