Compare commits
37 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f4ff31721b | ||
|
|
21ac91d2e6 | ||
|
|
2d98d26d0b | ||
|
|
3fda1bef60 | ||
|
|
4f1104c36e | ||
|
|
db1007ef12 | ||
|
|
13c76efcef | ||
|
|
f59c325b05 | ||
|
|
aac5157173 | ||
|
|
abc2705c64 | ||
|
|
e2fff45b16 | ||
|
|
b6ae3f99d9 | ||
|
|
a377ab4b61 | ||
|
|
ec9275d8d3 | ||
|
|
10ed5b3ea0 | ||
|
|
5f290419c6 | ||
|
|
0152af6e65 | ||
|
|
4adb9fba30 | ||
|
|
672931ee67 | ||
|
|
373a9aff2f | ||
|
|
4e3ceecac8 | ||
|
|
8bf694b2b2 | ||
|
|
caf03421a7 | ||
|
|
facf8adaf7 | ||
|
|
c8158c8224 | ||
|
|
7b9a0043d3 | ||
|
|
6517747fef | ||
|
|
fb7071adc4 | ||
|
|
d96c92f9ef | ||
|
|
d7c0054ea0 | ||
|
|
80d2215f2b | ||
|
|
b18bf937d3 | ||
|
|
4b6c5df74f | ||
|
|
89e3888bf8 | ||
|
|
c46125aef1 | ||
|
|
a8ca5d7a2b | ||
|
|
ae2d6580a2 |
43
.eslintrc.js
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
module.exports = {
|
||||||
|
'env': {
|
||||||
|
'browser': true,
|
||||||
|
'es6': true,
|
||||||
|
'commonjs': true,
|
||||||
|
'jquery': true
|
||||||
|
},
|
||||||
|
'extends': 'eslint:recommended',
|
||||||
|
'parserOptions': {
|
||||||
|
'ecmaVersion': 6
|
||||||
|
},
|
||||||
|
'rules': {
|
||||||
|
'indent': [
|
||||||
|
'error',
|
||||||
|
'tab',
|
||||||
|
{
|
||||||
|
'SwitchCase': 1
|
||||||
|
}
|
||||||
|
],
|
||||||
|
'linebreak-style': [
|
||||||
|
'error',
|
||||||
|
'unix'
|
||||||
|
],
|
||||||
|
'quotes': [
|
||||||
|
'error',
|
||||||
|
'single'
|
||||||
|
],
|
||||||
|
'semi': [
|
||||||
|
'error',
|
||||||
|
'always'
|
||||||
|
],
|
||||||
|
'no-console': 'off',
|
||||||
|
'no-unused-vars': [
|
||||||
|
'error', {
|
||||||
|
'vars': 'all',
|
||||||
|
'args': 'after-used',
|
||||||
|
'ignoreRestSiblings': false
|
||||||
|
}
|
||||||
|
],
|
||||||
|
// Requires eslint >= v8.14.0
|
||||||
|
'no-constant-binary-expression': 'error'
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -1,12 +1,12 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<phive xmlns="https://phar.io/phive">
|
<phive xmlns="https://phar.io/phive">
|
||||||
<phar name="phpunit" version="^9.6" installed="9.6.13" location="./tools/phpunit" copy="false"/>
|
<phar name="phpunit" version="^9.6" installed="9.6.19" location="./tools/phpunit" copy="false"/>
|
||||||
<phar name="phpcbf" version="^3.7.2" installed="3.7.2" location="./tools/phpcbf" copy="false"/>
|
<phar name="phpcbf" version="^3.7.2" installed="3.9.1" location="./tools/phpcbf" copy="false"/>
|
||||||
<phar name="phpcs" version="^3.7.2" installed="3.7.2" location="./tools/phpcs" copy="false"/>
|
<phar name="phpcs" version="^3.7.2" installed="3.9.1" location="./tools/phpcs" copy="false"/>
|
||||||
<phar name="phpstan" version="^1.10.37" installed="1.10.37" location="./tools/phpstan" copy="false"/>
|
<phar name="phpstan" version="^1.10.37" installed="1.10.67" location="./tools/phpstan" copy="false"/>
|
||||||
<phar name="phan" version="^5.4.2" installed="5.4.2" location="./tools/phan" copy="false"/>
|
<phar name="phan" version="^5.4.2" installed="5.4.3" location="./tools/phan" copy="false"/>
|
||||||
<phar name="psalm" version="^5.15.0" installed="5.15.0" location="./tools/psalm" copy="false"/>
|
<phar name="psalm" version="^5.15.0" installed="5.23.1" location="./tools/psalm" copy="false"/>
|
||||||
<phar name="phpdox" version="^0.12.0" installed="0.12.0" location="./tools/phpdox" copy="false"/>
|
<phar name="phpdox" version="^0.12.0" installed="0.12.0" location="./tools/phpdox" copy="false"/>
|
||||||
<phar name="phpdocumentor" version="^3.4.2" installed="3.4.2" location="./tools/phpDocumentor" copy="false"/>
|
<phar name="phpdocumentor" version="^3.4.2" installed="3.4.3" location="./tools/phpDocumentor" copy="false"/>
|
||||||
<phar name="php-cs-fixer" version="^3.34.1" installed="3.34.1" location="./tools/php-cs-fixer" copy="false"/>
|
<phar name="php-cs-fixer" version="^3.34.1" installed="3.53.0" location="./tools/php-cs-fixer" copy="false"/>
|
||||||
</phive>
|
</phive>
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ if [ "${target}" == '' ]; then
|
|||||||
# default is admin
|
# default is admin
|
||||||
TEXTDOMAIN=admin;
|
TEXTDOMAIN=admin;
|
||||||
fi;
|
fi;
|
||||||
js_folder="layout/${TEXTDOMAIN}/javascript/";
|
js_folder="${TEXTDOMAIN}/layout/javascript/";
|
||||||
|
|
||||||
error=0;
|
error=0;
|
||||||
# this checks if the TEXTDOMAIN target actually exists
|
# this checks if the TEXTDOMAIN target actually exists
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ if [ ! -z "${1}" ]; then
|
|||||||
# "8.0") php_bin="/usr/bin/php8.0 "; ;;
|
# "8.0") php_bin="/usr/bin/php8.0 "; ;;
|
||||||
# "8.1") php_bin="/usr/bin/php8.1 "; ;;
|
# "8.1") php_bin="/usr/bin/php8.1 "; ;;
|
||||||
"8.2") php_bin="/usr/bin/php8.2 "; ;;
|
"8.2") php_bin="/usr/bin/php8.2 "; ;;
|
||||||
|
"8.3") php_bin="/usr/bin/php8.4 "; ;;
|
||||||
*) echo "Not support PHP: ${1}"; exit; ;;
|
*) echo "Not support PHP: ${1}"; exit; ;;
|
||||||
esac;
|
esac;
|
||||||
fi;
|
fi;
|
||||||
@@ -29,6 +30,7 @@ if [ ! -z "${2}" ] && [ -z "${php_bin}" ]; then
|
|||||||
# "8.0") php_bin="/usr/bin/php8.0 "; ;;
|
# "8.0") php_bin="/usr/bin/php8.0 "; ;;
|
||||||
# "8.1") php_bin="/usr/bin/php8.1 "; ;;
|
# "8.1") php_bin="/usr/bin/php8.1 "; ;;
|
||||||
"8.2") php_bin="/usr/bin/php8.2 "; ;;
|
"8.2") php_bin="/usr/bin/php8.2 "; ;;
|
||||||
|
"8.3") php_bin="/usr/bin/php8.3 "; ;;
|
||||||
*) echo "Not support PHP: ${1}"; exit; ;;
|
*) echo "Not support PHP: ${1}"; exit; ;;
|
||||||
esac;
|
esac;
|
||||||
fi;
|
fi;
|
||||||
|
|||||||
31
4dev/documentation/DB_Query_Params.md
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
# DB Query Params ? and : to $
|
||||||
|
|
||||||
|
dbReturn*
|
||||||
|
dbExec
|
||||||
|
|
||||||
|
keep
|
||||||
|
->query
|
||||||
|
->params
|
||||||
|
for reference
|
||||||
|
|
||||||
|
## : named params
|
||||||
|
|
||||||
|
in order for each named found replace with order number:
|
||||||
|
|
||||||
|
```txt
|
||||||
|
:name, :foo, :bar, :name =>
|
||||||
|
$1, $2, $3, $1
|
||||||
|
```
|
||||||
|
|
||||||
|
```php
|
||||||
|
$query = str_replace(
|
||||||
|
[':name', ':foo', ':bar'],
|
||||||
|
['$1', '$2', '$3'],
|
||||||
|
$query
|
||||||
|
);
|
||||||
|
```
|
||||||
|
|
||||||
|
## ? Params
|
||||||
|
|
||||||
|
Foreach ? set $1 to $n and store that in new params array
|
||||||
|
in QUERY for each ? replace with matching $n
|
||||||
@@ -28,10 +28,10 @@ final class CoreLibsCheckFileTest extends TestCase
|
|||||||
public function filesList(): array
|
public function filesList(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
['filename.txt', 'txt', 5],
|
['filename.txt', 'txt', 5, 'text/plain'],
|
||||||
['filename.csv', 'csv', 15],
|
['filename.csv', 'csv', 15, 'text/csv'],
|
||||||
['filename.tsv', 'tsv', 0],
|
['filename.tsv', 'tsv', 0, 'text/plain'],
|
||||||
['file_does_not_exits', '', -1],
|
['file_does_not_exits', '', -1, ''],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,6 +63,15 @@ final class CoreLibsCheckFileTest extends TestCase
|
|||||||
return $list;
|
return $list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function mimeTypeProvider(): array
|
||||||
|
{
|
||||||
|
$list = [];
|
||||||
|
foreach ($this->filesList() as $row) {
|
||||||
|
$list[$row[0] . ' must be mime type ' . $row[3]] = [$row[0], $row[3]];
|
||||||
|
}
|
||||||
|
return $list;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests if file extension matches
|
* Tests if file extension matches
|
||||||
*
|
*
|
||||||
@@ -115,6 +124,51 @@ final class CoreLibsCheckFileTest extends TestCase
|
|||||||
unlink($this->base_folder . $input);
|
unlink($this->base_folder . $input);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @covers ::getMimeType
|
||||||
|
* @dataProvider mimeTypeProvider
|
||||||
|
* @testdox getMimeType $input must be mime type $expected [$_dataName]
|
||||||
|
*
|
||||||
|
* @param string $input
|
||||||
|
* @param string $expected
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testGetMimeType(string $input, string $expected): void
|
||||||
|
{
|
||||||
|
if (!empty($expected)) {
|
||||||
|
$file = $this->base_folder . $input;
|
||||||
|
$fp = fopen($file, 'w');
|
||||||
|
switch ($expected) {
|
||||||
|
case 'text/csv':
|
||||||
|
for ($i = 1; $i <= 10; $i++) {
|
||||||
|
fwrite($fp, '"This is row","' . $expected . '",' . $i . PHP_EOL);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'text/tsv':
|
||||||
|
for ($i = 1; $i <= 10; $i++) {
|
||||||
|
fwrite($fp, "\"This is row\"\t\"" . $expected . "\"\t\"" . $i . PHP_EOL);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'text/plain':
|
||||||
|
fwrite($fp, 'This is mime type: ' . $expected . PHP_EOL);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
fclose($fp);
|
||||||
|
} else {
|
||||||
|
$this->expectException(\UnexpectedValueException::class);
|
||||||
|
}
|
||||||
|
$this->assertEquals(
|
||||||
|
$expected,
|
||||||
|
\CoreLibs\Check\File::getMimeType($this->base_folder . $input)
|
||||||
|
);
|
||||||
|
// unlink file
|
||||||
|
if (is_file($this->base_folder . $input)) {
|
||||||
|
unlink($this->base_folder . $input);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// __END__
|
// __END__
|
||||||
|
|||||||
@@ -1098,16 +1098,109 @@ final class CoreLibsCombinedArrayHandlerTest extends TestCase
|
|||||||
* @testdox arrayFlatForKey array $input will be $expected [$_dataName]
|
* @testdox arrayFlatForKey array $input will be $expected [$_dataName]
|
||||||
*
|
*
|
||||||
* @param array $input
|
* @param array $input
|
||||||
|
* @param string $search
|
||||||
* @param array $expected
|
* @param array $expected
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testArrayFlatForKey(array $input, $search, array $expected): void
|
public function testArrayFlatForKey(array $input, string $search, array $expected): void
|
||||||
{
|
{
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
$expected,
|
$expected,
|
||||||
\CoreLibs\Combined\ArrayHandler::arrayFlatForKey($input, $search)
|
\CoreLibs\Combined\ArrayHandler::arrayFlatForKey($input, $search)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function providerArrayGetNextPrevKey(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'find, ok' => [
|
||||||
|
'input' => [
|
||||||
|
'a' => 'First',
|
||||||
|
'b' => 'Second',
|
||||||
|
'c' => 'Third',
|
||||||
|
],
|
||||||
|
'b',
|
||||||
|
'a',
|
||||||
|
'c'
|
||||||
|
],
|
||||||
|
'find, first' => [
|
||||||
|
'input' => [
|
||||||
|
'a' => 'First',
|
||||||
|
'b' => 'Second',
|
||||||
|
'c' => 'Third',
|
||||||
|
],
|
||||||
|
'a',
|
||||||
|
null,
|
||||||
|
'b'
|
||||||
|
],
|
||||||
|
'find, last' => [
|
||||||
|
'input' => [
|
||||||
|
'a' => 'First',
|
||||||
|
'b' => 'Second',
|
||||||
|
'c' => 'Third',
|
||||||
|
],
|
||||||
|
'c',
|
||||||
|
'b',
|
||||||
|
null
|
||||||
|
],
|
||||||
|
'find, not found' => [
|
||||||
|
'input' => [
|
||||||
|
'a' => 'First',
|
||||||
|
'b' => 'Second',
|
||||||
|
'c' => 'Third',
|
||||||
|
],
|
||||||
|
'z',
|
||||||
|
null,
|
||||||
|
null
|
||||||
|
],
|
||||||
|
'int, index' => [
|
||||||
|
'input' => [
|
||||||
|
'a',
|
||||||
|
'b',
|
||||||
|
'c'
|
||||||
|
],
|
||||||
|
1,
|
||||||
|
0,
|
||||||
|
2
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @covers ::arrayGetPrevKey, ::arrayGetNextKey
|
||||||
|
* @dataProvider providerArrayGetNextPrevKey
|
||||||
|
* @testdox arrayGetNextPrevKey get next/prev key for $search wtih $expected_prev/$expected_next [$_dataName]
|
||||||
|
*
|
||||||
|
* @param array $input
|
||||||
|
* @param int|string $search
|
||||||
|
* @param int|string|null $expected_prev
|
||||||
|
* @param int|string|null $expected_next
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testArrayGetNextPrevKey(
|
||||||
|
array $input,
|
||||||
|
int|string $search,
|
||||||
|
int|string|null $expected_prev,
|
||||||
|
int|string|null $expected_next
|
||||||
|
): void {
|
||||||
|
$this->assertEquals(
|
||||||
|
$expected_prev,
|
||||||
|
\CoreLibs\Combined\ArrayHandler::arrayGetPrevKey($input, $search),
|
||||||
|
'Find prev key in array'
|
||||||
|
);
|
||||||
|
$this->assertEquals(
|
||||||
|
$expected_next,
|
||||||
|
\CoreLibs\Combined\ArrayHandler::arrayGetNextKey($input, $search),
|
||||||
|
'Find next key in array'
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// __END__
|
// __END__
|
||||||
|
|||||||
@@ -66,6 +66,34 @@ final class CoreLibsCombinedDateTimeTest extends TestCase
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* date string convert test
|
||||||
|
*
|
||||||
|
* @covers ::dateStringFormat
|
||||||
|
* @dataProvider timestampProvider
|
||||||
|
* @testdox dateStringFormat $input (microtime $flag) will be $expected [$_dataName]
|
||||||
|
*
|
||||||
|
* @param int|float $input
|
||||||
|
* @param bool $flag
|
||||||
|
* @param string $expected
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testDateStringFormat(
|
||||||
|
$input,
|
||||||
|
bool $flag_show_micro,
|
||||||
|
bool $flag_micro_as_float,
|
||||||
|
string $expected
|
||||||
|
): void {
|
||||||
|
$this->assertEquals(
|
||||||
|
$expected,
|
||||||
|
\CoreLibs\Combined\DateTime::dateStringFormat(
|
||||||
|
$input,
|
||||||
|
$flag_show_micro,
|
||||||
|
$flag_micro_as_float
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* interval for both directions
|
* interval for both directions
|
||||||
*
|
*
|
||||||
@@ -74,6 +102,11 @@ final class CoreLibsCombinedDateTimeTest extends TestCase
|
|||||||
public function intervalProvider(): array
|
public function intervalProvider(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
'on hour' => [
|
||||||
|
3600,
|
||||||
|
false,
|
||||||
|
'1h 0m 0s'
|
||||||
|
],
|
||||||
'interval no microtime' => [
|
'interval no microtime' => [
|
||||||
1641515890,
|
1641515890,
|
||||||
false,
|
false,
|
||||||
@@ -82,7 +115,7 @@ final class CoreLibsCombinedDateTimeTest extends TestCase
|
|||||||
'interval with microtime' => [
|
'interval with microtime' => [
|
||||||
1641515890,
|
1641515890,
|
||||||
true,
|
true,
|
||||||
'18999d 0h 38m 10s',
|
'18999d 0h 38m 10s 0ms',
|
||||||
],
|
],
|
||||||
'micro interval no microtime' => [
|
'micro interval no microtime' => [
|
||||||
1641515890.123456,
|
1641515890.123456,
|
||||||
@@ -92,7 +125,7 @@ final class CoreLibsCombinedDateTimeTest extends TestCase
|
|||||||
'micro interval with microtime' => [
|
'micro interval with microtime' => [
|
||||||
1641515890.123456,
|
1641515890.123456,
|
||||||
true,
|
true,
|
||||||
'18999d 0h 38m 10s 1235ms',
|
'18999d 0h 38m 10s 124ms',
|
||||||
],
|
],
|
||||||
'negative interval no microtime' => [
|
'negative interval no microtime' => [
|
||||||
-1641515890,
|
-1641515890,
|
||||||
@@ -103,27 +136,27 @@ final class CoreLibsCombinedDateTimeTest extends TestCase
|
|||||||
'microtime only' => [
|
'microtime only' => [
|
||||||
0.123456,
|
0.123456,
|
||||||
true,
|
true,
|
||||||
'0s 1235ms',
|
'0s 123ms',
|
||||||
],
|
],
|
||||||
'seconds only' => [
|
'seconds only' => [
|
||||||
30.123456,
|
30.123456,
|
||||||
true,
|
true,
|
||||||
'30s 1235ms',
|
'30s 123ms',
|
||||||
],
|
],
|
||||||
'minutes only' => [
|
'minutes only' => [
|
||||||
90.123456,
|
90.123456,
|
||||||
true,
|
true,
|
||||||
'1m 30s 1235ms',
|
'1m 30s 123ms',
|
||||||
],
|
],
|
||||||
'hours only' => [
|
'hours only' => [
|
||||||
3690.123456,
|
3690.123456,
|
||||||
true,
|
true,
|
||||||
'1h 1m 30s 1235ms',
|
'1h 1m 30s 123ms',
|
||||||
],
|
],
|
||||||
'days only' => [
|
'days only' => [
|
||||||
90090.123456,
|
90090.123456,
|
||||||
true,
|
true,
|
||||||
'1d 1h 1m 30s 1235ms',
|
'1d 1h 1m 30s 123ms',
|
||||||
],
|
],
|
||||||
'already set' => [
|
'already set' => [
|
||||||
'1d 1h 1m 30s 1235ms',
|
'1d 1h 1m 30s 1235ms',
|
||||||
@@ -143,6 +176,306 @@ final class CoreLibsCombinedDateTimeTest extends TestCase
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* time seconds convert test
|
||||||
|
*
|
||||||
|
* @covers ::timeStringFormat
|
||||||
|
* @dataProvider intervalProvider
|
||||||
|
* @testdox timeStringFormat $input (microtime $flag) will be $expected [$_dataName]
|
||||||
|
*
|
||||||
|
* @param string|int|float $input
|
||||||
|
* @param bool $flag
|
||||||
|
* @param string $expected
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testTimeStringFormat(string|int|float $input, bool $flag, string $expected): void
|
||||||
|
{
|
||||||
|
$this->assertEquals(
|
||||||
|
$expected,
|
||||||
|
\CoreLibs\Combined\DateTime::timeStringFormat($input, $flag)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* interval seconds convert
|
||||||
|
*
|
||||||
|
* @covers ::intervalStringFormat
|
||||||
|
* @dataProvider intervalProvider
|
||||||
|
* @testdox intervalStringFormat $input (microtime $show_micro) will be $expected [$_dataName]
|
||||||
|
*
|
||||||
|
* @param string|int|float $input
|
||||||
|
* @param bool $show_micro
|
||||||
|
* @param string $expected
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testIntervalStringFormat(string|int|float $input, bool $show_micro, string $expected): void
|
||||||
|
{
|
||||||
|
// we skip string input, that is not allowed
|
||||||
|
if (is_string($input)) {
|
||||||
|
$this->assertTrue(true, 'Skip strings');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// invalid values throw exception in default
|
||||||
|
if ($input == 999999999999999) {
|
||||||
|
$this->expectException(\LengthException::class);
|
||||||
|
}
|
||||||
|
// below is equal to timeStringFormat
|
||||||
|
$this->assertEquals(
|
||||||
|
$expected,
|
||||||
|
\CoreLibs\Combined\DateTime::intervalStringFormat(
|
||||||
|
$input,
|
||||||
|
show_microseconds: $show_micro,
|
||||||
|
show_only_days: true,
|
||||||
|
skip_zero: false,
|
||||||
|
skip_last_zero: false,
|
||||||
|
truncate_nanoseconds: true,
|
||||||
|
truncate_zero_seconds_if_microseconds: false
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function intervalExtendedProvider(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
// A
|
||||||
|
'(60) default value' => [
|
||||||
|
[
|
||||||
|
'seconds' => 60,
|
||||||
|
],
|
||||||
|
'expected' => '1m',
|
||||||
|
'exception' => null
|
||||||
|
],
|
||||||
|
'(60) default value, skip_last_zero:false' => [
|
||||||
|
[
|
||||||
|
'seconds' => 60,
|
||||||
|
'skip_last_zero' => false,
|
||||||
|
],
|
||||||
|
'expected' => '1m 0s 0ms',
|
||||||
|
'exception' => null
|
||||||
|
],
|
||||||
|
// B
|
||||||
|
'(120.1) default value' => [
|
||||||
|
[
|
||||||
|
'seconds' => 120.1,
|
||||||
|
],
|
||||||
|
'expected' => '2m 100ms',
|
||||||
|
'exception' => null
|
||||||
|
],
|
||||||
|
'(120.1) default value, skip_zero:false' => [
|
||||||
|
[
|
||||||
|
'seconds' => 120.1,
|
||||||
|
'skip_zero' => false,
|
||||||
|
],
|
||||||
|
'expected' => '2m 0s 100ms',
|
||||||
|
'exception' => null
|
||||||
|
],
|
||||||
|
'(120.1) default value, skip_last_zero:false' => [
|
||||||
|
[
|
||||||
|
'seconds' => 120.1,
|
||||||
|
'skip_last_zero' => false,
|
||||||
|
],
|
||||||
|
'expected' => '2m 100ms',
|
||||||
|
'exception' => null
|
||||||
|
],
|
||||||
|
// C
|
||||||
|
'(3601) default value' => [
|
||||||
|
[
|
||||||
|
'seconds' => 3601,
|
||||||
|
],
|
||||||
|
'expected' => '1h 1s',
|
||||||
|
'exception' => null
|
||||||
|
],
|
||||||
|
'(3601) default value, skip_zero:false' => [
|
||||||
|
[
|
||||||
|
'seconds' => 3601,
|
||||||
|
'skip_zero' => false,
|
||||||
|
],
|
||||||
|
'expected' => '1h 0m 1s',
|
||||||
|
'exception' => null
|
||||||
|
],
|
||||||
|
'(3601) default value, skip_last_zero:false' => [
|
||||||
|
[
|
||||||
|
'seconds' => 3601,
|
||||||
|
'skip_last_zero' => false,
|
||||||
|
],
|
||||||
|
'expected' => '1h 1s 0ms',
|
||||||
|
'exception' => null
|
||||||
|
],
|
||||||
|
// TODO create unit tests for ALL edge cases
|
||||||
|
// CREATE abort tests, simple, all others are handled in exception tests
|
||||||
|
'exception: \UnexpectedValueException:1' => [
|
||||||
|
[
|
||||||
|
'seconds' => 99999999999999999999999
|
||||||
|
],
|
||||||
|
'expected' => null,
|
||||||
|
'exception' => [
|
||||||
|
'class' => \UnexpectedValueException::class,
|
||||||
|
'code' => 1,
|
||||||
|
],
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test all options for interval conversion
|
||||||
|
*
|
||||||
|
* @covers ::intervalStringFormat
|
||||||
|
* @dataProvider intervalExtendedProvider
|
||||||
|
* @testdox intervalStringFormat $input will be $expected / $exception [$_dataName]
|
||||||
|
*
|
||||||
|
* @param array<string,null|int|float|bool> $parameter_list
|
||||||
|
* @param string $expected
|
||||||
|
* @param array<string,mixed> $exception
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testExtendedIntervalStringFormat(
|
||||||
|
array $parameter_list,
|
||||||
|
?string $expected,
|
||||||
|
?array $exception
|
||||||
|
): void {
|
||||||
|
if ($expected === null && $exception === null) {
|
||||||
|
$this->assertFalse(true, 'Cannot have expected and exception null in test data');
|
||||||
|
}
|
||||||
|
$parameters = [];
|
||||||
|
foreach (
|
||||||
|
[
|
||||||
|
'seconds' => null,
|
||||||
|
'truncate_after' => '',
|
||||||
|
'natural_seperator' => false,
|
||||||
|
'name_space_seperator' => false,
|
||||||
|
'show_microseconds' => true,
|
||||||
|
'short_time_name' => true,
|
||||||
|
'skip_last_zero' => true,
|
||||||
|
'skip_zero' => true,
|
||||||
|
'show_only_days' => false,
|
||||||
|
'auto_fix_microseconds' => false,
|
||||||
|
'truncate_nanoseconds' => false,
|
||||||
|
'truncate_zero_seconds_if_microseconds' => true,
|
||||||
|
] as $param => $default
|
||||||
|
) {
|
||||||
|
if (empty($parameter_list[$param]) && $default === null) {
|
||||||
|
$this->assertFalse(true, 'Parameter ' . $param . ' is mandatory ');
|
||||||
|
} elseif (!isset($parameter_list[$param]) || $parameter_list[$param] === null) {
|
||||||
|
$parameters[] = $default;
|
||||||
|
} else {
|
||||||
|
$parameters[] = $parameter_list[$param];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($expected !== null) {
|
||||||
|
$this->assertEquals(
|
||||||
|
$expected,
|
||||||
|
call_user_func_array('CoreLibs\Combined\DateTime::intervalStringFormat', $parameters)
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
if (empty($exception['class']) || empty($exception['code'])) {
|
||||||
|
$this->assertFalse(true, 'Exception tests need Exception name and Code');
|
||||||
|
}
|
||||||
|
$this->expectException($exception['class']);
|
||||||
|
$this->expectExceptionCode($exception['code']);
|
||||||
|
// if we have a message, must be regex
|
||||||
|
if (!empty($exception['message'])) {
|
||||||
|
$this->expectExceptionMessageMatches($exception['message']);
|
||||||
|
}
|
||||||
|
call_user_func_array('CoreLibs\Combined\DateTime::intervalStringFormat', $parameters);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @return array<mixed>
|
||||||
|
*/
|
||||||
|
public function exceptionsIntervalProvider(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'UnexpectedValueException: 1 A' => [
|
||||||
|
'seconds' => 99999999999999999999999,
|
||||||
|
'params' => [],
|
||||||
|
'exception' => \UnexpectedValueException::class,
|
||||||
|
'exception_message' => "/^Seconds value is invalid, too large or more than six decimals: /",
|
||||||
|
'excpetion_code' => 1,
|
||||||
|
],
|
||||||
|
'UnexpectedValueException: 1 B' => [
|
||||||
|
'seconds' => 123.1234567,
|
||||||
|
'params' => [],
|
||||||
|
'exception' => \UnexpectedValueException::class,
|
||||||
|
'exception_message' => "/^Seconds value is invalid, too large or more than six decimals: /",
|
||||||
|
'excpetion_code' => 1,
|
||||||
|
],
|
||||||
|
// exception 2 is very likely covered by exception 1
|
||||||
|
'LengthException: 3' => [
|
||||||
|
'seconds' => 999999999999999999,
|
||||||
|
'params' => [
|
||||||
|
'show_only_days',
|
||||||
|
],
|
||||||
|
'exception' => \LengthException::class,
|
||||||
|
'exception_message' => "/^Input seconds value is too large for days output: /",
|
||||||
|
'excpetion_code' => 3,
|
||||||
|
],
|
||||||
|
'UnexpectedValueException: 4' => [
|
||||||
|
'seconds' => 1234567,
|
||||||
|
'params' => [
|
||||||
|
'truncate_after'
|
||||||
|
],
|
||||||
|
'exception' => \UnexpectedValueException::class,
|
||||||
|
'exception_message' => "/^truncate_after has an invalid value: /",
|
||||||
|
'excpetion_code' => 4,
|
||||||
|
],
|
||||||
|
'UnexpectedValueException: 5' => [
|
||||||
|
'seconds' => 1234567,
|
||||||
|
'params' => [
|
||||||
|
'show_only_days:truncate_after'
|
||||||
|
],
|
||||||
|
'exception' => \UnexpectedValueException::class,
|
||||||
|
'exception_message' =>
|
||||||
|
"/^If show_only_days is turned on, the truncate_after cannot be years or months: /",
|
||||||
|
'excpetion_code' => 5,
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test all exceptions
|
||||||
|
*
|
||||||
|
* @covers ::intervalStringFormat
|
||||||
|
* @dataProvider exceptionsIntervalProvider
|
||||||
|
* @testdox intervalStringFormat: test Exceptions
|
||||||
|
*
|
||||||
|
* @param int|float $seconds
|
||||||
|
* @param array<string> $params
|
||||||
|
* @param string $exception
|
||||||
|
* @param string $exception_message
|
||||||
|
* @param int $excpetion_code
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testExceptionsIntervalStringFormat(
|
||||||
|
int|float $seconds,
|
||||||
|
array $params,
|
||||||
|
string $exception,
|
||||||
|
string $exception_message,
|
||||||
|
int $excpetion_code,
|
||||||
|
): void {
|
||||||
|
$this->expectException($exception);
|
||||||
|
$this->expectExceptionMessageMatches($exception_message);
|
||||||
|
$this->expectExceptionCode($excpetion_code);
|
||||||
|
if (empty($params)) {
|
||||||
|
\CoreLibs\Combined\DateTime::intervalStringFormat($seconds);
|
||||||
|
} else {
|
||||||
|
if (in_array('show_only_days', $params)) {
|
||||||
|
\CoreLibs\Combined\DateTime::intervalStringFormat($seconds, show_only_days:true);
|
||||||
|
} elseif (in_array('truncate_after', $params)) {
|
||||||
|
\CoreLibs\Combined\DateTime::intervalStringFormat($seconds, truncate_after: 'v');
|
||||||
|
} elseif (in_array('show_only_days:truncate_after', $params)) {
|
||||||
|
\CoreLibs\Combined\DateTime::intervalStringFormat($seconds, show_only_days:true, truncate_after: 'y');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Undocumented function
|
* Undocumented function
|
||||||
*
|
*
|
||||||
@@ -203,6 +536,25 @@ final class CoreLibsCombinedDateTimeTest extends TestCase
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @covers ::stringToTime
|
||||||
|
* @dataProvider reverseIntervalProvider
|
||||||
|
* @testdox stringToTime $input will be $expected [$_dataName]
|
||||||
|
*
|
||||||
|
* @param string|int|float $input
|
||||||
|
* @param string|int|float $expected
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testStringToTime($input, $expected): void
|
||||||
|
{
|
||||||
|
$this->assertEquals(
|
||||||
|
$expected,
|
||||||
|
\CoreLibs\Combined\DateTime::stringToTime($input)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Undocumented function
|
* Undocumented function
|
||||||
*
|
*
|
||||||
@@ -238,6 +590,25 @@ final class CoreLibsCombinedDateTimeTest extends TestCase
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @covers ::checkDate
|
||||||
|
* @dataProvider dateProvider
|
||||||
|
* @testdox checkDate $input will be $expected [$_dataName]
|
||||||
|
*
|
||||||
|
* @param string $input
|
||||||
|
* @param bool $expected
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testCheckDate(string $input, bool $expected): void
|
||||||
|
{
|
||||||
|
$this->assertEquals(
|
||||||
|
$expected,
|
||||||
|
\CoreLibs\Combined\DateTime::checkDate($input)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Undocumented function
|
* Undocumented function
|
||||||
*
|
*
|
||||||
@@ -297,6 +668,25 @@ final class CoreLibsCombinedDateTimeTest extends TestCase
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @covers ::checkDateTime
|
||||||
|
* @dataProvider dateTimeProvider
|
||||||
|
* @testdox checkDateTime $input will be $expected [$_dataName]
|
||||||
|
*
|
||||||
|
* @param string $input
|
||||||
|
* @param bool $expected
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testCheckDateTime(string $input, bool $expected): void
|
||||||
|
{
|
||||||
|
$this->assertEquals(
|
||||||
|
$expected,
|
||||||
|
\CoreLibs\Combined\DateTime::checkDateTime($input)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Undocumented function
|
* Undocumented function
|
||||||
*
|
*
|
||||||
@@ -371,6 +761,37 @@ final class CoreLibsCombinedDateTimeTest extends TestCase
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @covers ::compareDate
|
||||||
|
* @dataProvider dateCompareProvider
|
||||||
|
* @testdox compareDate $input_a compared to $input_b will be $expected [$_dataName]
|
||||||
|
*
|
||||||
|
* @param string $input_a
|
||||||
|
* @param string $input_b
|
||||||
|
* @param int|bool $expected
|
||||||
|
* @param string|null $exception
|
||||||
|
* @param int|null $exception_code
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testCompareDate(
|
||||||
|
string $input_a,
|
||||||
|
string $input_b,
|
||||||
|
int|bool $expected,
|
||||||
|
?string $exception,
|
||||||
|
?int $exception_code
|
||||||
|
): void {
|
||||||
|
if ($expected === false) {
|
||||||
|
$this->expectException($exception);
|
||||||
|
$this->expectExceptionCode($exception_code);
|
||||||
|
}
|
||||||
|
$this->assertEquals(
|
||||||
|
$expected,
|
||||||
|
\CoreLibs\Combined\DateTime::compareDate($input_a, $input_b)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Undocumented function
|
* Undocumented function
|
||||||
*
|
*
|
||||||
@@ -466,6 +887,37 @@ final class CoreLibsCombinedDateTimeTest extends TestCase
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @covers ::compareDateTime
|
||||||
|
* @dataProvider dateTimeCompareProvider
|
||||||
|
* @testdox compareDateTime $input_a compared to $input_b will be $expected [$_dataName]
|
||||||
|
*
|
||||||
|
* @param string $input_a
|
||||||
|
* @param string $input_b
|
||||||
|
* @param int|bool $expected
|
||||||
|
* @param string|null $exception
|
||||||
|
* @param int|null $exception_code
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testCompareDateTime(
|
||||||
|
string $input_a,
|
||||||
|
string $input_b,
|
||||||
|
int|bool $expected,
|
||||||
|
?string $exception,
|
||||||
|
?int $exception_code
|
||||||
|
): void {
|
||||||
|
if ($expected === false) {
|
||||||
|
$this->expectException($exception);
|
||||||
|
$this->expectExceptionCode($exception_code);
|
||||||
|
}
|
||||||
|
$this->assertEquals(
|
||||||
|
$expected,
|
||||||
|
\CoreLibs\Combined\DateTime::compareDateTime($input_a, $input_b)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Undocumented function
|
* Undocumented function
|
||||||
*
|
*
|
||||||
@@ -520,214 +972,6 @@ final class CoreLibsCombinedDateTimeTest extends TestCase
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Undocumented function
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function dateRangeHasWeekendProvider(): array
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'no weekend' => [
|
|
||||||
'2023-07-03',
|
|
||||||
'2023-07-04',
|
|
||||||
false
|
|
||||||
],
|
|
||||||
'start weekend sat' => [
|
|
||||||
'2023-07-01',
|
|
||||||
'2023-07-04',
|
|
||||||
true
|
|
||||||
],
|
|
||||||
'start weekend sun' => [
|
|
||||||
'2023-07-02',
|
|
||||||
'2023-07-04',
|
|
||||||
true
|
|
||||||
],
|
|
||||||
'end weekend sat' => [
|
|
||||||
'2023-07-03',
|
|
||||||
'2023-07-08',
|
|
||||||
true
|
|
||||||
],
|
|
||||||
'end weekend sun' => [
|
|
||||||
'2023-07-03',
|
|
||||||
'2023-07-09',
|
|
||||||
true
|
|
||||||
],
|
|
||||||
'long period > 6 days' => [
|
|
||||||
'2023-07-03',
|
|
||||||
'2023-07-27',
|
|
||||||
true
|
|
||||||
]
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* date string convert test
|
|
||||||
*
|
|
||||||
* @covers ::dateStringFormat
|
|
||||||
* @dataProvider timestampProvider
|
|
||||||
* @testdox dateStringFormat $input (microtime $flag) will be $expected [$_dataName]
|
|
||||||
*
|
|
||||||
* @param int|float $input
|
|
||||||
* @param bool $flag
|
|
||||||
* @param string $expected
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function testDateStringFormat(
|
|
||||||
$input,
|
|
||||||
bool $flag_show_micro,
|
|
||||||
bool $flag_micro_as_float,
|
|
||||||
string $expected
|
|
||||||
): void {
|
|
||||||
$this->assertEquals(
|
|
||||||
$expected,
|
|
||||||
\CoreLibs\Combined\DateTime::dateStringFormat(
|
|
||||||
$input,
|
|
||||||
$flag_show_micro,
|
|
||||||
$flag_micro_as_float
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* interval convert test
|
|
||||||
*
|
|
||||||
* @covers ::timeStringFormat
|
|
||||||
* @dataProvider intervalProvider
|
|
||||||
* @testdox timeStringFormat $input (microtime $flag) will be $expected [$_dataName]
|
|
||||||
*
|
|
||||||
* @param int|float $input
|
|
||||||
* @param bool $flag
|
|
||||||
* @param string $expected
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function testTimeStringFormat($input, bool $flag, string $expected): void
|
|
||||||
{
|
|
||||||
$this->assertEquals(
|
|
||||||
$expected,
|
|
||||||
\CoreLibs\Combined\DateTime::timeStringFormat($input, $flag)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Undocumented function
|
|
||||||
*
|
|
||||||
* @covers ::stringToTime
|
|
||||||
* @dataProvider reverseIntervalProvider
|
|
||||||
* @testdox stringToTime $input will be $expected [$_dataName]
|
|
||||||
*
|
|
||||||
* @param string|int|float $input
|
|
||||||
* @param string|int|float $expected
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function testStringToTime($input, $expected): void
|
|
||||||
{
|
|
||||||
$this->assertEquals(
|
|
||||||
$expected,
|
|
||||||
\CoreLibs\Combined\DateTime::stringToTime($input)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Undocumented function
|
|
||||||
*
|
|
||||||
* @covers ::checkDate
|
|
||||||
* @dataProvider dateProvider
|
|
||||||
* @testdox checkDate $input will be $expected [$_dataName]
|
|
||||||
*
|
|
||||||
* @param string $input
|
|
||||||
* @param bool $expected
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function testCheckDate(string $input, bool $expected): void
|
|
||||||
{
|
|
||||||
$this->assertEquals(
|
|
||||||
$expected,
|
|
||||||
\CoreLibs\Combined\DateTime::checkDate($input)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Undocumented function
|
|
||||||
*
|
|
||||||
* @covers ::checkDateTime
|
|
||||||
* @dataProvider dateTimeProvider
|
|
||||||
* @testdox checkDateTime $input will be $expected [$_dataName]
|
|
||||||
*
|
|
||||||
* @param string $input
|
|
||||||
* @param bool $expected
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function testCheckDateTime(string $input, bool $expected): void
|
|
||||||
{
|
|
||||||
$this->assertEquals(
|
|
||||||
$expected,
|
|
||||||
\CoreLibs\Combined\DateTime::checkDateTime($input)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Undocumented function
|
|
||||||
*
|
|
||||||
* @covers ::compareDate
|
|
||||||
* @dataProvider dateCompareProvider
|
|
||||||
* @testdox compareDate $input_a compared to $input_b will be $expected [$_dataName]
|
|
||||||
*
|
|
||||||
* @param string $input_a
|
|
||||||
* @param string $input_b
|
|
||||||
* @param int|bool $expected
|
|
||||||
* @param string|null $exception
|
|
||||||
* @param int|null $exception_code
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function testCompareDate(
|
|
||||||
string $input_a,
|
|
||||||
string $input_b,
|
|
||||||
int|bool $expected,
|
|
||||||
?string $exception,
|
|
||||||
?int $exception_code
|
|
||||||
): void {
|
|
||||||
if ($expected === false) {
|
|
||||||
$this->expectException($exception);
|
|
||||||
$this->expectExceptionCode($exception_code);
|
|
||||||
}
|
|
||||||
$this->assertEquals(
|
|
||||||
$expected,
|
|
||||||
\CoreLibs\Combined\DateTime::compareDate($input_a, $input_b)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Undocumented function
|
|
||||||
*
|
|
||||||
* @covers ::compareDateTime
|
|
||||||
* @dataProvider dateTimeCompareProvider
|
|
||||||
* @testdox compareDateTime $input_a compared to $input_b will be $expected [$_dataName]
|
|
||||||
*
|
|
||||||
* @param string $input_a
|
|
||||||
* @param string $input_b
|
|
||||||
* @param int|bool $expected
|
|
||||||
* @param string|null $exception
|
|
||||||
* @param int|null $exception_code
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function testCompareDateTime(
|
|
||||||
string $input_a,
|
|
||||||
string $input_b,
|
|
||||||
int|bool $expected,
|
|
||||||
?string $exception,
|
|
||||||
?int $exception_code
|
|
||||||
): void {
|
|
||||||
if ($expected === false) {
|
|
||||||
$this->expectException($exception);
|
|
||||||
$this->expectExceptionCode($exception_code);
|
|
||||||
}
|
|
||||||
$this->assertEquals(
|
|
||||||
$expected,
|
|
||||||
\CoreLibs\Combined\DateTime::compareDateTime($input_a, $input_b)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Undocumented function
|
* Undocumented function
|
||||||
*
|
*
|
||||||
@@ -906,6 +1150,47 @@ final class CoreLibsCombinedDateTimeTest extends TestCase
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function dateRangeHasWeekendProvider(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'no weekend' => [
|
||||||
|
'2023-07-03',
|
||||||
|
'2023-07-04',
|
||||||
|
false
|
||||||
|
],
|
||||||
|
'start weekend sat' => [
|
||||||
|
'2023-07-01',
|
||||||
|
'2023-07-04',
|
||||||
|
true
|
||||||
|
],
|
||||||
|
'start weekend sun' => [
|
||||||
|
'2023-07-02',
|
||||||
|
'2023-07-04',
|
||||||
|
true
|
||||||
|
],
|
||||||
|
'end weekend sat' => [
|
||||||
|
'2023-07-03',
|
||||||
|
'2023-07-08',
|
||||||
|
true
|
||||||
|
],
|
||||||
|
'end weekend sun' => [
|
||||||
|
'2023-07-03',
|
||||||
|
'2023-07-09',
|
||||||
|
true
|
||||||
|
],
|
||||||
|
'long period > 6 days' => [
|
||||||
|
'2023-07-03',
|
||||||
|
'2023-07-27',
|
||||||
|
true
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Undocumented function
|
* Undocumented function
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -253,7 +253,8 @@ final class CoreLibsConvertByteTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testHumanReadableByteFormatException(int $flag): void
|
public function testHumanReadableByteFormatException(int $flag): void
|
||||||
{
|
{
|
||||||
$this->expectException(\Exception::class);
|
$this->expectException(\InvalidArgumentException::class);
|
||||||
|
$this->expectExceptionCode(1);
|
||||||
\CoreLibs\Convert\Byte::humanReadableByteFormat(12, $flag);
|
\CoreLibs\Convert\Byte::humanReadableByteFormat(12, $flag);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -272,7 +273,8 @@ final class CoreLibsConvertByteTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testStringByteFormatException(int $flag): void
|
public function testStringByteFormatException(int $flag): void
|
||||||
{
|
{
|
||||||
$this->expectException(\Exception::class);
|
$this->expectException(\InvalidArgumentException::class);
|
||||||
|
$this->expectExceptionCode(1);
|
||||||
\CoreLibs\Convert\Byte::stringByteFormat(12, $flag);
|
\CoreLibs\Convert\Byte::stringByteFormat(12, $flag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,15 +33,14 @@ final class CoreLibsConvertMimeEncodeTest extends TestCase
|
|||||||
'The quick brown fox jumps over the lazy sheep that sleeps in the ravine '
|
'The quick brown fox jumps over the lazy sheep that sleeps in the ravine '
|
||||||
. 'and has no idea what is going on here',
|
. 'and has no idea what is going on here',
|
||||||
'UTF-8',
|
'UTF-8',
|
||||||
'The quick brown fox jumps over the lazy sheep that sleeps in the ravine '
|
"The quick brown fox jumps over the lazy sheep that sleeps in the ravine and\r\n"
|
||||||
. 'and has no idea what is going on here'
|
. ' has no idea what is going on here'
|
||||||
],
|
],
|
||||||
'standard with special chars UTF-8' => [
|
'standard with special chars UTF-8' => [
|
||||||
'This is ümläßtと漢字もカタカナ!!^$%&',
|
'This is ümläßtと漢字もカタカナ!!^$%&',
|
||||||
'UTF-8',
|
'UTF-8',
|
||||||
'This is =?UTF-8?B?w7xtbMOkw59044Go5ryi5a2X44KC44Kr44K/44Kr44OK77yBIV4k?='
|
"This is =?UTF-8?B?w7xtbMOkw59044Go5ryi5a2X44KC44Kr44K/44Kr44OK77yBIV4k?=\r\n"
|
||||||
. "\r\n"
|
. ' =?UTF-8?B?JSY=?='
|
||||||
. ' =?UTF-8?B?JQ==?=&'
|
|
||||||
],
|
],
|
||||||
'35 chars and space at the end UTF-8' => [
|
'35 chars and space at the end UTF-8' => [
|
||||||
'12345678901234567890123456789012345 '
|
'12345678901234567890123456789012345 '
|
||||||
@@ -62,9 +61,8 @@ final class CoreLibsConvertMimeEncodeTest extends TestCase
|
|||||||
. 'is there a space?',
|
. 'is there a space?',
|
||||||
'UTF-8',
|
'UTF-8',
|
||||||
"=?UTF-8?B?44Kr44K/44Kr44OK44Kr44K/44Kr44OK44GL44Gq44Kr44K/44Kr44OK44Kr?=\r\n"
|
"=?UTF-8?B?44Kr44K/44Kr44OK44Kr44K/44Kr44OK44GL44Gq44Kr44K/44Kr44OK44Kr?=\r\n"
|
||||||
. " =?UTF-8?B?44K/44Kr44OK?=\r\n"
|
. " =?UTF-8?B?44K/44Kr44OK44GL44Gq44Kr44K/44Kr44OK44Kr44K/44Kr44OK44GL44Gq?=\r\n"
|
||||||
. " =?UTF-8?B?44GL44Gq44Kr44K/44Kr44OK44Kr44K/44Kr44OK44GL44Gq44Kr44K/44Kr?=\r\n"
|
. " =?UTF-8?B?44Kr44K/44Kr44OK44Kr44K/IGlzIHRoZXJlIGEgc3BhY2U/?="
|
||||||
. " =?UTF-8?B?44OK44Kr44K/?= is there a =?UTF-8?B?c3BhY2U/?="
|
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
@@ -85,16 +83,28 @@ final class CoreLibsConvertMimeEncodeTest extends TestCase
|
|||||||
// print "MIME: -" . $encoded . "-\n";
|
// print "MIME: -" . $encoded . "-\n";
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
$expected,
|
$expected,
|
||||||
$encoded
|
$encoded,
|
||||||
|
"__mbMimeEncode"
|
||||||
);
|
);
|
||||||
$decoded = mb_decode_mimeheader($encoded);
|
$decoded = mb_decode_mimeheader($encoded);
|
||||||
// print "INPUT : " . $input . "\n";
|
// print "ENCODED: " . $encoded . "\n";
|
||||||
// print "DECODED: " . $decoded . "\n";
|
// print "INPUT : " . $input . " | " . mb_strlen($input) . "\n";
|
||||||
|
// print "DECODED: " . $decoded . " | " . mb_strlen($decoded) . "\n";
|
||||||
|
// $test_enc = mb_encode_mimeheader($input, $encoding);
|
||||||
|
// $test_dec = mb_decode_mimeheader($test_enc);
|
||||||
|
// print "TEST ENC: " . $test_enc . "\n";
|
||||||
// back compare decoded
|
// back compare decoded
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
$input,
|
$input,
|
||||||
$decoded
|
$decoded,
|
||||||
|
"mb_decode_mimeheader"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// $this->assertEquals(
|
||||||
|
// $input,
|
||||||
|
// $test_dec,
|
||||||
|
// 'mb_encode_to_decode'
|
||||||
|
// );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -256,6 +256,80 @@ final class CoreLibsConvertStringsTest extends TestCase
|
|||||||
$output
|
$output
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* provider for testStripMultiplePathSlashes
|
||||||
|
*
|
||||||
|
* @return array<mixed>
|
||||||
|
*/
|
||||||
|
public function stripMultiplePathSlashesProvider(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'no slahses' => [
|
||||||
|
'input' => 'string_abc',
|
||||||
|
'expected' => 'string_abc',
|
||||||
|
],
|
||||||
|
'one slash' => [
|
||||||
|
'input' => 'some/foo',
|
||||||
|
'expected' => 'some/foo',
|
||||||
|
],
|
||||||
|
'two slashes' => [
|
||||||
|
'input' => 'some//foo',
|
||||||
|
'expected' => 'some/foo',
|
||||||
|
],
|
||||||
|
'three slashes' => [
|
||||||
|
'input' => 'some///foo',
|
||||||
|
'expected' => 'some/foo',
|
||||||
|
],
|
||||||
|
'slashes in front' => [
|
||||||
|
'input' => '/foo',
|
||||||
|
'expected' => '/foo',
|
||||||
|
],
|
||||||
|
'two slashes in front' => [
|
||||||
|
'input' => '//foo',
|
||||||
|
'expected' => '/foo',
|
||||||
|
],
|
||||||
|
'thee slashes in front' => [
|
||||||
|
'input' => '///foo',
|
||||||
|
'expected' => '/foo',
|
||||||
|
],
|
||||||
|
'slashes in back' => [
|
||||||
|
'input' => 'foo/',
|
||||||
|
'expected' => 'foo/',
|
||||||
|
],
|
||||||
|
'two slashes in back' => [
|
||||||
|
'input' => 'foo//',
|
||||||
|
'expected' => 'foo/',
|
||||||
|
],
|
||||||
|
'thee slashes in back' => [
|
||||||
|
'input' => 'foo///',
|
||||||
|
'expected' => 'foo/',
|
||||||
|
],
|
||||||
|
'multiple slashes' => [
|
||||||
|
'input' => '/foo//bar///string/end_times',
|
||||||
|
'expected' => '/foo/bar/string/end_times',
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test multiple slashes clean up
|
||||||
|
*
|
||||||
|
* @covers ::stripMultiplePathSlashes
|
||||||
|
* @dataProvider stripMultiplePathSlashesProvider
|
||||||
|
* @testdox stripMultiplePathSlashes $input will be $expected [$_dataName]
|
||||||
|
*
|
||||||
|
* @param string $input
|
||||||
|
* @param string $expected
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testStripMultiplePathSlashes(string $input, string $expected): void
|
||||||
|
{
|
||||||
|
$this->assertEquals(
|
||||||
|
$expected,
|
||||||
|
\CoreLibs\Convert\Strings::stripMultiplePathSlashes($input)
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// __END__
|
// __END__
|
||||||
|
|||||||
@@ -232,7 +232,7 @@ final class CoreLibsDBIOTest extends TestCase
|
|||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
$error,
|
$error,
|
||||||
$last_error,
|
$last_error,
|
||||||
'Assert query warning'
|
'Assert query error'
|
||||||
);
|
);
|
||||||
return [$last_warning, $last_error];
|
return [$last_warning, $last_error];
|
||||||
}
|
}
|
||||||
@@ -251,8 +251,6 @@ final class CoreLibsDBIOTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testDbVersion(): void
|
public function testDbVersion(): void
|
||||||
{
|
{
|
||||||
// self::$log->setLogLevelAll('debug', true);
|
|
||||||
// self::$log->setLogLevelAll('print', true);
|
|
||||||
$db = new \CoreLibs\DB\IO(
|
$db = new \CoreLibs\DB\IO(
|
||||||
self::$db_config['valid'],
|
self::$db_config['valid'],
|
||||||
self::$log
|
self::$log
|
||||||
@@ -276,8 +274,6 @@ final class CoreLibsDBIOTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testDbVersionNumeric(): void
|
public function testDbVersionNumeric(): void
|
||||||
{
|
{
|
||||||
// self::$log->setLogLevelAll('debug', true);
|
|
||||||
// self::$log->setLogLevelAll('print', true);
|
|
||||||
$db = new \CoreLibs\DB\IO(
|
$db = new \CoreLibs\DB\IO(
|
||||||
self::$db_config['valid'],
|
self::$db_config['valid'],
|
||||||
self::$log
|
self::$log
|
||||||
@@ -306,8 +302,6 @@ final class CoreLibsDBIOTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testDbVersionInfoParameters(): void
|
public function testDbVersionInfoParameters(): void
|
||||||
{
|
{
|
||||||
// self::$log->setLogLevelAll('debug', true);
|
|
||||||
// self::$log->setLogLevelAll('print', true);
|
|
||||||
$db = new \CoreLibs\DB\IO(
|
$db = new \CoreLibs\DB\IO(
|
||||||
self::$db_config['valid'],
|
self::$db_config['valid'],
|
||||||
self::$log
|
self::$log
|
||||||
@@ -365,8 +359,6 @@ final class CoreLibsDBIOTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testDbVersionInfo(string $parameter, string $expected): void
|
public function testDbVersionInfo(string $parameter, string $expected): void
|
||||||
{
|
{
|
||||||
// self::$log->setLogLevelAll('debug', true);
|
|
||||||
// self::$log->setLogLevelAll('print', true);
|
|
||||||
$db = new \CoreLibs\DB\IO(
|
$db = new \CoreLibs\DB\IO(
|
||||||
self::$db_config['valid'],
|
self::$db_config['valid'],
|
||||||
self::$log
|
self::$log
|
||||||
@@ -1592,8 +1584,6 @@ final class CoreLibsDBIOTest extends TestCase
|
|||||||
string $error,
|
string $error,
|
||||||
bool $run_many_times = false
|
bool $run_many_times = false
|
||||||
): void {
|
): void {
|
||||||
// self::$log->setLogLevelAll('debug', true);
|
|
||||||
// self::$log->setLogLevelAll('print', true);
|
|
||||||
$db = new \CoreLibs\DB\IO(
|
$db = new \CoreLibs\DB\IO(
|
||||||
self::$db_config['valid'],
|
self::$db_config['valid'],
|
||||||
self::$log
|
self::$log
|
||||||
@@ -1832,8 +1822,6 @@ final class CoreLibsDBIOTest extends TestCase
|
|||||||
string $error,
|
string $error,
|
||||||
string $insert_data
|
string $insert_data
|
||||||
): void {
|
): void {
|
||||||
// self::$log->setLogLevelAll('debug', true);
|
|
||||||
// self::$log->setLogLevelAll('print', true);
|
|
||||||
$db = new \CoreLibs\DB\IO(
|
$db = new \CoreLibs\DB\IO(
|
||||||
self::$db_config['valid'],
|
self::$db_config['valid'],
|
||||||
self::$log
|
self::$log
|
||||||
@@ -2002,8 +1990,6 @@ final class CoreLibsDBIOTest extends TestCase
|
|||||||
string $error,
|
string $error,
|
||||||
string $insert_data
|
string $insert_data
|
||||||
): void {
|
): void {
|
||||||
// self::$log->setLogLevelAll('debug', true);
|
|
||||||
// self::$log->setLogLevelAll('print', true);
|
|
||||||
$db = new \CoreLibs\DB\IO(
|
$db = new \CoreLibs\DB\IO(
|
||||||
self::$db_config['valid'],
|
self::$db_config['valid'],
|
||||||
self::$log
|
self::$log
|
||||||
@@ -3069,8 +3055,6 @@ final class CoreLibsDBIOTest extends TestCase
|
|||||||
string $error,
|
string $error,
|
||||||
string $insert_data
|
string $insert_data
|
||||||
): void {
|
): void {
|
||||||
// self::$log->setLogLevelAll('debug', true);
|
|
||||||
// self::$log->setLogLevelAll('print', true);
|
|
||||||
$db = new \CoreLibs\DB\IO(
|
$db = new \CoreLibs\DB\IO(
|
||||||
self::$db_config['valid'],
|
self::$db_config['valid'],
|
||||||
self::$log
|
self::$log
|
||||||
@@ -3465,7 +3449,7 @@ final class CoreLibsDBIOTest extends TestCase
|
|||||||
$read_query,
|
$read_query,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
//
|
// warning: 20
|
||||||
true, '20', '',
|
true, '20', '',
|
||||||
//
|
//
|
||||||
'result', '', '',
|
'result', '', '',
|
||||||
@@ -3482,6 +3466,31 @@ final class CoreLibsDBIOTest extends TestCase
|
|||||||
'returning_id' => false,
|
'returning_id' => false,
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
|
// prepare with different statement name
|
||||||
|
'prepare query with same statement name, different query' => [
|
||||||
|
'double_error',
|
||||||
|
$read_query,
|
||||||
|
// primary key
|
||||||
|
null,
|
||||||
|
// arguments (none)
|
||||||
|
null,
|
||||||
|
// expected return false, warning: no, error: 26
|
||||||
|
false, '', '26',
|
||||||
|
// return expected, warning, error
|
||||||
|
'', '', '',
|
||||||
|
// dummy query for second prepare with wrong query
|
||||||
|
$read_query . ' WHERE uid = $3',
|
||||||
|
[],
|
||||||
|
//
|
||||||
|
$insert_query,
|
||||||
|
//
|
||||||
|
[
|
||||||
|
'pk_name' => '',
|
||||||
|
'count' => 0,
|
||||||
|
'query' => 'SELECT row_int, uid FROM table_with_primary_key',
|
||||||
|
'returning_id' => false,
|
||||||
|
],
|
||||||
|
],
|
||||||
// insert wrong data count compared to needed (execute 23)
|
// insert wrong data count compared to needed (execute 23)
|
||||||
'wrong parmeter count' => [
|
'wrong parmeter count' => [
|
||||||
'wrong_param_count',
|
'wrong_param_count',
|
||||||
@@ -3554,8 +3563,6 @@ final class CoreLibsDBIOTest extends TestCase
|
|||||||
string $insert_data,
|
string $insert_data,
|
||||||
array $prepare_cursor,
|
array $prepare_cursor,
|
||||||
): void {
|
): void {
|
||||||
// self::$log->setLogLevelAll('debug', true);
|
|
||||||
// self::$log->setLogLevelAll('print', true);
|
|
||||||
$db = new \CoreLibs\DB\IO(
|
$db = new \CoreLibs\DB\IO(
|
||||||
self::$db_config['valid'],
|
self::$db_config['valid'],
|
||||||
self::$log
|
self::$log
|
||||||
@@ -3575,6 +3582,9 @@ final class CoreLibsDBIOTest extends TestCase
|
|||||||
$db->dbPrepare($stm_name, $query) :
|
$db->dbPrepare($stm_name, $query) :
|
||||||
$db->dbPrepare($stm_name, $query, $pk_name);
|
$db->dbPrepare($stm_name, $query, $pk_name);
|
||||||
}
|
}
|
||||||
|
if ($error_prepare == '26') {
|
||||||
|
$prepare_result = $db->dbPrepare($stm_name, $expected_data_query);
|
||||||
|
}
|
||||||
// if result type, or if forced bool
|
// if result type, or if forced bool
|
||||||
if (is_string($expected_prepare) && $expected_prepare == 'result') {
|
if (is_string($expected_prepare) && $expected_prepare == 'result') {
|
||||||
// if PHP or newer, must be Object PgSql\Result
|
// if PHP or newer, must be Object PgSql\Result
|
||||||
@@ -3597,66 +3607,68 @@ final class CoreLibsDBIOTest extends TestCase
|
|||||||
|
|
||||||
// for non fail prepare test exec
|
// for non fail prepare test exec
|
||||||
// check test result
|
// check test result
|
||||||
$execute_result = $query_data === null ?
|
if (!$error_prepare) {
|
||||||
$db->dbExecute($stm_name) :
|
$execute_result = $query_data === null ?
|
||||||
$db->dbExecute($stm_name, $query_data);
|
$db->dbExecute($stm_name) :
|
||||||
if ($expected_execute == 'result') {
|
$db->dbExecute($stm_name, $query_data);
|
||||||
// if PHP or newer, must be Object PgSql\Result
|
if ($expected_execute == 'result') {
|
||||||
$this->assertIsObject(
|
// if PHP or newer, must be Object PgSql\Result
|
||||||
$execute_result
|
$this->assertIsObject(
|
||||||
);
|
$execute_result
|
||||||
// also check that this is correct instance type
|
);
|
||||||
$this->assertInstanceOf(
|
// also check that this is correct instance type
|
||||||
'PgSql\Result',
|
$this->assertInstanceOf(
|
||||||
$execute_result
|
'PgSql\Result',
|
||||||
);
|
$execute_result
|
||||||
// if this is an select use dbFetchArray to get data and test
|
);
|
||||||
} else {
|
// if this is an select use dbFetchArray to get data and test
|
||||||
$this->assertEquals(
|
} else {
|
||||||
$expected_execute,
|
$this->assertEquals(
|
||||||
$execute_result
|
$expected_execute,
|
||||||
);
|
$execute_result
|
||||||
}
|
);
|
||||||
// error/warning check
|
}
|
||||||
$this->subAssertErrorTest($db, $warning_execute, $error_execute);
|
// error/warning check
|
||||||
// now check test result if expected return is result
|
$this->subAssertErrorTest($db, $warning_execute, $error_execute);
|
||||||
if (
|
// now check test result if expected return is result
|
||||||
$expected_execute == 'result' &&
|
if (
|
||||||
!empty($expected_data_query)
|
$expected_execute == 'result' &&
|
||||||
) {
|
!empty($expected_data_query)
|
||||||
// $expected_data_query
|
) {
|
||||||
// $expected_data
|
// $expected_data_query
|
||||||
$rows = $db->dbReturnArray($expected_data_query);
|
// $expected_data
|
||||||
$this->assertEquals(
|
$rows = $db->dbReturnArray($expected_data_query);
|
||||||
$expected_data,
|
$this->assertEquals(
|
||||||
$rows
|
$expected_data,
|
||||||
);
|
$rows
|
||||||
}
|
);
|
||||||
if (
|
}
|
||||||
$expected_execute == 'result' &&
|
if (
|
||||||
$execute_result !== false &&
|
$expected_execute == 'result' &&
|
||||||
empty($expected_data_query) &&
|
$execute_result !== false &&
|
||||||
count($expected_data)
|
empty($expected_data_query) &&
|
||||||
) {
|
count($expected_data)
|
||||||
// compare previously read data to compare data
|
) {
|
||||||
$compare_data = [];
|
// compare previously read data to compare data
|
||||||
// read in the query data
|
$compare_data = [];
|
||||||
while (is_array($row = $db->dbFetchArray($execute_result, true))) {
|
// read in the query data
|
||||||
$compare_data[] = $row;
|
while (is_array($row = $db->dbFetchArray($execute_result, true))) {
|
||||||
|
$compare_data[] = $row;
|
||||||
|
}
|
||||||
|
$this->assertEquals(
|
||||||
|
$expected_data,
|
||||||
|
$compare_data
|
||||||
|
);
|
||||||
}
|
}
|
||||||
$this->assertEquals(
|
|
||||||
$expected_data,
|
|
||||||
$compare_data
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// check dbGetPrepareCursorValue
|
// check dbGetPrepareCursorValue
|
||||||
foreach (['pk_name', 'count', 'query', 'returning_id'] as $key) {
|
foreach (['pk_name', 'count', 'query', 'returning_id'] as $key) {
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
$prepare_cursor[$key],
|
$prepare_cursor[$key],
|
||||||
$db->dbGetPrepareCursorValue($stm_name, $key),
|
$db->dbGetPrepareCursorValue($stm_name, $key),
|
||||||
'Prepared cursor: ' . $key . ': failed assertion'
|
'Prepared cursor: ' . $key . ': failed assertion'
|
||||||
);
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// reset all data
|
// reset all data
|
||||||
@@ -3844,8 +3856,6 @@ final class CoreLibsDBIOTest extends TestCase
|
|||||||
string $expected_get_var,
|
string $expected_get_var,
|
||||||
string $expected_get_db
|
string $expected_get_db
|
||||||
): void {
|
): void {
|
||||||
// self::$log->setLogLevelAll('debug', true);
|
|
||||||
// self::$log->setLogLevelAll('print', true);
|
|
||||||
$db = new \CoreLibs\DB\IO(
|
$db = new \CoreLibs\DB\IO(
|
||||||
self::$db_config[$connection],
|
self::$db_config[$connection],
|
||||||
self::$log
|
self::$log
|
||||||
@@ -3910,7 +3920,10 @@ final class CoreLibsDBIOTest extends TestCase
|
|||||||
// 'main::run::run::run::run::run::run::run::runBare::runTest::testDbErrorHandling::dbSetMaxQueryCall
|
// 'main::run::run::run::run::run::run::run::runBare::runTest::testDbErrorHandling::dbSetMaxQueryCall
|
||||||
'source' => "/^(include::)?main::(run::)+runBare::runTest::testDbErrorHandling::dbSetMaxQueryCall$/",
|
'source' => "/^(include::)?main::(run::)+runBare::runTest::testDbErrorHandling::dbSetMaxQueryCall$/",
|
||||||
'pg_error' => '',
|
'pg_error' => '',
|
||||||
'msg' => '',
|
'message' => '',
|
||||||
|
'context' => [
|
||||||
|
'max_calls' => 0
|
||||||
|
]
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
'trigger warning' => [
|
'trigger warning' => [
|
||||||
@@ -3943,8 +3956,6 @@ final class CoreLibsDBIOTest extends TestCase
|
|||||||
string $error_id,
|
string $error_id,
|
||||||
array $expected_history
|
array $expected_history
|
||||||
): void {
|
): void {
|
||||||
// self::$log->setLogLevelAll('debug', true);
|
|
||||||
// self::$log->setLogLevelAll('print', true);
|
|
||||||
$db = new \CoreLibs\DB\IO(
|
$db = new \CoreLibs\DB\IO(
|
||||||
self::$db_config['valid'],
|
self::$db_config['valid'],
|
||||||
self::$log
|
self::$log
|
||||||
@@ -3970,7 +3981,7 @@ final class CoreLibsDBIOTest extends TestCase
|
|||||||
foreach ($expected_history as $key => $value) {
|
foreach ($expected_history as $key => $value) {
|
||||||
// check if starts with / because this is regex (timestamp)
|
// check if starts with / because this is regex (timestamp)
|
||||||
// if (substr($expected_2, 0, 1) == '/) {
|
// if (substr($expected_2, 0, 1) == '/) {
|
||||||
if (strpos($value, '/') === 0) {
|
if (!is_array($value) && strpos($value, '/') === 0) {
|
||||||
// this is regex
|
// this is regex
|
||||||
$this->assertMatchesRegularExpression(
|
$this->assertMatchesRegularExpression(
|
||||||
$value,
|
$value,
|
||||||
@@ -4058,8 +4069,6 @@ final class CoreLibsDBIOTest extends TestCase
|
|||||||
bool $expected_set_flag,
|
bool $expected_set_flag,
|
||||||
string $expected_get_encoding
|
string $expected_get_encoding
|
||||||
): void {
|
): void {
|
||||||
// self::$log->setLogLevelAll('debug', true);
|
|
||||||
// self::$log->setLogLevelAll('print', true);
|
|
||||||
$db = new \CoreLibs\DB\IO(
|
$db = new \CoreLibs\DB\IO(
|
||||||
self::$db_config[$connection],
|
self::$db_config[$connection],
|
||||||
self::$log
|
self::$log
|
||||||
@@ -4141,8 +4150,6 @@ final class CoreLibsDBIOTest extends TestCase
|
|||||||
?string $encoding_php,
|
?string $encoding_php,
|
||||||
string $text
|
string $text
|
||||||
): void {
|
): void {
|
||||||
// self::$log->setLogLevelAll('debug', true);
|
|
||||||
// self::$log->setLogLevelAll('print', true);
|
|
||||||
$db = new \CoreLibs\DB\IO(
|
$db = new \CoreLibs\DB\IO(
|
||||||
self::$db_config[$connection],
|
self::$db_config[$connection],
|
||||||
self::$log
|
self::$log
|
||||||
@@ -4272,8 +4279,6 @@ final class CoreLibsDBIOTest extends TestCase
|
|||||||
string $table,
|
string $table,
|
||||||
string $primary_key
|
string $primary_key
|
||||||
): void {
|
): void {
|
||||||
// self::$log->setLogLevelAll('debug', true);
|
|
||||||
// self::$log->setLogLevelAll('print', true);
|
|
||||||
$db = new \CoreLibs\DB\IO(
|
$db = new \CoreLibs\DB\IO(
|
||||||
self::$db_config['valid'],
|
self::$db_config['valid'],
|
||||||
self::$log
|
self::$log
|
||||||
@@ -4330,7 +4335,7 @@ final class CoreLibsDBIOTest extends TestCase
|
|||||||
// NOTE if there are different INSERTS before the primary keys
|
// NOTE if there are different INSERTS before the primary keys
|
||||||
// will not match anymore. Must be updated by hand
|
// will not match anymore. Must be updated by hand
|
||||||
// IMPORTANT: if this is stand alone the primary key will not match and fail
|
// IMPORTANT: if this is stand alone the primary key will not match and fail
|
||||||
$table_with_primary_key_id = 68;
|
$table_with_primary_key_id = 70;
|
||||||
// 0: query + returning
|
// 0: query + returning
|
||||||
// 1: params
|
// 1: params
|
||||||
// 1: pk name for db exec
|
// 1: pk name for db exec
|
||||||
@@ -4530,8 +4535,6 @@ final class CoreLibsDBIOTest extends TestCase
|
|||||||
array|string|int|null $expected_ret_ext,
|
array|string|int|null $expected_ret_ext,
|
||||||
array $expected_ret_arr
|
array $expected_ret_arr
|
||||||
): void {
|
): void {
|
||||||
// self::$log->setLogLevelAll('debug', true);
|
|
||||||
// self::$log->setLogLevelAll('print', true);
|
|
||||||
$db = new \CoreLibs\DB\IO(
|
$db = new \CoreLibs\DB\IO(
|
||||||
self::$db_config['valid'],
|
self::$db_config['valid'],
|
||||||
self::$log
|
self::$log
|
||||||
@@ -4875,8 +4878,6 @@ final class CoreLibsDBIOTest extends TestCase
|
|||||||
array $expected_col_names,
|
array $expected_col_names,
|
||||||
array $expected_col_types
|
array $expected_col_types
|
||||||
): void {
|
): void {
|
||||||
// self::$log->setLogLevelAll('debug', true);
|
|
||||||
// self::$log->setLogLevelAll('print', true);
|
|
||||||
$db = new \CoreLibs\DB\IO(
|
$db = new \CoreLibs\DB\IO(
|
||||||
self::$db_config['valid'],
|
self::$db_config['valid'],
|
||||||
self::$log
|
self::$log
|
||||||
@@ -5030,6 +5031,147 @@ final class CoreLibsDBIOTest extends TestCase
|
|||||||
$db->dbClose();
|
$db->dbClose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// query placeholder convert
|
||||||
|
|
||||||
|
public function queryPlaceholderReplaceProvider(): array
|
||||||
|
{
|
||||||
|
// WHERE row_varchar = $1
|
||||||
|
return [
|
||||||
|
'select, no change' => [
|
||||||
|
'query' => <<<SQL
|
||||||
|
SELECT row_varchar, row_varchar_literal, row_int, row_date
|
||||||
|
FROM table_with_primary_key
|
||||||
|
SQL,
|
||||||
|
'params' => [],
|
||||||
|
'found' => 0,
|
||||||
|
'expected_query' => '',
|
||||||
|
'expected_params' => [],
|
||||||
|
],
|
||||||
|
'select, params ?' => [
|
||||||
|
'query' => <<<SQL
|
||||||
|
SELECT row_varchar, row_varchar_literal, row_int, row_date
|
||||||
|
FROM table_with_primary_key
|
||||||
|
WHERE row_varchar = ?
|
||||||
|
SQL,
|
||||||
|
'params' => ['string a'],
|
||||||
|
'found' => 1,
|
||||||
|
'expected_query' => <<<SQL
|
||||||
|
SELECT row_varchar, row_varchar_literal, row_int, row_date
|
||||||
|
FROM table_with_primary_key
|
||||||
|
WHERE row_varchar = $1
|
||||||
|
SQL,
|
||||||
|
'expected_params' => ['string a'],
|
||||||
|
],
|
||||||
|
'select, params :' => [
|
||||||
|
'query' => <<<SQL
|
||||||
|
SELECT row_varchar, row_varchar_literal, row_int, row_date
|
||||||
|
FROM table_with_primary_key
|
||||||
|
WHERE row_varchar = :row_varchar
|
||||||
|
SQL,
|
||||||
|
'params' => [':row_varchar' => 'string a'],
|
||||||
|
'found' => 1,
|
||||||
|
'expected_query' => <<<SQL
|
||||||
|
SELECT row_varchar, row_varchar_literal, row_int, row_date
|
||||||
|
FROM table_with_primary_key
|
||||||
|
WHERE row_varchar = $1
|
||||||
|
SQL,
|
||||||
|
'expected_params' => ['string a'],
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test query string with placeholders convert
|
||||||
|
*
|
||||||
|
* @dataProvider queryPlaceholderReplaceProvider
|
||||||
|
* @testdox Query replacement test [$_dataName]
|
||||||
|
*
|
||||||
|
* @param string $query
|
||||||
|
* @param array $params
|
||||||
|
* @param string $expected_query
|
||||||
|
* @param array $expected_params
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testQueryPlaceholderReplace(
|
||||||
|
string $query,
|
||||||
|
array $params,
|
||||||
|
int $expected_found,
|
||||||
|
string $expected_query,
|
||||||
|
array $expected_params
|
||||||
|
): void {
|
||||||
|
$db = new \CoreLibs\DB\IO(
|
||||||
|
self::$db_config['valid'],
|
||||||
|
self::$log
|
||||||
|
);
|
||||||
|
$db->dbSetConvertPlaceholder(true);
|
||||||
|
//
|
||||||
|
if ($db->dbCheckQueryForSelect($query)) {
|
||||||
|
$res = $db->dbReturnRowParams($query, $params);
|
||||||
|
$converted = $db->dbGetPlaceholderConverted();
|
||||||
|
} else {
|
||||||
|
$db->dbExecParams($query, $params);
|
||||||
|
$converted = $db->dbGetPlaceholderConverted();
|
||||||
|
}
|
||||||
|
$this->assertEquals(
|
||||||
|
$expected_found,
|
||||||
|
$converted['found'],
|
||||||
|
'Found not equal'
|
||||||
|
);
|
||||||
|
$this->assertEquals(
|
||||||
|
$expected_query,
|
||||||
|
$converted['query'],
|
||||||
|
'Query not equal'
|
||||||
|
);
|
||||||
|
$this->assertEquals(
|
||||||
|
$expected_params,
|
||||||
|
$converted['params'],
|
||||||
|
'Params not equal'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test exception for placeholder convert
|
||||||
|
* -> internally converted to error
|
||||||
|
*
|
||||||
|
* @testdox Query Replace error tests
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testQueryPlaceholderReplaceException(): void
|
||||||
|
{
|
||||||
|
$db = new \CoreLibs\DB\IO(
|
||||||
|
self::$db_config['valid'],
|
||||||
|
self::$log
|
||||||
|
);
|
||||||
|
$db->dbSetConvertPlaceholder(true);
|
||||||
|
$db->dbExecParams(
|
||||||
|
<<<SQL
|
||||||
|
SELECT foo FROM bar
|
||||||
|
WHERE a = ? and b = :bname
|
||||||
|
SQL,
|
||||||
|
['a', 'b']
|
||||||
|
);
|
||||||
|
$this->assertEquals(
|
||||||
|
200,
|
||||||
|
$db->dbGetLastError()
|
||||||
|
);
|
||||||
|
|
||||||
|
// catch unset, for :names
|
||||||
|
$db->dbExecParams(
|
||||||
|
<<<SQL
|
||||||
|
SELECT foo FROM bar
|
||||||
|
WHERE a = :aname and b = :bname
|
||||||
|
SQL,
|
||||||
|
[':foo' => 'a', ':bname' => 'b']
|
||||||
|
);
|
||||||
|
$this->assertEquals(
|
||||||
|
210,
|
||||||
|
$db->dbGetLastError()
|
||||||
|
);
|
||||||
|
|
||||||
|
// TODO: other way around for to pdo
|
||||||
|
}
|
||||||
|
|
||||||
// TODO implement below checks
|
// TODO implement below checks
|
||||||
// - complex write sets
|
// - complex write sets
|
||||||
// dbWriteData, dbWriteDataExt
|
// dbWriteData, dbWriteDataExt
|
||||||
@@ -5158,8 +5300,6 @@ final class CoreLibsDBIOTest extends TestCase
|
|||||||
string $warning_final,
|
string $warning_final,
|
||||||
string $error_final
|
string $error_final
|
||||||
): void {
|
): void {
|
||||||
// self::$log->setLogLevelAll('debug', true);
|
|
||||||
// self::$log->setLogLevelAll('print', true);
|
|
||||||
$db = new \CoreLibs\DB\IO(
|
$db = new \CoreLibs\DB\IO(
|
||||||
self::$db_config['valid'],
|
self::$db_config['valid'],
|
||||||
self::$log
|
self::$log
|
||||||
|
|||||||
@@ -513,7 +513,7 @@ final class CoreLibsDebugSupportTest extends TestCase
|
|||||||
public function testGetCallerMethodList(array $expected): void
|
public function testGetCallerMethodList(array $expected): void
|
||||||
{
|
{
|
||||||
$compare = Support::getCallerMethodList();
|
$compare = Support::getCallerMethodList();
|
||||||
// 10: legact
|
// 10: legacy
|
||||||
// 11: direct
|
// 11: direct
|
||||||
// 12: full call
|
// 12: full call
|
||||||
switch (count($compare)) {
|
switch (count($compare)) {
|
||||||
@@ -571,6 +571,31 @@ final class CoreLibsDebugSupportTest extends TestCase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @cover ::getCallStack
|
||||||
|
* @testdox getCallStack check if it returns data [$_dataName]
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testGetCallStack(): void
|
||||||
|
{
|
||||||
|
$call_stack = Support::getCallStack();
|
||||||
|
// print "Get CALL: " . print_r(Support::getCallStack(), true) . "\n";
|
||||||
|
if ($call_stack < 8) {
|
||||||
|
$this->assertFalse(true, 'getCallStack too low: 8');
|
||||||
|
} else {
|
||||||
|
$this->assertTrue(true, 'getCallSteck ok');
|
||||||
|
}
|
||||||
|
// just test top entry
|
||||||
|
$first = array_shift($call_stack);
|
||||||
|
$this->assertStringEndsWith(
|
||||||
|
':tests\CoreLibsDebugSupportTest->testGetCallStack',
|
||||||
|
$first,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* test the lowest one (one above base)
|
* test the lowest one (one above base)
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -16,17 +16,89 @@ final class CoreLibsOutputImageTest extends TestCase
|
|||||||
/**
|
/**
|
||||||
* Undocumented function
|
* Undocumented function
|
||||||
*
|
*
|
||||||
* @testdox Output\Image Class tests
|
* @covers ::createThumbnail
|
||||||
|
* @testdox createThumbnail checks
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testOutputImage()
|
public function testCreateThumbnail(): void
|
||||||
{
|
{
|
||||||
// $this->assertTrue(true, 'Output Image Tests not implemented');
|
// CONVERT does not exist
|
||||||
$this->markTestIncomplete(
|
$this->expectException(\RuntimeException::class);
|
||||||
'Output\Image Tests have not yet been implemented'
|
\CoreLibs\Output\Image::createThumbnail('do_not_exist.png', 200, 200);
|
||||||
|
// set convert
|
||||||
|
$paths = [
|
||||||
|
'/bin',
|
||||||
|
'/usr/bin',
|
||||||
|
'/usr/local/bin',
|
||||||
|
];
|
||||||
|
// find convert
|
||||||
|
foreach ($paths as $path) {
|
||||||
|
if (
|
||||||
|
file_exists($path . DIRECTORY_SEPARATOR . 'convert') &&
|
||||||
|
is_file($path . DIRECTORY_SEPARATOR . 'convert')
|
||||||
|
) {
|
||||||
|
// image magick convert location
|
||||||
|
define('CONVERT', $path . DIRECTORY_SEPARATOR . 'convert');
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
unset($paths);
|
||||||
|
// cannot set dummy file
|
||||||
|
$this->expectException(\Exception::class);
|
||||||
|
\CoreLibs\Output\Image::createThumbnail('do_not_exist.png', 200, 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @covers ::createThumbnailSimple
|
||||||
|
* @testdox createThumbnailSimple checks
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testCreateThumbnailSimple(): void
|
||||||
|
{
|
||||||
|
// file does not exist
|
||||||
|
$this->expectException(\UnexpectedValueException::class);
|
||||||
|
\CoreLibs\Output\Image::createThumbnailSimple(
|
||||||
|
'do_not_exist.png',
|
||||||
|
200,
|
||||||
|
200,
|
||||||
|
cache_folder: '/tmp/',
|
||||||
|
web_folder: '/tmp/'
|
||||||
);
|
);
|
||||||
// $this->markTestSkipped('No implementation for Output\Image at the moment');
|
// cache folder is not dir
|
||||||
|
$this->expectException(\UnexpectedValueException::class);
|
||||||
|
\CoreLibs\Output\Image::createThumbnailSimple(
|
||||||
|
'do_not_exist.png',
|
||||||
|
200,
|
||||||
|
200,
|
||||||
|
cache_folder: '/foo/bar/',
|
||||||
|
web_folder: '/tmp/'
|
||||||
|
);
|
||||||
|
// target cache folder is not writeable
|
||||||
|
|
||||||
|
// RuntimeException: imagecreatetruecolor failed
|
||||||
|
// RuntimeException: imagecolorallocatealpha failed
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @covers ::correctImageOrientation
|
||||||
|
* @testdox correctImageOrientation checks
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testCorrectImageOrientation(): void
|
||||||
|
{
|
||||||
|
// test file does not exist
|
||||||
|
$this->expectException(\UnexpectedValueException::class);
|
||||||
|
\CoreLibs\Output\Image::correctImageOrientation('do_not_exist.png');
|
||||||
|
// test folder not writeable
|
||||||
|
// test exit_read_data not present (how)?
|
||||||
|
// test image rotate
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
43
README.Exceptions.md
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
# Exception rules
|
||||||
|
|
||||||
|
What exceptions to use for what
|
||||||
|
|
||||||
|
NOTE: There will be custom Excpetions creaed and so some rules will change
|
||||||
|
|
||||||
|
NOTE: For catching: always catch \Exception at the end to avoid missing some changed exceptions
|
||||||
|
|
||||||
|
NOTE: Changed exceptions will have marked as critical API change
|
||||||
|
|
||||||
|
## \Exception
|
||||||
|
|
||||||
|
if there is nothing else matching, use this one
|
||||||
|
|
||||||
|
## \InvalidArgumentException
|
||||||
|
|
||||||
|
if argument to a function is not expected type
|
||||||
|
|
||||||
|
## \UnexpectedValueException
|
||||||
|
|
||||||
|
If the value is not matching to what we expect
|
||||||
|
|
||||||
|
## \LengthException
|
||||||
|
|
||||||
|
Given value is out of range
|
||||||
|
|
||||||
|
## \RuntimeException
|
||||||
|
|
||||||
|
Missing php modules or external programs
|
||||||
|
|
||||||
|
## \OutOfRangeException
|
||||||
|
|
||||||
|
Not in range of given expression (array or other)
|
||||||
|
|
||||||
|
## Below are ERRORs
|
||||||
|
|
||||||
|
### \ArgumentCountError [ERROR]
|
||||||
|
|
||||||
|
If we have dynamic argument methods and we are missing a certain arguemnt count
|
||||||
|
|
||||||
|
### \TypeError
|
||||||
|
|
||||||
|
Invalid type
|
||||||
15
jsconfig.json
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"module": "ESNext",
|
||||||
|
"moduleResolution": "Node",
|
||||||
|
"target": "ES2020",
|
||||||
|
"jsx": "react",
|
||||||
|
"allowImportingTsExtensions": true,
|
||||||
|
"strictNullChecks": true,
|
||||||
|
"strictFunctionTypes": true
|
||||||
|
},
|
||||||
|
"exclude": [
|
||||||
|
"node_modules",
|
||||||
|
"**/node_modules/*"
|
||||||
|
]
|
||||||
|
}
|
||||||
18
phpcs.xml
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
<ruleset name="MyStandard">
|
||||||
|
<description>PSR12 override rules (strict, standard). Switch spaces indent to tab.</description>
|
||||||
|
<arg name="tab-width" value="4"/>
|
||||||
|
<rule ref="PSR1"/>
|
||||||
|
<rule ref="PSR12">
|
||||||
|
<!-- turn off white space check for tab -->
|
||||||
|
<exclude name="Generic.WhiteSpace.DisallowTabIndent"/>
|
||||||
|
</rule>
|
||||||
|
<!-- no space indent, must be tab, 4 is tab iwdth -->
|
||||||
|
<rule ref="Generic.WhiteSpace.DisallowSpaceIndent"/>
|
||||||
|
<rule ref="Generic.WhiteSpace.ScopeIndent">
|
||||||
|
<properties>
|
||||||
|
<property name="indent" value="4"/>
|
||||||
|
<property name="tabIndent" value="true"/>
|
||||||
|
</properties>
|
||||||
|
</rule>
|
||||||
|
</ruleset>
|
||||||
@@ -1 +1 @@
|
|||||||
/home/clemens/.phive/phars/phan-5.4.2.phar
|
/home/clemens/.phive/phars/phan-5.4.3.phar
|
||||||
@@ -1 +1 @@
|
|||||||
/home/clemens/.phive/phars/php-cs-fixer-3.34.1.phar
|
/home/clemens/.phive/phars/php-cs-fixer-3.53.0.phar
|
||||||
@@ -1 +1 @@
|
|||||||
/home/clemens/.phive/phars/phpdocumentor-3.4.2.phar
|
/home/clemens/.phive/phars/phpdocumentor-3.4.3.phar
|
||||||
@@ -1 +1 @@
|
|||||||
/home/clemens/.phive/phars/phpcbf-3.7.2.phar
|
/home/clemens/.phive/phars/phpcbf-3.9.1.phar
|
||||||
@@ -1 +1 @@
|
|||||||
/home/clemens/.phive/phars/phpcs-3.7.2.phar
|
/home/clemens/.phive/phars/phpcs-3.9.1.phar
|
||||||
@@ -1 +1 @@
|
|||||||
/home/clemens/.phive/phars/phpstan-1.10.37.phar
|
/home/clemens/.phive/phars/phpstan-1.10.67.phar
|
||||||
@@ -1 +1 @@
|
|||||||
/home/clemens/.phive/phars/phpunit-9.6.13.phar
|
/home/clemens/.phive/phars/phpunit-9.6.19.phar
|
||||||
@@ -1 +1 @@
|
|||||||
/home/clemens/.phive/phars/psalm-5.15.0.phar
|
/home/clemens/.phive/phars/psalm-5.23.1.phar
|
||||||
@@ -21,6 +21,7 @@ ob_end_flush();
|
|||||||
use CoreLibs\Combined\ArrayHandler;
|
use CoreLibs\Combined\ArrayHandler;
|
||||||
use CoreLibs\Debug\Support as DgS;
|
use CoreLibs\Debug\Support as DgS;
|
||||||
use CoreLibs\Convert\SetVarType;
|
use CoreLibs\Convert\SetVarType;
|
||||||
|
use PHPUnit\Framework\Constraint\ArrayHasKey;
|
||||||
|
|
||||||
$log = new CoreLibs\Logging\Logging([
|
$log = new CoreLibs\Logging\Logging([
|
||||||
'log_folder' => BASE . LOG,
|
'log_folder' => BASE . LOG,
|
||||||
@@ -236,6 +237,22 @@ $flag = false;
|
|||||||
$output = \CoreLibs\Combined\ArrayHandler::genAssocArray($db_array, $key, $value, $flag);
|
$output = \CoreLibs\Combined\ArrayHandler::genAssocArray($db_array, $key, $value, $flag);
|
||||||
print "OUTPUT: " . \CoreLibs\Debug\Support::printAr($output) . "<br>";
|
print "OUTPUT: " . \CoreLibs\Debug\Support::printAr($output) . "<br>";
|
||||||
|
|
||||||
|
|
||||||
|
print "<hr>";
|
||||||
|
$array = [
|
||||||
|
'a' => 'First',
|
||||||
|
'b' => 'Second',
|
||||||
|
'c' => 'Third',
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach (array_keys($array) as $search) {
|
||||||
|
print "Result[" . $search . "]: "
|
||||||
|
. "next: " . DgS::printAr(ArrayHandler::arrayGetNextKey($array, $search)) . ", "
|
||||||
|
. "prev: " . DgS::printAr(ArrayHandler::arrayGetPrevKey($array, $search))
|
||||||
|
. "<br>";
|
||||||
|
}
|
||||||
|
print "Key not exists: " . DgS::printAr(ArrayHandler::arrayGetNextKey($array, 'z')) . "<br>";
|
||||||
|
|
||||||
print "</body></html>";
|
print "</body></html>";
|
||||||
|
|
||||||
// __END__
|
// __END__
|
||||||
|
|||||||
@@ -51,10 +51,7 @@ if (round($timestamp, 4) == DateTime::stringToTime($time_string)) {
|
|||||||
} else {
|
} else {
|
||||||
print "REVERSE TRIME STRING DO NOT MATCH<br>";
|
print "REVERSE TRIME STRING DO NOT MATCH<br>";
|
||||||
}
|
}
|
||||||
print "ZERO TIME STRING: " . DateTime::timeStringFormat(0, true) . "<br>";
|
print "<hr>";
|
||||||
print "ZERO TIME STRING: " . DateTime::timeStringFormat(0.0, true) . "<br>";
|
|
||||||
print "ZERO TIME STRING: " . DateTime::timeStringFormat(1.005, true) . "<br>";
|
|
||||||
|
|
||||||
$timestamps = [
|
$timestamps = [
|
||||||
1622788315.123456,
|
1622788315.123456,
|
||||||
-1622788315.456789
|
-1622788315.456789
|
||||||
@@ -64,6 +61,159 @@ foreach ($timestamps as $timestamp) {
|
|||||||
print "DATESTRINGFORMAT(sm:1:0): $timestamp: " . DateTime::dateStringFormat($timestamp, true) . "<br>";
|
print "DATESTRINGFORMAT(sm:1:0): $timestamp: " . DateTime::dateStringFormat($timestamp, true) . "<br>";
|
||||||
print "DATESTRINGFORMAT(sm:1:1): $timestamp: " . DateTime::dateStringFormat($timestamp, true, true) . "<br>";
|
print "DATESTRINGFORMAT(sm:1:1): $timestamp: " . DateTime::dateStringFormat($timestamp, true, true) . "<br>";
|
||||||
}
|
}
|
||||||
|
print "<hr>";
|
||||||
|
// $interval = 0;
|
||||||
|
// $interval = 1000000;
|
||||||
|
// $interval = 123456;
|
||||||
|
// $interval = 3600;
|
||||||
|
$interval = 3601;
|
||||||
|
// $interval = 86400;
|
||||||
|
// $interval = 86401;
|
||||||
|
// $interval = (86400 * 606) + 16434.5;
|
||||||
|
// $interval = 1.5;
|
||||||
|
// $interval = 123456;
|
||||||
|
// $interval = 120.1;
|
||||||
|
// $interval = 1641515890;
|
||||||
|
// $interval = 0.123456;
|
||||||
|
// $interval = 1641515890;
|
||||||
|
// $interval = 999999999999999999;
|
||||||
|
// $interval = 60;
|
||||||
|
try {
|
||||||
|
// print "Test-DEP: [$interval] "
|
||||||
|
// . intervalStringFormatDeprecated(
|
||||||
|
// $interval,
|
||||||
|
// truncate_after: '',
|
||||||
|
// natural_seperator: false,
|
||||||
|
// name_space_seperator: false,
|
||||||
|
// show_microseconds: true,
|
||||||
|
// short_time_name: true,
|
||||||
|
// skip_last_zero: true,
|
||||||
|
// skip_zero: false,
|
||||||
|
// show_only_days: false,
|
||||||
|
// auto_fix_microseconds: false,
|
||||||
|
// truncate_nanoseconds: false,
|
||||||
|
// truncate_zero_seconds_if_microseconds: true,
|
||||||
|
// )
|
||||||
|
// // . " => "
|
||||||
|
// // . DateTime::intervalStringFormat($interval)
|
||||||
|
// . "<br>";
|
||||||
|
print "Test-ACT: [$interval] "
|
||||||
|
. DateTime::intervalStringFormat(
|
||||||
|
$interval,
|
||||||
|
truncate_after: '',
|
||||||
|
natural_seperator: false,
|
||||||
|
name_space_seperator: false,
|
||||||
|
show_microseconds: true,
|
||||||
|
short_time_name: true,
|
||||||
|
skip_last_zero: true,
|
||||||
|
skip_zero: false,
|
||||||
|
show_only_days: false,
|
||||||
|
auto_fix_microseconds: false,
|
||||||
|
truncate_nanoseconds: false,
|
||||||
|
truncate_zero_seconds_if_microseconds: true,
|
||||||
|
)
|
||||||
|
. " => "
|
||||||
|
. DateTime::intervalStringFormat($interval)
|
||||||
|
. "<br>";
|
||||||
|
print "DEFAULT-DEP: " . intervalStringFormatDeprecated($interval) . "<br>";
|
||||||
|
print "DEFAULT-ACT: " . DateTime::intervalStringFormat($interval) . "<br>";
|
||||||
|
$show_micro = true;
|
||||||
|
// print "COMPATIBLE Test-DEP: " .
|
||||||
|
// intervalStringFormatDeprecated(
|
||||||
|
// $interval,
|
||||||
|
// show_microseconds: $show_micro,
|
||||||
|
// show_only_days: true,
|
||||||
|
// skip_zero: false,
|
||||||
|
// skip_last_zero: false,
|
||||||
|
// truncate_nanoseconds: true,
|
||||||
|
// truncate_zero_seconds_if_microseconds: false
|
||||||
|
// ) . "<br>";
|
||||||
|
print "COMPATIBLE Test-ACT: " .
|
||||||
|
DateTime::intervalStringFormat(
|
||||||
|
$interval,
|
||||||
|
show_microseconds: $show_micro,
|
||||||
|
show_only_days: true,
|
||||||
|
skip_zero: false,
|
||||||
|
skip_last_zero: false,
|
||||||
|
truncate_nanoseconds: true,
|
||||||
|
truncate_zero_seconds_if_microseconds: false
|
||||||
|
) . "<br>";
|
||||||
|
print "ORIGINAL: " . DateTime::timeStringFormat($interval, $show_micro) . "<br>";
|
||||||
|
} catch (\UnexpectedValueException $e) {
|
||||||
|
print "ERROR: " . $e->getMessage() . "<br><pre>" . $e . "</pre><br>";
|
||||||
|
} catch (\LengthException $e) {
|
||||||
|
print "ERROR interval: " . $e->getMessage() . "<br><pre>" . $e . "</pre><br>";
|
||||||
|
}
|
||||||
|
print "<hr>";
|
||||||
|
$intervals = [
|
||||||
|
['i' => 0, 'sm' => true],
|
||||||
|
['i' => 0.0, 'sm' => true],
|
||||||
|
['i' => 1.5, 'sm' => true],
|
||||||
|
['i' => 1.05, 'sm' => true],
|
||||||
|
['i' => 1.005, 'sm' => true],
|
||||||
|
['i' => 1.0005, 'sm' => true],
|
||||||
|
];
|
||||||
|
foreach ($intervals as $int) {
|
||||||
|
$info = 'ts:' . $int['i'] . '|' . 'sm:' . $int['sm'];
|
||||||
|
print "[tsf] ZERO TIME STRING [$info]: "
|
||||||
|
. DateTime::timeStringFormat($int['i'], $int['sm']) . "<br>";
|
||||||
|
print "[isf] ZERO TIME STRING [$info]: "
|
||||||
|
. DateTime::intervalStringFormat($int['i'], show_microseconds:$int['sm']) . "<br>";
|
||||||
|
}
|
||||||
|
print "<hr>";
|
||||||
|
$intervals = [
|
||||||
|
[
|
||||||
|
'i' => 788315.123456,
|
||||||
|
'truncate_after' => '',
|
||||||
|
'natural_seperator' => false,
|
||||||
|
'name_space_seperator' => false,
|
||||||
|
'show_microseconds' => true,
|
||||||
|
'short_time_name' => true,
|
||||||
|
'skip_last_zero' => false,
|
||||||
|
'skip_zero' => true,
|
||||||
|
'show_only_days' => false,
|
||||||
|
'auto_fix_microseconds' => false,
|
||||||
|
'truncate_nanoseconds' => false
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'i' => 788315.123456,
|
||||||
|
'truncate_after' => '',
|
||||||
|
'natural_seperator' => true,
|
||||||
|
'name_space_seperator' => true,
|
||||||
|
'show_microseconds' => true,
|
||||||
|
'short_time_name' => true,
|
||||||
|
'skip_last_zero' => false,
|
||||||
|
'skip_zero' => true,
|
||||||
|
'show_only_days' => false,
|
||||||
|
'auto_fix_microseconds' => false,
|
||||||
|
'truncate_nanoseconds' => false
|
||||||
|
],
|
||||||
|
];
|
||||||
|
foreach ($intervals as $int) {
|
||||||
|
$info = $int['i'];
|
||||||
|
try {
|
||||||
|
print "INTRVALSTRINGFORMAT(sm:0): $info: "
|
||||||
|
. DateTime::intervalStringFormat(
|
||||||
|
$int['i'],
|
||||||
|
truncate_after: (string)$int['truncate_after'],
|
||||||
|
natural_seperator: $int['natural_seperator'],
|
||||||
|
name_space_seperator: $int['name_space_seperator'],
|
||||||
|
show_microseconds: $int['show_microseconds'],
|
||||||
|
short_time_name: $int['short_time_name'],
|
||||||
|
skip_last_zero: $int['skip_last_zero'],
|
||||||
|
skip_zero: $int['skip_zero'],
|
||||||
|
show_only_days: $int['show_only_days'],
|
||||||
|
auto_fix_microseconds: $int['auto_fix_microseconds'],
|
||||||
|
truncate_nanoseconds: $int['truncate_nanoseconds'],
|
||||||
|
) . "<br>";
|
||||||
|
} catch (\UnexpectedValueException $e) {
|
||||||
|
print "ERROR: " . $e->getMessage() . "<br><pre>" . $e . "</pre><br>";
|
||||||
|
} catch (\LengthException $e) {
|
||||||
|
print "ERROR interval: " . $e->getMessage() . "<br><pre>" . $e . "</pre><br>";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
print "<hr>";
|
||||||
|
// convert and reverste tests
|
||||||
$intervals = [
|
$intervals = [
|
||||||
788315.123456,
|
788315.123456,
|
||||||
-123.456
|
-123.456
|
||||||
@@ -74,6 +224,7 @@ foreach ($intervals as $interval) {
|
|||||||
print "TIMESTRINGFORMAT(sm:1): $interval: " . $reverse_interval . "<br>";
|
print "TIMESTRINGFORMAT(sm:1): $interval: " . $reverse_interval . "<br>";
|
||||||
print "STRINGTOTIME: $reverse_interval: " . DateTime::stringToTime($reverse_interval) . "<br>";
|
print "STRINGTOTIME: $reverse_interval: " . DateTime::stringToTime($reverse_interval) . "<br>";
|
||||||
}
|
}
|
||||||
|
print "<hr>";
|
||||||
$check_dates = [
|
$check_dates = [
|
||||||
'2021-05-01',
|
'2021-05-01',
|
||||||
'2021-05-40'
|
'2021-05-40'
|
||||||
@@ -81,6 +232,7 @@ $check_dates = [
|
|||||||
foreach ($check_dates as $check_date) {
|
foreach ($check_dates as $check_date) {
|
||||||
print "CHECKDATE: $check_date: " . (string)DateTime::checkDate($check_date) . "<br>";
|
print "CHECKDATE: $check_date: " . (string)DateTime::checkDate($check_date) . "<br>";
|
||||||
}
|
}
|
||||||
|
print "<hr>";
|
||||||
$check_datetimes = [
|
$check_datetimes = [
|
||||||
'2021-05-01',
|
'2021-05-01',
|
||||||
'2021-05-40',
|
'2021-05-40',
|
||||||
@@ -91,6 +243,7 @@ $check_datetimes = [
|
|||||||
foreach ($check_datetimes as $check_datetime) {
|
foreach ($check_datetimes as $check_datetime) {
|
||||||
print "CHECKDATETIME: $check_datetime: " . (string)DateTime::checkDateTime($check_datetime) . "<br>";
|
print "CHECKDATETIME: $check_datetime: " . (string)DateTime::checkDateTime($check_datetime) . "<br>";
|
||||||
}
|
}
|
||||||
|
print "<hr>";
|
||||||
$compare_dates = [
|
$compare_dates = [
|
||||||
[ '2021-05-01', '2021-05-02', ],
|
[ '2021-05-01', '2021-05-02', ],
|
||||||
[ '2021-05-02', '2021-05-01', ],
|
[ '2021-05-02', '2021-05-01', ],
|
||||||
@@ -102,6 +255,7 @@ foreach ($compare_dates as $compare_date) {
|
|||||||
print "COMPAREDATE: $compare_date[0] = $compare_date[1]: "
|
print "COMPAREDATE: $compare_date[0] = $compare_date[1]: "
|
||||||
. (string)DateTime::compareDate($compare_date[0], $compare_date[1]) . "<br>";
|
. (string)DateTime::compareDate($compare_date[0], $compare_date[1]) . "<br>";
|
||||||
}
|
}
|
||||||
|
print "<hr>";
|
||||||
$compare_datetimes = [
|
$compare_datetimes = [
|
||||||
[ '2021-05-01', '2021-05-02', ],
|
[ '2021-05-01', '2021-05-02', ],
|
||||||
[ '2021-05-02', '2021-05-01', ],
|
[ '2021-05-02', '2021-05-01', ],
|
||||||
@@ -114,6 +268,7 @@ foreach ($compare_datetimes as $compare_datetime) {
|
|||||||
print "COMPAREDATE: $compare_datetime[0] = $compare_datetime[1]: "
|
print "COMPAREDATE: $compare_datetime[0] = $compare_datetime[1]: "
|
||||||
. (string)DateTime::compareDateTime($compare_datetime[0], $compare_datetime[1]) . "<br>";
|
. (string)DateTime::compareDateTime($compare_datetime[0], $compare_datetime[1]) . "<br>";
|
||||||
}
|
}
|
||||||
|
print "<hr>";
|
||||||
$compare_dates = [
|
$compare_dates = [
|
||||||
[ '2021-05-01', '2021-05-10', ],
|
[ '2021-05-01', '2021-05-10', ],
|
||||||
[ '2021-05-10', '2021-05-01', ],
|
[ '2021-05-10', '2021-05-01', ],
|
||||||
@@ -126,7 +281,7 @@ foreach ($compare_dates as $compare_date) {
|
|||||||
print "CALCDAYSINTERVAL(named): $compare_date[0] = $compare_date[1]: "
|
print "CALCDAYSINTERVAL(named): $compare_date[0] = $compare_date[1]: "
|
||||||
. DgS::printAr(DateTime::calcDaysInterval($compare_date[0], $compare_date[1], true)) . "<br>";
|
. DgS::printAr(DateTime::calcDaysInterval($compare_date[0], $compare_date[1], true)) . "<br>";
|
||||||
}
|
}
|
||||||
|
print "<hr>";
|
||||||
// test date conversion
|
// test date conversion
|
||||||
$dow = 2;
|
$dow = 2;
|
||||||
print "DOW[$dow]: " . DateTime::setWeekdayNameFromIsoDow($dow) . "<br>";
|
print "DOW[$dow]: " . DateTime::setWeekdayNameFromIsoDow($dow) . "<br>";
|
||||||
@@ -142,7 +297,7 @@ $date = '2022-70-242';
|
|||||||
print "DATE-dow[$date];invalid: " . DateTime::setWeekdayNameFromDate($date) . "<br>";
|
print "DATE-dow[$date];invalid: " . DateTime::setWeekdayNameFromDate($date) . "<br>";
|
||||||
print "DATE-dow[$date],long;invalid: " . DateTime::setWeekdayNameFromDate($date, true) . "<br>";
|
print "DATE-dow[$date],long;invalid: " . DateTime::setWeekdayNameFromDate($date, true) . "<br>";
|
||||||
print "DOW-date[$date];invalid: " . DateTime::setWeekdayNumberFromDate($date) . "<br>";
|
print "DOW-date[$date];invalid: " . DateTime::setWeekdayNumberFromDate($date) . "<br>";
|
||||||
|
print "<hr>";
|
||||||
// check date range includes a weekend
|
// check date range includes a weekend
|
||||||
// does not:
|
// does not:
|
||||||
$start_date = '2023-07-03';
|
$start_date = '2023-07-03';
|
||||||
@@ -165,4 +320,237 @@ print "Has Weekend: " . $start_date . " ~ " . $end_date . ": "
|
|||||||
|
|
||||||
print "</body></html>";
|
print "</body></html>";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DEPREACTED, original rewrite, do not use
|
||||||
|
*
|
||||||
|
* update timeStringFormat with year and month support
|
||||||
|
*
|
||||||
|
* The following flags have to be set to be timeStringFormat compatible.
|
||||||
|
* Not that on seconds overflow this method will throw an exception, timeStringFormat returned -1s
|
||||||
|
* show_only_days: true,
|
||||||
|
* skip_zero: false,
|
||||||
|
* skip_last_zero: false,
|
||||||
|
* truncate_nanoseconds: true,
|
||||||
|
* truncate_zero_seconds_if_microseconds: false
|
||||||
|
*
|
||||||
|
* @param int|float $seconds Seconds to convert, maxium 6 decimals,
|
||||||
|
* else \UnexpectedValueException will be thrown
|
||||||
|
* if days too large or years too large \LengthException is thrown
|
||||||
|
* @param string $truncate_after [=''] Truncate after which time name, will not round, hard end
|
||||||
|
* values are parts names or interval short names (y, d, f, ...)
|
||||||
|
* if illegal value \UnexpectedValueException is thrown
|
||||||
|
* @param bool $natural_seperator [=false] use ',' and 'and', if off use space
|
||||||
|
* @param bool $name_space_seperator [=false] add a space between the number and the time name
|
||||||
|
* @param bool $show_microseconds [=true] show microseconds
|
||||||
|
* @param bool $short_time_name [=true] use the short time names (eg s instead of seconds)
|
||||||
|
* @param bool $skip_last_zero [=true] skip all trailing zero values, eg 5m 0s => 5m
|
||||||
|
* @param bool $skip_zero [=true] do not show zero values anywhere, eg 1h 0m 20s => 1h 20s
|
||||||
|
* @param bool $show_only_days [=false] do not show years or months, show only days
|
||||||
|
* if truncate after is set to year or month
|
||||||
|
* throws \UnexpectedValueException
|
||||||
|
* @param bool $auto_fix_microseconds [=false] if the micro seconds decimals are more than 6, round them
|
||||||
|
* on defaul throw \UnexpectedValueException
|
||||||
|
* @param bool $truncate_nanoseconds [=false] if microseconds decimals >3 then normal we show 123.4ms
|
||||||
|
* cut the .4 is set to true
|
||||||
|
* @param bool $truncate_zero_seconds_if_microseconds [=true] if we have 0.123 seconds then if true no seconds
|
||||||
|
* will be shown
|
||||||
|
* @return string
|
||||||
|
* @throws \UnexpectedValueException if seconds has more than 6 decimals
|
||||||
|
* if truncate has an illegal value
|
||||||
|
* if truncate is set to year or month and show_only_days is turned on
|
||||||
|
* @throws \LengthException if seconds is too large and show_days_only is selected and days is negetive
|
||||||
|
* or if years is negativ
|
||||||
|
*/
|
||||||
|
function intervalStringFormatDeprecated(
|
||||||
|
int|float $seconds,
|
||||||
|
string $truncate_after = '',
|
||||||
|
bool $natural_seperator = false,
|
||||||
|
bool $name_space_seperator = false,
|
||||||
|
bool $show_microseconds = true,
|
||||||
|
bool $short_time_name = true,
|
||||||
|
bool $skip_last_zero = true,
|
||||||
|
bool $skip_zero = true,
|
||||||
|
bool $show_only_days = false,
|
||||||
|
bool $auto_fix_microseconds = false,
|
||||||
|
bool $truncate_nanoseconds = false,
|
||||||
|
bool $truncate_zero_seconds_if_microseconds = true,
|
||||||
|
): string {
|
||||||
|
// auto fix long seconds, else \UnexpectedValueException will be thrown on error
|
||||||
|
// check if we have float and -> round to 6
|
||||||
|
if ($auto_fix_microseconds === true && is_float($seconds)) {
|
||||||
|
$seconds = round($seconds, 6);
|
||||||
|
}
|
||||||
|
// flag negative + set abs
|
||||||
|
$negative = $seconds < 0 ? '-' : '';
|
||||||
|
$seconds = abs($seconds);
|
||||||
|
// create base time
|
||||||
|
$date_now = new \DateTime("@0");
|
||||||
|
try {
|
||||||
|
$date_seconds = new \DateTime("@$seconds");
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
throw new \UnexpectedValueException(
|
||||||
|
'Seconds value is invalid, too large or more than six decimals: ' . $seconds,
|
||||||
|
1,
|
||||||
|
$e
|
||||||
|
);
|
||||||
|
}
|
||||||
|
$interval = date_diff($date_now, $date_seconds);
|
||||||
|
// if show_only_days and negative but input postive alert that this has to be done in y/m/d ...
|
||||||
|
if ($interval->y < 0) {
|
||||||
|
throw new \LengthException('Input seconds value is too large for years output: ' . $seconds, 2);
|
||||||
|
} elseif ($interval->days < 0 && $show_only_days === true) {
|
||||||
|
throw new \LengthException('Input seconds value is too large for days output: ' . $seconds, 3);
|
||||||
|
}
|
||||||
|
// array order is important, small too large
|
||||||
|
$parts = [
|
||||||
|
'microseconds' => 'f',
|
||||||
|
'seconds' => 's', 'minutes' => 'i', 'hours' => 'h',
|
||||||
|
'days' => 'd', 'months' => 'm', 'years' => 'y',
|
||||||
|
];
|
||||||
|
$short_name = [
|
||||||
|
'years' => 'y', 'months' => 'm', 'days' => 'd',
|
||||||
|
'hours' => 'h', 'minutes' => 'm', 'seconds' => 's',
|
||||||
|
'microseconds' => 'ms'
|
||||||
|
];
|
||||||
|
$skip = false;
|
||||||
|
if (!empty($truncate_after)) {
|
||||||
|
// if truncate after not in key or value in parts
|
||||||
|
if (!in_array($truncate_after, array_keys($parts)) && !in_array($truncate_after, array_values($parts))) {
|
||||||
|
throw new \UnexpectedValueException(
|
||||||
|
'truncate_after has an invalid value: ' . $truncate_after,
|
||||||
|
4
|
||||||
|
);
|
||||||
|
}
|
||||||
|
// if truncate after is y or m and we have show_only_days, throw exception
|
||||||
|
if ($show_only_days === true && in_array($truncate_after, ['y', 'years', 'm', 'months'])) {
|
||||||
|
throw new \UnexpectedValueException(
|
||||||
|
'If show_only_days is turned on, the truncate_after cannot be years or months: '
|
||||||
|
. $truncate_after,
|
||||||
|
5
|
||||||
|
);
|
||||||
|
}
|
||||||
|
$skip = true;
|
||||||
|
}
|
||||||
|
$formatted = [];
|
||||||
|
$zero_list = [];
|
||||||
|
$zero_last_list = [];
|
||||||
|
$add_zero_seconds = false;
|
||||||
|
foreach ($parts as $time_name => $part) {
|
||||||
|
// end for micro seconds
|
||||||
|
if ($show_microseconds === false && $time_name == 'microseconds') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// skip at this time position
|
||||||
|
if ($part == $truncate_after || $truncate_after == $time_name) {
|
||||||
|
$skip = false;
|
||||||
|
}
|
||||||
|
if ($skip === true) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if ($show_only_days === true && $part == 'd') {
|
||||||
|
$value = $interval->days;
|
||||||
|
$skip = true;
|
||||||
|
} else {
|
||||||
|
$value = $interval->$part;
|
||||||
|
}
|
||||||
|
if ($value == 0 && $skip_last_zero === true) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// print "-> V: $value | $part, $time_name | I: " . is_int($value) . " | F: " . is_float($value)
|
||||||
|
// . " | " . ($value != 0 ? 'Not zero' : 'ZERO') . "<br>";
|
||||||
|
// var_dump($skip_last_zero);
|
||||||
|
if ($value != 0 || $skip_zero === false || $skip_last_zero === false) {
|
||||||
|
if ($part == 'f') {
|
||||||
|
if ($truncate_nanoseconds === true) {
|
||||||
|
$value = round($value, 3);
|
||||||
|
}
|
||||||
|
$value *= 1000;
|
||||||
|
// anything above that is nano seconds?
|
||||||
|
}
|
||||||
|
// on first hit turn off (full off)
|
||||||
|
if ($value) {
|
||||||
|
$skip_last_zero = null;
|
||||||
|
} elseif ($skip_last_zero === false) {
|
||||||
|
$zero_last_list[] = $part;
|
||||||
|
}
|
||||||
|
// build format
|
||||||
|
$format = "$value";
|
||||||
|
if ($name_space_seperator) {
|
||||||
|
$format .= " ";
|
||||||
|
}
|
||||||
|
if ($short_time_name) {
|
||||||
|
$format .= $short_name[$time_name];
|
||||||
|
} elseif ($value == 1) {
|
||||||
|
$format .= substr($time_name, 0, -1);
|
||||||
|
} else {
|
||||||
|
$format .= $time_name;
|
||||||
|
}
|
||||||
|
$formatted[] = $format;
|
||||||
|
}
|
||||||
|
// if we have 0 value, but only for skip zero condition
|
||||||
|
if ($skip_zero === false) {
|
||||||
|
if ($value == 0) {
|
||||||
|
$zero_list[] = $part;
|
||||||
|
} else {
|
||||||
|
$zero_list = [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
$part == 's' && $value == 0 &&
|
||||||
|
$show_microseconds === true &&
|
||||||
|
$truncate_zero_seconds_if_microseconds === false
|
||||||
|
) {
|
||||||
|
$add_zero_seconds = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// if there is a zero list, strip that from the beginning, this is done always
|
||||||
|
if (count($zero_list)) {
|
||||||
|
// strip
|
||||||
|
$formatted = array_slice($formatted, 0, count($zero_list) * -1);
|
||||||
|
} elseif (count($zero_last_list) == count($formatted)) {
|
||||||
|
// if we have all skip empty last, then we do not have any value
|
||||||
|
$formatted = [];
|
||||||
|
}
|
||||||
|
$formatted = array_reverse($formatted);
|
||||||
|
// print "=> F: " . print_r($formatted, true)
|
||||||
|
// . " | Z: " . print_r($zero_list, true)
|
||||||
|
// . " | ZL: " . print_r($zero_last_list, true)
|
||||||
|
// . "<br>";
|
||||||
|
if (count($formatted) == 0) {
|
||||||
|
// if we have truncate on, then we assume nothing was found
|
||||||
|
$str = "0";
|
||||||
|
if ($name_space_seperator) {
|
||||||
|
$str .= " ";
|
||||||
|
}
|
||||||
|
// if truncate is on, we assume we found nothing
|
||||||
|
if (!empty($truncate_after)) {
|
||||||
|
if (in_array($truncate_after, array_values($parts))) {
|
||||||
|
$truncate_after = array_flip($parts)[$truncate_after];
|
||||||
|
}
|
||||||
|
$str .= ($short_time_name ? $short_name[$truncate_after] : $truncate_after);
|
||||||
|
} else {
|
||||||
|
$str .= ($short_time_name ? $short_name['seconds'] : 'seconds');
|
||||||
|
}
|
||||||
|
return $str;
|
||||||
|
} elseif (count($formatted) == 1) {
|
||||||
|
return $negative .
|
||||||
|
($add_zero_seconds ?
|
||||||
|
'0'
|
||||||
|
. ($name_space_seperator ? ' ' : '')
|
||||||
|
. ($short_time_name ? $short_name['seconds'] : 'seconds')
|
||||||
|
. ' '
|
||||||
|
: ''
|
||||||
|
)
|
||||||
|
. $formatted[0];
|
||||||
|
} elseif ($natural_seperator === false) {
|
||||||
|
return $negative . implode(' ', $formatted);
|
||||||
|
} else {
|
||||||
|
$str = implode(', ', array_slice($formatted, 0, -1));
|
||||||
|
if (!empty($formatted[count($formatted) - 1])) {
|
||||||
|
$str .= ' and ' . $formatted[count($formatted) - 1];
|
||||||
|
}
|
||||||
|
return $negative . $str;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// __END__
|
// __END__
|
||||||
|
|||||||
@@ -56,7 +56,9 @@ print "<b>dbReturn CACHE tests</b><br>";
|
|||||||
$db->dbExec("DELETE FROM test_db_return");
|
$db->dbExec("DELETE FROM test_db_return");
|
||||||
$db->dbExec("INSERT INTO test_db_return (uid, data) VALUES ('A1', 'Test A'), ('B1', 'Test B')");
|
$db->dbExec("INSERT INTO test_db_return (uid, data) VALUES ('A1', 'Test A'), ('B1', 'Test B')");
|
||||||
// read query to use
|
// read query to use
|
||||||
$q_db_ret = "SELECT * FROM test_db_return ORDER BY uid";
|
$q_db_ret = <<<SQL
|
||||||
|
SELECT * FROM test_db_return ORDER BY uid
|
||||||
|
SQL;
|
||||||
|
|
||||||
RunningTime::hrRunningTime();
|
RunningTime::hrRunningTime();
|
||||||
|
|
||||||
@@ -157,4 +159,15 @@ $db->dbCacheReset($q_db_ret);
|
|||||||
print "<br>";
|
print "<br>";
|
||||||
print "Overall Run time: " . RunningTime::hrRunningTimeFromStart() . "<br>";
|
print "Overall Run time: " . RunningTime::hrRunningTimeFromStart() . "<br>";
|
||||||
|
|
||||||
|
print "<br>";
|
||||||
|
print "PARAM TEST RUN<br>";
|
||||||
|
// PARAM
|
||||||
|
$q_db_ret = <<<SQL
|
||||||
|
SELECT * FROM test_db_return WHERE uid = $1
|
||||||
|
SQL;
|
||||||
|
|
||||||
|
while (is_array($res = $db->dbReturnParams($q_db_ret, ['A1'], $db::NO_CACHE, true))) {
|
||||||
|
print "ROW: " . Support::printAr($res) . "<br>";
|
||||||
|
}
|
||||||
|
|
||||||
// __END__
|
// __END__
|
||||||
|
|||||||
@@ -38,9 +38,10 @@ print "<!DOCTYPE html>";
|
|||||||
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
|
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
|
||||||
print "<body>";
|
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>';
|
||||||
print '<div><a href="class_test.db.type.php">Class Test DB Types</a></div>';
|
print '<div><a href="class_test.db.type.php">Class Test DB row type convert to PHP type</a></div>';
|
||||||
|
print '<div><a href="class_test.db.query-placeholder.php">Class Test DB Query Placeholder convert</a></div>';
|
||||||
print '<div><a href="class_test.db.dbReturn.php">Class Test DB dbReturn</a></div>';
|
print '<div><a href="class_test.db.dbReturn.php">Class Test DB dbReturn</a></div>';
|
||||||
print '<div><a href="class_test.db.single.php">Class Test DB Single Aciont</a></div>';
|
print '<div><a href="class_test.db.single.php">Class Test DB Single Query tests</a></div>';
|
||||||
print '<div><h1>' . $PAGE_NAME . '</h1></div>';
|
print '<div><h1>' . $PAGE_NAME . '</h1></div>';
|
||||||
|
|
||||||
print "LOGFILE NAME: " . $db->log->getLogFile() . "<br>";
|
print "LOGFILE NAME: " . $db->log->getLogFile() . "<br>";
|
||||||
@@ -549,11 +550,13 @@ print "</pre>";
|
|||||||
|
|
||||||
print "<b>PREPARE QUERIES</b><br>";
|
print "<b>PREPARE QUERIES</b><br>";
|
||||||
// READ PREPARE
|
// READ PREPARE
|
||||||
$q_prep = "SELECT test_foo_id, test, some_bool, string_a, number_a, "
|
$q_prep = <<<SQL
|
||||||
. "number_a_numeric, some_time "
|
SELECT test_foo_id, test, some_bool, string_a, number_a,
|
||||||
. "FROM test_foo "
|
number_a_numeric, some_time
|
||||||
. "WHERE test = $1 "
|
FROM test_foo
|
||||||
. "ORDER BY test_foo_id DESC LIMIT 5";
|
WHERE test = $1
|
||||||
|
ORDER BY test_foo_id DESC LIMIT 5
|
||||||
|
SQL;
|
||||||
if ($db->dbPrepare('sel_test_foo', $q_prep) === false) {
|
if ($db->dbPrepare('sel_test_foo', $q_prep) === false) {
|
||||||
print "Error in sel_test_foo prepare<br>";
|
print "Error in sel_test_foo prepare<br>";
|
||||||
} else {
|
} else {
|
||||||
@@ -681,16 +684,27 @@ echo "<hr>";
|
|||||||
$db_pgb = new CoreLibs\DB\IO($DB_CONFIG['test_pgbouncer'] ?? [], $log);
|
$db_pgb = new CoreLibs\DB\IO($DB_CONFIG['test_pgbouncer'] ?? [], $log);
|
||||||
print "[PGB] DBINFO: " . $db_pgb->dbInfo() . "<br>";
|
print "[PGB] DBINFO: " . $db_pgb->dbInfo() . "<br>";
|
||||||
if ($db->dbPrepare('pgb_sel_test_foo', $q_prep) === false) {
|
if ($db->dbPrepare('pgb_sel_test_foo', $q_prep) === false) {
|
||||||
print "[PGB] [1] Error in pgb_sel_test_foo prepare<br>";
|
print "[PGB] [1] Warning in pgb_sel_test_foo prepare<br>";
|
||||||
} else {
|
} else {
|
||||||
print "[PGB] [1] pgb_sel_test_foo prepare OK<br>";
|
print "[PGB] [1] pgb_sel_test_foo prepare OK<br>";
|
||||||
}
|
}
|
||||||
// second prepare
|
// second prepare
|
||||||
if ($db->dbPrepare('pgb_sel_test_foo', $q_prep) === false) {
|
if ($db->dbPrepare('pgb_sel_test_foo', $q_prep) === false) {
|
||||||
print "[PGB] [2] Error in pgb_sel_test_foo prepare<br>";
|
print "[PGB] [2] Warning in pgb_sel_test_foo prepare<br>";
|
||||||
} else {
|
} else {
|
||||||
print "[PGB] [2] pgb_sel_test_foo prepare OK<br>";
|
print "[PGB] [2] pgb_sel_test_foo prepare OK<br>";
|
||||||
}
|
}
|
||||||
|
// same statment name, different query
|
||||||
|
if (
|
||||||
|
$db->dbPrepare('pgb_sel_test_foo', <<<SQL
|
||||||
|
SELECT * FROM test_foo WHERE test = $1
|
||||||
|
ORDER BY test_foo_id DESC LIMIT 5
|
||||||
|
SQL) === false
|
||||||
|
) {
|
||||||
|
print "[PGB] [3] Error in pgb_sel_test_foo prepare<br>";
|
||||||
|
} else {
|
||||||
|
print "[PGB] [3] pgb_sel_test_foo prepare OK<br>";
|
||||||
|
}
|
||||||
$db_pgb->dbClose();
|
$db_pgb->dbClose();
|
||||||
|
|
||||||
# db write class test
|
# db write class test
|
||||||
|
|||||||
210
www/admin/class_test.db.query-placeholder.php
Normal file
@@ -0,0 +1,210 @@
|
|||||||
|
<?php // phpcs:ignore warning
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @phan-file-suppress PhanTypeSuspiciousStringExpression
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
// turn on all error reporting
|
||||||
|
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
||||||
|
|
||||||
|
ob_start();
|
||||||
|
|
||||||
|
// basic class test file
|
||||||
|
define('USE_DATABASE', true);
|
||||||
|
// sample config
|
||||||
|
require 'config.php';
|
||||||
|
// define log file id
|
||||||
|
$LOG_FILE_ID = 'classTest-db-query-placeholder';
|
||||||
|
ob_end_flush();
|
||||||
|
|
||||||
|
use CoreLibs\Debug\Support;
|
||||||
|
use CoreLibs\DB\Support\ConvertPlaceholder;
|
||||||
|
|
||||||
|
$log = new CoreLibs\Logging\Logging([
|
||||||
|
'log_folder' => BASE . LOG,
|
||||||
|
'log_file_id' => $LOG_FILE_ID,
|
||||||
|
'log_per_date' => true,
|
||||||
|
]);
|
||||||
|
// db connection and attach logger
|
||||||
|
$db = new CoreLibs\DB\IO(DB_CONFIG, $log);
|
||||||
|
$db->log->debug('START', '=============================>');
|
||||||
|
|
||||||
|
$PAGE_NAME = 'TEST CLASS: DB QUERY PLACEHOLDER';
|
||||||
|
print "<!DOCTYPE html>";
|
||||||
|
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
|
||||||
|
print "<body>";
|
||||||
|
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||||
|
print '<div><h1>' . $PAGE_NAME . '</h1></div>';
|
||||||
|
|
||||||
|
print "LOGFILE NAME: " . $db->log->getLogFile() . "<br>";
|
||||||
|
print "LOGFILE ID: " . $db->log->getLogFileId() . "<br>";
|
||||||
|
print "DBINFO: " . $db->dbInfo() . "<br>";
|
||||||
|
// DB client encoding
|
||||||
|
print "DB client encoding: " . $db->dbGetEncoding() . "<br>";
|
||||||
|
print "DB search path: " . $db->dbGetSchema() . "<br>";
|
||||||
|
|
||||||
|
$to_db_version = '15.2';
|
||||||
|
print "VERSION DB: " . $db->dbVersion() . "<br>";
|
||||||
|
print "SERVER ENCODING: " . $db->dbVersionInfo('server_encoding') . "<br>";
|
||||||
|
if (($dbh = $db->dbGetDbh()) instanceof \PgSql\Connection) {
|
||||||
|
print "ALL OUTPUT [TEST]: <pre>" . print_r(pg_version($dbh), true) . "</pre><br>";
|
||||||
|
} else {
|
||||||
|
print "NO DB HANDLER<br>";
|
||||||
|
}
|
||||||
|
// turn on debug replace for placeholders
|
||||||
|
$db->dbSetDebugReplacePlaceholder(true);
|
||||||
|
|
||||||
|
print "<b>TRUNCATE test_foo</b><br>";
|
||||||
|
$db->dbExec("TRUNCATE test_foo");
|
||||||
|
|
||||||
|
$uniqid = \CoreLibs\Create\Uids::uniqIdShort();
|
||||||
|
$binary_data = $db->dbEscapeBytea(file_get_contents('class_test.db.php') ?: '');
|
||||||
|
$query_params = [
|
||||||
|
$uniqid,
|
||||||
|
true,
|
||||||
|
'STRING A',
|
||||||
|
2,
|
||||||
|
2.5,
|
||||||
|
1,
|
||||||
|
date('H:m:s'),
|
||||||
|
date('Y-m-d H:i:s'),
|
||||||
|
json_encode(['a' => 'string', 'b' => 1, 'c' => 1.5, 'f' => true, 'g' => ['a', 1, 1.5]]),
|
||||||
|
null,
|
||||||
|
'{"a", "b"}',
|
||||||
|
'{1,2}',
|
||||||
|
'{"(array Text A, 5, 8.8)","(array Text B, 10, 15.2)"}',
|
||||||
|
'("Text", 4, 6.3)',
|
||||||
|
$binary_data
|
||||||
|
];
|
||||||
|
|
||||||
|
$query_insert = <<<SQL
|
||||||
|
INSERT INTO test_foo (
|
||||||
|
test, some_bool, string_a, number_a, number_a_numeric, smallint_a,
|
||||||
|
some_time, some_timestamp, json_string, null_var,
|
||||||
|
array_char_1, array_int_1,
|
||||||
|
array_composite,
|
||||||
|
composite_item,
|
||||||
|
some_binary
|
||||||
|
) VALUES (
|
||||||
|
$1, $2, $3, $4, $5, $6,
|
||||||
|
$7, $8, $9, $10,
|
||||||
|
$11, $12,
|
||||||
|
$13,
|
||||||
|
$14,
|
||||||
|
$15
|
||||||
|
)
|
||||||
|
RETURNING
|
||||||
|
test_foo_id,
|
||||||
|
test, some_bool, string_a, number_a, number_a_numeric, smallint_a,
|
||||||
|
some_time, some_timestamp, json_string, null_var,
|
||||||
|
array_char_1, array_int_1,
|
||||||
|
array_composite,
|
||||||
|
composite_item,
|
||||||
|
some_binary
|
||||||
|
SQL;
|
||||||
|
$status = $db->dbExecParams($query_insert, $query_params);
|
||||||
|
echo "<b>*</b><br>";
|
||||||
|
echo "INSERT ALL COLUMN TYPES: "
|
||||||
|
. Support::printToString($query_params) . " |<br>"
|
||||||
|
. "QUERY: " . $db->dbGetQuery() . " |<br>"
|
||||||
|
. "PRIMARY KEY: " . Support::printToString($db->dbGetInsertPK()) . " |<br>"
|
||||||
|
. "RETURNING EXT: <pre>" . print_r($db->dbGetReturningExt(), true) . "</pre> |<br>"
|
||||||
|
. "RETURNING RETURN: <pre>" . print_r($db->dbGetReturningArray(), true) . "<pre> |<br>"
|
||||||
|
. "ERROR: " . $db->dbGetLastError(true) . "<br>";
|
||||||
|
echo "<hr>";
|
||||||
|
|
||||||
|
// test connectors: = , <> () for query detection
|
||||||
|
|
||||||
|
// convert placeholder tests
|
||||||
|
// ? -> $n
|
||||||
|
// :name -> $n
|
||||||
|
|
||||||
|
// other way around (just visual)
|
||||||
|
$test_queries = [
|
||||||
|
'skip' => [
|
||||||
|
'query' => <<<SQL
|
||||||
|
SELECT test, string_a, number_a
|
||||||
|
FROM test_foo
|
||||||
|
SQL,
|
||||||
|
'params' => [],
|
||||||
|
'direction' => 'pg',
|
||||||
|
],
|
||||||
|
'a?' => [
|
||||||
|
'query' => <<<SQL
|
||||||
|
INSERT INTO test_foo (
|
||||||
|
test, string_a, number_a
|
||||||
|
) VALUES (
|
||||||
|
?, ?, ?
|
||||||
|
)
|
||||||
|
SQL,
|
||||||
|
'params' => [\CoreLibs\Create\Uids::uniqIdShort(), 'string A-1', 1234],
|
||||||
|
'direction' => 'pg',
|
||||||
|
],
|
||||||
|
'b:' => [
|
||||||
|
'query' => <<<SQL
|
||||||
|
INSERT INTO test_foo (
|
||||||
|
test, string_a, number_a
|
||||||
|
) VALUES (
|
||||||
|
:test, :string_a, :number_a
|
||||||
|
)
|
||||||
|
SQL,
|
||||||
|
'params' => [
|
||||||
|
':test' => \CoreLibs\Create\Uids::uniqIdShort(),
|
||||||
|
':string_a' => 'string B-1',
|
||||||
|
':number_a' => 5678
|
||||||
|
],
|
||||||
|
'direction' => 'pg',
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
$db->dbSetConvertPlaceholder(true);
|
||||||
|
foreach ($test_queries as $info => $data) {
|
||||||
|
$query = $data['query'];
|
||||||
|
$params = $data['params'];
|
||||||
|
$direction = $data['direction'];
|
||||||
|
// print "[$info] Convert: "
|
||||||
|
// . Support::printAr(ConvertPlaceholder::convertPlaceholderInQuery($query, $params, $direction))
|
||||||
|
// . "<br>";
|
||||||
|
if ($db->dbCheckQueryForSelect($query)) {
|
||||||
|
$row = $db->dbReturnRowParams($query, $params);
|
||||||
|
print "[$info] SELECT: " . Support::prAr($row) . "<br>";
|
||||||
|
} else {
|
||||||
|
$db->dbExecParams($query, $params);
|
||||||
|
}
|
||||||
|
print "[$info] " . Support::printAr($db->dbGetPlaceholderConverted()) . "<br>";
|
||||||
|
echo "<hr>";
|
||||||
|
}
|
||||||
|
|
||||||
|
echo "dbReturn read: <br>";
|
||||||
|
while (
|
||||||
|
is_array($res = $db->dbReturnParams(
|
||||||
|
<<<SQL
|
||||||
|
SELECT test, string_a, number_a
|
||||||
|
FROM test_foo
|
||||||
|
WHERE string_a = ?
|
||||||
|
SQL,
|
||||||
|
['string A-1']
|
||||||
|
))
|
||||||
|
) {
|
||||||
|
print "RES: " . Support::prAr($res) . "<br>";
|
||||||
|
}
|
||||||
|
|
||||||
|
print "CursorExt: " . Support::prAr($db->dbGetCursorExt(<<<SQL
|
||||||
|
SELECT test, string_a, number_a
|
||||||
|
FROM test_foo
|
||||||
|
WHERE string_a = ?
|
||||||
|
SQL, ['string A-1']));
|
||||||
|
|
||||||
|
$res = $db->dbReturnRowParams(<<<SQL
|
||||||
|
SELECT test, string_a, number_a
|
||||||
|
FROM test_foo
|
||||||
|
WHERE string_a = $1
|
||||||
|
SQL, []);
|
||||||
|
print "PL: " . Support::PrAr($db->dbGetPlaceholderConverted()) . "<br>";
|
||||||
|
|
||||||
|
print "</body></html>";
|
||||||
|
$db->log->debug('DEBUGEND', '==================================== [END]');
|
||||||
|
|
||||||
|
// __END__
|
||||||
@@ -16,7 +16,7 @@ define('USE_DATABASE', true);
|
|||||||
// sample config
|
// sample config
|
||||||
require 'config.php';
|
require 'config.php';
|
||||||
// define log file id
|
// define log file id
|
||||||
$LOG_FILE_ID = 'classTest-db-single';
|
$LOG_FILE_ID = 'classTest-db-query-placeholders';
|
||||||
ob_end_flush();
|
ob_end_flush();
|
||||||
|
|
||||||
use CoreLibs\Debug\Support;
|
use CoreLibs\Debug\Support;
|
||||||
@@ -30,7 +30,7 @@ $log = new CoreLibs\Logging\Logging([
|
|||||||
$db = new CoreLibs\DB\IO(DB_CONFIG, $log);
|
$db = new CoreLibs\DB\IO(DB_CONFIG, $log);
|
||||||
$db->log->debug('START', '=============================>');
|
$db->log->debug('START', '=============================>');
|
||||||
|
|
||||||
$PAGE_NAME = 'TEST CLASS: DB SINGLE';
|
$PAGE_NAME = 'TEST CLASS: DB QUERY PLACEHOLDERS';
|
||||||
print "<!DOCTYPE html>";
|
print "<!DOCTYPE html>";
|
||||||
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
|
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
|
||||||
print "<body>";
|
print "<body>";
|
||||||
@@ -65,63 +65,6 @@ function testDBS(\CoreLibs\DB\IO $dbc): void
|
|||||||
$dbc->dbReturnRow("SELECT test FROM test_foo LIMIT 1");
|
$dbc->dbReturnRow("SELECT test FROM test_foo LIMIT 1");
|
||||||
}
|
}
|
||||||
|
|
||||||
$uniqid = \CoreLibs\Create\Uids::uniqIdShort();
|
|
||||||
$binary_data = $db->dbEscapeBytea(file_get_contents('class_test.db.php') ?: '');
|
|
||||||
$query_params = [
|
|
||||||
$uniqid,
|
|
||||||
true,
|
|
||||||
'STRING A',
|
|
||||||
2,
|
|
||||||
2.5,
|
|
||||||
1,
|
|
||||||
date('H:m:s'),
|
|
||||||
date('Y-m-d H:m:s'),
|
|
||||||
json_encode(['a' => 'string', 'b' => 1, 'c' => 1.5, 'f' => true, 'g' => ['a', 1, 1.5]]),
|
|
||||||
null,
|
|
||||||
'{"a", "b"}',
|
|
||||||
'{1,2}',
|
|
||||||
'{"(array Text A, 5, 8.8)","(array Text B, 10, 15.2)"}',
|
|
||||||
'("Text", 4, 6.3)',
|
|
||||||
$binary_data
|
|
||||||
];
|
|
||||||
|
|
||||||
$query_insert = <<<SQL
|
|
||||||
INSERT INTO test_foo (
|
|
||||||
test, some_bool, string_a, number_a, number_a_numeric, smallint_a,
|
|
||||||
some_time, some_timestamp, json_string, null_var,
|
|
||||||
array_char_1, array_int_1,
|
|
||||||
array_composite,
|
|
||||||
composite_item,
|
|
||||||
some_binary
|
|
||||||
) VALUES (
|
|
||||||
$1, $2, $3, $4, $5, $6,
|
|
||||||
$7, $8, $9, $10,
|
|
||||||
$11, $12,
|
|
||||||
$13,
|
|
||||||
$14,
|
|
||||||
$15
|
|
||||||
)
|
|
||||||
SQL;
|
|
||||||
$status = $db->dbExecParams($query_insert, $query_params);
|
|
||||||
$query_select = <<<SQL
|
|
||||||
SELECT
|
|
||||||
test_foo_id,
|
|
||||||
test, some_bool, string_a, number_a, number_a_numeric, smallint_a,
|
|
||||||
number_real, number_double, number_serial,
|
|
||||||
some_time, some_timestamp, json_string, null_var,
|
|
||||||
array_char_1, array_char_2, array_int_1, array_int_2, array_composite,
|
|
||||||
composite_item, (composite_item).*
|
|
||||||
some_binary
|
|
||||||
FROM
|
|
||||||
test_foo
|
|
||||||
WHERE
|
|
||||||
test = $1;
|
|
||||||
SQL;
|
|
||||||
$res = $db->dbReturnRowParams($query_select, [$uniqid]);
|
|
||||||
if (is_array($res)) {
|
|
||||||
var_dump($res);
|
|
||||||
}
|
|
||||||
|
|
||||||
testDBS($db);
|
testDBS($db);
|
||||||
|
|
||||||
print "</body></html>";
|
print "</body></html>";
|
||||||
|
|||||||
@@ -170,6 +170,8 @@ class TestL
|
|||||||
{
|
{
|
||||||
print "* GETCALLERCLASS(INSIDE CLASS): " . \CoreLibs\Debug\Support::getCallerClass() . "<br>";
|
print "* GETCALLERCLASS(INSIDE CLASS): " . \CoreLibs\Debug\Support::getCallerClass() . "<br>";
|
||||||
print "* GETCALLERTOPCLASS(INSIDE CLASS): " . \CoreLibs\Debug\Support::getCallerTopLevelClass() . "<br>";
|
print "* GETCALLERTOPCLASS(INSIDE CLASS): " . \CoreLibs\Debug\Support::getCallerTopLevelClass() . "<br>";
|
||||||
|
print "* GETCALLSTACK(INSIDE CLASS): <pre>"
|
||||||
|
. DebugSupport::prAr(\CoreLibs\Debug\Support::getCallStack()) . "</pre><br>";
|
||||||
$this->log->debug('TESTL', 'Logging in class testL' . ($ts !== null ? ': ' . $ts : ''));
|
$this->log->debug('TESTL', 'Logging in class testL' . ($ts !== null ? ': ' . $ts : ''));
|
||||||
$this->log->debug('TESTL', 'Some other message');
|
$this->log->debug('TESTL', 'Some other message');
|
||||||
return true;
|
return true;
|
||||||
@@ -193,6 +195,8 @@ class TestR extends TestL
|
|||||||
{
|
{
|
||||||
print "** GETCALLERCLASS(INSIDE EXTND CLASS): " . \CoreLibs\Debug\Support::getCallerClass() . "<br>";
|
print "** GETCALLERCLASS(INSIDE EXTND CLASS): " . \CoreLibs\Debug\Support::getCallerClass() . "<br>";
|
||||||
print "** GETCALLERTOPCLASS(INSIDE EXTND CLASS): " . \CoreLibs\Debug\Support::getCallerTopLevelClass() . "<br>";
|
print "** GETCALLERTOPCLASS(INSIDE EXTND CLASS): " . \CoreLibs\Debug\Support::getCallerTopLevelClass() . "<br>";
|
||||||
|
print "** GETCALLSTACK(INSIDE EXTND CLASS): <pre>"
|
||||||
|
. DebugSupport::prAr(\CoreLibs\Debug\Support::getCallStack()) . "</pre><br>";
|
||||||
$this->log->debug('TESTR', 'Logging in class testR (extends testL)');
|
$this->log->debug('TESTR', 'Logging in class testR (extends testL)');
|
||||||
$this->test('TESTR INSIDE');
|
$this->test('TESTR INSIDE');
|
||||||
$this->log->debug('TESTR', 'Array: '
|
$this->log->debug('TESTR', 'Array: '
|
||||||
|
|||||||
@@ -92,6 +92,13 @@ try {
|
|||||||
print "Error: " . $e->getMessage() . "<br>";
|
print "Error: " . $e->getMessage() . "<br>";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// echo "<hr>";
|
||||||
|
// $key = CreateKey::generateRandomKey();
|
||||||
|
// $se = new SymmetricEncryption($key);
|
||||||
|
// $string = "I a some deep secret";
|
||||||
|
// $encrypted = $se->encrypt($string);
|
||||||
|
// $decrypted = $se->decrypt($encrypted);
|
||||||
|
|
||||||
print "</body></html>";
|
print "</body></html>";
|
||||||
|
|
||||||
// __END__
|
// __END__
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ $file = '/some/path/to/some/file.txt';
|
|||||||
print "GETFILENAMEENDING: $file: " . File::getFilenameEnding($file) . "<br>";
|
print "GETFILENAMEENDING: $file: " . File::getFilenameEnding($file) . "<br>";
|
||||||
$file = getcwd() . DIRECTORY_SEPARATOR . 'class_test.file.php';
|
$file = getcwd() . DIRECTORY_SEPARATOR . 'class_test.file.php';
|
||||||
print "GETLINESFROMFILE: $file: " . File::getLinesFromFile($file) . "<br>";
|
print "GETLINESFROMFILE: $file: " . File::getLinesFromFile($file) . "<br>";
|
||||||
|
print "MIMEINFO: $file: " . File::getMimeType($file) . "<br>";
|
||||||
|
|
||||||
print "</body></html>";
|
print "</body></html>";
|
||||||
|
|
||||||
|
|||||||
@@ -41,20 +41,32 @@ print '<div><h1>' . $PAGE_NAME . '</h1></div>';
|
|||||||
$thumb_width = 250;
|
$thumb_width = 250;
|
||||||
$thumb_height = 300;
|
$thumb_height = 300;
|
||||||
// class
|
// class
|
||||||
$image = BASE . LAYOUT . CONTENT_PATH . IMAGES . 'no_picture_square.jpg';
|
$image = BASE . CONTENT_PATH . LAYOUT . IMAGES . 'no_picture_square.jpg';
|
||||||
// folders
|
// folders
|
||||||
$cache_folder = BASE . LAYOUT . CONTENT_PATH . CACHE . IMAGES;
|
$cache_folder = BASE . CONTENT_PATH . LAYOUT . CACHE . IMAGES;
|
||||||
$web_folder = LAYOUT . CACHE . IMAGES;
|
$web_folder = LAYOUT . CACHE . IMAGES;
|
||||||
// rotate image first
|
// rotate image first
|
||||||
$_image->correctImageOrientation($image);
|
try {
|
||||||
|
$_image->correctImageOrientation($image);
|
||||||
|
} catch (\UnexpectedValueException $e) {
|
||||||
|
print "Message:<br>" . $e->getMessage() . "<br>" . $e . "<br>";
|
||||||
|
} catch (\RuntimeException $e) {
|
||||||
|
print "Message:<br>" . $e->getMessage() . "<br>" . $e . "<br>";
|
||||||
|
}
|
||||||
// thumbnail tests
|
// thumbnail tests
|
||||||
echo "<div>CLASS->CREATETHUMBNAILSIMPLE: "
|
echo "<div>CLASS->CREATETHUMBNAILSIMPLE: "
|
||||||
. basename($image) . ": WIDTH: $thumb_width<br><img src="
|
. basename($image) . ": WIDTH: $thumb_width<br><img src="
|
||||||
. $_image->createThumbnailSimple($image, $thumb_width, 0, $cache_folder, $web_folder) . "></div>";
|
. $_image->createThumbnailSimple($image, $thumb_width, 0, $cache_folder, $web_folder) . "></div>";
|
||||||
// static
|
// static
|
||||||
$image = BASE . LAYOUT . CONTENT_PATH . IMAGES . 'no_picture.jpg';
|
$image = BASE . CONTENT_PATH . LAYOUT . IMAGES . 'no_picture.jpg';
|
||||||
// rotate image first
|
// rotate image first
|
||||||
$image_class::correctImageOrientation($image);
|
try {
|
||||||
|
$image_class::correctImageOrientation($image);
|
||||||
|
} catch (\UnexpectedValueException $e) {
|
||||||
|
print "Message:<br>" . $e->getMessage() . "<br>" . $e . "<br>";
|
||||||
|
} catch (\RuntimeException $e) {
|
||||||
|
print "Message:<br>" . $e->getMessage() . "<br>" . $e . "<br>";
|
||||||
|
}
|
||||||
// thumbnail tests
|
// thumbnail tests
|
||||||
echo "<div>S::CREATETHUMBNAILSIMPLE: "
|
echo "<div>S::CREATETHUMBNAILSIMPLE: "
|
||||||
. basename($image) . ": WIDTH: $thumb_width<br><img src="
|
. basename($image) . ": WIDTH: $thumb_width<br><img src="
|
||||||
@@ -82,12 +94,18 @@ $images = array(
|
|||||||
// return mime type ala mimetype
|
// return mime type ala mimetype
|
||||||
$finfo = new finfo(FILEINFO_MIME_TYPE);
|
$finfo = new finfo(FILEINFO_MIME_TYPE);
|
||||||
foreach ($images as $image) {
|
foreach ($images as $image) {
|
||||||
$image = BASE . LAYOUT . CONTENT_PATH . IMAGES . $image;
|
$image = BASE . CONTENT_PATH . LAYOUT . IMAGES . $image;
|
||||||
list ($height, $width, $img_type) = \CoreLibs\Convert\SetVarType::setArray(getimagesize($image));
|
list ($height, $width, $img_type) = \CoreLibs\Convert\SetVarType::setArray(getimagesize($image));
|
||||||
echo "<div><b>IMAGE INFO</b>: " . $height . "x" . $width . ", TYPE: "
|
echo "<div><b>IMAGE INFO</b>: " . $height . "x" . $width . ", TYPE: "
|
||||||
. \CoreLibs\Debug\Support::dumpVar($img_type) . " [" . $finfo->file($image) . "]</div>";
|
. \CoreLibs\Debug\Support::dumpVar($img_type) . " [" . $finfo->file($image) . "]</div>";
|
||||||
// rotate image first
|
// rotate image first
|
||||||
Image::correctImageOrientation($image);
|
try {
|
||||||
|
Image::correctImageOrientation($image);
|
||||||
|
} catch (\UnexpectedValueException $e) {
|
||||||
|
print "Message:<br>" . $e->getMessage() . "<br>" . $e . "<br>";
|
||||||
|
} catch (\RuntimeException $e) {
|
||||||
|
print "Message:<br>" . $e->getMessage() . "<br>" . $e . "<br>";
|
||||||
|
}
|
||||||
// thumbnail tests
|
// thumbnail tests
|
||||||
echo "<div>" . basename($image) . ": WIDTH: $thumb_width<br><img src="
|
echo "<div>" . basename($image) . ": WIDTH: $thumb_width<br><img src="
|
||||||
. Image::createThumbnailSimple($image, $thumb_width, 0, $cache_folder, $web_folder) . "></div>";
|
. Image::createThumbnailSimple($image, $thumb_width, 0, $cache_folder, $web_folder) . "></div>";
|
||||||
|
|||||||
@@ -69,9 +69,10 @@ print "<body>";
|
|||||||
// key: file name, value; name
|
// key: file name, value; name
|
||||||
$test_files = [
|
$test_files = [
|
||||||
'class_test.db.php' => 'Class Test: DB',
|
'class_test.db.php' => 'Class Test: DB',
|
||||||
'class_test.db.types.php' => 'Class Test: DB COLUMN TYPES',
|
'class_test.db.types.php' => 'Class Test: DB column type convert',
|
||||||
'class_test.db.single.php' => 'Class Test: DB SINGLE',
|
'class_test.db.query-placeholder.php' => 'Class Test: DB query placeholder convert',
|
||||||
'class_test.db.dbReturn.php' => 'Class Test: DB dbReturn',
|
'class_test.db.dbReturn.php' => 'Class Test: DB dbReturn',
|
||||||
|
'class_test.db.single.php' => 'Class Test: DB single query tests',
|
||||||
'class_test.convert.colors.php' => 'Class Test: CONVERT COLORS',
|
'class_test.convert.colors.php' => 'Class Test: CONVERT COLORS',
|
||||||
'class_test.check.colors.php' => 'Class Test: CHECK COLORS',
|
'class_test.check.colors.php' => 'Class Test: CHECK COLORS',
|
||||||
'class_test.mime.php' => 'Class Test: MIME',
|
'class_test.mime.php' => 'Class Test: MIME',
|
||||||
|
|||||||
@@ -3,4 +3,3 @@
|
|||||||
// empty file for add and remove test
|
// empty file for add and remove test
|
||||||
|
|
||||||
// __END__
|
// __END__
|
||||||
|
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
../layout/admin/
|
|
||||||
|
Before Width: | Height: | Size: 1.5 MiB After Width: | Height: | Size: 1.5 MiB |
|
Before Width: | Height: | Size: 489 KiB After Width: | Height: | Size: 489 KiB |
|
Before Width: | Height: | Size: 807 KiB After Width: | Height: | Size: 807 KiB |
|
Before Width: | Height: | Size: 26 KiB After Width: | Height: | Size: 26 KiB |
|
Before Width: | Height: | Size: 6.6 KiB After Width: | Height: | Size: 6.6 KiB |
|
Before Width: | Height: | Size: 34 KiB After Width: | Height: | Size: 34 KiB |
|
Before Width: | Height: | Size: 7.2 KiB After Width: | Height: | Size: 7.2 KiB |
|
Before Width: | Height: | Size: 31 KiB After Width: | Height: | Size: 31 KiB |
|
Before Width: | Height: | Size: 7.0 KiB After Width: | Height: | Size: 7.0 KiB |
|
Before Width: | Height: | Size: 56 B After Width: | Height: | Size: 56 B |
|
Before Width: | Height: | Size: 87 B After Width: | Height: | Size: 87 B |
|
Before Width: | Height: | Size: 56 B After Width: | Height: | Size: 56 B |
|
Before Width: | Height: | Size: 260 B After Width: | Height: | Size: 260 B |
|
Before Width: | Height: | Size: 210 B After Width: | Height: | Size: 210 B |
|
Before Width: | Height: | Size: 87 B After Width: | Height: | Size: 87 B |
|
Before Width: | Height: | Size: 1.0 KiB After Width: | Height: | Size: 1.0 KiB |
|
Before Width: | Height: | Size: 250 B After Width: | Height: | Size: 250 B |
|
Before Width: | Height: | Size: 257 B After Width: | Height: | Size: 257 B |
|
Before Width: | Height: | Size: 275 B After Width: | Height: | Size: 275 B |
|
Before Width: | Height: | Size: 270 B After Width: | Height: | Size: 270 B |
|
Before Width: | Height: | Size: 279 B After Width: | Height: | Size: 279 B |
|
Before Width: | Height: | Size: 257 B After Width: | Height: | Size: 257 B |
|
Before Width: | Height: | Size: 261 B After Width: | Height: | Size: 261 B |
|
Before Width: | Height: | Size: 208 B After Width: | Height: | Size: 208 B |
|
Before Width: | Height: | Size: 279 B After Width: | Height: | Size: 279 B |
|
Before Width: | Height: | Size: 268 B After Width: | Height: | Size: 268 B |
|
Before Width: | Height: | Size: 260 B After Width: | Height: | Size: 260 B |
|
Before Width: | Height: | Size: 169 B After Width: | Height: | Size: 169 B |
|
Before Width: | Height: | Size: 169 B After Width: | Height: | Size: 169 B |
|
Before Width: | Height: | Size: 169 B After Width: | Height: | Size: 169 B |
|
Before Width: | Height: | Size: 165 B After Width: | Height: | Size: 165 B |
|
Before Width: | Height: | Size: 167 B After Width: | Height: | Size: 167 B |
|
Before Width: | Height: | Size: 171 B After Width: | Height: | Size: 171 B |
|
Before Width: | Height: | Size: 173 B After Width: | Height: | Size: 173 B |
|
Before Width: | Height: | Size: 159 B After Width: | Height: | Size: 159 B |
|
Before Width: | Height: | Size: 159 B After Width: | Height: | Size: 159 B |
|
Before Width: | Height: | Size: 116 B After Width: | Height: | Size: 116 B |
|
Before Width: | Height: | Size: 211 B After Width: | Height: | Size: 211 B |
|
Before Width: | Height: | Size: 85 B After Width: | Height: | Size: 85 B |