From a9aab9163ebdb0cbcadedd652bf93b26fcbfaf19 Mon Sep 17 00:00:00 2001 From: Little Fluffy Clouds Date: Fri, 11 Jul 2025 22:56:37 +0300 Subject: [PATCH 1/8] Resolved #25 --- .editorconfig | 5 + README.md | 4 +- mirzaev/baza/system/database.php | 54 +++- mirzaev/baza/system/enumerations/type.php | 6 +- mirzaev/baza/system/record.php | 10 +- mirzaev/baza/tests/record.php | 307 +++++++++++++--------- 6 files changed, 244 insertions(+), 142 deletions(-) diff --git a/.editorconfig b/.editorconfig index a16b527..79ccfd2 100755 --- a/.editorconfig +++ b/.editorconfig @@ -1,5 +1,10 @@ root = true +[*] +charset = utf-8 +indent_style = tab +tab_width = 4 + [README.md] charset = utf-8 indent_style = tab diff --git a/README.md b/README.md index 632076b..961ea8a 100755 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ $record = $database->record( ); if ($database->write($record)) { - // Writed the record into the database + // Wrote the record into the database // Updating the record in the database $updated = $database->read( @@ -48,7 +48,7 @@ if ($database->write($record)) { ); // Reading the record from the database - $readed = $database->read( + $read = $database->read( filter: fn($record) => $record->name === 'Arsen' && $record->age === 24, amount: 1 ); diff --git a/mirzaev/baza/system/database.php b/mirzaev/baza/system/database.php index 27c202f..9da96d3 100755 --- a/mirzaev/baza/system/database.php +++ b/mirzaev/baza/system/database.php @@ -13,6 +13,16 @@ use LogicException as exception_logic, InvalidArgumentException as exception_invalid_argument, RuntimeException as exception_runtime; +/** + * ARCH + * + * Checking for PHP implementation architecture + * + * Using php_uname('m') is another way of doing that + * but it's simpler to check for max integer size + */ +define('ARCH', (PHP_INT_SIZE === 8) ? 64 : 32); + /** * Database * @@ -60,7 +70,7 @@ class database public protected(set) string $backups = __DIR__ . DIRECTORY_SEPARATOR . 'backups'; /** - * Encoding + * Encoding * * @var encoding $encoding Encoding of records in the database file */ @@ -140,7 +150,7 @@ class database } /** - * Connect + * Connect * * Initialize the database files * @@ -234,12 +244,27 @@ class database // Converting to the database encoding $value = mb_convert_encoding($record->values()[$column->name], $this->encoding->value); - // Packung the value and writing into the buffer of packed values + // Packing the value and writing into the buffer of packed values $packed .= pack($column->type->value . $column->length, $value); + } else if (ARCH === 64 && + ($column->type === type::integer || + $column->type === type::integer_unsigned) + ) { + // Initialize variables for left and right masks of the 64-bit variable + $left = 0xffffffff00000000; + $right = 0x00000000ffffffff; + + // Bitwise and the value with the left mask with shift right by 32bits to get first half of the integer + $l = ($record->values()[$column->name] & $left) >> 32; + // Bitwise and the value with the right mask to get the second half + $r = $record->values()[$column->name] & $right; + + // Pack into 64bit binary value + $packed .= pack('NN', $l, $r); } else { // Other types - // Packung the value and writing into the buffer of packed values + // Packing the value and writing into the buffer of packed values $packed .= pack($column->type->value, $record->values()[$column->name]); } } @@ -250,7 +275,7 @@ class database /** * Unpack - * + * * Unpack binary values and implement them as a `record` instance * * @param array $binaries Binary values in the same order as the columns @@ -280,12 +305,19 @@ class database // Encoding the unpacked value $encoded = mb_convert_encoding($unnulled, $this->encoding->value); - // Writing into the buffer of readed values + // Writing into the buffer of read values $unpacked[] = $encoded; + } else if (ARCH === 64 && + ($column->type === type::integer || + $column->type === type::integer_unsigned) + ) { + // Unpacking the integer + $value = unpack('N2', $binary ?? "\0"); + $unpacked[] = $value[1] << 32 | $value[2]; } else { // Other types - // Writing into the buffer of readed values + // Writing into the buffer of read values $unpacked[] = unpack($column->type->value, $binary ?? "\0")[1]; } } @@ -307,7 +339,7 @@ class database * @throws exception_runtime If failed to lock the file * @throws exception_runtime If failed to unlock the file * - * @return bool Is the record was writed into the end of the database file + * @return bool Is the record was wrote into the end of the database file */ public function write(record $record): bool { @@ -366,7 +398,7 @@ class database * @param int $amount Amount iterator * @param int $offset Offset iterator * - * @return array|null Readed records + * @return array|null Read records */ public function read( ?callable $filter = null, @@ -381,7 +413,7 @@ class database if (flock($file, LOCK_EX)) { // The file was locked - // Declaring the buffer of readed records + // Declaring the buffer of read records $records = []; // Declaring the buffer of failed to reading records @@ -394,7 +426,7 @@ class database $binaries = []; foreach ($this->columns as $column) { - // Iterating over columns + // Iterating over columns if ($column->type === type::string) { // String diff --git a/mirzaev/baza/system/enumerations/type.php b/mirzaev/baza/system/enumerations/type.php index 4e62b46..4182d25 100755 --- a/mirzaev/baza/system/enumerations/type.php +++ b/mirzaev/baza/system/enumerations/type.php @@ -61,6 +61,10 @@ enum type: string public function size(): int { // Exit (success) - return strlen(pack($this->value, 0)); + + // If type is (unsigned) integer, return size of integer + return (strtoupper($this->value) === 'I') + ? PHP_INT_SIZE + : strlen(pack($this->value, 0)); } } diff --git a/mirzaev/baza/system/record.php b/mirzaev/baza/system/record.php index 20c5a97..952441e 100755 --- a/mirzaev/baza/system/record.php +++ b/mirzaev/baza/system/record.php @@ -17,7 +17,7 @@ use DomainException as exception_domain; * @method void __construct(string|int|float $values) Constructor * @method array values() Read all values of the record * @method void __set(string $name, mixed $value) Write the record value - * @method mized __get(string $name) Read the record value + * @method mixed __get(string $name) Read the record value * @method void __unset(string $name) Delete the record value * @method bool __isset(string $name) Check for initializing of the record value * @@ -49,7 +49,7 @@ class record /** * Values * - * Read all values of the record + * Read all values of the record * * @return array All values of the record */ @@ -81,13 +81,13 @@ class record // Not initialized the parameter // Exit (fail) - throw new exception_domain("Not found the parameter: $name"); + throw new exception_domain("Not found the parameter: $name"); } } /** * Read - * + * * Read the value * * @param string $name Name of the value @@ -119,7 +119,7 @@ class record * Check for initializing * * Check for initializing the value - * + * * @param string $name Name of the value * * @return bool Is the value initialized? diff --git a/mirzaev/baza/tests/record.php b/mirzaev/baza/tests/record.php index 72e00ea..7ec9d09 100755 --- a/mirzaev/baza/tests/record.php +++ b/mirzaev/baza/tests/record.php @@ -9,23 +9,23 @@ use mirzaev\baza\database, mirzaev\baza\enumerations\type; // Initializing path to the composer loader file (main project) -$autoload = - __DIR__ . DIRECTORY_SEPARATOR . - '..' . DIRECTORY_SEPARATOR . - '..' . DIRECTORY_SEPARATOR . - '..' . DIRECTORY_SEPARATOR . - 'vendor' . DIRECTORY_SEPARATOR . +$autoload = + __DIR__ . DIRECTORY_SEPARATOR . + '..' . DIRECTORY_SEPARATOR . + '..' . DIRECTORY_SEPARATOR . + '..' . DIRECTORY_SEPARATOR . + 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php'; // Reinitializing path to the composer loaded file (depencendy project) -if (!file_exists($autoload)) - $autoload = - __DIR__ . DIRECTORY_SEPARATOR . - '..' . DIRECTORY_SEPARATOR . - '..' . DIRECTORY_SEPARATOR . - '..' . DIRECTORY_SEPARATOR . - '..' . DIRECTORY_SEPARATOR . - '..' . DIRECTORY_SEPARATOR . +if (!file_exists($autoload)) + $autoload = + __DIR__ . DIRECTORY_SEPARATOR . + '..' . DIRECTORY_SEPARATOR . + '..' . DIRECTORY_SEPARATOR . + '..' . DIRECTORY_SEPARATOR . + '..' . DIRECTORY_SEPARATOR . + '..' . DIRECTORY_SEPARATOR . 'autoload.php'; // Importing files of thr project and dependencies @@ -53,27 +53,57 @@ if (!file_exists($file) || unlink($file)) { // Initializing the test database /* $database = new database() */ -$database = (new database()) - ->encoding(encoding::utf8) - ->columns( - new column('name', type::string, ['length' => 32]), - new column('second_name', type::string, ['length' => 64]), - new column('age', type::integer), - new column('height', type::float), - new column('active', type::char) - ) - ->connect($file); +if (PHP_INT_SIZE === 8) { + $database = (new database()) + ->encoding(encoding::utf8) + ->columns( + new column('name', type::string, ['length' => 32]), + new column('second_name', type::string, ['length' => 64]), + new column('age', type::integer), + new column('height', type::float), + // 64-bit values test + new column('neuron_count', type::integer_unsigned), + new column('ambition_level', type::double), + new column('reputation', type::integer), + new column('active', type::char) + ) + ->connect($file); +} else { + $database = (new database()) + ->encoding(encoding::utf8) + ->columns( + new column('name', type::string, ['length' => 32]), + new column('second_name', type::string, ['length' => 64]), + new column('age', type::integer), + new column('height', type::float), + new column('active', type::char) + ) + ->connect($file); +} echo '[' . ++$action . "] Initialized the database\n"; // Initializing the record -$record = $database->record( - 'Arsen', - 'Mirzaev', - 24, - 165.5, - 1 -); +if (ARCH === 64) { + $record = $database->record( + 'Arsen', + 'Mirzaev', + 24, + 165.5, + 91000000000, + 1.7976931348623E+238, + 7355608, + 1 + ); +} else { + $record = $database->record( + 'Arsen', + 'Mirzaev', + 24, + 165.5, + 1 + ); +} echo '[' . ++$action . "] Initialized the record\n"; @@ -84,6 +114,11 @@ echo '[' . ++$action . '][' . ++$test . '][' . ($record->name === 'Arsen' ? 'SUC echo '[' . $action . '][' . ++$test . '][' . ($record->second_name === 'Mirzaev' ? 'SUCCESS' : 'FAIL') . "][\"second_name\"] Expected: \"Mirzaev\" (string). Actual: \"$record->second_name\" (" . gettype($record->second_name) . ")\n"; echo '[' . $action . '][' . ++$test . '][' . ($record->age === 24 ? 'SUCCESS' : 'FAIL') . "][\"age\"] Expected: \"24\" (integer). Actual: \"$record->age\" (" . gettype($record->age) . ")\n"; echo '[' . $action . '][' . ++$test . '][' . ($record->height === 165.5 ? 'SUCCESS' : 'FAIL') . "][\"height\"] Expected: \"165.5\" (double). Actual: \"$record->height\" (" . gettype($record->height) . ")\n"; +if (ARCH === 64) { + echo '[' . $action . '][' . ++$test . '][' . ($record->neuron_count === 91000000000 ? 'SUCCESS' : 'FAIL') . "][\"neuron_count\"] Expected: \"91000000000\" (integer_unsigned). Actual: \"$record->neuron_count\" (" . gettype($record->neuron_count) . ")\n"; + echo '[' . $action . '][' . ++$test . '][' . ($record->ambition_level === 1.7976931348623E+238 ? 'SUCCESS' : 'FAIL') . "][\"ambition_level\"] Expected: \"1.7976931348623E+238\" (double). Actual: \"$record->ambition_level\" (" . gettype($record->ambition_level) . ")\n"; + echo '[' . $action . '][' . ++$test . '][' . ($record->reputation === 7355608 ? 'SUCCESS' : 'FAIL') . "][\"reputation\"] Expected: \"7355608\" (integer). Actual: \"$record->reputation\" (" . gettype($record->reputation) . ")\n"; +} echo '[' . $action . '][' . ++$test . '][' . ($record->active === 1 ? 'SUCCESS' : 'FAIL') . "][\"active\"] Expected: \"1\" (integer). Actual: \"$record->active\" (" . gettype($record->active) . ")\n"; echo '[' . $action . "] The record parameters checks have been completed\n"; @@ -94,178 +129,204 @@ $test = 0; // Writing the record into the database $database->write($record); -echo '[' . ++$action . "] Writed the record into the database\n"; +echo '[' . ++$action . "] Wrote the record into the database\n"; // Initializing the second record -$record_ivan = $database->record( - 'Ivan', - 'Ivanov', - 24, - (float) 210, - 0 -); +if (ARCH === 64) { + $record_ivan = $database->record( + 'Ivan', + 'Ivanov', + 24, + (float) 210, + PHP_INT_MAX, + PHP_FLOAT_MIN, + PHP_INT_MIN, + 0 + ); +} else { + $record_ivan = $database->record( + 'Ivan', + 'Ivanov', + 24, + (float) 210, + 0 + ); +} echo '[' . ++$action . "] Initialized the record\n"; // Writing the second record into the databasse $database->write($record_ivan); -echo '[' . ++$action . "] Writed the record into the database\n"; +echo '[' . ++$action . "] Wrote the record into the database\n"; // Initializing the second record -$record_ivan = $database->record( - 'Margarita', - 'Esenina', - 19, - (float) 165, - 1 -); +if (ARCH === 64) { + $record_margarita = $database->record( + 'Margarita', + 'Esenina', + 19, + (float) 165, + 89000000000, + (float) 163, + PHP_INT_MAX, + 1 + ); +} else { + $record_margarita = $database->record( + 'Margarita', + 'Esenina', + 19, + (float) 165, + 1 + ); +} echo '[' . ++$action . "] Initialized the record\n"; // Writing the second record into the databasse -$database->write($record_ivan); +$database->write($record_margarita); -echo '[' . ++$action . "] Writed the record into the database\n"; +echo '[' . ++$action . "] Wrote the record into the database\n"; // Reading all records from the database -$records_readed_all = $database->read(amount: 99999); +$records_read_all = $database->read(amount: 99999); -echo '[' . ++$action . "] Readed all records from the database\n"; +echo '[' . ++$action . "] Read all records from the database\n"; try { - echo '[' . ++$action . '][' . ++$test . '][' . (gettype($records_readed_all) === 'array' ? 'SUCCESS' : 'FAIL') . '][type of returned value] Expected: "array". Actual: "' . gettype($records_readed_all) . "\"\n"; - echo '[' . $action . '][' . ++$test . '][' . (count($records_readed_all) === 3 ? 'SUCCESS' : 'FAIL') . '][amount of readed records] Expected: 3 records. Actual: ' . count($records_readed_all) . " records\n"; - echo '[' . $action . '][' . ++$test . '][' . (gettype($records_readed_all[0]) === 'object' ? 'SUCCESS' : 'FAIL') . '][type of readed values] Expected: "object". Actual: "' . gettype($records_readed_all[0]) . "\"\n"; - echo '[' . $action . '][' . ++$test . '][' . ($records_readed_all[0] instanceof record ? 'SUCCESS' : 'FAIL') . '][class of readed object values] Expected: "' . record::class . '". Actual: "' . $records_readed_all[0]::class . "\"\n"; + echo '[' . ++$action . '][' . ++$test . '][' . (gettype($records_read_all) === 'array' ? 'SUCCESS' : 'FAIL') . '][type of returned value] Expected: "array". Actual: "' . gettype($records_read_all) . "\"\n"; + echo '[' . $action . '][' . ++$test . '][' . (count($records_read_all) === 3 ? 'SUCCESS' : 'FAIL') . '][amount of read records] Expected: 3 records. Actual: ' . count($records_read_all) . " records\n"; + echo '[' . $action . '][' . ++$test . '][' . (gettype($records_read_all[0]) === 'object' ? 'SUCCESS' : 'FAIL') . '][type of read values] Expected: "object". Actual: "' . gettype($records_read_all[0]) . "\"\n"; + echo '[' . $action . '][' . ++$test . '][' . ($records_read_all[0] instanceof record ? 'SUCCESS' : 'FAIL') . '][class of read object values] Expected: "' . record::class . '". Actual: "' . $records_read_all[0]::class . "\"\n"; - echo '[' . $action . "] The readed all records checks have been completed\n"; + echo '[' . $action . "] The read all records checks have been completed\n"; } catch (exception $e) { - echo '[' . $action . "][WARNING] The readed all records checks have been completed with errors\n"; + echo '[' . $action . "][WARNING] The read all records checks have been completed with errors\n"; } // Reinitializing the counter of tests $test = 0; // Reading the first record from the database -$record_readed_first = $database->read(amount: 1); +$record_read_first = $database->read(amount: 1); -echo '[' . ++$action . "] Readed the first record from the database\n"; +echo '[' . ++$action . "] Read the first record from the database\n"; try { - echo '[' . ++$action . '][' . ++$test . '][' . (gettype($record_readed_first) === 'array' ? 'SUCCESS' : 'FAIL') . '][type of returned value] Expected: "array". Actual: "' . gettype($record_readed_first) . "\"\n"; - echo '[' . $action . '][' . ++$test . '][' . (count($record_readed_first) === 1 ? 'SUCCESS' : 'FAIL') . '][amount of readed records] Expected: 1 records. Actual: ' . count($record_readed_first) . " records\n"; - echo '[' . $action . '][' . ++$test . '][' . (gettype($record_readed_first[0]) === 'object' ? 'SUCCESS' : 'FAIL') . '][type of readed values] Expected: "object". Actual: "' . gettype($record_readed_first[0]) . "\"\n"; - echo '[' . $action . '][' . ++$test . '][' . ($record_readed_first[0] instanceof record ? 'SUCCESS' : 'FAIL') . '][class of readed object values] Expected: "' . record::class . '". Actual: "' . $record_readed_first[0]::class . "\"\n"; - echo '[' . $action . '][' . ++$test . '][' . ($record_readed_first[0]->second_name === 'Mirzaev' ? 'SUCCESS' : 'FAIL') . ']["second_name"] Expected: "Mirzaev" (string). Actual: "' . $record_readed_first[0]->second_name . '" (' . gettype($record_readed_first[0]->second_name) . ")\n"; + echo '[' . ++$action . '][' . ++$test . '][' . (gettype($record_read_first) === 'array' ? 'SUCCESS' : 'FAIL') . '][type of returned value] Expected: "array". Actual: "' . gettype($record_read_first) . "\"\n"; + echo '[' . $action . '][' . ++$test . '][' . (count($record_read_first) === 1 ? 'SUCCESS' : 'FAIL') . '][amount of read records] Expected: 1 records. Actual: ' . count($record_read_first) . " records\n"; + echo '[' . $action . '][' . ++$test . '][' . (gettype($record_read_first[0]) === 'object' ? 'SUCCESS' : 'FAIL') . '][type of read values] Expected: "object". Actual: "' . gettype($record_read_first[0]) . "\"\n"; + echo '[' . $action . '][' . ++$test . '][' . ($record_read_first[0] instanceof record ? 'SUCCESS' : 'FAIL') . '][class of read object values] Expected: "' . record::class . '". Actual: "' . $record_read_first[0]::class . "\"\n"; + echo '[' . $action . '][' . ++$test . '][' . ($record_read_first[0]->second_name === 'Mirzaev' ? 'SUCCESS' : 'FAIL') . ']["second_name"] Expected: "Mirzaev" (string). Actual: "' . $record_read_first[0]->second_name . '" (' . gettype($record_read_first[0]->second_name) . ")\n"; - echo '[' . $action . "] The readed first record checks have been completed\n"; + echo '[' . $action . "] The read first record checks have been completed\n"; } catch (exception $e) { - echo '[' . $action . "][WARNING] The readed first record checks have been completed with errors\n"; + echo '[' . $action . "][WARNING] The read first record checks have been completed with errors\n"; } // Reinitializing the counter of tests $test = 0; // Reading the second record from the database -$record_readed_second = $database->read(amount: 1, offset: 1); +$record_read_second = $database->read(amount: 1, offset: 1); -echo '[' . ++$action . "] Readed the second record from the database\n"; +echo '[' . ++$action . "] Read the second record from the database\n"; try { - echo '[' . ++$action . '][' . ++$test . '][' . (gettype($record_readed_second) === 'array' ? 'SUCCESS' : 'FAIL') . '][type of returned value] Expected: "array". Actual: "' . gettype($record_readed_second) . "\"\n"; - echo '[' . $action . '][' . ++$test . '][' . (count($record_readed_second) === 1 ? 'SUCCESS' : 'FAIL') . '][amount of readed records] Expected: 1 records. Actual: ' . count($record_readed_second) . " records\n"; - echo '[' . $action . '][' . ++$test . '][' . (gettype($record_readed_second[0]) === 'object' ? 'SUCCESS' : 'FAIL') . '][type of readed values] Expected: "object". Actual: "' . gettype($record_readed_second[0]) . "\"\n"; - echo '[' . $action . '][' . ++$test . '][' . ($record_readed_second[0] instanceof record ? 'SUCCESS' : 'FAIL') . '][class of readed object values] Expected: "' . record::class . '". Actual: "' . $record_readed_second[0]::class . "\"\n"; - echo '[' . $action . '][' . ++$test . '][' . ($record_readed_second[0]->second_name === 'Ivanov' ? 'SUCCESS' : 'FAIL') . ']["second_name"] Expected: "Ivanov" (string). Actual: "' . $record_readed_second[0]->second_name . '" (' . gettype($record_readed_second[0]->second_name) . ")\n"; + echo '[' . ++$action . '][' . ++$test . '][' . (gettype($record_read_second) === 'array' ? 'SUCCESS' : 'FAIL') . '][type of returned value] Expected: "array". Actual: "' . gettype($record_read_second) . "\"\n"; + echo '[' . $action . '][' . ++$test . '][' . (count($record_read_second) === 1 ? 'SUCCESS' : 'FAIL') . '][amount of read records] Expected: 1 records. Actual: ' . count($record_read_second) . " records\n"; + echo '[' . $action . '][' . ++$test . '][' . (gettype($record_read_second[0]) === 'object' ? 'SUCCESS' : 'FAIL') . '][type of read values] Expected: "object". Actual: "' . gettype($record_read_second[0]) . "\"\n"; + echo '[' . $action . '][' . ++$test . '][' . ($record_read_second[0] instanceof record ? 'SUCCESS' : 'FAIL') . '][class of read object values] Expected: "' . record::class . '". Actual: "' . $record_read_second[0]::class . "\"\n"; + echo '[' . $action . '][' . ++$test . '][' . ($record_read_second[0]->second_name === 'Ivanov' ? 'SUCCESS' : 'FAIL') . ']["second_name"] Expected: "Ivanov" (string). Actual: "' . $record_read_second[0]->second_name . '" (' . gettype($record_read_second[0]->second_name) . ")\n"; - echo '[' . $action . "] The readed second record checks have been completed\n"; + echo '[' . $action . "] The read second record checks have been completed\n"; } catch (exception $e) { - echo '[' . $action . "][WARNING] The readed second record checks have been completed with errors\n"; + echo '[' . $action . "][WARNING] The read second record checks have been completed with errors\n"; } // Reinitializing the counter of tests $test = 0; // Reading the record from the database by filter -$record_readed_filter = $database->read(filter: fn($record) => $record?->second_name === 'Ivanov', amount: 1); +$record_read_filter = $database->read(filter: fn($record) => $record?->second_name === 'Ivanov', amount: 1); -echo '[' . ++$action . "] Readed the record from the database by filter\n"; +echo '[' . ++$action . "] Read the record from the database by filter\n"; try { - echo '[' . ++$action . '][' . ++$test . '][' . (gettype($record_readed_filter) === 'array' ? 'SUCCESS' : 'FAIL') . '][type of returned value] Expected: "array". Actual: "' . gettype($record_readed_filter) . "\"\n"; - echo '[' . $action . '][' . ++$test . '][' . (count($record_readed_filter) === 1 ? 'SUCCESS' : 'FAIL') . '][amount of readed records] Expected: 1 records. Actual: ' . count($record_readed_filter) . " records\n"; - echo '[' . $action . '][' . ++$test . '][' . (gettype($record_readed_filter[0]) === 'object' ? 'SUCCESS' : 'FAIL') . '][type of readed values] Expected: "object". Actual: "' . gettype($record_readed_filter[0]) . "\"\n"; - echo '[' . $action . '][' . ++$test . '][' . ($record_readed_filter[0] instanceof record ? 'SUCCESS' : 'FAIL') . '][class of readed object values] Expected: "' . record::class . '". Actual: "' . $record_readed_filter[0]::class . "\"\n"; - echo '[' . $action . '][' . ++$test . '][' . ($record_readed_filter[0]->second_name === 'Ivanov' ? 'SUCCESS' : 'FAIL') . ']["second_name"] Expected: "Ivanov" (string). Actual: "' . $record_readed_filter[0]->second_name . '" (' . gettype($record_readed_filter[0]->second_name) . ")\n"; + echo '[' . ++$action . '][' . ++$test . '][' . (gettype($record_read_filter) === 'array' ? 'SUCCESS' : 'FAIL') . '][type of returned value] Expected: "array". Actual: "' . gettype($record_read_filter) . "\"\n"; + echo '[' . $action . '][' . ++$test . '][' . (count($record_read_filter) === 1 ? 'SUCCESS' : 'FAIL') . '][amount of read records] Expected: 1 records. Actual: ' . count($record_read_filter) . " records\n"; + echo '[' . $action . '][' . ++$test . '][' . (gettype($record_read_filter[0]) === 'object' ? 'SUCCESS' : 'FAIL') . '][type of read values] Expected: "object". Actual: "' . gettype($record_read_filter[0]) . "\"\n"; + echo '[' . $action . '][' . ++$test . '][' . ($record_read_filter[0] instanceof record ? 'SUCCESS' : 'FAIL') . '][class of read object values] Expected: "' . record::class . '". Actual: "' . $record_read_filter[0]::class . "\"\n"; + echo '[' . $action . '][' . ++$test . '][' . ($record_read_filter[0]->second_name === 'Ivanov' ? 'SUCCESS' : 'FAIL') . ']["second_name"] Expected: "Ivanov" (string). Actual: "' . $record_read_filter[0]->second_name . '" (' . gettype($record_read_filter[0]->second_name) . ")\n"; - echo '[' . $action . "] The readed record by filter checks have been completed\n"; + echo '[' . $action . "] The read record by filter checks have been completed\n"; } catch (exception $e) { - echo '[' . $action . "][WARNING] The readed record by filter checks have been completed with errors\n"; + echo '[' . $action . "][WARNING] The read record by filter checks have been completed with errors\n"; } // Reinitializing the counter of tests $test = 0; // Reading the record from the database by filter with amount limit -$records_readed_filter_amount = $database->read(filter: fn($record) => $record?->age === 24, amount: 1); +$records_read_filter_amount = $database->read(filter: fn($record) => $record?->age === 24, amount: 1); -echo '[' . ++$action . "] Readed the record from the database by filter with amount limit\n"; +echo '[' . ++$action . "] Read the record from the database by filter with amount limit\n"; try { - echo '[' . ++$action . '][' . ++$test . '][' . (gettype($records_readed_filter_amount) === 'array' ? 'SUCCESS' : 'FAIL') . '][type of returned value] Expected: "array". Actual: "' . gettype($records_readed_filter_amount) . "\"\n"; - echo '[' . $action . '][' . ++$test . '][' . (count($records_readed_filter_amount) === 1 ? 'SUCCESS' : 'FAIL') . '][amount of readed records] Expected: 1 records. Actual: ' . count($records_readed_filter_amount) . " records\n"; - echo '[' . $action . '][' . ++$test . '][' . (gettype($records_readed_filter_amount[0]) === 'object' ? 'SUCCESS' : 'FAIL') . '][type of readed values] Expected: "object". Actual: "' . gettype($records_readed_filter_amount[0]) . "\"\n"; - echo '[' . $action . '][' . ++$test . '][' . ($records_readed_filter_amount[0] instanceof record ? 'SUCCESS' : 'FAIL') . '][class of readed object values] Expected: "' . record::class . '". Actual: "' . $records_readed_filter_amount[0]::class . "\"\n"; - echo '[' . $action . '][' . ++$test . '][' . ($records_readed_filter_amount[0]->age === 24 ? 'SUCCESS' : 'FAIL') . ']["age"] Expected: "24" (integer). Actual: "' . $records_readed_filter_amount[0]->age . '" (' . gettype($records_readed_filter_amount[0]->age) . ")\n"; - echo '[' . $action . '][' . ++$test . '][' . ($records_readed_filter_amount[0]->second_name === 'Mirzaev' ? 'SUCCESS' : 'FAIL') . ']["second_name"] Expected: "Mirzaev" (string). Actual: "' . $records_readed_filter_amount[0]->second_name . '" (' . gettype($records_readed_filter_amount[0]->second_name) . ")\n"; + echo '[' . ++$action . '][' . ++$test . '][' . (gettype($records_read_filter_amount) === 'array' ? 'SUCCESS' : 'FAIL') . '][type of returned value] Expected: "array". Actual: "' . gettype($records_read_filter_amount) . "\"\n"; + echo '[' . $action . '][' . ++$test . '][' . (count($records_read_filter_amount) === 1 ? 'SUCCESS' : 'FAIL') . '][amount of read records] Expected: 1 records. Actual: ' . count($records_read_filter_amount) . " records\n"; + echo '[' . $action . '][' . ++$test . '][' . (gettype($records_read_filter_amount[0]) === 'object' ? 'SUCCESS' : 'FAIL') . '][type of read values] Expected: "object". Actual: "' . gettype($records_read_filter_amount[0]) . "\"\n"; + echo '[' . $action . '][' . ++$test . '][' . ($records_read_filter_amount[0] instanceof record ? 'SUCCESS' : 'FAIL') . '][class of read object values] Expected: "' . record::class . '". Actual: "' . $records_read_filter_amount[0]::class . "\"\n"; + echo '[' . $action . '][' . ++$test . '][' . ($records_read_filter_amount[0]->age === 24 ? 'SUCCESS' : 'FAIL') . ']["age"] Expected: "24" (integer). Actual: "' . $records_read_filter_amount[0]->age . '" (' . gettype($records_read_filter_amount[0]->age) . ")\n"; + echo '[' . $action . '][' . ++$test . '][' . ($records_read_filter_amount[0]->second_name === 'Mirzaev' ? 'SUCCESS' : 'FAIL') . ']["second_name"] Expected: "Mirzaev" (string). Actual: "' . $records_read_filter_amount[0]->second_name . '" (' . gettype($records_read_filter_amount[0]->second_name) . ")\n"; - echo '[' . $action . "] The readed record by filter with amount limit checks have been completed\n"; + echo '[' . $action . "] The read record by filter with amount limit checks have been completed\n"; } catch (exception $e) { - echo '[' . $action . "][WARNING] The readed record by filter with amount limit checks have been completed with errors\n"; + echo '[' . $action . "][WARNING] The read record by filter with amount limit checks have been completed with errors\n"; } // Reinitializing the counter of tests $test = 0; // Reading the record from the database by filter with amount limit and offset -$records_readed_filter_amount_offset = $database->read(filter: fn($record) => $record?->age === 24, amount: 1, offset: 1); +$records_read_filter_amount_offset = $database->read(filter: fn($record) => $record?->age === 24, amount: 1, offset: 1); -echo '[' . ++$action . "] Readed the record from the database by filter with amount limit and offset\n"; +echo '[' . ++$action . "] Read the record from the database by filter with amount limit and offset\n"; try { - echo '[' . ++$action . '][' . ++$test . '][' . (gettype($records_readed_filter_amount_offset) === 'array' ? 'SUCCESS' : 'FAIL') . '][type of returned value] Expected: "array". Actual: "' . gettype($records_readed_filter_amount_offset) . "\"\n"; - echo '[' . $action . '][' . ++$test . '][' . (count($records_readed_filter_amount_offset) === 1 ? 'SUCCESS' : 'FAIL') . '][amount of readed records] Expected: 1 records. Actual: ' . count($records_readed_filter_amount_offset) . " records\n"; - echo '[' . $action . '][' . ++$test . '][' . (gettype($records_readed_filter_amount_offset[0]) === 'object' ? 'SUCCESS' : 'FAIL') . '][type of readed values] Expected: "object". Actual: "' . gettype($records_readed_filter_amount_offset[0]) . "\"\n"; - echo '[' . $action . '][' . ++$test . '][' . ($records_readed_filter_amount_offset[0] instanceof record ? 'SUCCESS' : 'FAIL') . '][class of readed object values] Expected: "' . record::class . '". Actual: "' . $records_readed_filter_amount_offset[0]::class . "\"\n"; - echo '[' . $action . '][' . ++$test . '][' . ($records_readed_filter_amount_offset[0]->age === 24 ? 'SUCCESS' : 'FAIL') . ']["age"] Expected: "24" (integer). Actual: "' . $records_readed_filter_amount_offset[0]->age . '" (' . gettype($records_readed_filter_amount_offset[0]->age) . ")\n"; - echo '[' . $action . '][' . ++$test . '][' . ($records_readed_filter_amount_offset[0]->second_name === 'Ivanov' ? 'SUCCESS' : 'FAIL') . ']["second_name"] Expected: "Ivanov" (string). Actual: "' . $records_readed_filter_amount_offset[0]->second_name . '" (' . gettype($records_readed_filter_amount_offset[0]->second_name) . ")\n"; + echo '[' . ++$action . '][' . ++$test . '][' . (gettype($records_read_filter_amount_offset) === 'array' ? 'SUCCESS' : 'FAIL') . '][type of returned value] Expected: "array". Actual: "' . gettype($records_read_filter_amount_offset) . "\"\n"; + echo '[' . $action . '][' . ++$test . '][' . (count($records_read_filter_amount_offset) === 1 ? 'SUCCESS' : 'FAIL') . '][amount of read records] Expected: 1 records. Actual: ' . count($records_read_filter_amount_offset) . " records\n"; + echo '[' . $action . '][' . ++$test . '][' . (gettype($records_read_filter_amount_offset[0]) === 'object' ? 'SUCCESS' : 'FAIL') . '][type of read values] Expected: "object". Actual: "' . gettype($records_read_filter_amount_offset[0]) . "\"\n"; + echo '[' . $action . '][' . ++$test . '][' . ($records_read_filter_amount_offset[0] instanceof record ? 'SUCCESS' : 'FAIL') . '][class of read object values] Expected: "' . record::class . '". Actual: "' . $records_read_filter_amount_offset[0]::class . "\"\n"; + echo '[' . $action . '][' . ++$test . '][' . ($records_read_filter_amount_offset[0]->age === 24 ? 'SUCCESS' : 'FAIL') . ']["age"] Expected: "24" (integer). Actual: "' . $records_read_filter_amount_offset[0]->age . '" (' . gettype($records_read_filter_amount_offset[0]->age) . ")\n"; + echo '[' . $action . '][' . ++$test . '][' . ($records_read_filter_amount_offset[0]->second_name === 'Ivanov' ? 'SUCCESS' : 'FAIL') . ']["second_name"] Expected: "Ivanov" (string). Actual: "' . $records_read_filter_amount_offset[0]->second_name . '" (' . gettype($records_read_filter_amount_offset[0]->second_name) . ")\n"; - echo '[' . $action . "] The readed record by filter with amount limit and offset checks have been completed\n"; + echo '[' . $action . "] The read record by filter with amount limit and offset checks have been completed\n"; } catch (exception $e) { - echo '[' . $action . "][WARNING] The readed record by filter with amount limit and offset checks have been completed with errors\n"; + echo '[' . $action . "][WARNING] The read record by filter with amount limit and offset checks have been completed with errors\n"; } // Reinitializing the counter of tests $test = 0; // Deleting the record in the database by filter -$records_readed_filter_delete = $database->read(filter: fn($record) => $record?->name === 'Ivan', delete: true, amount: 1); +$records_read_filter_delete = $database->read(filter: fn($record) => $record?->name === 'Ivan', delete: true, amount: 1); echo '[' . ++$action . "] Deleted the record from the database by filter\n"; // Reading records from the database after deleting -$records_readed_filter_delete_readed = $database->read(amount: 100); +$records_read_filter_delete_read = $database->read(amount: 100); -echo '[' . ++$action . "] Readed records from the database after deleting the record\n"; +echo '[' . ++$action . "] Read records from the database after deleting the record\n"; try { - echo '[' . ++$action . '][' . ++$test . '][' . (gettype($records_readed_filter_delete) === 'array' ? 'SUCCESS' : 'FAIL') . '][type of returned value] Expected: "array". Actual: "' . gettype($records_readed_filter_delete) . "\"\n"; - echo '[' . $action . '][' . ++$test . '][' . (count($records_readed_filter_delete) === 1 ? 'SUCCESS' : 'FAIL') . '][amount of deleted records] Expected: 1 records. Actual: ' . count($records_readed_filter_delete) . " records\n"; - echo '[' . $action . '][' . ++$test . '][' . (gettype($records_readed_filter_delete[0]) === 'object' ? 'SUCCESS' : 'FAIL') . '][type of readed values] Expected: "object". Actual: "' . gettype($records_readed_filter_delete[0]) . "\"\n"; - echo '[' . $action . '][' . ++$test . '][' . ($records_readed_filter_delete[0] instanceof record ? 'SUCCESS' : 'FAIL') . '][class of readed object values] Expected: "' . record::class . '". Actual: "' . $records_readed_filter_delete[0]::class . "\"\n"; - echo '[' . $action . '][' . ++$test . '][' . ($records_readed_filter_delete[0]->name === 'Ivan' ? 'SUCCESS' : 'FAIL') . ']["name"] Expected: "Ivan" (string). Actual: "' . $records_readed_filter_delete[0]->second_name . '" (' . gettype($records_readed_filter_delete[0]->second_name) . ")\n"; - echo '[' . $action . '][' . ++$test . '][' . (count($records_readed_filter_delete_readed) === 2 ? 'SUCCESS' : 'FAIL') . '][amount of readed records after deleting] Expected: 2 records. Actual: ' . count($records_readed_filter_delete_readed) . " records\n"; + echo '[' . ++$action . '][' . ++$test . '][' . (gettype($records_read_filter_delete) === 'array' ? 'SUCCESS' : 'FAIL') . '][type of returned value] Expected: "array". Actual: "' . gettype($records_read_filter_delete) . "\"\n"; + echo '[' . $action . '][' . ++$test . '][' . (count($records_read_filter_delete) === 1 ? 'SUCCESS' : 'FAIL') . '][amount of deleted records] Expected: 1 records. Actual: ' . count($records_read_filter_delete) . " records\n"; + echo '[' . $action . '][' . ++$test . '][' . (gettype($records_read_filter_delete[0]) === 'object' ? 'SUCCESS' : 'FAIL') . '][type of read values] Expected: "object". Actual: "' . gettype($records_read_filter_delete[0]) . "\"\n"; + echo '[' . $action . '][' . ++$test . '][' . ($records_read_filter_delete[0] instanceof record ? 'SUCCESS' : 'FAIL') . '][class of read object values] Expected: "' . record::class . '". Actual: "' . $records_read_filter_delete[0]::class . "\"\n"; + echo '[' . $action . '][' . ++$test . '][' . ($records_read_filter_delete[0]->name === 'Ivan' ? 'SUCCESS' : 'FAIL') . ']["name"] Expected: "Ivan" (string). Actual: "' . $records_read_filter_delete[0]->second_name . '" (' . gettype($records_read_filter_delete[0]->second_name) . ")\n"; + echo '[' . $action . '][' . ++$test . '][' . (count($records_read_filter_delete_read) === 2 ? 'SUCCESS' : 'FAIL') . '][amount of read records after deleting] Expected: 2 records. Actual: ' . count($records_read_filter_delete_read) . " records\n"; echo '[' . $action . "] The deleted record by filter checks have been completed\n"; } catch (exception $e) { @@ -276,23 +337,23 @@ try { $test = 0; // Updating the record in the database -$records_readed_filter_update = $database->read(filter: fn($record) => $record?->name === 'Margarita', update: fn(&$record) => $record->height += 0.5, amount: 1); +$records_read_filter_update = $database->read(filter: fn($record) => $record?->name === 'Margarita', update: fn(&$record) => $record->height += 0.5, amount: 1); echo '[' . ++$action . "] Updated the record in the database by filter\n"; // Reading records from the database after updating -$records_readed_filter_update_readed = $database->read(amount: 100); +$records_read_filter_update_read = $database->read(amount: 100); -echo '[' . ++$action . "] Readed records from the database after updating the record\n"; +echo '[' . ++$action . "] Read records from the database after updating the record\n"; try { - echo '[' . ++$action . '][' . ++$test . '][' . (gettype($records_readed_filter_update) === 'array' ? 'SUCCESS' : 'FAIL') . '][type of returned value] Expected: "array". Actual: "' . gettype($records_readed_filter_update) . "\"\n"; - echo '[' . $action . '][' . ++$test . '][' . (count($records_readed_filter_update) === 1 ? 'SUCCESS' : 'FAIL') . '][amount of updated records] Expected: 1 records. Actual: ' . count($records_readed_filter_update) . " records\n"; - echo '[' . $action . '][' . ++$test . '][' . (gettype($records_readed_filter_update[0]) === 'object' ? 'SUCCESS' : 'FAIL') . '][type of readed values] Expected: "object". Actual: "' . gettype($records_readed_filter_update[0]) . "\"\n"; - echo '[' . $action . '][' . ++$test . '][' . ($records_readed_filter_update[0] instanceof record ? 'SUCCESS' : 'FAIL') . '][class of readed object values] Expected: "' . record::class . '". Actual: "' . $records_readed_filter_update[0]::class . "\"\n"; - echo '[' . $action . '][' . ++$test . '][' . ($records_readed_filter_update[0]->height === 165.5 ? 'SUCCESS' : 'FAIL') . ']["height"] Expected: "165.5" (double). Actual: "' . $records_readed_filter_update[0]->height . '" (' . gettype($records_readed_filter_update[0]->height) . ")\n"; - echo '[' . $action . '][' . ++$test . '][' . (count($records_readed_filter_update_readed) === 2 ? 'SUCCESS' : 'FAIL') . '][amount of readed records after updating] Expected: 2 records. Actual: ' . count($records_readed_filter_update_readed) . " records\n"; - echo '[' . $action . '][' . ++$test . '][' . ($records_readed_filter_update_readed[1]->height === $records_readed_filter_update[0]->height ? 'SUCCESS' : 'FAIL') . "] Height from `update` process response matched height from the `read` preocess response\n"; + echo '[' . ++$action . '][' . ++$test . '][' . (gettype($records_read_filter_update) === 'array' ? 'SUCCESS' : 'FAIL') . '][type of returned value] Expected: "array". Actual: "' . gettype($records_read_filter_update) . "\"\n"; + echo '[' . $action . '][' . ++$test . '][' . (count($records_read_filter_update) === 1 ? 'SUCCESS' : 'FAIL') . '][amount of updated records] Expected: 1 records. Actual: ' . count($records_read_filter_update) . " records\n"; + echo '[' . $action . '][' . ++$test . '][' . (gettype($records_read_filter_update[0]) === 'object' ? 'SUCCESS' : 'FAIL') . '][type of read values] Expected: "object". Actual: "' . gettype($records_read_filter_update[0]) . "\"\n"; + echo '[' . $action . '][' . ++$test . '][' . ($records_read_filter_update[0] instanceof record ? 'SUCCESS' : 'FAIL') . '][class of read object values] Expected: "' . record::class . '". Actual: "' . $records_read_filter_update[0]::class . "\"\n"; + echo '[' . $action . '][' . ++$test . '][' . ($records_read_filter_update[0]->height === 165.5 ? 'SUCCESS' : 'FAIL') . ']["height"] Expected: "165.5" (double). Actual: "' . $records_read_filter_update[0]->height . '" (' . gettype($records_read_filter_update[0]->height) . ")\n"; + echo '[' . $action . '][' . ++$test . '][' . (count($records_read_filter_update_read) === 2 ? 'SUCCESS' : 'FAIL') . '][amount of read records after updating] Expected: 2 records. Actual: ' . count($records_read_filter_update_read) . " records\n"; + echo '[' . $action . '][' . ++$test . '][' . ($records_read_filter_update_read[1]->height === $records_read_filter_update[0]->height ? 'SUCCESS' : 'FAIL') . "] Height from `update` process response matched height from the `read` preocess response\n"; echo '[' . $action . "] The updated record by filter checks have been completed\n"; } catch (exception $e) { -- 2.34.1 From 13b27b3faca5b33b42b1068ab69c2b76dc1d2552 Mon Sep 17 00:00:00 2001 From: Little Fluffy Clouds Date: Fri, 11 Jul 2025 23:24:51 +0300 Subject: [PATCH 2/8] Add explanations --- mirzaev/baza/system/database.php | 42 +++++++++++++++++------ mirzaev/baza/system/enumerations/type.php | 8 +++++ 2 files changed, 40 insertions(+), 10 deletions(-) diff --git a/mirzaev/baza/system/database.php b/mirzaev/baza/system/database.php index 9da96d3..d3fb0b1 100755 --- a/mirzaev/baza/system/database.php +++ b/mirzaev/baza/system/database.php @@ -227,6 +227,7 @@ class database * Pack the record values * * @param record $record The record + * @const integer ARCH PHP architecture * * @return string Packed values */ @@ -246,10 +247,20 @@ class database // Packing the value and writing into the buffer of packed values $packed .= pack($column->type->value . $column->length, $value); - } else if (ARCH === 64 && - ($column->type === type::integer || - $column->type === type::integer_unsigned) - ) { + } + /** + * PHP builtin pack() ignores 64-bit integer values + * found on 64-bit PHP distributions + * @see https://www.php.net/manual/en/function.pack.php#109382 + * + * In case of integer type on 64-bit PHP distributions + * we got to splice 64-bit integer into two separate longs + * next to each other in binary representation + */ + else if (ARCH === 64 && + ($column->type === type::integer || + $column->type === type::integer_unsigned)) + { // Initialize variables for left and right masks of the 64-bit variable $left = 0xffffffff00000000; $right = 0x00000000ffffffff; @@ -259,7 +270,7 @@ class database // Bitwise and the value with the right mask to get the second half $r = $record->values()[$column->name] & $right; - // Pack into 64bit binary value + // Pack into 64bit binary value with two longs $packed .= pack('NN', $l, $r); } else { // Other types @@ -279,6 +290,7 @@ class database * Unpack binary values and implement them as a `record` instance * * @param array $binaries Binary values in the same order as the columns + * @const integer ARCH PHP architecture * * @return record The unpacked record from binary values */ @@ -307,12 +319,22 @@ class database // Writing into the buffer of read values $unpacked[] = $encoded; - } else if (ARCH === 64 && - ($column->type === type::integer || - $column->type === type::integer_unsigned) - ) { - // Unpacking the integer + } + /** + * PHP builtin pack() ignores 64-bit integer values + * found on 64-bit PHP distributions + * @see https://www.php.net/manual/en/function.pack.php#109382 + * + * In case of integer type on 64-bit PHP distributions + * we got to reconstruct previosly spliced integer value + */ + else if (ARCH === 64 && + ($column->type === type::integer || + $column->type === type::integer_unsigned)) + { + // Unpacking the integer values into array of two longs $value = unpack('N2', $binary ?? "\0"); + // Reconstructing original integer value $unpacked[] = $value[1] << 32 | $value[2]; } else { // Other types diff --git a/mirzaev/baza/system/enumerations/type.php b/mirzaev/baza/system/enumerations/type.php index 4182d25..3b10589 100755 --- a/mirzaev/baza/system/enumerations/type.php +++ b/mirzaev/baza/system/enumerations/type.php @@ -62,6 +62,14 @@ enum type: string { // Exit (success) + /** + * PHP builtin pack() ignores 64-bit integer values + * found on 64-bit PHP distributions + * @see https://www.php.net/manual/en/function.pack.php#109382 + * + * Architecture-specific size should always be returned + */ + // If type is (unsigned) integer, return size of integer return (strtoupper($this->value) === 'I') ? PHP_INT_SIZE -- 2.34.1 From f87475779a626c36a9094b1914760be6d1a89e34 Mon Sep 17 00:00:00 2001 From: Little Fluffy Clouds Date: Sat, 12 Jul 2025 00:17:22 +0300 Subject: [PATCH 3/8] add more coverage --- mirzaev/baza/tests/record.php | 66 +++++++++++++++++++++++++++++++++-- 1 file changed, 63 insertions(+), 3 deletions(-) diff --git a/mirzaev/baza/tests/record.php b/mirzaev/baza/tests/record.php index 7ec9d09..4b235fc 100755 --- a/mirzaev/baza/tests/record.php +++ b/mirzaev/baza/tests/record.php @@ -63,7 +63,7 @@ if (PHP_INT_SIZE === 8) { new column('height', type::float), // 64-bit values test new column('neuron_count', type::integer_unsigned), - new column('ambition_level', type::double), + new column('motivation', type::double), new column('reputation', type::integer), new column('active', type::char) ) @@ -115,8 +115,8 @@ echo '[' . $action . '][' . ++$test . '][' . ($record->second_name === 'Mirzaev' echo '[' . $action . '][' . ++$test . '][' . ($record->age === 24 ? 'SUCCESS' : 'FAIL') . "][\"age\"] Expected: \"24\" (integer). Actual: \"$record->age\" (" . gettype($record->age) . ")\n"; echo '[' . $action . '][' . ++$test . '][' . ($record->height === 165.5 ? 'SUCCESS' : 'FAIL') . "][\"height\"] Expected: \"165.5\" (double). Actual: \"$record->height\" (" . gettype($record->height) . ")\n"; if (ARCH === 64) { - echo '[' . $action . '][' . ++$test . '][' . ($record->neuron_count === 91000000000 ? 'SUCCESS' : 'FAIL') . "][\"neuron_count\"] Expected: \"91000000000\" (integer_unsigned). Actual: \"$record->neuron_count\" (" . gettype($record->neuron_count) . ")\n"; - echo '[' . $action . '][' . ++$test . '][' . ($record->ambition_level === 1.7976931348623E+238 ? 'SUCCESS' : 'FAIL') . "][\"ambition_level\"] Expected: \"1.7976931348623E+238\" (double). Actual: \"$record->ambition_level\" (" . gettype($record->ambition_level) . ")\n"; + echo '[' . $action . '][' . ++$test . '][' . ($record->neuron_count === 91000000000 ? 'SUCCESS' : 'FAIL') . "][\"neuron_count\"] Expected: \"91000000000\" (integer). Actual: \"$record->neuron_count\" (" . gettype($record->neuron_count) . ")\n"; + echo '[' . $action . '][' . ++$test . '][' . ($record->motivation === 1.7976931348623E+238 ? 'SUCCESS' : 'FAIL') . "][\"motivation\"] Expected: \"1.7976931348623E+238\" (double). Actual: \"$record->motivation\" (" . gettype($record->motivation) . ")\n"; echo '[' . $action . '][' . ++$test . '][' . ($record->reputation === 7355608 ? 'SUCCESS' : 'FAIL') . "][\"reputation\"] Expected: \"7355608\" (integer). Actual: \"$record->reputation\" (" . gettype($record->reputation) . ")\n"; } echo '[' . $action . '][' . ++$test . '][' . ($record->active === 1 ? 'SUCCESS' : 'FAIL') . "][\"active\"] Expected: \"1\" (integer). Actual: \"$record->active\" (" . gettype($record->active) . ")\n"; @@ -199,6 +199,9 @@ try { echo '[' . $action . '][' . ++$test . '][' . (count($records_read_all) === 3 ? 'SUCCESS' : 'FAIL') . '][amount of read records] Expected: 3 records. Actual: ' . count($records_read_all) . " records\n"; echo '[' . $action . '][' . ++$test . '][' . (gettype($records_read_all[0]) === 'object' ? 'SUCCESS' : 'FAIL') . '][type of read values] Expected: "object". Actual: "' . gettype($records_read_all[0]) . "\"\n"; echo '[' . $action . '][' . ++$test . '][' . ($records_read_all[0] instanceof record ? 'SUCCESS' : 'FAIL') . '][class of read object values] Expected: "' . record::class . '". Actual: "' . $records_read_all[0]::class . "\"\n"; + if (ARCH === 64) { + echo '[' . $action . '][' . ++$test . '][' . ($records_read_all[0]->neuron_count === 91000000000 ? 'SUCCESS' : 'FAIL') . ']["neuron_count"] Expected: "91000000000" (integer). Actual: "' . $records_read_all[0]->neuron_count . '" (' . gettype($records_read_all[0]->neuron_count) . ")\n"; + } echo '[' . $action . "] The read all records checks have been completed\n"; } catch (exception $e) { @@ -219,6 +222,9 @@ try { echo '[' . $action . '][' . ++$test . '][' . (gettype($record_read_first[0]) === 'object' ? 'SUCCESS' : 'FAIL') . '][type of read values] Expected: "object". Actual: "' . gettype($record_read_first[0]) . "\"\n"; echo '[' . $action . '][' . ++$test . '][' . ($record_read_first[0] instanceof record ? 'SUCCESS' : 'FAIL') . '][class of read object values] Expected: "' . record::class . '". Actual: "' . $record_read_first[0]::class . "\"\n"; echo '[' . $action . '][' . ++$test . '][' . ($record_read_first[0]->second_name === 'Mirzaev' ? 'SUCCESS' : 'FAIL') . ']["second_name"] Expected: "Mirzaev" (string). Actual: "' . $record_read_first[0]->second_name . '" (' . gettype($record_read_first[0]->second_name) . ")\n"; + if (ARCH === 64) { + echo '[' . $action . '][' . ++$test . '][' . ($record_read_first[0]->neuron_count === 91000000000 ? 'SUCCESS' : 'FAIL') . ']["neuron_count"] Expected: "91000000000" (integer). Actual: "' . $record_read_first[0]->neuron_count . '" (' . gettype($record_read_first[0]->neuron_count) . ")\n"; + } echo '[' . $action . "] The read first record checks have been completed\n"; } catch (exception $e) { @@ -239,6 +245,15 @@ try { echo '[' . $action . '][' . ++$test . '][' . (gettype($record_read_second[0]) === 'object' ? 'SUCCESS' : 'FAIL') . '][type of read values] Expected: "object". Actual: "' . gettype($record_read_second[0]) . "\"\n"; echo '[' . $action . '][' . ++$test . '][' . ($record_read_second[0] instanceof record ? 'SUCCESS' : 'FAIL') . '][class of read object values] Expected: "' . record::class . '". Actual: "' . $record_read_second[0]::class . "\"\n"; echo '[' . $action . '][' . ++$test . '][' . ($record_read_second[0]->second_name === 'Ivanov' ? 'SUCCESS' : 'FAIL') . ']["second_name"] Expected: "Ivanov" (string). Actual: "' . $record_read_second[0]->second_name . '" (' . gettype($record_read_second[0]->second_name) . ")\n"; + if (ARCH === 64) { + /** + * Due to IEEE 754 double precision format double equility is problematic + * + * @see https://www.php.net/manual/en/language.types.float.php#113703 + */ + echo '[' . $action . '][' . ++$test . '][' . (round($record_read_second[0]->motivation, 2) === round(2.2250738585072E-308, 2) ? 'SUCCESS' : 'FAIL') . ']["motivation"] Expected: "2.2250738585072E-308" (double). Actual: "' . $record_read_second[0]->motivation . '" (' . gettype($record_read_second[0]->motivation) . ")\n"; + echo '[' . $action . '][' . ++$test . '][' . ($record_read_second[0]->reputation === (int) -9223372036854775808 ? 'SUCCESS' : 'FAIL') . ']["reputation"] Expected: "-9223372036854775808" (integer). Actual: "' . $record_read_second[0]->reputation . '" (' . gettype($record_read_second[0]->reputation) . ")\n"; + } echo '[' . $action . "] The read second record checks have been completed\n"; } catch (exception $e) { @@ -259,6 +274,15 @@ try { echo '[' . $action . '][' . ++$test . '][' . (gettype($record_read_filter[0]) === 'object' ? 'SUCCESS' : 'FAIL') . '][type of read values] Expected: "object". Actual: "' . gettype($record_read_filter[0]) . "\"\n"; echo '[' . $action . '][' . ++$test . '][' . ($record_read_filter[0] instanceof record ? 'SUCCESS' : 'FAIL') . '][class of read object values] Expected: "' . record::class . '". Actual: "' . $record_read_filter[0]::class . "\"\n"; echo '[' . $action . '][' . ++$test . '][' . ($record_read_filter[0]->second_name === 'Ivanov' ? 'SUCCESS' : 'FAIL') . ']["second_name"] Expected: "Ivanov" (string). Actual: "' . $record_read_filter[0]->second_name . '" (' . gettype($record_read_filter[0]->second_name) . ")\n"; + if (ARCH === 64) { + /** + * Due to IEEE 754 double precision format double equility is problematic + * + * @see https://www.php.net/manual/en/language.types.float.php#113703 + */ + echo '[' . $action . '][' . ++$test . '][' . (round($record_read_second[0]->motivation, 2) === round(2.2250738585072E-308, 2) ? 'SUCCESS' : 'FAIL') . ']["motivation"] Expected: "2.2250738585072E-308" (double). Actual: "' . $record_read_second[0]->motivation . '" (' . gettype($record_read_second[0]->motivation) . ")\n"; + echo '[' . $action . '][' . ++$test . '][' . ($record_read_second[0]->reputation === (int) -9223372036854775808 ? 'SUCCESS' : 'FAIL') . ']["reputation"] Expected: "-9223372036854775808" (integer). Actual: "' . $record_read_second[0]->reputation . '" (' . gettype($record_read_second[0]->reputation) . ")\n"; + } echo '[' . $action . "] The read record by filter checks have been completed\n"; } catch (exception $e) { @@ -280,6 +304,15 @@ try { echo '[' . $action . '][' . ++$test . '][' . ($records_read_filter_amount[0] instanceof record ? 'SUCCESS' : 'FAIL') . '][class of read object values] Expected: "' . record::class . '". Actual: "' . $records_read_filter_amount[0]::class . "\"\n"; echo '[' . $action . '][' . ++$test . '][' . ($records_read_filter_amount[0]->age === 24 ? 'SUCCESS' : 'FAIL') . ']["age"] Expected: "24" (integer). Actual: "' . $records_read_filter_amount[0]->age . '" (' . gettype($records_read_filter_amount[0]->age) . ")\n"; echo '[' . $action . '][' . ++$test . '][' . ($records_read_filter_amount[0]->second_name === 'Mirzaev' ? 'SUCCESS' : 'FAIL') . ']["second_name"] Expected: "Mirzaev" (string). Actual: "' . $records_read_filter_amount[0]->second_name . '" (' . gettype($records_read_filter_amount[0]->second_name) . ")\n"; + if (ARCH === 64) { + /** + * Due to IEEE 754 double precision format double equility is problematic + * + * @see https://www.php.net/manual/en/language.types.float.php#113703 + */ + echo '[' . $action . '][' . ++$test . '][' . (round($record_read_second[0]->motivation, 2) === round(2.2250738585072E-308, 2) ? 'SUCCESS' : 'FAIL') . ']["motivation"] Expected: "2.2250738585072E-308" (double). Actual: "' . $record_read_second[0]->motivation . '" (' . gettype($record_read_second[0]->motivation) . ")\n"; + echo '[' . $action . '][' . ++$test . '][' . ($record_read_second[0]->reputation === (int) -9223372036854775808 ? 'SUCCESS' : 'FAIL') . ']["reputation"] Expected: "-9223372036854775808" (integer). Actual: "' . $record_read_second[0]->reputation . '" (' . gettype($record_read_second[0]->reputation) . ")\n"; + } echo '[' . $action . "] The read record by filter with amount limit checks have been completed\n"; } catch (exception $e) { @@ -301,6 +334,15 @@ try { echo '[' . $action . '][' . ++$test . '][' . ($records_read_filter_amount_offset[0] instanceof record ? 'SUCCESS' : 'FAIL') . '][class of read object values] Expected: "' . record::class . '". Actual: "' . $records_read_filter_amount_offset[0]::class . "\"\n"; echo '[' . $action . '][' . ++$test . '][' . ($records_read_filter_amount_offset[0]->age === 24 ? 'SUCCESS' : 'FAIL') . ']["age"] Expected: "24" (integer). Actual: "' . $records_read_filter_amount_offset[0]->age . '" (' . gettype($records_read_filter_amount_offset[0]->age) . ")\n"; echo '[' . $action . '][' . ++$test . '][' . ($records_read_filter_amount_offset[0]->second_name === 'Ivanov' ? 'SUCCESS' : 'FAIL') . ']["second_name"] Expected: "Ivanov" (string). Actual: "' . $records_read_filter_amount_offset[0]->second_name . '" (' . gettype($records_read_filter_amount_offset[0]->second_name) . ")\n"; + if (ARCH === 64) { + /** + * Due to IEEE 754 double precision format double equility is problematic + * + * @see https://www.php.net/manual/en/language.types.float.php#113703 + */ + echo '[' . $action . '][' . ++$test . '][' . (round($record_read_second[0]->motivation, 2) === round(2.2250738585072E-308, 2) ? 'SUCCESS' : 'FAIL') . ']["motivation"] Expected: "2.2250738585072E-308" (double). Actual: "' . $record_read_second[0]->motivation . '" (' . gettype($record_read_second[0]->motivation) . ")\n"; + echo '[' . $action . '][' . ++$test . '][' . ($record_read_second[0]->reputation === (int) -9223372036854775808 ? 'SUCCESS' : 'FAIL') . ']["reputation"] Expected: "-9223372036854775808" (integer). Actual: "' . $record_read_second[0]->reputation . '" (' . gettype($record_read_second[0]->reputation) . ")\n"; + } echo '[' . $action . "] The read record by filter with amount limit and offset checks have been completed\n"; } catch (exception $e) { @@ -327,6 +369,15 @@ try { echo '[' . $action . '][' . ++$test . '][' . ($records_read_filter_delete[0] instanceof record ? 'SUCCESS' : 'FAIL') . '][class of read object values] Expected: "' . record::class . '". Actual: "' . $records_read_filter_delete[0]::class . "\"\n"; echo '[' . $action . '][' . ++$test . '][' . ($records_read_filter_delete[0]->name === 'Ivan' ? 'SUCCESS' : 'FAIL') . ']["name"] Expected: "Ivan" (string). Actual: "' . $records_read_filter_delete[0]->second_name . '" (' . gettype($records_read_filter_delete[0]->second_name) . ")\n"; echo '[' . $action . '][' . ++$test . '][' . (count($records_read_filter_delete_read) === 2 ? 'SUCCESS' : 'FAIL') . '][amount of read records after deleting] Expected: 2 records. Actual: ' . count($records_read_filter_delete_read) . " records\n"; + if (ARCH === 64) { + /** + * Due to IEEE 754 double precision format double equility is problematic + * + * @see https://www.php.net/manual/en/language.types.float.php#113703 + */ + echo '[' . $action . '][' . ++$test . '][' . (round($record_read_second[0]->motivation, 2) === round(2.2250738585072E-308, 2) ? 'SUCCESS' : 'FAIL') . ']["motivation"] Expected: "2.2250738585072E-308" (double). Actual: "' . $record_read_second[0]->motivation . '" (' . gettype($record_read_second[0]->motivation) . ")\n"; + echo '[' . $action . '][' . ++$test . '][' . ($record_read_second[0]->reputation === (int) -9223372036854775808 ? 'SUCCESS' : 'FAIL') . ']["reputation"] Expected: "-9223372036854775808" (integer). Actual: "' . $record_read_second[0]->reputation . '" (' . gettype($record_read_second[0]->reputation) . ")\n"; + } echo '[' . $action . "] The deleted record by filter checks have been completed\n"; } catch (exception $e) { @@ -354,6 +405,15 @@ try { echo '[' . $action . '][' . ++$test . '][' . ($records_read_filter_update[0]->height === 165.5 ? 'SUCCESS' : 'FAIL') . ']["height"] Expected: "165.5" (double). Actual: "' . $records_read_filter_update[0]->height . '" (' . gettype($records_read_filter_update[0]->height) . ")\n"; echo '[' . $action . '][' . ++$test . '][' . (count($records_read_filter_update_read) === 2 ? 'SUCCESS' : 'FAIL') . '][amount of read records after updating] Expected: 2 records. Actual: ' . count($records_read_filter_update_read) . " records\n"; echo '[' . $action . '][' . ++$test . '][' . ($records_read_filter_update_read[1]->height === $records_read_filter_update[0]->height ? 'SUCCESS' : 'FAIL') . "] Height from `update` process response matched height from the `read` preocess response\n"; + if (ARCH === 64) { + /** + * Due to IEEE 754 double precision format double equility is problematic + * + * @see https://www.php.net/manual/en/language.types.float.php#113703 + */ + echo '[' . $action . '][' . ++$test . '][' . (round($record_read_second[0]->motivation, 2) === round(2.2250738585072E-308, 2) ? 'SUCCESS' : 'FAIL') . ']["motivation"] Expected: "2.2250738585072E-308" (double). Actual: "' . $record_read_second[0]->motivation . '" (' . gettype($record_read_second[0]->motivation) . ")\n"; + echo '[' . $action . '][' . ++$test . '][' . ($record_read_second[0]->reputation === (int) -9223372036854775808 ? 'SUCCESS' : 'FAIL') . ']["reputation"] Expected: "-9223372036854775808" (integer). Actual: "' . $record_read_second[0]->reputation . '" (' . gettype($record_read_second[0]->reputation) . ")\n"; + } echo '[' . $action . "] The updated record by filter checks have been completed\n"; } catch (exception $e) { -- 2.34.1 From 3fa2359a6f4eaff2fedb93ecc413da0a1ef2a355 Mon Sep 17 00:00:00 2001 From: Little Fluffy Clouds Date: Sat, 12 Jul 2025 10:45:52 +0300 Subject: [PATCH 4/8] Arsen english dialect --- README.md | 4 +- mirzaev/baza/system/database.php | 10 +- mirzaev/baza/tests/record.php | 180 +++++++++++++++---------------- 3 files changed, 97 insertions(+), 97 deletions(-) diff --git a/README.md b/README.md index 961ea8a..632076b 100755 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ $record = $database->record( ); if ($database->write($record)) { - // Wrote the record into the database + // Writed the record into the database // Updating the record in the database $updated = $database->read( @@ -48,7 +48,7 @@ if ($database->write($record)) { ); // Reading the record from the database - $read = $database->read( + $readed = $database->read( filter: fn($record) => $record->name === 'Arsen' && $record->age === 24, amount: 1 ); diff --git a/mirzaev/baza/system/database.php b/mirzaev/baza/system/database.php index d3fb0b1..af560c1 100755 --- a/mirzaev/baza/system/database.php +++ b/mirzaev/baza/system/database.php @@ -317,7 +317,7 @@ class database // Encoding the unpacked value $encoded = mb_convert_encoding($unnulled, $this->encoding->value); - // Writing into the buffer of read values + // Writing into the buffer of readed values $unpacked[] = $encoded; } /** @@ -339,7 +339,7 @@ class database } else { // Other types - // Writing into the buffer of read values + // Writing into the buffer of readed values $unpacked[] = unpack($column->type->value, $binary ?? "\0")[1]; } } @@ -361,7 +361,7 @@ class database * @throws exception_runtime If failed to lock the file * @throws exception_runtime If failed to unlock the file * - * @return bool Is the record was wrote into the end of the database file + * @return bool Is the record was writed into the end of the database file */ public function write(record $record): bool { @@ -420,7 +420,7 @@ class database * @param int $amount Amount iterator * @param int $offset Offset iterator * - * @return array|null Read records + * @return array|null Readed records */ public function read( ?callable $filter = null, @@ -435,7 +435,7 @@ class database if (flock($file, LOCK_EX)) { // The file was locked - // Declaring the buffer of read records + // Declaring the buffer of readed records $records = []; // Declaring the buffer of failed to reading records diff --git a/mirzaev/baza/tests/record.php b/mirzaev/baza/tests/record.php index 4b235fc..8fff350 100755 --- a/mirzaev/baza/tests/record.php +++ b/mirzaev/baza/tests/record.php @@ -158,7 +158,7 @@ echo '[' . ++$action . "] Initialized the record\n"; // Writing the second record into the databasse $database->write($record_ivan); -echo '[' . ++$action . "] Wrote the record into the database\n"; +echo '[' . ++$action . "] Writed the record into the database\n"; // Initializing the second record if (ARCH === 64) { @@ -187,196 +187,196 @@ echo '[' . ++$action . "] Initialized the record\n"; // Writing the second record into the databasse $database->write($record_margarita); -echo '[' . ++$action . "] Wrote the record into the database\n"; +echo '[' . ++$action . "] Writed the record into the database\n"; // Reading all records from the database -$records_read_all = $database->read(amount: 99999); +$records_readed_all = $database->read(amount: 99999); -echo '[' . ++$action . "] Read all records from the database\n"; +echo '[' . ++$action . "] Readed all records from the database\n"; try { - echo '[' . ++$action . '][' . ++$test . '][' . (gettype($records_read_all) === 'array' ? 'SUCCESS' : 'FAIL') . '][type of returned value] Expected: "array". Actual: "' . gettype($records_read_all) . "\"\n"; - echo '[' . $action . '][' . ++$test . '][' . (count($records_read_all) === 3 ? 'SUCCESS' : 'FAIL') . '][amount of read records] Expected: 3 records. Actual: ' . count($records_read_all) . " records\n"; - echo '[' . $action . '][' . ++$test . '][' . (gettype($records_read_all[0]) === 'object' ? 'SUCCESS' : 'FAIL') . '][type of read values] Expected: "object". Actual: "' . gettype($records_read_all[0]) . "\"\n"; - echo '[' . $action . '][' . ++$test . '][' . ($records_read_all[0] instanceof record ? 'SUCCESS' : 'FAIL') . '][class of read object values] Expected: "' . record::class . '". Actual: "' . $records_read_all[0]::class . "\"\n"; + echo '[' . ++$action . '][' . ++$test . '][' . (gettype($records_readed_all) === 'array' ? 'SUCCESS' : 'FAIL') . '][type of returned value] Expected: "array". Actual: "' . gettype($records_readed_all) . "\"\n"; + echo '[' . $action . '][' . ++$test . '][' . (count($records_readed_all) === 3 ? 'SUCCESS' : 'FAIL') . '][amount of read records] Expected: 3 records. Actual: ' . count($records_readed_all) . " records\n"; + echo '[' . $action . '][' . ++$test . '][' . (gettype($records_readed_all[0]) === 'object' ? 'SUCCESS' : 'FAIL') . '][type of read values] Expected: "object". Actual: "' . gettype($records_readed_all[0]) . "\"\n"; + echo '[' . $action . '][' . ++$test . '][' . ($records_readed_all[0] instanceof record ? 'SUCCESS' : 'FAIL') . '][class of read object values] Expected: "' . record::class . '". Actual: "' . $records_readed_all[0]::class . "\"\n"; if (ARCH === 64) { - echo '[' . $action . '][' . ++$test . '][' . ($records_read_all[0]->neuron_count === 91000000000 ? 'SUCCESS' : 'FAIL') . ']["neuron_count"] Expected: "91000000000" (integer). Actual: "' . $records_read_all[0]->neuron_count . '" (' . gettype($records_read_all[0]->neuron_count) . ")\n"; + echo '[' . $action . '][' . ++$test . '][' . ($records_readed_all[0]->neuron_count === 91000000000 ? 'SUCCESS' : 'FAIL') . ']["neuron_count"] Expected: "91000000000" (integer). Actual: "' . $records_readed_all[0]->neuron_count . '" (' . gettype($records_readed_all[0]->neuron_count) . ")\n"; } - echo '[' . $action . "] The read all records checks have been completed\n"; + echo '[' . $action . "] The readed all records checks have been completed\n"; } catch (exception $e) { - echo '[' . $action . "][WARNING] The read all records checks have been completed with errors\n"; + echo '[' . $action . "][WARNING] The readed all records checks have been completed with errors\n"; } // Reinitializing the counter of tests $test = 0; // Reading the first record from the database -$record_read_first = $database->read(amount: 1); +$record_readed_first = $database->read(amount: 1); -echo '[' . ++$action . "] Read the first record from the database\n"; +echo '[' . ++$action . "] Readed the first record from the database\n"; try { - echo '[' . ++$action . '][' . ++$test . '][' . (gettype($record_read_first) === 'array' ? 'SUCCESS' : 'FAIL') . '][type of returned value] Expected: "array". Actual: "' . gettype($record_read_first) . "\"\n"; - echo '[' . $action . '][' . ++$test . '][' . (count($record_read_first) === 1 ? 'SUCCESS' : 'FAIL') . '][amount of read records] Expected: 1 records. Actual: ' . count($record_read_first) . " records\n"; - echo '[' . $action . '][' . ++$test . '][' . (gettype($record_read_first[0]) === 'object' ? 'SUCCESS' : 'FAIL') . '][type of read values] Expected: "object". Actual: "' . gettype($record_read_first[0]) . "\"\n"; - echo '[' . $action . '][' . ++$test . '][' . ($record_read_first[0] instanceof record ? 'SUCCESS' : 'FAIL') . '][class of read object values] Expected: "' . record::class . '". Actual: "' . $record_read_first[0]::class . "\"\n"; - echo '[' . $action . '][' . ++$test . '][' . ($record_read_first[0]->second_name === 'Mirzaev' ? 'SUCCESS' : 'FAIL') . ']["second_name"] Expected: "Mirzaev" (string). Actual: "' . $record_read_first[0]->second_name . '" (' . gettype($record_read_first[0]->second_name) . ")\n"; + echo '[' . ++$action . '][' . ++$test . '][' . (gettype($record_readed_first) === 'array' ? 'SUCCESS' : 'FAIL') . '][type of returned value] Expected: "array". Actual: "' . gettype($record_readed_first) . "\"\n"; + echo '[' . $action . '][' . ++$test . '][' . (count($record_readed_first) === 1 ? 'SUCCESS' : 'FAIL') . '][amount of read records] Expected: 1 records. Actual: ' . count($record_readed_first) . " records\n"; + echo '[' . $action . '][' . ++$test . '][' . (gettype($record_readed_first[0]) === 'object' ? 'SUCCESS' : 'FAIL') . '][type of read values] Expected: "object". Actual: "' . gettype($record_readed_first[0]) . "\"\n"; + echo '[' . $action . '][' . ++$test . '][' . ($record_readed_first[0] instanceof record ? 'SUCCESS' : 'FAIL') . '][class of read object values] Expected: "' . record::class . '". Actual: "' . $record_readed_first[0]::class . "\"\n"; + echo '[' . $action . '][' . ++$test . '][' . ($record_readed_first[0]->second_name === 'Mirzaev' ? 'SUCCESS' : 'FAIL') . ']["second_name"] Expected: "Mirzaev" (string). Actual: "' . $record_readed_first[0]->second_name . '" (' . gettype($record_readed_first[0]->second_name) . ")\n"; if (ARCH === 64) { - echo '[' . $action . '][' . ++$test . '][' . ($record_read_first[0]->neuron_count === 91000000000 ? 'SUCCESS' : 'FAIL') . ']["neuron_count"] Expected: "91000000000" (integer). Actual: "' . $record_read_first[0]->neuron_count . '" (' . gettype($record_read_first[0]->neuron_count) . ")\n"; + echo '[' . $action . '][' . ++$test . '][' . ($record_readed_first[0]->neuron_count === 91000000000 ? 'SUCCESS' : 'FAIL') . ']["neuron_count"] Expected: "91000000000" (integer). Actual: "' . $record_readed_first[0]->neuron_count . '" (' . gettype($record_readed_first[0]->neuron_count) . ")\n"; } - echo '[' . $action . "] The read first record checks have been completed\n"; + echo '[' . $action . "] The readed first record checks have been completed\n"; } catch (exception $e) { - echo '[' . $action . "][WARNING] The read first record checks have been completed with errors\n"; + echo '[' . $action . "][WARNING] The readed first record checks have been completed with errors\n"; } // Reinitializing the counter of tests $test = 0; // Reading the second record from the database -$record_read_second = $database->read(amount: 1, offset: 1); +$record_readed_second = $database->read(amount: 1, offset: 1); -echo '[' . ++$action . "] Read the second record from the database\n"; +echo '[' . ++$action . "] Readed the second record from the database\n"; try { - echo '[' . ++$action . '][' . ++$test . '][' . (gettype($record_read_second) === 'array' ? 'SUCCESS' : 'FAIL') . '][type of returned value] Expected: "array". Actual: "' . gettype($record_read_second) . "\"\n"; - echo '[' . $action . '][' . ++$test . '][' . (count($record_read_second) === 1 ? 'SUCCESS' : 'FAIL') . '][amount of read records] Expected: 1 records. Actual: ' . count($record_read_second) . " records\n"; - echo '[' . $action . '][' . ++$test . '][' . (gettype($record_read_second[0]) === 'object' ? 'SUCCESS' : 'FAIL') . '][type of read values] Expected: "object". Actual: "' . gettype($record_read_second[0]) . "\"\n"; - echo '[' . $action . '][' . ++$test . '][' . ($record_read_second[0] instanceof record ? 'SUCCESS' : 'FAIL') . '][class of read object values] Expected: "' . record::class . '". Actual: "' . $record_read_second[0]::class . "\"\n"; - echo '[' . $action . '][' . ++$test . '][' . ($record_read_second[0]->second_name === 'Ivanov' ? 'SUCCESS' : 'FAIL') . ']["second_name"] Expected: "Ivanov" (string). Actual: "' . $record_read_second[0]->second_name . '" (' . gettype($record_read_second[0]->second_name) . ")\n"; + echo '[' . ++$action . '][' . ++$test . '][' . (gettype($record_readed_second) === 'array' ? 'SUCCESS' : 'FAIL') . '][type of returned value] Expected: "array". Actual: "' . gettype($record_readed_second) . "\"\n"; + echo '[' . $action . '][' . ++$test . '][' . (count($record_readed_second) === 1 ? 'SUCCESS' : 'FAIL') . '][amount of read records] Expected: 1 records. Actual: ' . count($record_readed_second) . " records\n"; + echo '[' . $action . '][' . ++$test . '][' . (gettype($record_readed_second[0]) === 'object' ? 'SUCCESS' : 'FAIL') . '][type of read values] Expected: "object". Actual: "' . gettype($record_readed_second[0]) . "\"\n"; + echo '[' . $action . '][' . ++$test . '][' . ($record_readed_second[0] instanceof record ? 'SUCCESS' : 'FAIL') . '][class of read object values] Expected: "' . record::class . '". Actual: "' . $record_readed_second[0]::class . "\"\n"; + echo '[' . $action . '][' . ++$test . '][' . ($record_readed_second[0]->second_name === 'Ivanov' ? 'SUCCESS' : 'FAIL') . ']["second_name"] Expected: "Ivanov" (string). Actual: "' . $record_readed_second[0]->second_name . '" (' . gettype($record_readed_second[0]->second_name) . ")\n"; if (ARCH === 64) { /** * Due to IEEE 754 double precision format double equility is problematic * * @see https://www.php.net/manual/en/language.types.float.php#113703 */ - echo '[' . $action . '][' . ++$test . '][' . (round($record_read_second[0]->motivation, 2) === round(2.2250738585072E-308, 2) ? 'SUCCESS' : 'FAIL') . ']["motivation"] Expected: "2.2250738585072E-308" (double). Actual: "' . $record_read_second[0]->motivation . '" (' . gettype($record_read_second[0]->motivation) . ")\n"; - echo '[' . $action . '][' . ++$test . '][' . ($record_read_second[0]->reputation === (int) -9223372036854775808 ? 'SUCCESS' : 'FAIL') . ']["reputation"] Expected: "-9223372036854775808" (integer). Actual: "' . $record_read_second[0]->reputation . '" (' . gettype($record_read_second[0]->reputation) . ")\n"; + echo '[' . $action . '][' . ++$test . '][' . (round($record_readed_second[0]->motivation, 2) === round(2.2250738585072E-308, 2) ? 'SUCCESS' : 'FAIL') . ']["motivation"] Expected: "2.2250738585072E-308" (double). Actual: "' . $record_readed_second[0]->motivation . '" (' . gettype($record_readed_second[0]->motivation) . ")\n"; + echo '[' . $action . '][' . ++$test . '][' . ($record_readed_second[0]->reputation === (int) -9223372036854775808 ? 'SUCCESS' : 'FAIL') . ']["reputation"] Expected: "-9223372036854775808" (integer). Actual: "' . $record_readed_second[0]->reputation . '" (' . gettype($record_readed_second[0]->reputation) . ")\n"; } - echo '[' . $action . "] The read second record checks have been completed\n"; + echo '[' . $action . "] The readed second record checks have been completed\n"; } catch (exception $e) { - echo '[' . $action . "][WARNING] The read second record checks have been completed with errors\n"; + echo '[' . $action . "][WARNING] The readed second record checks have been completed with errors\n"; } // Reinitializing the counter of tests $test = 0; // Reading the record from the database by filter -$record_read_filter = $database->read(filter: fn($record) => $record?->second_name === 'Ivanov', amount: 1); +$record_readed_filter = $database->read(filter: fn($record) => $record?->second_name === 'Ivanov', amount: 1); -echo '[' . ++$action . "] Read the record from the database by filter\n"; +echo '[' . ++$action . "] Readed the record from the database by filter\n"; try { - echo '[' . ++$action . '][' . ++$test . '][' . (gettype($record_read_filter) === 'array' ? 'SUCCESS' : 'FAIL') . '][type of returned value] Expected: "array". Actual: "' . gettype($record_read_filter) . "\"\n"; - echo '[' . $action . '][' . ++$test . '][' . (count($record_read_filter) === 1 ? 'SUCCESS' : 'FAIL') . '][amount of read records] Expected: 1 records. Actual: ' . count($record_read_filter) . " records\n"; - echo '[' . $action . '][' . ++$test . '][' . (gettype($record_read_filter[0]) === 'object' ? 'SUCCESS' : 'FAIL') . '][type of read values] Expected: "object". Actual: "' . gettype($record_read_filter[0]) . "\"\n"; - echo '[' . $action . '][' . ++$test . '][' . ($record_read_filter[0] instanceof record ? 'SUCCESS' : 'FAIL') . '][class of read object values] Expected: "' . record::class . '". Actual: "' . $record_read_filter[0]::class . "\"\n"; - echo '[' . $action . '][' . ++$test . '][' . ($record_read_filter[0]->second_name === 'Ivanov' ? 'SUCCESS' : 'FAIL') . ']["second_name"] Expected: "Ivanov" (string). Actual: "' . $record_read_filter[0]->second_name . '" (' . gettype($record_read_filter[0]->second_name) . ")\n"; + echo '[' . ++$action . '][' . ++$test . '][' . (gettype($record_readed_filter) === 'array' ? 'SUCCESS' : 'FAIL') . '][type of returned value] Expected: "array". Actual: "' . gettype($record_readed_filter) . "\"\n"; + echo '[' . $action . '][' . ++$test . '][' . (count($record_readed_filter) === 1 ? 'SUCCESS' : 'FAIL') . '][amount of read records] Expected: 1 records. Actual: ' . count($record_readed_filter) . " records\n"; + echo '[' . $action . '][' . ++$test . '][' . (gettype($record_readed_filter[0]) === 'object' ? 'SUCCESS' : 'FAIL') . '][type of read values] Expected: "object". Actual: "' . gettype($record_readed_filter[0]) . "\"\n"; + echo '[' . $action . '][' . ++$test . '][' . ($record_readed_filter[0] instanceof record ? 'SUCCESS' : 'FAIL') . '][class of read object values] Expected: "' . record::class . '". Actual: "' . $record_readed_filter[0]::class . "\"\n"; + echo '[' . $action . '][' . ++$test . '][' . ($record_readed_filter[0]->second_name === 'Ivanov' ? 'SUCCESS' : 'FAIL') . ']["second_name"] Expected: "Ivanov" (string). Actual: "' . $record_readed_filter[0]->second_name . '" (' . gettype($record_readed_filter[0]->second_name) . ")\n"; if (ARCH === 64) { /** * Due to IEEE 754 double precision format double equility is problematic * * @see https://www.php.net/manual/en/language.types.float.php#113703 */ - echo '[' . $action . '][' . ++$test . '][' . (round($record_read_second[0]->motivation, 2) === round(2.2250738585072E-308, 2) ? 'SUCCESS' : 'FAIL') . ']["motivation"] Expected: "2.2250738585072E-308" (double). Actual: "' . $record_read_second[0]->motivation . '" (' . gettype($record_read_second[0]->motivation) . ")\n"; - echo '[' . $action . '][' . ++$test . '][' . ($record_read_second[0]->reputation === (int) -9223372036854775808 ? 'SUCCESS' : 'FAIL') . ']["reputation"] Expected: "-9223372036854775808" (integer). Actual: "' . $record_read_second[0]->reputation . '" (' . gettype($record_read_second[0]->reputation) . ")\n"; + echo '[' . $action . '][' . ++$test . '][' . (round($record_readed_filter[0]->motivation, 2) === round(2.2250738585072E-308, 2) ? 'SUCCESS' : 'FAIL') . ']["motivation"] Expected: "2.2250738585072E-308" (double). Actual: "' . $record_readed_filter[0]->motivation . '" (' . gettype($record_readed_filter[0]->motivation) . ")\n"; + echo '[' . $action . '][' . ++$test . '][' . ($record_readed_filter[0]->reputation === (int) -9223372036854775808 ? 'SUCCESS' : 'FAIL') . ']["reputation"] Expected: "-9223372036854775808" (integer). Actual: "' . $record_readed_filter[0]->reputation . '" (' . gettype($record_readed_filter[0]->reputation) . ")\n"; } - echo '[' . $action . "] The read record by filter checks have been completed\n"; + echo '[' . $action . "] The readed record by filter checks have been completed\n"; } catch (exception $e) { - echo '[' . $action . "][WARNING] The read record by filter checks have been completed with errors\n"; + echo '[' . $action . "][WARNING] The readed record by filter checks have been completed with errors\n"; } // Reinitializing the counter of tests $test = 0; // Reading the record from the database by filter with amount limit -$records_read_filter_amount = $database->read(filter: fn($record) => $record?->age === 24, amount: 1); +$records_readed_filter_amount = $database->read(filter: fn($record) => $record?->age === 24, amount: 1); -echo '[' . ++$action . "] Read the record from the database by filter with amount limit\n"; +echo '[' . ++$action . "] Readed the record from the database by filter with amount limit\n"; try { - echo '[' . ++$action . '][' . ++$test . '][' . (gettype($records_read_filter_amount) === 'array' ? 'SUCCESS' : 'FAIL') . '][type of returned value] Expected: "array". Actual: "' . gettype($records_read_filter_amount) . "\"\n"; - echo '[' . $action . '][' . ++$test . '][' . (count($records_read_filter_amount) === 1 ? 'SUCCESS' : 'FAIL') . '][amount of read records] Expected: 1 records. Actual: ' . count($records_read_filter_amount) . " records\n"; - echo '[' . $action . '][' . ++$test . '][' . (gettype($records_read_filter_amount[0]) === 'object' ? 'SUCCESS' : 'FAIL') . '][type of read values] Expected: "object". Actual: "' . gettype($records_read_filter_amount[0]) . "\"\n"; - echo '[' . $action . '][' . ++$test . '][' . ($records_read_filter_amount[0] instanceof record ? 'SUCCESS' : 'FAIL') . '][class of read object values] Expected: "' . record::class . '". Actual: "' . $records_read_filter_amount[0]::class . "\"\n"; - echo '[' . $action . '][' . ++$test . '][' . ($records_read_filter_amount[0]->age === 24 ? 'SUCCESS' : 'FAIL') . ']["age"] Expected: "24" (integer). Actual: "' . $records_read_filter_amount[0]->age . '" (' . gettype($records_read_filter_amount[0]->age) . ")\n"; - echo '[' . $action . '][' . ++$test . '][' . ($records_read_filter_amount[0]->second_name === 'Mirzaev' ? 'SUCCESS' : 'FAIL') . ']["second_name"] Expected: "Mirzaev" (string). Actual: "' . $records_read_filter_amount[0]->second_name . '" (' . gettype($records_read_filter_amount[0]->second_name) . ")\n"; + echo '[' . ++$action . '][' . ++$test . '][' . (gettype($records_readed_filter_amount) === 'array' ? 'SUCCESS' : 'FAIL') . '][type of returned value] Expected: "array". Actual: "' . gettype($records_readed_filter_amount) . "\"\n"; + echo '[' . $action . '][' . ++$test . '][' . (count($records_readed_filter_amount) === 1 ? 'SUCCESS' : 'FAIL') . '][amount of read records] Expected: 1 records. Actual: ' . count($records_readed_filter_amount) . " records\n"; + echo '[' . $action . '][' . ++$test . '][' . (gettype($records_readed_filter_amount[0]) === 'object' ? 'SUCCESS' : 'FAIL') . '][type of read values] Expected: "object". Actual: "' . gettype($records_readed_filter_amount[0]) . "\"\n"; + echo '[' . $action . '][' . ++$test . '][' . ($records_readed_filter_amount[0] instanceof record ? 'SUCCESS' : 'FAIL') . '][class of read object values] Expected: "' . record::class . '". Actual: "' . $records_readed_filter_amount[0]::class . "\"\n"; + echo '[' . $action . '][' . ++$test . '][' . ($records_readed_filter_amount[0]->age === 24 ? 'SUCCESS' : 'FAIL') . ']["age"] Expected: "24" (integer). Actual: "' . $records_readed_filter_amount[0]->age . '" (' . gettype($records_readed_filter_amount[0]->age) . ")\n"; + echo '[' . $action . '][' . ++$test . '][' . ($records_readed_filter_amount[0]->second_name === 'Mirzaev' ? 'SUCCESS' : 'FAIL') . ']["second_name"] Expected: "Mirzaev" (string). Actual: "' . $records_readed_filter_amount[0]->second_name . '" (' . gettype($records_readed_filter_amount[0]->second_name) . ")\n"; if (ARCH === 64) { /** * Due to IEEE 754 double precision format double equility is problematic * * @see https://www.php.net/manual/en/language.types.float.php#113703 */ - echo '[' . $action . '][' . ++$test . '][' . (round($record_read_second[0]->motivation, 2) === round(2.2250738585072E-308, 2) ? 'SUCCESS' : 'FAIL') . ']["motivation"] Expected: "2.2250738585072E-308" (double). Actual: "' . $record_read_second[0]->motivation . '" (' . gettype($record_read_second[0]->motivation) . ")\n"; - echo '[' . $action . '][' . ++$test . '][' . ($record_read_second[0]->reputation === (int) -9223372036854775808 ? 'SUCCESS' : 'FAIL') . ']["reputation"] Expected: "-9223372036854775808" (integer). Actual: "' . $record_read_second[0]->reputation . '" (' . gettype($record_read_second[0]->reputation) . ")\n"; + echo '[' . $action . '][' . ++$test . '][' . (round($record_readed_second[0]->motivation, 2) === round(2.2250738585072E-308, 2) ? 'SUCCESS' : 'FAIL') . ']["motivation"] Expected: "2.2250738585072E-308" (double). Actual: "' . $record_readed_second[0]->motivation . '" (' . gettype($record_readed_second[0]->motivation) . ")\n"; + echo '[' . $action . '][' . ++$test . '][' . ($record_readed_second[0]->reputation === (int) -9223372036854775808 ? 'SUCCESS' : 'FAIL') . ']["reputation"] Expected: "-9223372036854775808" (integer). Actual: "' . $record_readed_second[0]->reputation . '" (' . gettype($record_readed_second[0]->reputation) . ")\n"; } - echo '[' . $action . "] The read record by filter with amount limit checks have been completed\n"; + echo '[' . $action . "] The readed record by filter with amount limit checks have been completed\n"; } catch (exception $e) { - echo '[' . $action . "][WARNING] The read record by filter with amount limit checks have been completed with errors\n"; + echo '[' . $action . "][WARNING] The readed record by filter with amount limit checks have been completed with errors\n"; } // Reinitializing the counter of tests $test = 0; // Reading the record from the database by filter with amount limit and offset -$records_read_filter_amount_offset = $database->read(filter: fn($record) => $record?->age === 24, amount: 1, offset: 1); +$records_readed_filter_amount_offset = $database->read(filter: fn($record) => $record?->age === 24, amount: 1, offset: 1); -echo '[' . ++$action . "] Read the record from the database by filter with amount limit and offset\n"; +echo '[' . ++$action . "] Readed the record from the database by filter with amount limit and offset\n"; try { - echo '[' . ++$action . '][' . ++$test . '][' . (gettype($records_read_filter_amount_offset) === 'array' ? 'SUCCESS' : 'FAIL') . '][type of returned value] Expected: "array". Actual: "' . gettype($records_read_filter_amount_offset) . "\"\n"; - echo '[' . $action . '][' . ++$test . '][' . (count($records_read_filter_amount_offset) === 1 ? 'SUCCESS' : 'FAIL') . '][amount of read records] Expected: 1 records. Actual: ' . count($records_read_filter_amount_offset) . " records\n"; - echo '[' . $action . '][' . ++$test . '][' . (gettype($records_read_filter_amount_offset[0]) === 'object' ? 'SUCCESS' : 'FAIL') . '][type of read values] Expected: "object". Actual: "' . gettype($records_read_filter_amount_offset[0]) . "\"\n"; - echo '[' . $action . '][' . ++$test . '][' . ($records_read_filter_amount_offset[0] instanceof record ? 'SUCCESS' : 'FAIL') . '][class of read object values] Expected: "' . record::class . '". Actual: "' . $records_read_filter_amount_offset[0]::class . "\"\n"; - echo '[' . $action . '][' . ++$test . '][' . ($records_read_filter_amount_offset[0]->age === 24 ? 'SUCCESS' : 'FAIL') . ']["age"] Expected: "24" (integer). Actual: "' . $records_read_filter_amount_offset[0]->age . '" (' . gettype($records_read_filter_amount_offset[0]->age) . ")\n"; - echo '[' . $action . '][' . ++$test . '][' . ($records_read_filter_amount_offset[0]->second_name === 'Ivanov' ? 'SUCCESS' : 'FAIL') . ']["second_name"] Expected: "Ivanov" (string). Actual: "' . $records_read_filter_amount_offset[0]->second_name . '" (' . gettype($records_read_filter_amount_offset[0]->second_name) . ")\n"; + echo '[' . ++$action . '][' . ++$test . '][' . (gettype($records_readed_filter_amount_offset) === 'array' ? 'SUCCESS' : 'FAIL') . '][type of returned value] Expected: "array". Actual: "' . gettype($records_readed_filter_amount_offset) . "\"\n"; + echo '[' . $action . '][' . ++$test . '][' . (count($records_readed_filter_amount_offset) === 1 ? 'SUCCESS' : 'FAIL') . '][amount of read records] Expected: 1 records. Actual: ' . count($records_readed_filter_amount_offset) . " records\n"; + echo '[' . $action . '][' . ++$test . '][' . (gettype($records_readed_filter_amount_offset[0]) === 'object' ? 'SUCCESS' : 'FAIL') . '][type of read values] Expected: "object". Actual: "' . gettype($records_readed_filter_amount_offset[0]) . "\"\n"; + echo '[' . $action . '][' . ++$test . '][' . ($records_readed_filter_amount_offset[0] instanceof record ? 'SUCCESS' : 'FAIL') . '][class of read object values] Expected: "' . record::class . '". Actual: "' . $records_readed_filter_amount_offset[0]::class . "\"\n"; + echo '[' . $action . '][' . ++$test . '][' . ($records_readed_filter_amount_offset[0]->age === 24 ? 'SUCCESS' : 'FAIL') . ']["age"] Expected: "24" (integer). Actual: "' . $records_readed_filter_amount_offset[0]->age . '" (' . gettype($records_readed_filter_amount_offset[0]->age) . ")\n"; + echo '[' . $action . '][' . ++$test . '][' . ($records_readed_filter_amount_offset[0]->second_name === 'Ivanov' ? 'SUCCESS' : 'FAIL') . ']["second_name"] Expected: "Ivanov" (string). Actual: "' . $records_readed_filter_amount_offset[0]->second_name . '" (' . gettype($records_readed_filter_amount_offset[0]->second_name) . ")\n"; if (ARCH === 64) { /** * Due to IEEE 754 double precision format double equility is problematic * * @see https://www.php.net/manual/en/language.types.float.php#113703 */ - echo '[' . $action . '][' . ++$test . '][' . (round($record_read_second[0]->motivation, 2) === round(2.2250738585072E-308, 2) ? 'SUCCESS' : 'FAIL') . ']["motivation"] Expected: "2.2250738585072E-308" (double). Actual: "' . $record_read_second[0]->motivation . '" (' . gettype($record_read_second[0]->motivation) . ")\n"; - echo '[' . $action . '][' . ++$test . '][' . ($record_read_second[0]->reputation === (int) -9223372036854775808 ? 'SUCCESS' : 'FAIL') . ']["reputation"] Expected: "-9223372036854775808" (integer). Actual: "' . $record_read_second[0]->reputation . '" (' . gettype($record_read_second[0]->reputation) . ")\n"; + echo '[' . $action . '][' . ++$test . '][' . (round($records_readed_filter_amount_offset[0]->motivation, 2) === round(2.2250738585072E-308, 2) ? 'SUCCESS' : 'FAIL') . ']["motivation"] Expected: "2.2250738585072E-308" (double). Actual: "' . $records_readed_filter_amount_offset[0]->motivation . '" (' . gettype($records_readed_filter_amount_offset[0]->motivation) . ")\n"; + echo '[' . $action . '][' . ++$test . '][' . ($records_readed_filter_amount_offset[0]->reputation === (int) -9223372036854775808 ? 'SUCCESS' : 'FAIL') . ']["reputation"] Expected: "-9223372036854775808" (integer). Actual: "' . $records_readed_filter_amount_offset[0]->reputation . '" (' . gettype($records_readed_filter_amount_offset[0]->reputation) . ")\n"; } - echo '[' . $action . "] The read record by filter with amount limit and offset checks have been completed\n"; + echo '[' . $action . "] The readed record by filter with amount limit and offset checks have been completed\n"; } catch (exception $e) { - echo '[' . $action . "][WARNING] The read record by filter with amount limit and offset checks have been completed with errors\n"; + echo '[' . $action . "][WARNING] The readed record by filter with amount limit and offset checks have been completed with errors\n"; } // Reinitializing the counter of tests $test = 0; // Deleting the record in the database by filter -$records_read_filter_delete = $database->read(filter: fn($record) => $record?->name === 'Ivan', delete: true, amount: 1); +$records_readed_filter_delete = $database->read(filter: fn($record) => $record?->name === 'Ivan', delete: true, amount: 1); echo '[' . ++$action . "] Deleted the record from the database by filter\n"; // Reading records from the database after deleting -$records_read_filter_delete_read = $database->read(amount: 100); +$records_readed_filter_delete_readed = $database->read(amount: 100); -echo '[' . ++$action . "] Read records from the database after deleting the record\n"; +echo '[' . ++$action . "] Readed records from the database after deleting the record\n"; try { - echo '[' . ++$action . '][' . ++$test . '][' . (gettype($records_read_filter_delete) === 'array' ? 'SUCCESS' : 'FAIL') . '][type of returned value] Expected: "array". Actual: "' . gettype($records_read_filter_delete) . "\"\n"; - echo '[' . $action . '][' . ++$test . '][' . (count($records_read_filter_delete) === 1 ? 'SUCCESS' : 'FAIL') . '][amount of deleted records] Expected: 1 records. Actual: ' . count($records_read_filter_delete) . " records\n"; - echo '[' . $action . '][' . ++$test . '][' . (gettype($records_read_filter_delete[0]) === 'object' ? 'SUCCESS' : 'FAIL') . '][type of read values] Expected: "object". Actual: "' . gettype($records_read_filter_delete[0]) . "\"\n"; - echo '[' . $action . '][' . ++$test . '][' . ($records_read_filter_delete[0] instanceof record ? 'SUCCESS' : 'FAIL') . '][class of read object values] Expected: "' . record::class . '". Actual: "' . $records_read_filter_delete[0]::class . "\"\n"; - echo '[' . $action . '][' . ++$test . '][' . ($records_read_filter_delete[0]->name === 'Ivan' ? 'SUCCESS' : 'FAIL') . ']["name"] Expected: "Ivan" (string). Actual: "' . $records_read_filter_delete[0]->second_name . '" (' . gettype($records_read_filter_delete[0]->second_name) . ")\n"; - echo '[' . $action . '][' . ++$test . '][' . (count($records_read_filter_delete_read) === 2 ? 'SUCCESS' : 'FAIL') . '][amount of read records after deleting] Expected: 2 records. Actual: ' . count($records_read_filter_delete_read) . " records\n"; + echo '[' . ++$action . '][' . ++$test . '][' . (gettype($records_readed_filter_delete) === 'array' ? 'SUCCESS' : 'FAIL') . '][type of returned value] Expected: "array". Actual: "' . gettype($records_readed_filter_delete) . "\"\n"; + echo '[' . $action . '][' . ++$test . '][' . (count($records_readed_filter_delete) === 1 ? 'SUCCESS' : 'FAIL') . '][amount of deleted records] Expected: 1 records. Actual: ' . count($records_readed_filter_delete) . " records\n"; + echo '[' . $action . '][' . ++$test . '][' . (gettype($records_readed_filter_delete[0]) === 'object' ? 'SUCCESS' : 'FAIL') . '][type of read values] Expected: "object". Actual: "' . gettype($records_readed_filter_delete[0]) . "\"\n"; + echo '[' . $action . '][' . ++$test . '][' . ($records_readed_filter_delete[0] instanceof record ? 'SUCCESS' : 'FAIL') . '][class of read object values] Expected: "' . record::class . '". Actual: "' . $records_readed_filter_delete[0]::class . "\"\n"; + echo '[' . $action . '][' . ++$test . '][' . ($records_readed_filter_delete[0]->name === 'Ivan' ? 'SUCCESS' : 'FAIL') . ']["name"] Expected: "Ivan" (string). Actual: "' . $records_readed_filter_delete[0]->second_name . '" (' . gettype($records_readed_filter_delete[0]->second_name) . ")\n"; + echo '[' . $action . '][' . ++$test . '][' . (count($records_readed_filter_delete_readed) === 2 ? 'SUCCESS' : 'FAIL') . '][amount of read records after deleting] Expected: 2 records. Actual: ' . count($records_readed_filter_delete_readed) . " records\n"; if (ARCH === 64) { /** * Due to IEEE 754 double precision format double equility is problematic * * @see https://www.php.net/manual/en/language.types.float.php#113703 */ - echo '[' . $action . '][' . ++$test . '][' . (round($record_read_second[0]->motivation, 2) === round(2.2250738585072E-308, 2) ? 'SUCCESS' : 'FAIL') . ']["motivation"] Expected: "2.2250738585072E-308" (double). Actual: "' . $record_read_second[0]->motivation . '" (' . gettype($record_read_second[0]->motivation) . ")\n"; - echo '[' . $action . '][' . ++$test . '][' . ($record_read_second[0]->reputation === (int) -9223372036854775808 ? 'SUCCESS' : 'FAIL') . ']["reputation"] Expected: "-9223372036854775808" (integer). Actual: "' . $record_read_second[0]->reputation . '" (' . gettype($record_read_second[0]->reputation) . ")\n"; + echo '[' . $action . '][' . ++$test . '][' . (round($records_readed_filter_delete[0]->motivation, 2) === round(2.2250738585072E-308, 2) ? 'SUCCESS' : 'FAIL') . ']["motivation"] Expected: "2.2250738585072E-308" (double). Actual: "' . $records_readed_filter_delete[0]->motivation . '" (' . gettype($records_readed_filter_delete[0]->motivation) . ")\n"; + echo '[' . $action . '][' . ++$test . '][' . ($records_readed_filter_delete[0]->reputation === (int) -9223372036854775808 ? 'SUCCESS' : 'FAIL') . ']["reputation"] Expected: "-9223372036854775808" (integer). Actual: "' . $records_readed_filter_delete[0]->reputation . '" (' . gettype($records_readed_filter_delete[0]->reputation) . ")\n"; } echo '[' . $action . "] The deleted record by filter checks have been completed\n"; @@ -388,31 +388,31 @@ try { $test = 0; // Updating the record in the database -$records_read_filter_update = $database->read(filter: fn($record) => $record?->name === 'Margarita', update: fn(&$record) => $record->height += 0.5, amount: 1); +$records_readed_filter_update = $database->read(filter: fn($record) => $record?->name === 'Margarita', update: fn(&$record) => $record->height += 0.5, amount: 1); echo '[' . ++$action . "] Updated the record in the database by filter\n"; // Reading records from the database after updating -$records_read_filter_update_read = $database->read(amount: 100); +$records_readed_filter_update_readed = $database->read(amount: 100); -echo '[' . ++$action . "] Read records from the database after updating the record\n"; +echo '[' . ++$action . "] Readed records from the database after updating the record\n"; try { - echo '[' . ++$action . '][' . ++$test . '][' . (gettype($records_read_filter_update) === 'array' ? 'SUCCESS' : 'FAIL') . '][type of returned value] Expected: "array". Actual: "' . gettype($records_read_filter_update) . "\"\n"; - echo '[' . $action . '][' . ++$test . '][' . (count($records_read_filter_update) === 1 ? 'SUCCESS' : 'FAIL') . '][amount of updated records] Expected: 1 records. Actual: ' . count($records_read_filter_update) . " records\n"; - echo '[' . $action . '][' . ++$test . '][' . (gettype($records_read_filter_update[0]) === 'object' ? 'SUCCESS' : 'FAIL') . '][type of read values] Expected: "object". Actual: "' . gettype($records_read_filter_update[0]) . "\"\n"; - echo '[' . $action . '][' . ++$test . '][' . ($records_read_filter_update[0] instanceof record ? 'SUCCESS' : 'FAIL') . '][class of read object values] Expected: "' . record::class . '". Actual: "' . $records_read_filter_update[0]::class . "\"\n"; - echo '[' . $action . '][' . ++$test . '][' . ($records_read_filter_update[0]->height === 165.5 ? 'SUCCESS' : 'FAIL') . ']["height"] Expected: "165.5" (double). Actual: "' . $records_read_filter_update[0]->height . '" (' . gettype($records_read_filter_update[0]->height) . ")\n"; - echo '[' . $action . '][' . ++$test . '][' . (count($records_read_filter_update_read) === 2 ? 'SUCCESS' : 'FAIL') . '][amount of read records after updating] Expected: 2 records. Actual: ' . count($records_read_filter_update_read) . " records\n"; - echo '[' . $action . '][' . ++$test . '][' . ($records_read_filter_update_read[1]->height === $records_read_filter_update[0]->height ? 'SUCCESS' : 'FAIL') . "] Height from `update` process response matched height from the `read` preocess response\n"; + echo '[' . ++$action . '][' . ++$test . '][' . (gettype($records_readed_filter_update) === 'array' ? 'SUCCESS' : 'FAIL') . '][type of returned value] Expected: "array". Actual: "' . gettype($records_readed_filter_update) . "\"\n"; + echo '[' . $action . '][' . ++$test . '][' . (count($records_readed_filter_update) === 1 ? 'SUCCESS' : 'FAIL') . '][amount of updated records] Expected: 1 records. Actual: ' . count($records_readed_filter_update) . " records\n"; + echo '[' . $action . '][' . ++$test . '][' . (gettype($records_readed_filter_update[0]) === 'object' ? 'SUCCESS' : 'FAIL') . '][type of read values] Expected: "object". Actual: "' . gettype($records_readed_filter_update[0]) . "\"\n"; + echo '[' . $action . '][' . ++$test . '][' . ($records_readed_filter_update[0] instanceof record ? 'SUCCESS' : 'FAIL') . '][class of read object values] Expected: "' . record::class . '". Actual: "' . $records_readed_filter_update[0]::class . "\"\n"; + echo '[' . $action . '][' . ++$test . '][' . ($records_readed_filter_update[0]->height === 165.5 ? 'SUCCESS' : 'FAIL') . ']["height"] Expected: "165.5" (double). Actual: "' . $records_readed_filter_update[0]->height . '" (' . gettype($records_readed_filter_update[0]->height) . ")\n"; + echo '[' . $action . '][' . ++$test . '][' . (count($records_readed_filter_update_readed) === 2 ? 'SUCCESS' : 'FAIL') . '][amount of read records after updating] Expected: 2 records. Actual: ' . count($records_readed_filter_update_readed) . " records\n"; + echo '[' . $action . '][' . ++$test . '][' . ($records_readed_filter_update_readed[1]->height === $records_readed_filter_update[0]->height ? 'SUCCESS' : 'FAIL') . "] Height from `update` process response matched height from the `read` preocess response\n"; if (ARCH === 64) { /** * Due to IEEE 754 double precision format double equility is problematic * * @see https://www.php.net/manual/en/language.types.float.php#113703 */ - echo '[' . $action . '][' . ++$test . '][' . (round($record_read_second[0]->motivation, 2) === round(2.2250738585072E-308, 2) ? 'SUCCESS' : 'FAIL') . ']["motivation"] Expected: "2.2250738585072E-308" (double). Actual: "' . $record_read_second[0]->motivation . '" (' . gettype($record_read_second[0]->motivation) . ")\n"; - echo '[' . $action . '][' . ++$test . '][' . ($record_read_second[0]->reputation === (int) -9223372036854775808 ? 'SUCCESS' : 'FAIL') . ']["reputation"] Expected: "-9223372036854775808" (integer). Actual: "' . $record_read_second[0]->reputation . '" (' . gettype($record_read_second[0]->reputation) . ")\n"; + echo '[' . $action . '][' . ++$test . '][' . (round($records_readed_filter_update[0]->motivation, 2) === round(163, 2) ? 'SUCCESS' : 'FAIL') . ']["motivation"] Expected: "163" (double). Actual: "' . $records_readed_filter_update[0]->motivation . '" (' . gettype($records_readed_filter_update[0]->motivation) . ")\n"; + echo '[' . $action . '][' . ++$test . '][' . ($records_readed_filter_update[0]->reputation === (int) 9223372036854775807 ? 'SUCCESS' : 'FAIL') . ']["reputation"] Expected: "9223372036854775807" (integer). Actual: "' . $records_readed_filter_update[0]->reputation . '" (' . gettype($records_readed_filter_update[0]->reputation) . ")\n"; } echo '[' . $action . "] The updated record by filter checks have been completed\n"; -- 2.34.1 From e5fa761e8ecf6f23c94066ea492e747751341512 Mon Sep 17 00:00:00 2001 From: Little Fluffy Clouds Date: Sat, 12 Jul 2025 10:49:49 +0300 Subject: [PATCH 5/8] follow-up --- mirzaev/baza/tests/record.php | 50 +++++++++++++++++------------------ 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/mirzaev/baza/tests/record.php b/mirzaev/baza/tests/record.php index 8fff350..62402b6 100755 --- a/mirzaev/baza/tests/record.php +++ b/mirzaev/baza/tests/record.php @@ -129,7 +129,7 @@ $test = 0; // Writing the record into the database $database->write($record); -echo '[' . ++$action . "] Wrote the record into the database\n"; +echo '[' . ++$action . "] Writed the record into the database\n"; // Initializing the second record if (ARCH === 64) { @@ -196,9 +196,9 @@ echo '[' . ++$action . "] Readed all records from the database\n"; try { echo '[' . ++$action . '][' . ++$test . '][' . (gettype($records_readed_all) === 'array' ? 'SUCCESS' : 'FAIL') . '][type of returned value] Expected: "array". Actual: "' . gettype($records_readed_all) . "\"\n"; - echo '[' . $action . '][' . ++$test . '][' . (count($records_readed_all) === 3 ? 'SUCCESS' : 'FAIL') . '][amount of read records] Expected: 3 records. Actual: ' . count($records_readed_all) . " records\n"; - echo '[' . $action . '][' . ++$test . '][' . (gettype($records_readed_all[0]) === 'object' ? 'SUCCESS' : 'FAIL') . '][type of read values] Expected: "object". Actual: "' . gettype($records_readed_all[0]) . "\"\n"; - echo '[' . $action . '][' . ++$test . '][' . ($records_readed_all[0] instanceof record ? 'SUCCESS' : 'FAIL') . '][class of read object values] Expected: "' . record::class . '". Actual: "' . $records_readed_all[0]::class . "\"\n"; + echo '[' . $action . '][' . ++$test . '][' . (count($records_readed_all) === 3 ? 'SUCCESS' : 'FAIL') . '][amount of readed records] Expected: 3 records. Actual: ' . count($records_readed_all) . " records\n"; + echo '[' . $action . '][' . ++$test . '][' . (gettype($records_readed_all[0]) === 'object' ? 'SUCCESS' : 'FAIL') . '][type of readedvalues] Expected: "object". Actual: "' . gettype($records_readed_all[0]) . "\"\n"; + echo '[' . $action . '][' . ++$test . '][' . ($records_readed_all[0] instanceof record ? 'SUCCESS' : 'FAIL') . '][class of readedobject values] Expected: "' . record::class . '". Actual: "' . $records_readed_all[0]::class . "\"\n"; if (ARCH === 64) { echo '[' . $action . '][' . ++$test . '][' . ($records_readed_all[0]->neuron_count === 91000000000 ? 'SUCCESS' : 'FAIL') . ']["neuron_count"] Expected: "91000000000" (integer). Actual: "' . $records_readed_all[0]->neuron_count . '" (' . gettype($records_readed_all[0]->neuron_count) . ")\n"; } @@ -218,9 +218,9 @@ echo '[' . ++$action . "] Readed the first record from the database\n"; try { echo '[' . ++$action . '][' . ++$test . '][' . (gettype($record_readed_first) === 'array' ? 'SUCCESS' : 'FAIL') . '][type of returned value] Expected: "array". Actual: "' . gettype($record_readed_first) . "\"\n"; - echo '[' . $action . '][' . ++$test . '][' . (count($record_readed_first) === 1 ? 'SUCCESS' : 'FAIL') . '][amount of read records] Expected: 1 records. Actual: ' . count($record_readed_first) . " records\n"; - echo '[' . $action . '][' . ++$test . '][' . (gettype($record_readed_first[0]) === 'object' ? 'SUCCESS' : 'FAIL') . '][type of read values] Expected: "object". Actual: "' . gettype($record_readed_first[0]) . "\"\n"; - echo '[' . $action . '][' . ++$test . '][' . ($record_readed_first[0] instanceof record ? 'SUCCESS' : 'FAIL') . '][class of read object values] Expected: "' . record::class . '". Actual: "' . $record_readed_first[0]::class . "\"\n"; + echo '[' . $action . '][' . ++$test . '][' . (count($record_readed_first) === 1 ? 'SUCCESS' : 'FAIL') . '][amount of readed records] Expected: 1 records. Actual: ' . count($record_readed_first) . " records\n"; + echo '[' . $action . '][' . ++$test . '][' . (gettype($record_readed_first[0]) === 'object' ? 'SUCCESS' : 'FAIL') . '][type of readedvalues] Expected: "object". Actual: "' . gettype($record_readed_first[0]) . "\"\n"; + echo '[' . $action . '][' . ++$test . '][' . ($record_readed_first[0] instanceof record ? 'SUCCESS' : 'FAIL') . '][class of readedobject values] Expected: "' . record::class . '". Actual: "' . $record_readed_first[0]::class . "\"\n"; echo '[' . $action . '][' . ++$test . '][' . ($record_readed_first[0]->second_name === 'Mirzaev' ? 'SUCCESS' : 'FAIL') . ']["second_name"] Expected: "Mirzaev" (string). Actual: "' . $record_readed_first[0]->second_name . '" (' . gettype($record_readed_first[0]->second_name) . ")\n"; if (ARCH === 64) { echo '[' . $action . '][' . ++$test . '][' . ($record_readed_first[0]->neuron_count === 91000000000 ? 'SUCCESS' : 'FAIL') . ']["neuron_count"] Expected: "91000000000" (integer). Actual: "' . $record_readed_first[0]->neuron_count . '" (' . gettype($record_readed_first[0]->neuron_count) . ")\n"; @@ -241,9 +241,9 @@ echo '[' . ++$action . "] Readed the second record from the database\n"; try { echo '[' . ++$action . '][' . ++$test . '][' . (gettype($record_readed_second) === 'array' ? 'SUCCESS' : 'FAIL') . '][type of returned value] Expected: "array". Actual: "' . gettype($record_readed_second) . "\"\n"; - echo '[' . $action . '][' . ++$test . '][' . (count($record_readed_second) === 1 ? 'SUCCESS' : 'FAIL') . '][amount of read records] Expected: 1 records. Actual: ' . count($record_readed_second) . " records\n"; - echo '[' . $action . '][' . ++$test . '][' . (gettype($record_readed_second[0]) === 'object' ? 'SUCCESS' : 'FAIL') . '][type of read values] Expected: "object". Actual: "' . gettype($record_readed_second[0]) . "\"\n"; - echo '[' . $action . '][' . ++$test . '][' . ($record_readed_second[0] instanceof record ? 'SUCCESS' : 'FAIL') . '][class of read object values] Expected: "' . record::class . '". Actual: "' . $record_readed_second[0]::class . "\"\n"; + echo '[' . $action . '][' . ++$test . '][' . (count($record_readed_second) === 1 ? 'SUCCESS' : 'FAIL') . '][amount of readed records] Expected: 1 records. Actual: ' . count($record_readed_second) . " records\n"; + echo '[' . $action . '][' . ++$test . '][' . (gettype($record_readed_second[0]) === 'object' ? 'SUCCESS' : 'FAIL') . '][type of readedvalues] Expected: "object". Actual: "' . gettype($record_readed_second[0]) . "\"\n"; + echo '[' . $action . '][' . ++$test . '][' . ($record_readed_second[0] instanceof record ? 'SUCCESS' : 'FAIL') . '][class of readedobject values] Expected: "' . record::class . '". Actual: "' . $record_readed_second[0]::class . "\"\n"; echo '[' . $action . '][' . ++$test . '][' . ($record_readed_second[0]->second_name === 'Ivanov' ? 'SUCCESS' : 'FAIL') . ']["second_name"] Expected: "Ivanov" (string). Actual: "' . $record_readed_second[0]->second_name . '" (' . gettype($record_readed_second[0]->second_name) . ")\n"; if (ARCH === 64) { /** @@ -270,9 +270,9 @@ echo '[' . ++$action . "] Readed the record from the database by filter\n"; try { echo '[' . ++$action . '][' . ++$test . '][' . (gettype($record_readed_filter) === 'array' ? 'SUCCESS' : 'FAIL') . '][type of returned value] Expected: "array". Actual: "' . gettype($record_readed_filter) . "\"\n"; - echo '[' . $action . '][' . ++$test . '][' . (count($record_readed_filter) === 1 ? 'SUCCESS' : 'FAIL') . '][amount of read records] Expected: 1 records. Actual: ' . count($record_readed_filter) . " records\n"; - echo '[' . $action . '][' . ++$test . '][' . (gettype($record_readed_filter[0]) === 'object' ? 'SUCCESS' : 'FAIL') . '][type of read values] Expected: "object". Actual: "' . gettype($record_readed_filter[0]) . "\"\n"; - echo '[' . $action . '][' . ++$test . '][' . ($record_readed_filter[0] instanceof record ? 'SUCCESS' : 'FAIL') . '][class of read object values] Expected: "' . record::class . '". Actual: "' . $record_readed_filter[0]::class . "\"\n"; + echo '[' . $action . '][' . ++$test . '][' . (count($record_readed_filter) === 1 ? 'SUCCESS' : 'FAIL') . '][amount of readed records] Expected: 1 records. Actual: ' . count($record_readed_filter) . " records\n"; + echo '[' . $action . '][' . ++$test . '][' . (gettype($record_readed_filter[0]) === 'object' ? 'SUCCESS' : 'FAIL') . '][type of readedvalues] Expected: "object". Actual: "' . gettype($record_readed_filter[0]) . "\"\n"; + echo '[' . $action . '][' . ++$test . '][' . ($record_readed_filter[0] instanceof record ? 'SUCCESS' : 'FAIL') . '][class of readedobject values] Expected: "' . record::class . '". Actual: "' . $record_readed_filter[0]::class . "\"\n"; echo '[' . $action . '][' . ++$test . '][' . ($record_readed_filter[0]->second_name === 'Ivanov' ? 'SUCCESS' : 'FAIL') . ']["second_name"] Expected: "Ivanov" (string). Actual: "' . $record_readed_filter[0]->second_name . '" (' . gettype($record_readed_filter[0]->second_name) . ")\n"; if (ARCH === 64) { /** @@ -299,9 +299,9 @@ echo '[' . ++$action . "] Readed the record from the database by filter with amo try { echo '[' . ++$action . '][' . ++$test . '][' . (gettype($records_readed_filter_amount) === 'array' ? 'SUCCESS' : 'FAIL') . '][type of returned value] Expected: "array". Actual: "' . gettype($records_readed_filter_amount) . "\"\n"; - echo '[' . $action . '][' . ++$test . '][' . (count($records_readed_filter_amount) === 1 ? 'SUCCESS' : 'FAIL') . '][amount of read records] Expected: 1 records. Actual: ' . count($records_readed_filter_amount) . " records\n"; - echo '[' . $action . '][' . ++$test . '][' . (gettype($records_readed_filter_amount[0]) === 'object' ? 'SUCCESS' : 'FAIL') . '][type of read values] Expected: "object". Actual: "' . gettype($records_readed_filter_amount[0]) . "\"\n"; - echo '[' . $action . '][' . ++$test . '][' . ($records_readed_filter_amount[0] instanceof record ? 'SUCCESS' : 'FAIL') . '][class of read object values] Expected: "' . record::class . '". Actual: "' . $records_readed_filter_amount[0]::class . "\"\n"; + echo '[' . $action . '][' . ++$test . '][' . (count($records_readed_filter_amount) === 1 ? 'SUCCESS' : 'FAIL') . '][amount of readed records] Expected: 1 records. Actual: ' . count($records_readed_filter_amount) . " records\n"; + echo '[' . $action . '][' . ++$test . '][' . (gettype($records_readed_filter_amount[0]) === 'object' ? 'SUCCESS' : 'FAIL') . '][type of readedvalues] Expected: "object". Actual: "' . gettype($records_readed_filter_amount[0]) . "\"\n"; + echo '[' . $action . '][' . ++$test . '][' . ($records_readed_filter_amount[0] instanceof record ? 'SUCCESS' : 'FAIL') . '][class of readedobject values] Expected: "' . record::class . '". Actual: "' . $records_readed_filter_amount[0]::class . "\"\n"; echo '[' . $action . '][' . ++$test . '][' . ($records_readed_filter_amount[0]->age === 24 ? 'SUCCESS' : 'FAIL') . ']["age"] Expected: "24" (integer). Actual: "' . $records_readed_filter_amount[0]->age . '" (' . gettype($records_readed_filter_amount[0]->age) . ")\n"; echo '[' . $action . '][' . ++$test . '][' . ($records_readed_filter_amount[0]->second_name === 'Mirzaev' ? 'SUCCESS' : 'FAIL') . ']["second_name"] Expected: "Mirzaev" (string). Actual: "' . $records_readed_filter_amount[0]->second_name . '" (' . gettype($records_readed_filter_amount[0]->second_name) . ")\n"; if (ARCH === 64) { @@ -329,9 +329,9 @@ echo '[' . ++$action . "] Readed the record from the database by filter with amo try { echo '[' . ++$action . '][' . ++$test . '][' . (gettype($records_readed_filter_amount_offset) === 'array' ? 'SUCCESS' : 'FAIL') . '][type of returned value] Expected: "array". Actual: "' . gettype($records_readed_filter_amount_offset) . "\"\n"; - echo '[' . $action . '][' . ++$test . '][' . (count($records_readed_filter_amount_offset) === 1 ? 'SUCCESS' : 'FAIL') . '][amount of read records] Expected: 1 records. Actual: ' . count($records_readed_filter_amount_offset) . " records\n"; - echo '[' . $action . '][' . ++$test . '][' . (gettype($records_readed_filter_amount_offset[0]) === 'object' ? 'SUCCESS' : 'FAIL') . '][type of read values] Expected: "object". Actual: "' . gettype($records_readed_filter_amount_offset[0]) . "\"\n"; - echo '[' . $action . '][' . ++$test . '][' . ($records_readed_filter_amount_offset[0] instanceof record ? 'SUCCESS' : 'FAIL') . '][class of read object values] Expected: "' . record::class . '". Actual: "' . $records_readed_filter_amount_offset[0]::class . "\"\n"; + echo '[' . $action . '][' . ++$test . '][' . (count($records_readed_filter_amount_offset) === 1 ? 'SUCCESS' : 'FAIL') . '][amount of readed records] Expected: 1 records. Actual: ' . count($records_readed_filter_amount_offset) . " records\n"; + echo '[' . $action . '][' . ++$test . '][' . (gettype($records_readed_filter_amount_offset[0]) === 'object' ? 'SUCCESS' : 'FAIL') . '][type of readedvalues] Expected: "object". Actual: "' . gettype($records_readed_filter_amount_offset[0]) . "\"\n"; + echo '[' . $action . '][' . ++$test . '][' . ($records_readed_filter_amount_offset[0] instanceof record ? 'SUCCESS' : 'FAIL') . '][class of readedobject values] Expected: "' . record::class . '". Actual: "' . $records_readed_filter_amount_offset[0]::class . "\"\n"; echo '[' . $action . '][' . ++$test . '][' . ($records_readed_filter_amount_offset[0]->age === 24 ? 'SUCCESS' : 'FAIL') . ']["age"] Expected: "24" (integer). Actual: "' . $records_readed_filter_amount_offset[0]->age . '" (' . gettype($records_readed_filter_amount_offset[0]->age) . ")\n"; echo '[' . $action . '][' . ++$test . '][' . ($records_readed_filter_amount_offset[0]->second_name === 'Ivanov' ? 'SUCCESS' : 'FAIL') . ']["second_name"] Expected: "Ivanov" (string). Actual: "' . $records_readed_filter_amount_offset[0]->second_name . '" (' . gettype($records_readed_filter_amount_offset[0]->second_name) . ")\n"; if (ARCH === 64) { @@ -365,10 +365,10 @@ echo '[' . ++$action . "] Readed records from the database after deleting the re try { echo '[' . ++$action . '][' . ++$test . '][' . (gettype($records_readed_filter_delete) === 'array' ? 'SUCCESS' : 'FAIL') . '][type of returned value] Expected: "array". Actual: "' . gettype($records_readed_filter_delete) . "\"\n"; echo '[' . $action . '][' . ++$test . '][' . (count($records_readed_filter_delete) === 1 ? 'SUCCESS' : 'FAIL') . '][amount of deleted records] Expected: 1 records. Actual: ' . count($records_readed_filter_delete) . " records\n"; - echo '[' . $action . '][' . ++$test . '][' . (gettype($records_readed_filter_delete[0]) === 'object' ? 'SUCCESS' : 'FAIL') . '][type of read values] Expected: "object". Actual: "' . gettype($records_readed_filter_delete[0]) . "\"\n"; - echo '[' . $action . '][' . ++$test . '][' . ($records_readed_filter_delete[0] instanceof record ? 'SUCCESS' : 'FAIL') . '][class of read object values] Expected: "' . record::class . '". Actual: "' . $records_readed_filter_delete[0]::class . "\"\n"; + echo '[' . $action . '][' . ++$test . '][' . (gettype($records_readed_filter_delete[0]) === 'object' ? 'SUCCESS' : 'FAIL') . '][type of readed values] Expected: "object". Actual: "' . gettype($records_readed_filter_delete[0]) . "\"\n"; + echo '[' . $action . '][' . ++$test . '][' . ($records_readed_filter_delete[0] instanceof record ? 'SUCCESS' : 'FAIL') . '][class of readed object values] Expected: "' . record::class . '". Actual: "' . $records_readed_filter_delete[0]::class . "\"\n"; echo '[' . $action . '][' . ++$test . '][' . ($records_readed_filter_delete[0]->name === 'Ivan' ? 'SUCCESS' : 'FAIL') . ']["name"] Expected: "Ivan" (string). Actual: "' . $records_readed_filter_delete[0]->second_name . '" (' . gettype($records_readed_filter_delete[0]->second_name) . ")\n"; - echo '[' . $action . '][' . ++$test . '][' . (count($records_readed_filter_delete_readed) === 2 ? 'SUCCESS' : 'FAIL') . '][amount of read records after deleting] Expected: 2 records. Actual: ' . count($records_readed_filter_delete_readed) . " records\n"; + echo '[' . $action . '][' . ++$test . '][' . (count($records_readed_filter_delete_readed) === 2 ? 'SUCCESS' : 'FAIL') . '][amount of readed records after deleting] Expected: 2 records. Actual: ' . count($records_readed_filter_delete_readed) . " records\n"; if (ARCH === 64) { /** * Due to IEEE 754 double precision format double equility is problematic @@ -400,10 +400,10 @@ echo '[' . ++$action . "] Readed records from the database after updating the re try { echo '[' . ++$action . '][' . ++$test . '][' . (gettype($records_readed_filter_update) === 'array' ? 'SUCCESS' : 'FAIL') . '][type of returned value] Expected: "array". Actual: "' . gettype($records_readed_filter_update) . "\"\n"; echo '[' . $action . '][' . ++$test . '][' . (count($records_readed_filter_update) === 1 ? 'SUCCESS' : 'FAIL') . '][amount of updated records] Expected: 1 records. Actual: ' . count($records_readed_filter_update) . " records\n"; - echo '[' . $action . '][' . ++$test . '][' . (gettype($records_readed_filter_update[0]) === 'object' ? 'SUCCESS' : 'FAIL') . '][type of read values] Expected: "object". Actual: "' . gettype($records_readed_filter_update[0]) . "\"\n"; - echo '[' . $action . '][' . ++$test . '][' . ($records_readed_filter_update[0] instanceof record ? 'SUCCESS' : 'FAIL') . '][class of read object values] Expected: "' . record::class . '". Actual: "' . $records_readed_filter_update[0]::class . "\"\n"; + echo '[' . $action . '][' . ++$test . '][' . (gettype($records_readed_filter_update[0]) === 'object' ? 'SUCCESS' : 'FAIL') . '][type of readed values] Expected: "object". Actual: "' . gettype($records_readed_filter_update[0]) . "\"\n"; + echo '[' . $action . '][' . ++$test . '][' . ($records_readed_filter_update[0] instanceof record ? 'SUCCESS' : 'FAIL') . '][class of readed object values] Expected: "' . record::class . '". Actual: "' . $records_readed_filter_update[0]::class . "\"\n"; echo '[' . $action . '][' . ++$test . '][' . ($records_readed_filter_update[0]->height === 165.5 ? 'SUCCESS' : 'FAIL') . ']["height"] Expected: "165.5" (double). Actual: "' . $records_readed_filter_update[0]->height . '" (' . gettype($records_readed_filter_update[0]->height) . ")\n"; - echo '[' . $action . '][' . ++$test . '][' . (count($records_readed_filter_update_readed) === 2 ? 'SUCCESS' : 'FAIL') . '][amount of read records after updating] Expected: 2 records. Actual: ' . count($records_readed_filter_update_readed) . " records\n"; + echo '[' . $action . '][' . ++$test . '][' . (count($records_readed_filter_update_readed) === 2 ? 'SUCCESS' : 'FAIL') . '][amount of readed records after updating] Expected: 2 records. Actual: ' . count($records_readed_filter_update_readed) . " records\n"; echo '[' . $action . '][' . ++$test . '][' . ($records_readed_filter_update_readed[1]->height === $records_readed_filter_update[0]->height ? 'SUCCESS' : 'FAIL') . "] Height from `update` process response matched height from the `read` preocess response\n"; if (ARCH === 64) { /** -- 2.34.1 From 6610acf82d78631ac6d7314a95cd727132c6e615 Mon Sep 17 00:00:00 2001 From: Little Fluffy Clouds Date: Sat, 12 Jul 2025 10:52:22 +0300 Subject: [PATCH 6/8] mess-up --- mirzaev/baza/tests/record.php | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/mirzaev/baza/tests/record.php b/mirzaev/baza/tests/record.php index 62402b6..8fa2afc 100755 --- a/mirzaev/baza/tests/record.php +++ b/mirzaev/baza/tests/record.php @@ -197,8 +197,8 @@ echo '[' . ++$action . "] Readed all records from the database\n"; try { echo '[' . ++$action . '][' . ++$test . '][' . (gettype($records_readed_all) === 'array' ? 'SUCCESS' : 'FAIL') . '][type of returned value] Expected: "array". Actual: "' . gettype($records_readed_all) . "\"\n"; echo '[' . $action . '][' . ++$test . '][' . (count($records_readed_all) === 3 ? 'SUCCESS' : 'FAIL') . '][amount of readed records] Expected: 3 records. Actual: ' . count($records_readed_all) . " records\n"; - echo '[' . $action . '][' . ++$test . '][' . (gettype($records_readed_all[0]) === 'object' ? 'SUCCESS' : 'FAIL') . '][type of readedvalues] Expected: "object". Actual: "' . gettype($records_readed_all[0]) . "\"\n"; - echo '[' . $action . '][' . ++$test . '][' . ($records_readed_all[0] instanceof record ? 'SUCCESS' : 'FAIL') . '][class of readedobject values] Expected: "' . record::class . '". Actual: "' . $records_readed_all[0]::class . "\"\n"; + echo '[' . $action . '][' . ++$test . '][' . (gettype($records_readed_all[0]) === 'object' ? 'SUCCESS' : 'FAIL') . '][type of readed values] Expected: "object". Actual: "' . gettype($records_readed_all[0]) . "\"\n"; + echo '[' . $action . '][' . ++$test . '][' . ($records_readed_all[0] instanceof record ? 'SUCCESS' : 'FAIL') . '][class of readed object values] Expected: "' . record::class . '". Actual: "' . $records_readed_all[0]::class . "\"\n"; if (ARCH === 64) { echo '[' . $action . '][' . ++$test . '][' . ($records_readed_all[0]->neuron_count === 91000000000 ? 'SUCCESS' : 'FAIL') . ']["neuron_count"] Expected: "91000000000" (integer). Actual: "' . $records_readed_all[0]->neuron_count . '" (' . gettype($records_readed_all[0]->neuron_count) . ")\n"; } @@ -219,8 +219,8 @@ echo '[' . ++$action . "] Readed the first record from the database\n"; try { echo '[' . ++$action . '][' . ++$test . '][' . (gettype($record_readed_first) === 'array' ? 'SUCCESS' : 'FAIL') . '][type of returned value] Expected: "array". Actual: "' . gettype($record_readed_first) . "\"\n"; echo '[' . $action . '][' . ++$test . '][' . (count($record_readed_first) === 1 ? 'SUCCESS' : 'FAIL') . '][amount of readed records] Expected: 1 records. Actual: ' . count($record_readed_first) . " records\n"; - echo '[' . $action . '][' . ++$test . '][' . (gettype($record_readed_first[0]) === 'object' ? 'SUCCESS' : 'FAIL') . '][type of readedvalues] Expected: "object". Actual: "' . gettype($record_readed_first[0]) . "\"\n"; - echo '[' . $action . '][' . ++$test . '][' . ($record_readed_first[0] instanceof record ? 'SUCCESS' : 'FAIL') . '][class of readedobject values] Expected: "' . record::class . '". Actual: "' . $record_readed_first[0]::class . "\"\n"; + echo '[' . $action . '][' . ++$test . '][' . (gettype($record_readed_first[0]) === 'object' ? 'SUCCESS' : 'FAIL') . '][type of readed values] Expected: "object". Actual: "' . gettype($record_readed_first[0]) . "\"\n"; + echo '[' . $action . '][' . ++$test . '][' . ($record_readed_first[0] instanceof record ? 'SUCCESS' : 'FAIL') . '][class of readed object values] Expected: "' . record::class . '". Actual: "' . $record_readed_first[0]::class . "\"\n"; echo '[' . $action . '][' . ++$test . '][' . ($record_readed_first[0]->second_name === 'Mirzaev' ? 'SUCCESS' : 'FAIL') . ']["second_name"] Expected: "Mirzaev" (string). Actual: "' . $record_readed_first[0]->second_name . '" (' . gettype($record_readed_first[0]->second_name) . ")\n"; if (ARCH === 64) { echo '[' . $action . '][' . ++$test . '][' . ($record_readed_first[0]->neuron_count === 91000000000 ? 'SUCCESS' : 'FAIL') . ']["neuron_count"] Expected: "91000000000" (integer). Actual: "' . $record_readed_first[0]->neuron_count . '" (' . gettype($record_readed_first[0]->neuron_count) . ")\n"; @@ -242,8 +242,8 @@ echo '[' . ++$action . "] Readed the second record from the database\n"; try { echo '[' . ++$action . '][' . ++$test . '][' . (gettype($record_readed_second) === 'array' ? 'SUCCESS' : 'FAIL') . '][type of returned value] Expected: "array". Actual: "' . gettype($record_readed_second) . "\"\n"; echo '[' . $action . '][' . ++$test . '][' . (count($record_readed_second) === 1 ? 'SUCCESS' : 'FAIL') . '][amount of readed records] Expected: 1 records. Actual: ' . count($record_readed_second) . " records\n"; - echo '[' . $action . '][' . ++$test . '][' . (gettype($record_readed_second[0]) === 'object' ? 'SUCCESS' : 'FAIL') . '][type of readedvalues] Expected: "object". Actual: "' . gettype($record_readed_second[0]) . "\"\n"; - echo '[' . $action . '][' . ++$test . '][' . ($record_readed_second[0] instanceof record ? 'SUCCESS' : 'FAIL') . '][class of readedobject values] Expected: "' . record::class . '". Actual: "' . $record_readed_second[0]::class . "\"\n"; + echo '[' . $action . '][' . ++$test . '][' . (gettype($record_readed_second[0]) === 'object' ? 'SUCCESS' : 'FAIL') . '][type of readed values] Expected: "object". Actual: "' . gettype($record_readed_second[0]) . "\"\n"; + echo '[' . $action . '][' . ++$test . '][' . ($record_readed_second[0] instanceof record ? 'SUCCESS' : 'FAIL') . '][class of readed object values] Expected: "' . record::class . '". Actual: "' . $record_readed_second[0]::class . "\"\n"; echo '[' . $action . '][' . ++$test . '][' . ($record_readed_second[0]->second_name === 'Ivanov' ? 'SUCCESS' : 'FAIL') . ']["second_name"] Expected: "Ivanov" (string). Actual: "' . $record_readed_second[0]->second_name . '" (' . gettype($record_readed_second[0]->second_name) . ")\n"; if (ARCH === 64) { /** @@ -271,8 +271,8 @@ echo '[' . ++$action . "] Readed the record from the database by filter\n"; try { echo '[' . ++$action . '][' . ++$test . '][' . (gettype($record_readed_filter) === 'array' ? 'SUCCESS' : 'FAIL') . '][type of returned value] Expected: "array". Actual: "' . gettype($record_readed_filter) . "\"\n"; echo '[' . $action . '][' . ++$test . '][' . (count($record_readed_filter) === 1 ? 'SUCCESS' : 'FAIL') . '][amount of readed records] Expected: 1 records. Actual: ' . count($record_readed_filter) . " records\n"; - echo '[' . $action . '][' . ++$test . '][' . (gettype($record_readed_filter[0]) === 'object' ? 'SUCCESS' : 'FAIL') . '][type of readedvalues] Expected: "object". Actual: "' . gettype($record_readed_filter[0]) . "\"\n"; - echo '[' . $action . '][' . ++$test . '][' . ($record_readed_filter[0] instanceof record ? 'SUCCESS' : 'FAIL') . '][class of readedobject values] Expected: "' . record::class . '". Actual: "' . $record_readed_filter[0]::class . "\"\n"; + echo '[' . $action . '][' . ++$test . '][' . (gettype($record_readed_filter[0]) === 'object' ? 'SUCCESS' : 'FAIL') . '][type of readed values] Expected: "object". Actual: "' . gettype($record_readed_filter[0]) . "\"\n"; + echo '[' . $action . '][' . ++$test . '][' . ($record_readed_filter[0] instanceof record ? 'SUCCESS' : 'FAIL') . '][class of readed object values] Expected: "' . record::class . '". Actual: "' . $record_readed_filter[0]::class . "\"\n"; echo '[' . $action . '][' . ++$test . '][' . ($record_readed_filter[0]->second_name === 'Ivanov' ? 'SUCCESS' : 'FAIL') . ']["second_name"] Expected: "Ivanov" (string). Actual: "' . $record_readed_filter[0]->second_name . '" (' . gettype($record_readed_filter[0]->second_name) . ")\n"; if (ARCH === 64) { /** @@ -300,8 +300,8 @@ echo '[' . ++$action . "] Readed the record from the database by filter with amo try { echo '[' . ++$action . '][' . ++$test . '][' . (gettype($records_readed_filter_amount) === 'array' ? 'SUCCESS' : 'FAIL') . '][type of returned value] Expected: "array". Actual: "' . gettype($records_readed_filter_amount) . "\"\n"; echo '[' . $action . '][' . ++$test . '][' . (count($records_readed_filter_amount) === 1 ? 'SUCCESS' : 'FAIL') . '][amount of readed records] Expected: 1 records. Actual: ' . count($records_readed_filter_amount) . " records\n"; - echo '[' . $action . '][' . ++$test . '][' . (gettype($records_readed_filter_amount[0]) === 'object' ? 'SUCCESS' : 'FAIL') . '][type of readedvalues] Expected: "object". Actual: "' . gettype($records_readed_filter_amount[0]) . "\"\n"; - echo '[' . $action . '][' . ++$test . '][' . ($records_readed_filter_amount[0] instanceof record ? 'SUCCESS' : 'FAIL') . '][class of readedobject values] Expected: "' . record::class . '". Actual: "' . $records_readed_filter_amount[0]::class . "\"\n"; + echo '[' . $action . '][' . ++$test . '][' . (gettype($records_readed_filter_amount[0]) === 'object' ? 'SUCCESS' : 'FAIL') . '][type of readed values] Expected: "object". Actual: "' . gettype($records_readed_filter_amount[0]) . "\"\n"; + echo '[' . $action . '][' . ++$test . '][' . ($records_readed_filter_amount[0] instanceof record ? 'SUCCESS' : 'FAIL') . '][class of readed object values] Expected: "' . record::class . '". Actual: "' . $records_readed_filter_amount[0]::class . "\"\n"; echo '[' . $action . '][' . ++$test . '][' . ($records_readed_filter_amount[0]->age === 24 ? 'SUCCESS' : 'FAIL') . ']["age"] Expected: "24" (integer). Actual: "' . $records_readed_filter_amount[0]->age . '" (' . gettype($records_readed_filter_amount[0]->age) . ")\n"; echo '[' . $action . '][' . ++$test . '][' . ($records_readed_filter_amount[0]->second_name === 'Mirzaev' ? 'SUCCESS' : 'FAIL') . ']["second_name"] Expected: "Mirzaev" (string). Actual: "' . $records_readed_filter_amount[0]->second_name . '" (' . gettype($records_readed_filter_amount[0]->second_name) . ")\n"; if (ARCH === 64) { @@ -330,8 +330,8 @@ echo '[' . ++$action . "] Readed the record from the database by filter with amo try { echo '[' . ++$action . '][' . ++$test . '][' . (gettype($records_readed_filter_amount_offset) === 'array' ? 'SUCCESS' : 'FAIL') . '][type of returned value] Expected: "array". Actual: "' . gettype($records_readed_filter_amount_offset) . "\"\n"; echo '[' . $action . '][' . ++$test . '][' . (count($records_readed_filter_amount_offset) === 1 ? 'SUCCESS' : 'FAIL') . '][amount of readed records] Expected: 1 records. Actual: ' . count($records_readed_filter_amount_offset) . " records\n"; - echo '[' . $action . '][' . ++$test . '][' . (gettype($records_readed_filter_amount_offset[0]) === 'object' ? 'SUCCESS' : 'FAIL') . '][type of readedvalues] Expected: "object". Actual: "' . gettype($records_readed_filter_amount_offset[0]) . "\"\n"; - echo '[' . $action . '][' . ++$test . '][' . ($records_readed_filter_amount_offset[0] instanceof record ? 'SUCCESS' : 'FAIL') . '][class of readedobject values] Expected: "' . record::class . '". Actual: "' . $records_readed_filter_amount_offset[0]::class . "\"\n"; + echo '[' . $action . '][' . ++$test . '][' . (gettype($records_readed_filter_amount_offset[0]) === 'object' ? 'SUCCESS' : 'FAIL') . '][type of readed values] Expected: "object". Actual: "' . gettype($records_readed_filter_amount_offset[0]) . "\"\n"; + echo '[' . $action . '][' . ++$test . '][' . ($records_readed_filter_amount_offset[0] instanceof record ? 'SUCCESS' : 'FAIL') . '][class of readed object values] Expected: "' . record::class . '". Actual: "' . $records_readed_filter_amount_offset[0]::class . "\"\n"; echo '[' . $action . '][' . ++$test . '][' . ($records_readed_filter_amount_offset[0]->age === 24 ? 'SUCCESS' : 'FAIL') . ']["age"] Expected: "24" (integer). Actual: "' . $records_readed_filter_amount_offset[0]->age . '" (' . gettype($records_readed_filter_amount_offset[0]->age) . ")\n"; echo '[' . $action . '][' . ++$test . '][' . ($records_readed_filter_amount_offset[0]->second_name === 'Ivanov' ? 'SUCCESS' : 'FAIL') . ']["second_name"] Expected: "Ivanov" (string). Actual: "' . $records_readed_filter_amount_offset[0]->second_name . '" (' . gettype($records_readed_filter_amount_offset[0]->second_name) . ")\n"; if (ARCH === 64) { -- 2.34.1 From cb0660505249f9f4b4874cc168d2d2baf922cac8 Mon Sep 17 00:00:00 2001 From: Little Fluffy Clouds Date: Sat, 12 Jul 2025 11:02:41 +0300 Subject: [PATCH 7/8] fix useless deleted entry test --- mirzaev/baza/tests/record.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mirzaev/baza/tests/record.php b/mirzaev/baza/tests/record.php index 8fa2afc..32b81dc 100755 --- a/mirzaev/baza/tests/record.php +++ b/mirzaev/baza/tests/record.php @@ -375,8 +375,8 @@ try { * * @see https://www.php.net/manual/en/language.types.float.php#113703 */ - echo '[' . $action . '][' . ++$test . '][' . (round($records_readed_filter_delete[0]->motivation, 2) === round(2.2250738585072E-308, 2) ? 'SUCCESS' : 'FAIL') . ']["motivation"] Expected: "2.2250738585072E-308" (double). Actual: "' . $records_readed_filter_delete[0]->motivation . '" (' . gettype($records_readed_filter_delete[0]->motivation) . ")\n"; - echo '[' . $action . '][' . ++$test . '][' . ($records_readed_filter_delete[0]->reputation === (int) -9223372036854775808 ? 'SUCCESS' : 'FAIL') . ']["reputation"] Expected: "-9223372036854775808" (integer). Actual: "' . $records_readed_filter_delete[0]->reputation . '" (' . gettype($records_readed_filter_delete[0]->reputation) . ")\n"; + echo '[' . $action . '][' . ++$test . '][' . (round($records_readed_filter_delete_readed[1]->motivation, 2) === round(163, 2) ? 'SUCCESS' : 'FAIL') . ']["motivation"] Expected: "163" (double). Actual: "' . $records_readed_filter_delete_readed[1]->motivation . '" (' . gettype($records_readed_filter_delete_readed[1]->motivation) . ")\n"; + echo '[' . $action . '][' . ++$test . '][' . ($records_readed_filter_delete_readed[1]->reputation === (int) 9223372036854775807 ? 'SUCCESS' : 'FAIL') . ']["reputation"] Expected: "9223372036854775807" (integer). Actual: "' . $records_readed_filter_delete_readed[1]->reputation . '" (' . gettype($records_readed_filter_delete_readed[1]->reputation) . ")\n"; } echo '[' . $action . "] The deleted record by filter checks have been completed\n"; -- 2.34.1 From 7783dab80be4d2c7e17f085c6afe5c79cd4f5023 Mon Sep 17 00:00:00 2001 From: Little Fluffy Clouds Date: Sat, 12 Jul 2025 12:18:08 +0300 Subject: [PATCH 8/8] implement core class and architecture enum --- mirzaev/baza/system/core.php | 34 +++++++++++++++ mirzaev/baza/system/database.php | 21 +++------ .../baza/system/enumerations/architecture.php | 22 ++++++++++ mirzaev/baza/tests/record.php | 43 +++++++++++-------- 4 files changed, 85 insertions(+), 35 deletions(-) create mode 100644 mirzaev/baza/system/core.php create mode 100644 mirzaev/baza/system/enumerations/architecture.php diff --git a/mirzaev/baza/system/core.php b/mirzaev/baza/system/core.php new file mode 100644 index 0000000..1277a0d --- /dev/null +++ b/mirzaev/baza/system/core.php @@ -0,0 +1,34 @@ + + */ + +final class core +{ + public static function architecture(): ?architecture { + return match(PHP_INT_SIZE) { + 4 => architecture::x86, + 8 => architecture::x86_64, + default => throw new exception_domain('Failed to determinate the system architecture'), + }; + } +} diff --git a/mirzaev/baza/system/database.php b/mirzaev/baza/system/database.php index af560c1..2fd09f2 100755 --- a/mirzaev/baza/system/database.php +++ b/mirzaev/baza/system/database.php @@ -6,6 +6,7 @@ namespace mirzaev\baza; // Files of the project use mirzaev\baza\enumerations\encoding, + mirzaev\baza\enumerations\architecture, mirzaev\baza\enumerations\type; // Built-in libraries @@ -13,16 +14,6 @@ use LogicException as exception_logic, InvalidArgumentException as exception_invalid_argument, RuntimeException as exception_runtime; -/** - * ARCH - * - * Checking for PHP implementation architecture - * - * Using php_uname('m') is another way of doing that - * but it's simpler to check for max integer size - */ -define('ARCH', (PHP_INT_SIZE === 8) ? 64 : 32); - /** * Database * @@ -176,7 +167,7 @@ class database * * @param mixed[] $values Values of the record * - * @throws exceptiin_invalid_argument if the balue type not matches the column values types + * @throws exception_invalid_argument if the balue type not matches the column values types * @throws exception_logic if amount of columns not matches the amount of values * * @return record|null The record instance @@ -227,7 +218,6 @@ class database * Pack the record values * * @param record $record The record - * @const integer ARCH PHP architecture * * @return string Packed values */ @@ -257,7 +247,7 @@ class database * we got to splice 64-bit integer into two separate longs * next to each other in binary representation */ - else if (ARCH === 64 && + else if (core::architecture() === architecture::x86_64 && ($column->type === type::integer || $column->type === type::integer_unsigned)) { @@ -290,7 +280,6 @@ class database * Unpack binary values and implement them as a `record` instance * * @param array $binaries Binary values in the same order as the columns - * @const integer ARCH PHP architecture * * @return record The unpacked record from binary values */ @@ -321,14 +310,14 @@ class database $unpacked[] = $encoded; } /** - * PHP builtin pack() ignores 64-bit integer values +p * PHP builtin pack() ignores 64-bit integer values * found on 64-bit PHP distributions * @see https://www.php.net/manual/en/function.pack.php#109382 * * In case of integer type on 64-bit PHP distributions * we got to reconstruct previosly spliced integer value */ - else if (ARCH === 64 && + else if (core::architecture() === architecture::x86_64 && ($column->type === type::integer || $column->type === type::integer_unsigned)) { diff --git a/mirzaev/baza/system/enumerations/architecture.php b/mirzaev/baza/system/enumerations/architecture.php new file mode 100644 index 0000000..cef1791 --- /dev/null +++ b/mirzaev/baza/system/enumerations/architecture.php @@ -0,0 +1,22 @@ + + */ + +enum architecture: int +{ + case x86 = 32; + case x86_64 = 64; +} diff --git a/mirzaev/baza/tests/record.php b/mirzaev/baza/tests/record.php index 32b81dc..15c93a1 100755 --- a/mirzaev/baza/tests/record.php +++ b/mirzaev/baza/tests/record.php @@ -3,9 +3,11 @@ declare(strict_types=1); use mirzaev\baza\database, + mirzaev\baza\core, mirzaev\baza\record, mirzaev\baza\column, mirzaev\baza\enumerations\encoding, + mirzaev\baza\enumerations\architecture, mirzaev\baza\enumerations\type; // Initializing path to the composer loader file (main project) @@ -34,6 +36,9 @@ require($autoload); // Initializing path to the database file $file = __DIR__ . DIRECTORY_SEPARATOR . 'temporary' . DIRECTORY_SEPARATOR . 'database.baza'; +// Initilized architecture runtime constant +define('ARCHITECTURE', core::architecture()); + echo "Started testing\n\n\n"; // Initializing the counter of actions @@ -53,7 +58,7 @@ if (!file_exists($file) || unlink($file)) { // Initializing the test database /* $database = new database() */ -if (PHP_INT_SIZE === 8) { +if (ARCHITECTURE === architecture::x86_64) { $database = (new database()) ->encoding(encoding::utf8) ->columns( @@ -84,7 +89,7 @@ if (PHP_INT_SIZE === 8) { echo '[' . ++$action . "] Initialized the database\n"; // Initializing the record -if (ARCH === 64) { +if (ARCHITECTURE === architecture::x86_64) { $record = $database->record( 'Arsen', 'Mirzaev', @@ -114,7 +119,7 @@ echo '[' . ++$action . '][' . ++$test . '][' . ($record->name === 'Arsen' ? 'SUC echo '[' . $action . '][' . ++$test . '][' . ($record->second_name === 'Mirzaev' ? 'SUCCESS' : 'FAIL') . "][\"second_name\"] Expected: \"Mirzaev\" (string). Actual: \"$record->second_name\" (" . gettype($record->second_name) . ")\n"; echo '[' . $action . '][' . ++$test . '][' . ($record->age === 24 ? 'SUCCESS' : 'FAIL') . "][\"age\"] Expected: \"24\" (integer). Actual: \"$record->age\" (" . gettype($record->age) . ")\n"; echo '[' . $action . '][' . ++$test . '][' . ($record->height === 165.5 ? 'SUCCESS' : 'FAIL') . "][\"height\"] Expected: \"165.5\" (double). Actual: \"$record->height\" (" . gettype($record->height) . ")\n"; -if (ARCH === 64) { +if (ARCHITECTURE === architecture::x86_64) { echo '[' . $action . '][' . ++$test . '][' . ($record->neuron_count === 91000000000 ? 'SUCCESS' : 'FAIL') . "][\"neuron_count\"] Expected: \"91000000000\" (integer). Actual: \"$record->neuron_count\" (" . gettype($record->neuron_count) . ")\n"; echo '[' . $action . '][' . ++$test . '][' . ($record->motivation === 1.7976931348623E+238 ? 'SUCCESS' : 'FAIL') . "][\"motivation\"] Expected: \"1.7976931348623E+238\" (double). Actual: \"$record->motivation\" (" . gettype($record->motivation) . ")\n"; echo '[' . $action . '][' . ++$test . '][' . ($record->reputation === 7355608 ? 'SUCCESS' : 'FAIL') . "][\"reputation\"] Expected: \"7355608\" (integer). Actual: \"$record->reputation\" (" . gettype($record->reputation) . ")\n"; @@ -132,7 +137,7 @@ $database->write($record); echo '[' . ++$action . "] Writed the record into the database\n"; // Initializing the second record -if (ARCH === 64) { +if (ARCHITECTURE === architecture::x86_64) { $record_ivan = $database->record( 'Ivan', 'Ivanov', @@ -161,7 +166,7 @@ $database->write($record_ivan); echo '[' . ++$action . "] Writed the record into the database\n"; // Initializing the second record -if (ARCH === 64) { +if (ARCHITECTURE === architecture::x86_64) { $record_margarita = $database->record( 'Margarita', 'Esenina', @@ -199,7 +204,7 @@ try { echo '[' . $action . '][' . ++$test . '][' . (count($records_readed_all) === 3 ? 'SUCCESS' : 'FAIL') . '][amount of readed records] Expected: 3 records. Actual: ' . count($records_readed_all) . " records\n"; echo '[' . $action . '][' . ++$test . '][' . (gettype($records_readed_all[0]) === 'object' ? 'SUCCESS' : 'FAIL') . '][type of readed values] Expected: "object". Actual: "' . gettype($records_readed_all[0]) . "\"\n"; echo '[' . $action . '][' . ++$test . '][' . ($records_readed_all[0] instanceof record ? 'SUCCESS' : 'FAIL') . '][class of readed object values] Expected: "' . record::class . '". Actual: "' . $records_readed_all[0]::class . "\"\n"; - if (ARCH === 64) { + if (ARCHITECTURE === architecture::x86_64) { echo '[' . $action . '][' . ++$test . '][' . ($records_readed_all[0]->neuron_count === 91000000000 ? 'SUCCESS' : 'FAIL') . ']["neuron_count"] Expected: "91000000000" (integer). Actual: "' . $records_readed_all[0]->neuron_count . '" (' . gettype($records_readed_all[0]->neuron_count) . ")\n"; } @@ -222,7 +227,7 @@ try { echo '[' . $action . '][' . ++$test . '][' . (gettype($record_readed_first[0]) === 'object' ? 'SUCCESS' : 'FAIL') . '][type of readed values] Expected: "object". Actual: "' . gettype($record_readed_first[0]) . "\"\n"; echo '[' . $action . '][' . ++$test . '][' . ($record_readed_first[0] instanceof record ? 'SUCCESS' : 'FAIL') . '][class of readed object values] Expected: "' . record::class . '". Actual: "' . $record_readed_first[0]::class . "\"\n"; echo '[' . $action . '][' . ++$test . '][' . ($record_readed_first[0]->second_name === 'Mirzaev' ? 'SUCCESS' : 'FAIL') . ']["second_name"] Expected: "Mirzaev" (string). Actual: "' . $record_readed_first[0]->second_name . '" (' . gettype($record_readed_first[0]->second_name) . ")\n"; - if (ARCH === 64) { + if (ARCHITECTURE === architecture::x86_64) { echo '[' . $action . '][' . ++$test . '][' . ($record_readed_first[0]->neuron_count === 91000000000 ? 'SUCCESS' : 'FAIL') . ']["neuron_count"] Expected: "91000000000" (integer). Actual: "' . $record_readed_first[0]->neuron_count . '" (' . gettype($record_readed_first[0]->neuron_count) . ")\n"; } @@ -245,9 +250,9 @@ try { echo '[' . $action . '][' . ++$test . '][' . (gettype($record_readed_second[0]) === 'object' ? 'SUCCESS' : 'FAIL') . '][type of readed values] Expected: "object". Actual: "' . gettype($record_readed_second[0]) . "\"\n"; echo '[' . $action . '][' . ++$test . '][' . ($record_readed_second[0] instanceof record ? 'SUCCESS' : 'FAIL') . '][class of readed object values] Expected: "' . record::class . '". Actual: "' . $record_readed_second[0]::class . "\"\n"; echo '[' . $action . '][' . ++$test . '][' . ($record_readed_second[0]->second_name === 'Ivanov' ? 'SUCCESS' : 'FAIL') . ']["second_name"] Expected: "Ivanov" (string). Actual: "' . $record_readed_second[0]->second_name . '" (' . gettype($record_readed_second[0]->second_name) . ")\n"; - if (ARCH === 64) { + if (ARCHITECTURE === architecture::x86_64) { /** - * Due to IEEE 754 double precision format double equility is problematic + * Due to IEEE 754 double precision format double equality is problematic * * @see https://www.php.net/manual/en/language.types.float.php#113703 */ @@ -274,9 +279,9 @@ try { echo '[' . $action . '][' . ++$test . '][' . (gettype($record_readed_filter[0]) === 'object' ? 'SUCCESS' : 'FAIL') . '][type of readed values] Expected: "object". Actual: "' . gettype($record_readed_filter[0]) . "\"\n"; echo '[' . $action . '][' . ++$test . '][' . ($record_readed_filter[0] instanceof record ? 'SUCCESS' : 'FAIL') . '][class of readed object values] Expected: "' . record::class . '". Actual: "' . $record_readed_filter[0]::class . "\"\n"; echo '[' . $action . '][' . ++$test . '][' . ($record_readed_filter[0]->second_name === 'Ivanov' ? 'SUCCESS' : 'FAIL') . ']["second_name"] Expected: "Ivanov" (string). Actual: "' . $record_readed_filter[0]->second_name . '" (' . gettype($record_readed_filter[0]->second_name) . ")\n"; - if (ARCH === 64) { + if (ARCHITECTURE === architecture::x86_64) { /** - * Due to IEEE 754 double precision format double equility is problematic + * Due to IEEE 754 double precision format double equality is problematic * * @see https://www.php.net/manual/en/language.types.float.php#113703 */ @@ -304,9 +309,9 @@ try { echo '[' . $action . '][' . ++$test . '][' . ($records_readed_filter_amount[0] instanceof record ? 'SUCCESS' : 'FAIL') . '][class of readed object values] Expected: "' . record::class . '". Actual: "' . $records_readed_filter_amount[0]::class . "\"\n"; echo '[' . $action . '][' . ++$test . '][' . ($records_readed_filter_amount[0]->age === 24 ? 'SUCCESS' : 'FAIL') . ']["age"] Expected: "24" (integer). Actual: "' . $records_readed_filter_amount[0]->age . '" (' . gettype($records_readed_filter_amount[0]->age) . ")\n"; echo '[' . $action . '][' . ++$test . '][' . ($records_readed_filter_amount[0]->second_name === 'Mirzaev' ? 'SUCCESS' : 'FAIL') . ']["second_name"] Expected: "Mirzaev" (string). Actual: "' . $records_readed_filter_amount[0]->second_name . '" (' . gettype($records_readed_filter_amount[0]->second_name) . ")\n"; - if (ARCH === 64) { + if (ARCHITECTURE === architecture::x86_64) { /** - * Due to IEEE 754 double precision format double equility is problematic + * Due to IEEE 754 double precision format double equality is problematic * * @see https://www.php.net/manual/en/language.types.float.php#113703 */ @@ -334,9 +339,9 @@ try { echo '[' . $action . '][' . ++$test . '][' . ($records_readed_filter_amount_offset[0] instanceof record ? 'SUCCESS' : 'FAIL') . '][class of readed object values] Expected: "' . record::class . '". Actual: "' . $records_readed_filter_amount_offset[0]::class . "\"\n"; echo '[' . $action . '][' . ++$test . '][' . ($records_readed_filter_amount_offset[0]->age === 24 ? 'SUCCESS' : 'FAIL') . ']["age"] Expected: "24" (integer). Actual: "' . $records_readed_filter_amount_offset[0]->age . '" (' . gettype($records_readed_filter_amount_offset[0]->age) . ")\n"; echo '[' . $action . '][' . ++$test . '][' . ($records_readed_filter_amount_offset[0]->second_name === 'Ivanov' ? 'SUCCESS' : 'FAIL') . ']["second_name"] Expected: "Ivanov" (string). Actual: "' . $records_readed_filter_amount_offset[0]->second_name . '" (' . gettype($records_readed_filter_amount_offset[0]->second_name) . ")\n"; - if (ARCH === 64) { + if (ARCHITECTURE === architecture::x86_64) { /** - * Due to IEEE 754 double precision format double equility is problematic + * Due to IEEE 754 double precision format double equality is problematic * * @see https://www.php.net/manual/en/language.types.float.php#113703 */ @@ -369,9 +374,9 @@ try { echo '[' . $action . '][' . ++$test . '][' . ($records_readed_filter_delete[0] instanceof record ? 'SUCCESS' : 'FAIL') . '][class of readed object values] Expected: "' . record::class . '". Actual: "' . $records_readed_filter_delete[0]::class . "\"\n"; echo '[' . $action . '][' . ++$test . '][' . ($records_readed_filter_delete[0]->name === 'Ivan' ? 'SUCCESS' : 'FAIL') . ']["name"] Expected: "Ivan" (string). Actual: "' . $records_readed_filter_delete[0]->second_name . '" (' . gettype($records_readed_filter_delete[0]->second_name) . ")\n"; echo '[' . $action . '][' . ++$test . '][' . (count($records_readed_filter_delete_readed) === 2 ? 'SUCCESS' : 'FAIL') . '][amount of readed records after deleting] Expected: 2 records. Actual: ' . count($records_readed_filter_delete_readed) . " records\n"; - if (ARCH === 64) { + if (ARCHITECTURE === architecture::x86_64) { /** - * Due to IEEE 754 double precision format double equility is problematic + * Due to IEEE 754 double precision format double equality is problematic * * @see https://www.php.net/manual/en/language.types.float.php#113703 */ @@ -405,9 +410,9 @@ try { echo '[' . $action . '][' . ++$test . '][' . ($records_readed_filter_update[0]->height === 165.5 ? 'SUCCESS' : 'FAIL') . ']["height"] Expected: "165.5" (double). Actual: "' . $records_readed_filter_update[0]->height . '" (' . gettype($records_readed_filter_update[0]->height) . ")\n"; echo '[' . $action . '][' . ++$test . '][' . (count($records_readed_filter_update_readed) === 2 ? 'SUCCESS' : 'FAIL') . '][amount of readed records after updating] Expected: 2 records. Actual: ' . count($records_readed_filter_update_readed) . " records\n"; echo '[' . $action . '][' . ++$test . '][' . ($records_readed_filter_update_readed[1]->height === $records_readed_filter_update[0]->height ? 'SUCCESS' : 'FAIL') . "] Height from `update` process response matched height from the `read` preocess response\n"; - if (ARCH === 64) { + if (ARCHITECTURE === architecture::x86_64) { /** - * Due to IEEE 754 double precision format double equility is problematic + * Due to IEEE 754 double precision format double equality is problematic * * @see https://www.php.net/manual/en/language.types.float.php#113703 */ -- 2.34.1