PHPunit tests addition, update to test files

Update to admin/class_* test files
Add stubb file for Debug/Logging
Finalize the Debug/RunningTime test
This commit is contained in:
Clemens Schwaighofer
2022-01-13 08:48:49 +09:00
parent 4363f289fc
commit cb63a3eaa9
7 changed files with 114 additions and 39 deletions

View File

@@ -0,0 +1,36 @@
<?php
declare(strict_types=1);
namespace tests;
use PHPUnit\Framework\TestCase;
/**
* Test class for Debug\Logging
* @coversDefaultClass \CoreLibs\Debug\Logging
* @testdox \CoreLibs\Debug\Logging method tests
*/
final class CoreLibsDebugLoggingTest extends TestCase
{
// init tests
// - __construct call with options
// setting tests
// - basicSetLogId
// - getLogLevelAll
// - setLogLevelAll
// - debugFor
// - setLogLevel
// - getLogLevel
// - setLogPer
// - getLogPer
// debug tets
// - pr
// - debug
// - mergeErrors
// - printErrorMsg
// - resetErrorMsg
// - getErrorMsg
}
// __END__

View File

@@ -1,7 +1,5 @@
<?php
// phpcs:disable Generic.Files.LineLength
declare(strict_types=1);
namespace tests;
@@ -20,7 +18,7 @@ final class CoreLibsDebugRunningTimeTest extends TestCase
return [
'default time' => [
0 => null,
1 => '/^\d{4}\.\d{5,}$/'
1 => '/^\d{4}\.\d{1,}$/'
],
'nanoseconds' => [
0 => 'ns',
@@ -28,19 +26,19 @@ final class CoreLibsDebugRunningTimeTest extends TestCase
],
'microseconds' => [
0 => 'ys',
1 => '/^\d{7}\.\d{3}$/'
1 => '/^\d{7}\.\d{1,}$/'
],
'milliseconds' => [
0 => 'ms',
1 => '/^\d{4}\.\d{6}$/'
1 => '/^\d{4}\.\d{1,}$/'
],
'seconds' => [
0 => 's',
1 => '/^\d{1}\.\d{9}$/'
1 => '/^\d{1}\.\d{4,}$/'
],
'invalid fallback to ms' => [
0 => 'invalid',
1 => '/^\d{4}\.\d{6}$/'
1 => '/^\d{4}\.\d{1,}$/'
]
];
}
@@ -49,9 +47,11 @@ final class CoreLibsDebugRunningTimeTest extends TestCase
{
return [
'run time test' => [
0 => '/^\d{1}$/',
1 => '/^Start: \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} 0\.\d{7,}$/',
2 => '/^Start:$/'
0 => '/^\d{1,}\.\d{1,}$/',
1 => '/^Start: \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} 0\.\d{8}, $/',
2 => '/^Start: \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} 0\.\d{8}, '
. 'End: \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} 0\.\d{8}, '
. 'Run: \d{1,}\.\d{1,} s$/'
]
];
}
@@ -80,6 +80,7 @@ final class CoreLibsDebugRunningTimeTest extends TestCase
} else {
$end = \CoreLibs\Debug\RunningTime::hrRunningTime($out_time);
}
// print "E: " . $end . "\n";
$this->assertMatchesRegularExpression(
$expected,
(string)$end
@@ -100,20 +101,24 @@ final class CoreLibsDebugRunningTimeTest extends TestCase
public function testRunningTime(string $expected_number, string $expected_start, string $expected_end): void
{
$start = \CoreLibs\Debug\RunningTime::runningTime(true);
// print "Start: " . $start . "\n";
$this->assertEquals(
0,
$start
);
// print "STRING: " . \CoreLibs\Debug\RunningTime::runningTimeString() . "\n";
$this->assertMatchesRegularExpression(
$expected_start,
\CoreLibs\Debug\RunningTime::runningTimeString()
);
time_nanosleep(1, 500);
$end = \CoreLibs\Debug\RunningTime::runningTime(true);
// print "Start: " . $end . "\n";
$this->assertMatchesRegularExpression(
$expected_number,
(string)$end
);
// print "STRING: " . \CoreLibs\Debug\RunningTime::runningTimeString() . "\n";
$this->assertMatchesRegularExpression(
$expected_end,
\CoreLibs\Debug\RunningTime::runningTimeString()

View File

@@ -65,6 +65,8 @@ echo "ARRAYSEARCHRECURSIVE(email, [array]['input'], type): "
// all return
echo "ARRAYSEARCHRECURSIVEALL(email, [array], type): "
. Dgs::printAr((array)ArrayHandler::arraySearchRecursiveAll('email', $test_array, 'type')) . "<br>";
echo "ARRAYSEARCHRECURSIVEALL(email, [array], type, false): "
. Dgs::printAr((array)ArrayHandler::arraySearchRecursiveAll('email', $test_array, 'type', false)) . "<br>";
// simple search
echo "ARRAYSEARCHSIMPLE([array], type, email): "
@@ -139,24 +141,6 @@ function rec(string $pre, string $cur, array $node = [])
return $node;
}
/**
* flatten array down to own level
*
* @param array $array
* @param array $return
* @return array
*/
function flattenArrayKey(array $array, array $return = [])
{
foreach ($array as $key => $sub) {
$return[] = $key;
if (count($sub) > 0) {
$return = flattenArrayKey($sub, $return);
}
}
return $return;
}
// $test = [
// 'A' => [
// 'B' => [],
@@ -193,7 +177,34 @@ $test = rec('F', 'U', $test);
$test = rec('', 'Al', $test);
$test = rec('B', 'B1', $test);
print "ORIGINAL: " . \CoreLibs\Debug\Support::printAr($test) . "<br>";
print "FLATTEN: " . \CoreLibs\Debug\Support::printAr(flattenArrayKey($test)) . "<br>";
print "FLATTEN-c: " . \CoreLibs\Debug\Support::printAr(ArrayHandler::flattenArrayKey($test)) . "<br>";
$test = [
'a' => ['a1' => 'a1foo', 'a2' => 'a1bar'],
1 => 'bar',
'c' => [2, 3, 4],
'd' => [
'e' => [
'de1' => 'subfoo', 'de2' => 'subbar', 'a2' => 'a1bar'
]
]
];
print "ORIGINAL: " . \CoreLibs\Debug\Support::printAr($test) . "<br>";
print "FLATTEN: " . \CoreLibs\Debug\Support::printAr(ArrayHandler::flattenArrayKey($test)) . "<br>";
// genAssocArray
$db_array = [
0 => ['a' => 'a1', 'b' => 2],
1 => ['a' => 'a2', 'b' => 3],
2 => ['a' => '', 'b' => ''],
];
// $key = false;
$key = 'a';
// $value = false;
$value = 'b';
$flag = false;
$output = \CoreLibs\Combined\ArrayHandler::genAssocArray($db_array, $key, $value, $flag);
print "OUTPUT: " . \CoreLibs\Debug\Support::printAr($output) . "<br>";
// error message
print $basic->log->printErrorMsg();

View File

@@ -43,10 +43,23 @@ $byte = 254779258;
$string = '242.98 MB';
// static
print "S::BYTE TO: $byte: " . $byte_class::humanReadableByteFormat($byte) . "<br>";
print "S::BYTE TO: $byte: " . $byte_class::humanReadableByteFormat($byte, Byte::BYTE_FORMAT_SI) . "<br>";
print "S::BYTE TO: $byte: " . $byte_class::humanReadableByteFormat($byte, Byte::BYTE_FORMAT_ADJUST) . "<br>";
print "S::BYTE TO: $byte: " . $byte_class::humanReadableByteFormat($byte, Byte::BYTE_FORMAT_NOSPACE) . "<br>";
print "S::BYTE FROM: $string: " . $byte_class::stringByteFormat($string) . "<br>";
//
$byte = 314572800;
$string = '300 MB';
print "S::BYTE TO: $byte: " . $byte_class::humanReadableByteFormat($byte) . "<br>";
print "S::BYTE TO: $byte: " . $byte_class::humanReadableByteFormat($byte, Byte::BYTE_FORMAT_SI) . "<br>";
print "S::BYTE TO: $byte: " . $byte_class::humanReadableByteFormat($byte, Byte::BYTE_FORMAT_ADJUST) . "<br>";
print "S::BYTE TO: $byte: "
. $byte_class::humanReadableByteFormat($byte, Byte::BYTE_FORMAT_ADJUST | Byte::BYTE_FORMAT_NOSPACE) . "<br>";
print "S::BYTE TO: $byte: " . $byte_class::humanReadableByteFormat($byte, Byte::BYTE_FORMAT_NOSPACE) . "<br>";
print "S::BYTE FROM: $string: " . $byte_class::stringByteFormat($string) . "<br>";
// *** BYTES TEST ***
$bytes = array(
$bytes = [
-123123123,
999999, // KB-1
999999999, // MB-1
@@ -56,7 +69,7 @@ $bytes = array(
999999999999999999, // PB-1
9223372036854775807, // MAX INT
999999999999999999999, // EB-1
);
];
print "<b>BYTE FORMAT TESTS</b><br>";
foreach ($bytes as $byte) {
print '<div style="display: flex; border-bottom: 1px dashed gray;">';

View File

@@ -43,7 +43,7 @@ print '<div><a href="class_test.php">Class Test Master</a></div>';
// A(out of bounds)
print "C::S/COLOR invalid rgb->hex (gray 125): -1, -1, -1: " . CoreLibs\Convert\Colors::rgb2hex(-1, -1, -1) . "<br>";
print "\$C::S/COLOR invalid rgb->hex (gary 125): -1, -1, -1: " . $color_class::rgb2hex(-1, -1, -1) . "<br>";
print "\$C::S/COLOR invalid rgb->hex (gray 125): -1, -1, -1: " . $color_class::rgb2hex(-1, -1, -1) . "<br>";
// B(valid)
$rgb = [10, 20, 30];
$hex = '#0a141e';
@@ -63,6 +63,10 @@ print "S::COLOR hsb->rgb: $hsb[0], $hsb[1], $hsb[2]: "
print "S::COLOR hsl->rgb: $hsl[0], $hsl[1], $hsl[2]: "
. DgS::printAr(Colors::hsl2rgb($hsl[0], $hsl[1], $hsl[2])) . "<br>";
$hsb = [0, 0, 5];
print "S::COLOR hsb->rgb: $hsb[0], $hsb[1], $hsb[2]: "
. DgS::printAr(Colors::hsb2rgb($hsb[0], $hsb[1], $hsb[2])) . "<br>";
// TODO: run compare check input must match output
// error message

View File

@@ -72,7 +72,7 @@ $checked_list = [
];
foreach ($checked_list as $check) {
print "CHECKED(0): $check[0]: " . Html::checked($check[1], $check[0]) . "<br>";
print "CHECKED(1): $check[0]: " . Html::checked($check[1], $check[0], 1) . "<br>";
print "CHECKED(1): $check[0]: " . Html::checked($check[1], $check[0], Html::CHECKED) . "<br>";
}
// magic link creation test

View File

@@ -29,11 +29,12 @@ if (!defined('SET_SESSION_NAME')) {
$LOG_FILE_ID = 'classTest-json';
ob_end_flush();
use CoreLibs\Check\Jason;
use CoreLibs\Check\Json;
// use CoreLibs\Check\Jason;
use CoreLibs\Debug\Support as DgS;
$basic = new CoreLibs\Basic();
$json_class = 'CoreLibs\Check\Jason';
$json_class = 'CoreLibs\Check\Json';
// define a list of from to color sets for conversion test
@@ -42,14 +43,14 @@ print "<body>";
print '<div><a href="class_test.php">Class Test Master</a></div>';
$json = '{"foo": "bar"}';
$output = Jason::jsonConvertToArray($json);
$output = Json::jsonConvertToArray($json);
print "S::JSON: $json: " . DgS::printAr($output) . "<br>";
print "S::JSON ERROR: " . Jason::jsonGetLastError() . ": " . Jason::jsonGetLastError(true) . "<br>";
print "S::JSON ERROR: " . Json::jsonGetLastError() . ": " . Json::jsonGetLastError(true) . "<br>";
$json = '["f: {b"""ar}]';
$output = Jason::jsonConvertToArray($json);
$output = Json::jsonConvertToArray($json);
print "S::E-JSON: $json: " . DgS::printAr($output) . "<br>";
print "S::E-JSON ERROR: " . Jason::jsonGetLastError() . ": " . Jason::jsonGetLastError(true) . "<br>";
print "S::E-JSON ERROR: " . Json::jsonGetLastError() . ": " . Json::jsonGetLastError(true) . "<br>";
// direct
$json = '{"direct": "static function call"}';
@@ -68,6 +69,11 @@ $output = $basic->jsonConvertToArray($json);
print "E-JSON: $json: ".DgS::printAr($output)."<br>";
print "E-JSON ERROR: ".$basic->jsonGetLastError().": ".$basic->jsonGetLastError(true)."<br>"; */
// $json = '{"foo": "bar"}';
// $output = Jason::jsonConvertToArray($json);
// print "S::JSON: $json: " . DgS::printAr($output) . "<br>";
// print "S::JSON ERROR: " . Jason::jsonGetLastError() . ": " . Jason::jsonGetLastError(true) . "<br>";
// error message
print $basic->log->printErrorMsg();