diff --git a/build/logs/junit.xml b/build/logs/junit.xml new file mode 100644 index 0000000..ebc2b04 --- /dev/null +++ b/build/logs/junit.xml @@ -0,0 +1,2384 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/build/testdox.html b/build/testdox.html new file mode 100644 index 0000000..ea35043 --- /dev/null +++ b/build/testdox.html @@ -0,0 +1,1999 @@ + + + + + Test Documentation + + + +

AAASetupData\AAASetupDataTest just setup BASE

+ +

\CoreLibs\ACL\Login method tests

+ +

\CoreLibs\Admin\Backend method tests

+ +

\CoreLibs\Admin\EditPage method tests

+ +

\CoreLibs\Check\Colors method tests

+ +

\CoreLibs\Check\Email method tests

+ +

\CoreLibs\Check\Encoding method tests

+ +

\CoreLibs\Check\File method tests

+ +

\CoreLibs\Check\PHPVersion method tests

+ +

Core Libs Combined Array Handler Find Arrays Missing Key (tests\CoreLibsCombinedArrayHandlerFindArraysMissingKey)

+ +

Core Libs Combined Array Handler Ksort Array (tests\CoreLibsCombinedArrayHandlerKsortArray)

+ +

Core Libs Combined Array Handler Select Array From Option (tests\CoreLibsCombinedArrayHandlerSelectArrayFromOption)

+ +

Core Libs Combined Array Handler Sort Array (tests\CoreLibsCombinedArrayHandlerSortArray)

+ +

\CoreLibs\Combined\ArrayHandler method tests

+ +

\CoreLibs\Combined\DateTime method tests

+ +

\CoreLibs\Convert\Byte method tests

+ +

\CoreLibs\Convert\Color\Color method tests

+ +

\CoreLibs\Convert\Colors legacy method tests

+ +

\CoreLibs\Convert\Encoding method tests

+ +

\CoreLibs\Convert\Html method tests

+ +

\CoreLibs\Convert\Json method tests

+ +

\CoreLibs\Convert\Math method tests

+ +

\CoreLibs\Convert\MimeAppName method tests

+ +

\CoreLibs\Convert\MimeEncode method tests

+ +

\CoreLibs\Convert\SetVarTypeNull method tests

+ +

\CoreLibs\Convert\SetVarType method tests

+ +

Core Libs Convert Strings Regex Validate (tests\CoreLibsConvertStringsRegexValidate)

+ +

\CoreLibs\Convert\Strings method tests

+ +

\CoreLibs\Create\Crc64 method tests

+ +

\CoreLibs\Create\Email method tests

+ +

\CoreLibs\Create\Hash method tests

+ +

\CoreLibs\Create\RandomKey method tests

+ +

\CoreLibs\Create\Session method tests

+ +

\CoreLibs\Create\Uids method tests

+ +

\CoreLibs\Extended\ArrayIO method tests for extended DB interface

+ +

\CoreLibs\DB\IO method tests for SQL\PgSQL

+ +

\CoreLibs\Debug\FileWriter method tests

+ +

\CoreLibs\Debug\LoggingLegacy method tests

+ +

\CoreLibs\Debug\MemoryUsage method tests

+ +

\CoreLibs\Debug\RunningTime method tests

+ +

\CoreLibs\Debug\Support method tests

+ +

\CoreLibs\Get\DotEnv method tests

+ +

\CoreLibs\Get\System method tests

+ +

\CoreLibs\Language\GetLocale method tests

+ +

\CoreLibs\Language\L10n method tests

+ +

\CoreLibs\Logging\ErrorMessages method tests

+ +

\CoreLibs\Logging\Logging method tests

+ +

\CoreLibs\Output\Form\Elements method tests

+ +

\CoreLibs\Output\Form\Generate method tests

+ +

\CoreLibs\Output\Form\Token method tests

+ +

\CoreLibs\Output\Image method tests

+ +

\CoreLibs\Output\Progressbar method tests

+ +

\CoreLibs\Security\AsymmetricAnonymousEncryption method tests

+ +

\CoreLibs\Security\Password method tests

+ +

\CoreLibs\Security\SymmetricEncryption method tests

+ +

\CoreLibs\Template\HtmlBuilder\Block method tests

+ +

\CoreLibs\Template\HtmlBuilder\Element method tests

+ +

\CoreLibs\Template\HtmlBuilder\StringReplace method tests

+ +

\CoreLibs\UrlRequests\Curl method tests

+ + + \ No newline at end of file diff --git a/src/Create/Crc64.php b/src/Create/Crc64.php new file mode 100644 index 0000000..eab5ac4 --- /dev/null +++ b/src/Create/Crc64.php @@ -0,0 +1,106 @@ +> is arithmetic, so mask off the sign bit + $c = ($c & 1) + ? ((($c >> 1) & PHP_INT_MAX) ^ $poly) + : (($c >> 1) & PHP_INT_MAX); + } + $table[$i] = $c; + } + } + $crc = ~$crc; // xor 0xFFFFFFFFFFFFFFFF + foreach (unpack('C*', $data) ?: [] as $b) { + $crc = $table[($crc ^ $b) & 0xFF] ^ (($crc >> 8) & 0x00FFFFFFFFFFFFFF); + } + return ~$crc; + } + + /** + * Returns int value of the CRC64 checksum for the given file. + * + * @param string $path + * @param int<1,16777216> $chunkSize + * @return int + */ + private function crc64CalcFile(string $path, int $chunkSize = 8 * 1024 * 1024): int + { + $fh = fopen($path, 'rb'); + if ($fh === false) { + throw new \RuntimeException("Cannot open $path"); + } + $crc = 0; + try { + while (!feof($fh)) { + $chunk = fread($fh, $chunkSize); + if ($chunk === false) { + throw new \RuntimeException("Read error on $path"); + } + $crc = $this->crc64Calc($chunk, $crc); + } + } finally { + fclose($fh); + } + return $crc; + } + + /** + * Returns the Base64-encoded CRC64 checksum for the given file. + * + * @param string $path + * @return string + */ + public static function crc64(string $path): string + { + return base64_encode(pack('J', (new self())->crc64CalcFile($path))); // J = uint64 big-endian + } + + /** + * Returns the 16-character lowercase hexadecimal CRC64 checksum for the given file. + * Same as base64.b64decode(...).hex() + * + * @param string $path + * @return string + */ + public static function crc64hex(string $path): string + { + return sprintf('%016x', (new self())->crc64CalcFile($path)); + } +} + +// __END__ diff --git a/test/phpunit/ACL/CoreLibsACLLoginTest.php b/test/phpunit/ACL/CoreLibsACLLoginTest.php index 2be4285..eedaa3a 100644 --- a/test/phpunit/ACL/CoreLibsACLLoginTest.php +++ b/test/phpunit/ACL/CoreLibsACLLoginTest.php @@ -46,7 +46,8 @@ final class CoreLibsACLLoginTest extends TestCase // database/CoreLibsACLLogin_database_create_data.sql $load_sql_file = __DIR__ . DIRECTORY_SEPARATOR - . 'database/CoreLibsACLLogin_database_create_data.sql'; + . 'database' . DIRECTORY_SEPARATOR + . 'CoreLibsACLLogin_database_create_data.sql'; if (!is_file($load_sql_file)) { self::markTestIncomplete( 'Missing ACL\Login database load SQL file' @@ -63,6 +64,7 @@ final class CoreLibsACLLoginTest extends TestCase . "CoreLibsACLLogin_database_prepare.sh " . "$load_sql_file " . "$db_user " + . "$db_password " . "$db_name " . "$db_host "; exec($command, $ouput, $result); diff --git a/test/phpunit/ACL/CoreLibsACLLogin_database_prepare.sh b/test/phpunit/ACL/CoreLibsACLLogin_database_prepare.sh index 012b17a..d7671f8 100755 --- a/test/phpunit/ACL/CoreLibsACLLogin_database_prepare.sh +++ b/test/phpunit/ACL/CoreLibsACLLogin_database_prepare.sh @@ -22,31 +22,32 @@ if ! command -v dropdb &> /dev/null || ! command -v createdb &> /dev/null || ! c fi; db_user="${2}"; -db_name="${3}"; -db_host="${4}"; +db_password="${3}"; +db_name="${4}"; +db_host="${5}"; # empty db name or db user -> exit with 2 -if [ -z "${db_user}" ] || [ -z "${db_name}" ] || [ -z "${db_host}" ]; then +if [ -z "${db_user}" ] || [ -z "${db_name}" ] || [ -z "${db_password}" ] || [ -z "${db_host}" ]; then echo 2; exit 2; fi; # drop database, on error exit with 3 -dropdb -U "${db_user}" -h "${db_host}" "${db_name}" 2>&1; +PGPASSWORD="${db_password}" dropdb -U "${db_user}" -h "${db_host}" "${db_name}" 2>&1; if [ ! $? ]; then echo 3; exit 3; fi; # create database, on error exit with 4 -createdb -U "${db_user}" -O "${db_user}" -h "${db_host}" -E utf8 "${db_name}" 2>&1; +PGPASSWORD="${db_password}" createdb -U "${db_user}" -O "${db_user}" -h "${db_host}" -E utf8 "${db_name}" 2>&1; if [ ! $? ]; then echo 4; exit 4; fi; # if error 5 thrown, test with enabled below if [ -n "${5}" ]; then - psql -U "${db_user}" -h "${db_host}" -f "${load_sql}" "${db_name}"; + PGPASSWORD="${db_password}" psql -U "${db_user}" -h "${db_host}" -f "${load_sql}" "${db_name}"; else # load data (redirect ALL error to null), on error exit with 5 - psql -U "${db_user}" -h "${db_host}" -f "${load_sql}" "${db_name}" 2>&1 1>/dev/null 2>/dev/null; + PGPASSWORD="${db_password}" psql -U "${db_user}" -h "${db_host}" -f "${load_sql}" "${db_name}" 2>&1 1>/dev/null 2>/dev/null; fi; if [ ! $? ]; then echo 5; diff --git a/test/phpunit/Create/CoreLibsCreateCrc64Test.php b/test/phpunit/Create/CoreLibsCreateCrc64Test.php new file mode 100644 index 0000000..dffa02a --- /dev/null +++ b/test/phpunit/Create/CoreLibsCreateCrc64Test.php @@ -0,0 +1,73 @@ + [ + 'file' => __DIR__ . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR . 'random_10KB.bin', + 'crc64_base64' => 'oMgkUkGrDME=', + 'crc64_hex' => 'a0c8245241ab0cc1', + ], + '100kb' => [ + 'file' => __DIR__ . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR . 'random_100KB.bin', + 'crc64_base64' => 'i9Lpf3Y3D3M=', + 'crc64_hex' => '8bd2e97f76370f73', + ], + '1mb' => [ + 'file' => __DIR__ . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR . 'random_1MB.bin', + 'crc64_base64' => 'WqYAirRJ0q8=', + 'crc64_hex' => '5aa6008ab449d2af', + ], + '5mb' => [ + 'file' => __DIR__ . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR . 'random_5MB.bin', + 'crc64_base64' => '9hS5kUxbgR0=', + 'crc64_hex' => 'f614b9914c5b811d', + ], + '10mb' => [ + 'file' => __DIR__ . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR . 'random_10MB.bin', + 'crc64_base64' => 'xDmtkk1JhjM=', + 'crc64_hex' => 'c439ad924d498633', + ], + // everything above 10MB is too slow, sow do not check this + ]; + } + + /** + * Undocumented function + * + * @covers ::crc64 + * @covers ::crc64hex + * @dataProvider providerFiles + * @testdox generate crc64 for $file and expecting $crc64_base64 and $crc64_hex [$_dataName] + * + * @return void + */ + public function testCrc64(string $file, string $crc64_base64, string $crc64_hex): void + { + $this->assertSame( + $crc64_base64, + \CoreLibs\Create\Crc64::crc64($file), + "Failed asserting base64 CRC64 for $file" + ); + $this->assertSame( + $crc64_hex, + \CoreLibs\Create\Crc64::crc64hex($file), + "Failed asserting hex CRC64 for $file" + ); + } +} + +// __END__ diff --git a/test/phpunit/Create/files/random_100KB.bin b/test/phpunit/Create/files/random_100KB.bin new file mode 100644 index 0000000..c9ab5ea Binary files /dev/null and b/test/phpunit/Create/files/random_100KB.bin differ diff --git a/test/phpunit/Create/files/random_10KB.bin b/test/phpunit/Create/files/random_10KB.bin new file mode 100644 index 0000000..c6d3b8c Binary files /dev/null and b/test/phpunit/Create/files/random_10KB.bin differ diff --git a/test/phpunit/Create/files/random_10MB.bin b/test/phpunit/Create/files/random_10MB.bin new file mode 100644 index 0000000..81f205d Binary files /dev/null and b/test/phpunit/Create/files/random_10MB.bin differ diff --git a/test/phpunit/Create/files/random_1MB.bin b/test/phpunit/Create/files/random_1MB.bin new file mode 100644 index 0000000..0002c67 Binary files /dev/null and b/test/phpunit/Create/files/random_1MB.bin differ diff --git a/test/phpunit/Create/files/random_5MB.bin b/test/phpunit/Create/files/random_5MB.bin new file mode 100644 index 0000000..796bfda Binary files /dev/null and b/test/phpunit/Create/files/random_5MB.bin differ