From 8a8ee4ed906aaad2c758f4ccd41207e0fb9110b2 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sun, 22 Oct 2023 11:52:44 +0000 Subject: [PATCH] fix tests --- Log/FileLogger.php | 2 +- Utils/ArrayUtils.php | 20 +++++++++++++++++++ tests/Business/Recommendation/ModelCFTest.php | 6 +++--- .../Database/DataMapperAbstractTest.php | 5 +++++ 4 files changed, 29 insertions(+), 4 deletions(-) diff --git a/Log/FileLogger.php b/Log/FileLogger.php index 6209391ac..09925c0e2 100755 --- a/Log/FileLogger.php +++ b/Log/FileLogger.php @@ -60,7 +60,7 @@ final class FileLogger implements LoggerInterface * @var bool * @since 1.0.0 */ - protected bool $verbose = false; + public bool $verbose = false; /** * The file pointer for the logging. diff --git a/Utils/ArrayUtils.php b/Utils/ArrayUtils.php index 9a2cc314a..8c9770837 100755 --- a/Utils/ArrayUtils.php +++ b/Utils/ArrayUtils.php @@ -454,6 +454,26 @@ final class ArrayUtils return $squared; } + /** + * Get a column of 2D matrix. + * + * @param array $matrix Matrix + * @param mixed $index Column index to return + * + * @return array + * + * @since 1.0.0 + */ + public static function column(array $matrix, mixed $index) : array + { + $column = []; + foreach ($matrix as $id => $row) { + $column[$id] = $row[$index]; + } + + return $column; + } + /** * Sqrt all values in array. * diff --git a/tests/Business/Recommendation/ModelCFTest.php b/tests/Business/Recommendation/ModelCFTest.php index 47418cb38..4e10ac810 100644 --- a/tests/Business/Recommendation/ModelCFTest.php +++ b/tests/Business/Recommendation/ModelCFTest.php @@ -27,9 +27,9 @@ final class ModelCFTest extends \PHPUnit\Framework\TestCase { self::assertEquals( [ - [], - [], - [], + [14.0, 12.0, 10.0], + [17.0, 11.0, 10.0], + [15.0, 15.0, 12.0], ], ModelCF::score( [ diff --git a/tests/DataStorage/Database/DataMapperAbstractTest.php b/tests/DataStorage/Database/DataMapperAbstractTest.php index 436e88a60..935172944 100755 --- a/tests/DataStorage/Database/DataMapperAbstractTest.php +++ b/tests/DataStorage/Database/DataMapperAbstractTest.php @@ -14,6 +14,8 @@ declare(strict_types=1); namespace phpOMS\tests\DataStorage\Database; +include_once __DIR__ . '/../../Autoloader.php'; + use phpOMS\DataStorage\Database\Query\OrderType; use phpOMS\tests\DataStorage\Database\TestModel\BaseModel; use phpOMS\tests\DataStorage\Database\TestModel\BaseModelMapper; @@ -42,10 +44,13 @@ final class DataMapperAbstractTest extends \PHPUnit\Framework\TestCase { $this->model = new BaseModel(); + \phpOMS\Log\FileLogger::getInstance()->verbose = true; + $GLOBALS['dbpool']->get()->con->prepare( 'CREATE TABLE `test_base` ( `test_base_id` int(11) NOT NULL AUTO_INCREMENT, `test_base_string` varchar(254) NOT NULL, + `test_base_compress` varchar(254) NOT NULL, `test_base_pstring` varchar(254) NOT NULL, `test_base_int` int(11) NOT NULL, `test_base_bool` tinyint(1) DEFAULT NULL,