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:
36
4dev/tests/CoreLibsDebugLoggingTest.php
Normal file
36
4dev/tests/CoreLibsDebugLoggingTest.php
Normal 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__
|
||||||
@@ -1,7 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
// phpcs:disable Generic.Files.LineLength
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace tests;
|
namespace tests;
|
||||||
@@ -20,7 +18,7 @@ final class CoreLibsDebugRunningTimeTest extends TestCase
|
|||||||
return [
|
return [
|
||||||
'default time' => [
|
'default time' => [
|
||||||
0 => null,
|
0 => null,
|
||||||
1 => '/^\d{4}\.\d{5,}$/'
|
1 => '/^\d{4}\.\d{1,}$/'
|
||||||
],
|
],
|
||||||
'nanoseconds' => [
|
'nanoseconds' => [
|
||||||
0 => 'ns',
|
0 => 'ns',
|
||||||
@@ -28,19 +26,19 @@ final class CoreLibsDebugRunningTimeTest extends TestCase
|
|||||||
],
|
],
|
||||||
'microseconds' => [
|
'microseconds' => [
|
||||||
0 => 'ys',
|
0 => 'ys',
|
||||||
1 => '/^\d{7}\.\d{3}$/'
|
1 => '/^\d{7}\.\d{1,}$/'
|
||||||
],
|
],
|
||||||
'milliseconds' => [
|
'milliseconds' => [
|
||||||
0 => 'ms',
|
0 => 'ms',
|
||||||
1 => '/^\d{4}\.\d{6}$/'
|
1 => '/^\d{4}\.\d{1,}$/'
|
||||||
],
|
],
|
||||||
'seconds' => [
|
'seconds' => [
|
||||||
0 => 's',
|
0 => 's',
|
||||||
1 => '/^\d{1}\.\d{9}$/'
|
1 => '/^\d{1}\.\d{4,}$/'
|
||||||
],
|
],
|
||||||
'invalid fallback to ms' => [
|
'invalid fallback to ms' => [
|
||||||
0 => 'invalid',
|
0 => 'invalid',
|
||||||
1 => '/^\d{4}\.\d{6}$/'
|
1 => '/^\d{4}\.\d{1,}$/'
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
@@ -49,9 +47,11 @@ final class CoreLibsDebugRunningTimeTest extends TestCase
|
|||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'run time test' => [
|
'run time test' => [
|
||||||
0 => '/^\d{1}$/',
|
0 => '/^\d{1,}\.\d{1,}$/',
|
||||||
1 => '/^Start: \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} 0\.\d{7,}$/',
|
1 => '/^Start: \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} 0\.\d{8}, $/',
|
||||||
2 => '/^Start:$/'
|
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 {
|
} else {
|
||||||
$end = \CoreLibs\Debug\RunningTime::hrRunningTime($out_time);
|
$end = \CoreLibs\Debug\RunningTime::hrRunningTime($out_time);
|
||||||
}
|
}
|
||||||
|
// print "E: " . $end . "\n";
|
||||||
$this->assertMatchesRegularExpression(
|
$this->assertMatchesRegularExpression(
|
||||||
$expected,
|
$expected,
|
||||||
(string)$end
|
(string)$end
|
||||||
@@ -100,20 +101,24 @@ final class CoreLibsDebugRunningTimeTest extends TestCase
|
|||||||
public function testRunningTime(string $expected_number, string $expected_start, string $expected_end): void
|
public function testRunningTime(string $expected_number, string $expected_start, string $expected_end): void
|
||||||
{
|
{
|
||||||
$start = \CoreLibs\Debug\RunningTime::runningTime(true);
|
$start = \CoreLibs\Debug\RunningTime::runningTime(true);
|
||||||
|
// print "Start: " . $start . "\n";
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
0,
|
0,
|
||||||
$start
|
$start
|
||||||
);
|
);
|
||||||
|
// print "STRING: " . \CoreLibs\Debug\RunningTime::runningTimeString() . "\n";
|
||||||
$this->assertMatchesRegularExpression(
|
$this->assertMatchesRegularExpression(
|
||||||
$expected_start,
|
$expected_start,
|
||||||
\CoreLibs\Debug\RunningTime::runningTimeString()
|
\CoreLibs\Debug\RunningTime::runningTimeString()
|
||||||
);
|
);
|
||||||
time_nanosleep(1, 500);
|
time_nanosleep(1, 500);
|
||||||
$end = \CoreLibs\Debug\RunningTime::runningTime(true);
|
$end = \CoreLibs\Debug\RunningTime::runningTime(true);
|
||||||
|
// print "Start: " . $end . "\n";
|
||||||
$this->assertMatchesRegularExpression(
|
$this->assertMatchesRegularExpression(
|
||||||
$expected_number,
|
$expected_number,
|
||||||
(string)$end
|
(string)$end
|
||||||
);
|
);
|
||||||
|
// print "STRING: " . \CoreLibs\Debug\RunningTime::runningTimeString() . "\n";
|
||||||
$this->assertMatchesRegularExpression(
|
$this->assertMatchesRegularExpression(
|
||||||
$expected_end,
|
$expected_end,
|
||||||
\CoreLibs\Debug\RunningTime::runningTimeString()
|
\CoreLibs\Debug\RunningTime::runningTimeString()
|
||||||
|
|||||||
@@ -65,6 +65,8 @@ echo "ARRAYSEARCHRECURSIVE(email, [array]['input'], type): "
|
|||||||
// all return
|
// all return
|
||||||
echo "ARRAYSEARCHRECURSIVEALL(email, [array], type): "
|
echo "ARRAYSEARCHRECURSIVEALL(email, [array], type): "
|
||||||
. Dgs::printAr((array)ArrayHandler::arraySearchRecursiveAll('email', $test_array, 'type')) . "<br>";
|
. 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
|
// simple search
|
||||||
echo "ARRAYSEARCHSIMPLE([array], type, email): "
|
echo "ARRAYSEARCHSIMPLE([array], type, email): "
|
||||||
@@ -139,24 +141,6 @@ function rec(string $pre, string $cur, array $node = [])
|
|||||||
return $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 = [
|
// $test = [
|
||||||
// 'A' => [
|
// 'A' => [
|
||||||
// 'B' => [],
|
// 'B' => [],
|
||||||
@@ -193,7 +177,34 @@ $test = rec('F', 'U', $test);
|
|||||||
$test = rec('', 'Al', $test);
|
$test = rec('', 'Al', $test);
|
||||||
$test = rec('B', 'B1', $test);
|
$test = rec('B', 'B1', $test);
|
||||||
print "ORIGINAL: " . \CoreLibs\Debug\Support::printAr($test) . "<br>";
|
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
|
// error message
|
||||||
print $basic->log->printErrorMsg();
|
print $basic->log->printErrorMsg();
|
||||||
|
|||||||
@@ -43,10 +43,23 @@ $byte = 254779258;
|
|||||||
$string = '242.98 MB';
|
$string = '242.98 MB';
|
||||||
// static
|
// static
|
||||||
print "S::BYTE TO: $byte: " . $byte_class::humanReadableByteFormat($byte) . "<br>";
|
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>";
|
print "S::BYTE FROM: $string: " . $byte_class::stringByteFormat($string) . "<br>";
|
||||||
|
|
||||||
// *** BYTES TEST ***
|
// *** BYTES TEST ***
|
||||||
$bytes = array(
|
$bytes = [
|
||||||
-123123123,
|
-123123123,
|
||||||
999999, // KB-1
|
999999, // KB-1
|
||||||
999999999, // MB-1
|
999999999, // MB-1
|
||||||
@@ -56,7 +69,7 @@ $bytes = array(
|
|||||||
999999999999999999, // PB-1
|
999999999999999999, // PB-1
|
||||||
9223372036854775807, // MAX INT
|
9223372036854775807, // MAX INT
|
||||||
999999999999999999999, // EB-1
|
999999999999999999999, // EB-1
|
||||||
);
|
];
|
||||||
print "<b>BYTE FORMAT TESTS</b><br>";
|
print "<b>BYTE FORMAT TESTS</b><br>";
|
||||||
foreach ($bytes as $byte) {
|
foreach ($bytes as $byte) {
|
||||||
print '<div style="display: flex; border-bottom: 1px dashed gray;">';
|
print '<div style="display: flex; border-bottom: 1px dashed gray;">';
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ print '<div><a href="class_test.php">Class Test Master</a></div>';
|
|||||||
|
|
||||||
// A(out of bounds)
|
// 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 (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)
|
// B(valid)
|
||||||
$rgb = [10, 20, 30];
|
$rgb = [10, 20, 30];
|
||||||
$hex = '#0a141e';
|
$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]: "
|
print "S::COLOR hsl->rgb: $hsl[0], $hsl[1], $hsl[2]: "
|
||||||
. DgS::printAr(Colors::hsl2rgb($hsl[0], $hsl[1], $hsl[2])) . "<br>";
|
. 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
|
// TODO: run compare check input must match output
|
||||||
|
|
||||||
// error message
|
// error message
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ $checked_list = [
|
|||||||
];
|
];
|
||||||
foreach ($checked_list as $check) {
|
foreach ($checked_list as $check) {
|
||||||
print "CHECKED(0): $check[0]: " . Html::checked($check[1], $check[0]) . "<br>";
|
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
|
// magic link creation test
|
||||||
|
|||||||
@@ -29,11 +29,12 @@ if (!defined('SET_SESSION_NAME')) {
|
|||||||
$LOG_FILE_ID = 'classTest-json';
|
$LOG_FILE_ID = 'classTest-json';
|
||||||
ob_end_flush();
|
ob_end_flush();
|
||||||
|
|
||||||
use CoreLibs\Check\Jason;
|
use CoreLibs\Check\Json;
|
||||||
|
// use CoreLibs\Check\Jason;
|
||||||
use CoreLibs\Debug\Support as DgS;
|
use CoreLibs\Debug\Support as DgS;
|
||||||
|
|
||||||
$basic = new CoreLibs\Basic();
|
$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
|
// 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>';
|
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||||
|
|
||||||
$json = '{"foo": "bar"}';
|
$json = '{"foo": "bar"}';
|
||||||
$output = Jason::jsonConvertToArray($json);
|
$output = Json::jsonConvertToArray($json);
|
||||||
print "S::JSON: $json: " . DgS::printAr($output) . "<br>";
|
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}]';
|
$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: $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
|
// direct
|
||||||
$json = '{"direct": "static function call"}';
|
$json = '{"direct": "static function call"}';
|
||||||
@@ -68,6 +69,11 @@ $output = $basic->jsonConvertToArray($json);
|
|||||||
print "E-JSON: $json: ".DgS::printAr($output)."<br>";
|
print "E-JSON: $json: ".DgS::printAr($output)."<br>";
|
||||||
print "E-JSON ERROR: ".$basic->jsonGetLastError().": ".$basic->jsonGetLastError(true)."<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
|
// error message
|
||||||
print $basic->log->printErrorMsg();
|
print $basic->log->printErrorMsg();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user