Compare commits
314 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0ff6294faa | ||
|
|
757d7ae01d | ||
|
|
4e78b21c67 | ||
|
|
d7e6434808 | ||
|
|
443cc2751d | ||
|
|
cf6500b55a | ||
|
|
09c2ec653f | ||
|
|
fc105f9295 | ||
|
|
053ab69330 | ||
|
|
fd079316f5 | ||
|
|
08664e9834 | ||
|
|
e063162161 | ||
|
|
7fbc449a5c | ||
|
|
72912c8c90 | ||
|
|
de2ed8be3d | ||
|
|
9d65f5d7c1 | ||
|
|
fbe827e989 | ||
|
|
c778a4eb81 | ||
|
|
ce1c72a0bc | ||
|
|
10319ef728 | ||
|
|
8d0036eaac | ||
|
|
d1e65c702e | ||
|
|
7248906da7 | ||
|
|
7f9a4dc04f | ||
|
|
10935214eb | ||
|
|
41e116f7d4 | ||
|
|
881c93c343 | ||
|
|
185d044a0b | ||
|
|
cc067cc202 | ||
|
|
37e2e54b2a | ||
|
|
711b3bfe97 | ||
|
|
3bd21c75d8 | ||
|
|
4971f62490 | ||
|
|
1cf4fdf31a | ||
|
|
d16b920966 | ||
|
|
ab52bf59b5 | ||
|
|
a8dd076aac | ||
|
|
c17ca1f847 | ||
|
|
e349613d60 | ||
|
|
e9cfdb4bf0 | ||
|
|
f966209e0a | ||
|
|
c13934de99 | ||
|
|
1e90bb677e | ||
|
|
540269e61f | ||
|
|
e793c3975b | ||
|
|
7d4c9724fe | ||
|
|
d1c4611431 | ||
|
|
8d3882a6fe | ||
|
|
2b0434e36b | ||
|
|
ba11a936db | ||
|
|
df591659cb | ||
|
|
5343034768 | ||
|
|
dec56c9559 | ||
|
|
880f15ac6f | ||
|
|
a46601fe03 | ||
|
|
022c39e791 | ||
|
|
fdefaca301 | ||
|
|
46e44c19bf | ||
|
|
41cb6358f9 | ||
|
|
23142a4549 | ||
|
|
a7742bd5c8 | ||
|
|
50f83b822c | ||
|
|
78591d6ba4 | ||
|
|
e8299a123b | ||
|
|
10c320f60c | ||
|
|
eeca138192 | ||
|
|
65715ea9c3 | ||
|
|
a56cbd8e97 | ||
|
|
fe50a988a0 | ||
|
|
a84ab86e31 | ||
|
|
b044999772 | ||
|
|
98bf3a40cd | ||
|
|
cbd47fb015 | ||
|
|
5f89917abd | ||
|
|
eeaff3042e | ||
|
|
d070c4e461 | ||
|
|
e57c336dba | ||
|
|
075fe967d5 | ||
|
|
0e5f637052 | ||
|
|
2e1b767a85 | ||
|
|
f78c67c378 | ||
|
|
75e69932fc | ||
|
|
7354632479 | ||
|
|
5a21d22c7b | ||
|
|
cee3b5c2d1 | ||
|
|
47e44c15cc | ||
|
|
83738adcb6 | ||
|
|
5454133239 | ||
|
|
87f35f23c3 | ||
|
|
3c4c5d3106 | ||
|
|
b080727ff3 | ||
|
|
ae044bee6f | ||
|
|
529b6a75ba | ||
|
|
8de112ba7e | ||
|
|
ad070ebdf4 | ||
|
|
9edfc2acb6 | ||
|
|
35cc6dbf91 | ||
|
|
cb3d5e1f27 | ||
|
|
0a45300c21 | ||
|
|
54ce378ae2 | ||
|
|
4ac659f7d9 | ||
|
|
497833ca71 | ||
|
|
e5a9b149b1 | ||
|
|
5213805a58 | ||
|
|
a9f1d878f7 | ||
|
|
3845bc7ff5 | ||
|
|
32c192a362 | ||
|
|
2bd68f32ac | ||
|
|
f5964fed02 | ||
|
|
625272198d | ||
|
|
00821bd5ea | ||
|
|
921b9cb3d9 | ||
|
|
720b78b687 | ||
|
|
565014e1e2 | ||
|
|
d9bcb577d7 | ||
|
|
8613e8977b | ||
|
|
0c51a3be87 | ||
|
|
f9cf36524e | ||
|
|
bacb9881ac | ||
|
|
f0fae1f76d | ||
|
|
1653e6b684 | ||
|
|
c8bc0062ad | ||
|
|
5c8a2ef8da | ||
|
|
d8379a10d9 | ||
|
|
30e2f33620 | ||
|
|
a4f16f4ca9 | ||
|
|
6e7b9cd033 | ||
|
|
4bc2ad8fa0 | ||
|
|
0d4e959f39 | ||
|
|
95d567545a | ||
|
|
d89c6d1bde | ||
|
|
337ebb9032 | ||
|
|
9538ebce7b | ||
|
|
1bff19f4b6 | ||
|
|
66dc72ec67 | ||
|
|
f781b5e55f | ||
|
|
934db50b3a | ||
|
|
573588ad3c | ||
|
|
d04addba81 | ||
|
|
a50a38fd40 | ||
|
|
3c5200cd99 | ||
|
|
50a4b88f55 | ||
|
|
e82929f512 | ||
|
|
5fc55c53b8 | ||
|
|
47da4d02ff | ||
|
|
9d131cf6dd | ||
|
|
dfcae20f64 | ||
|
|
61e489ee4c | ||
|
|
29982f90bc | ||
|
|
7cced63c4b | ||
|
|
06c2ea5e0d | ||
|
|
2e9239ec23 | ||
|
|
0c89840dba | ||
|
|
db144493f3 | ||
|
|
5cec54d508 | ||
|
|
8e60c992f1 | ||
|
|
1b5437b675 | ||
|
|
ef80cba561 | ||
|
|
2d71e760e8 | ||
|
|
a8d07634ff | ||
|
|
aa2b60973e | ||
|
|
554dd5f73c | ||
|
|
e6f9559fbb | ||
|
|
770d6f30a4 | ||
|
|
f94f6cbe87 | ||
|
|
9b69390fa2 | ||
|
|
0524d8ac1b | ||
|
|
e933022671 | ||
|
|
c549d34e65 | ||
|
|
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 | ||
|
|
97e1b2b63d | ||
|
|
d632a2599e | ||
|
|
2f81009a97 | ||
|
|
e9799f888b | ||
|
|
94b24b4eae | ||
|
|
a304d29698 | ||
|
|
c4c809be66 | ||
|
|
a3bf38f6cf | ||
|
|
c1b906e701 | ||
|
|
32f8e1440d | ||
|
|
2f8f98642b | ||
|
|
7ab03913ac | ||
|
|
a7853171e0 | ||
|
|
dfdfcf87f2 | ||
|
|
6218e0a6a8 | ||
|
|
a84a745be2 | ||
|
|
312762e92e | ||
|
|
fa4c1f0597 | ||
|
|
438a75af23 | ||
|
|
afd8ff3e31 | ||
|
|
4343af7937 | ||
|
|
d06769c48b | ||
|
|
4c0390f082 | ||
|
|
95bee3dc8c | ||
|
|
65132d8a4a | ||
|
|
b2243cd06d | ||
|
|
8f09b67d86 | ||
|
|
fe459aec80 | ||
|
|
de0ed058ca | ||
|
|
f90bd193d9 | ||
|
|
0e31180868 | ||
|
|
68c9164eaa | ||
|
|
c2389db1c9 | ||
|
|
f9558cd3aa | ||
|
|
ae3011fe22 | ||
|
|
9b9dfeac69 | ||
|
|
33cb05a002 | ||
|
|
ec110499a8 | ||
|
|
09839f3451 | ||
|
|
067e0aed5d | ||
|
|
545de5c4a1 | ||
|
|
2fe37bf92a | ||
|
|
cd81d15d9a | ||
|
|
8a33ee5c15 | ||
|
|
46e1419ef5 | ||
|
|
c441063437 | ||
|
|
5290d5f351 | ||
|
|
2635ccb82b | ||
|
|
4f2ac2ed1b | ||
|
|
5b8e4e4e3e | ||
|
|
53192da571 | ||
|
|
f29e915068 | ||
|
|
46bc5f2da6 | ||
|
|
d70182a84e | ||
|
|
7243f69826 | ||
|
|
1fc144e178 | ||
|
|
c383a7b7b7 | ||
|
|
69077c384c | ||
|
|
cfd49947ad | ||
|
|
6985dc4e9d | ||
|
|
5f2668b011 | ||
|
|
eba1ef9c59 | ||
|
|
8497144053 | ||
|
|
2006798388 | ||
|
|
bf63d850ca | ||
|
|
53e267ce24 | ||
|
|
1754ecf2ee | ||
|
|
3c37899a48 | ||
|
|
0436cfe3da | ||
|
|
3606de1a00 | ||
|
|
3081439eda | ||
|
|
7af0e74b85 | ||
|
|
7748b83a6b | ||
|
|
f83293ff1a | ||
|
|
9c3be2942e | ||
|
|
ee62bd98ee | ||
|
|
02e9610fad | ||
|
|
8a41db4649 | ||
|
|
e27ea3dc9f | ||
|
|
ec4bf54d81 | ||
|
|
ec3ca787fa | ||
|
|
86acbbb85b | ||
|
|
8e0af7a5f7 | ||
|
|
b022662dfc | ||
|
|
3039ebf913 | ||
|
|
e2e080c404 | ||
|
|
4671143d1c | ||
|
|
b492558cca | ||
|
|
64e76530d4 | ||
|
|
0b93f9f146 | ||
|
|
4c6fe1cd6c | ||
|
|
83ba48f598 | ||
|
|
62c6de8244 | ||
|
|
1c2f9f0c2c | ||
|
|
30bb0e8895 | ||
|
|
75c4c98de8 | ||
|
|
f72055909b | ||
|
|
b0a8783276 | ||
|
|
7b5ad92e66 | ||
|
|
250067927a | ||
|
|
7c2cbbaca7 | ||
|
|
ac037eabde | ||
|
|
0250b86b3f | ||
|
|
e45acc412b | ||
|
|
854206bc70 | ||
|
|
b192e98a8a | ||
|
|
c4e2c781c6 | ||
|
|
e80b3b8dfd |
43
.eslintrc.js
Normal file
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'
|
||||
}
|
||||
};
|
||||
7
.gitignore
vendored
7
.gitignore
vendored
@@ -0,0 +1,7 @@
|
||||
.libs
|
||||
node_modules/
|
||||
composer.lock
|
||||
vendor/
|
||||
tools/
|
||||
www/composer.lock
|
||||
www/vendor
|
||||
|
||||
@@ -27,7 +27,7 @@ use Phan\Config;
|
||||
|
||||
return [
|
||||
// "target_php_version" => "8.2",
|
||||
"minimum_target_php_version" => "8.1",
|
||||
"minimum_target_php_version" => "8.2",
|
||||
// turn color on (-C)
|
||||
"color_issue_messages_if_supported" => true,
|
||||
// If true, missing properties will be created when
|
||||
@@ -128,7 +128,12 @@ return [
|
||||
'PhanWriteOnlyPublicProperty',
|
||||
'PhanUnreferencedConstant',
|
||||
'PhanWriteOnlyPublicProperty',
|
||||
'PhanReadOnlyPublicProperty'
|
||||
'PhanReadOnlyPublicProperty',
|
||||
// start ignore annotations
|
||||
'PhanUnextractableAnnotationElementName',
|
||||
'PhanUnextractableAnnotationSuffix',
|
||||
// enum problems in comments
|
||||
'PhanCommentObjectInClassConstantType'
|
||||
],
|
||||
|
||||
// Override to hardcode existence and types of (non-builtin) globals in the global scope.
|
||||
|
||||
12
.phive/phars.xml
Normal file
12
.phive/phars.xml
Normal file
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<phive xmlns="https://phar.io/phive">
|
||||
<phar name="phpunit" version="^10.3.5" installed="10.3.5" location="./tools/phpunit" copy="false"/>
|
||||
<phar name="phpcbf" version="^3.7.2" installed="3.10.3" location="./tools/phpcbf" copy="false"/>
|
||||
<phar name="phpcs" version="^3.10.3" installed="3.10.3" location="./tools/phpcs" copy="false"/>
|
||||
<phar name="phpstan" version="^2.0" installed="2.0.4" location="./tools/phpstan" copy="false"/>
|
||||
<phar name="phan" version="^5.4.3" installed="5.4.3" location="./tools/phan" copy="false"/>
|
||||
<phar name="psalm" version="^5.15.0" installed="5.24.0" location="./tools/psalm" 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.3" location="./tools/phpDocumentor" copy="false"/>
|
||||
<phar name="php-cs-fixer" version="^3.34.1" installed="3.57.2" location="./tools/php-cs-fixer" copy="false"/>
|
||||
</phive>
|
||||
2
.shellcheckrc
Normal file
2
.shellcheckrc
Normal file
@@ -0,0 +1,2 @@
|
||||
shell=bash
|
||||
external-sources=true
|
||||
@@ -1,19 +1,20 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
BASE_FOLDER=$(dirname $(readlink -f $0))"/";
|
||||
BASE_FOLDER=$(dirname "$(readlink -f "$0")")"/";
|
||||
# Assume script is in 4dev/bin
|
||||
base_folder="${BASE_FOLDER}../../www/";
|
||||
|
||||
# locale gettext po to mo translator master
|
||||
for file in $(ls -1 ${base_folder}../4dev/locale/*.po); do
|
||||
file=$(basename $file .po);
|
||||
for file in "${base_folder}"../4dev/locale/*.po; do
|
||||
[[ -e "$file" ]] || break
|
||||
file=$(basename "$file" .po);
|
||||
locale=$(echo "${file}" | cut -d "-" -f 1);
|
||||
domain=$(echo "${file}" | cut -d "-" -f 2);
|
||||
echo "- Translate language file '${file}' for locale '${locale}' and domain '${domain}':";
|
||||
if [ ! -d "${base_folder}/includes/locale/${locale}/LC_MESSAGES/" ]; then
|
||||
mkdir -p "${base_folder}/includes/locale/${locale}/LC_MESSAGES/";
|
||||
fi;
|
||||
msgfmt -o ${base_folder}/includes/locale/${locale}/LC_MESSAGES/${domain}.mo ${base_folder}../4dev/locale/${locale}-${domain}.po;
|
||||
msgfmt -o "${base_folder}/includes/locale/${locale}/LC_MESSAGES/${domain}.mo" "${base_folder}../4dev/locale/${locale}-${domain}.po";
|
||||
done;
|
||||
|
||||
# __END__
|
||||
|
||||
@@ -2,16 +2,18 @@
|
||||
|
||||
# read source mo files and writes target js files in object form
|
||||
|
||||
# check for ARG 1 is "mv"
|
||||
# then move the files directly and don't do manual check (don't create temp files)
|
||||
FILE_MOVE=0;
|
||||
if [ "${1}" = "mv" ]; then
|
||||
# check for ARG 1 is "no-move"
|
||||
# then do not move the files directly for manual check
|
||||
FILE_MOVE=1;
|
||||
if [ "${1}" = "no-move" ]; then
|
||||
echo "+++ CREATE TEMPORARY FILES +++";
|
||||
FILE_MOVE=0;
|
||||
else
|
||||
echo "*** Direct write ***";
|
||||
FILE_MOVE=1;
|
||||
fi;
|
||||
|
||||
target='';
|
||||
BASE_FOLDER=$(dirname $(readlink -f $0))"/";
|
||||
BASE_FOLDER=$(dirname "$(readlink -f "$0")")"/";
|
||||
# Assume script is in 4dev/bin
|
||||
base_folder="${BASE_FOLDER}../../www/";
|
||||
po_folder='../4dev/locale/'
|
||||
@@ -26,9 +28,9 @@ if [ "${target}" == '' ]; then
|
||||
echo "*** Non smarty ***";
|
||||
TEXTDOMAINDIR=${base_folder}${mo_folder}.
|
||||
# default is admin
|
||||
TEXTDOMAIN=admin;
|
||||
TEXTDOMAIN="admin";
|
||||
fi;
|
||||
js_folder="layout/${TEXTDOMAIN}/javascript/";
|
||||
js_folder="${TEXTDOMAIN}/layout/javascript/";
|
||||
|
||||
error=0;
|
||||
# this checks if the TEXTDOMAIN target actually exists
|
||||
@@ -44,15 +46,16 @@ if [ ${error} -eq 1 ]; then
|
||||
fi;
|
||||
|
||||
# locale gettext po to mo translator master
|
||||
for file in $(ls -1 ${base_folder}../4dev/locale/*.po); do
|
||||
file=$(basename $file .po);
|
||||
echo "Translate language ${file}";
|
||||
for file in "${base_folder}"../4dev/locale/*.po; do
|
||||
[[ -e "$file" ]] || break
|
||||
file=$(basename "$file" .po);
|
||||
locale=$(echo "${file}" | cut -d "-" -f 1);
|
||||
domain=$(echo "${file}" | cut -d "-" -f 2);
|
||||
echo "- Translate language file '${file}' for locale '${locale}' and domain '${domain}':";
|
||||
if [ ! -d "${base_folder}/includes/locale/${locale}/LC_MESSAGES/" ]; then
|
||||
mkdir -p "${base_folder}/includes/locale/${locale}/LC_MESSAGES/";
|
||||
fi;
|
||||
msgfmt -o ${base_folder}/includes/locale/${locale}/LC_MESSAGES/${domain}.mo ${base_folder}${po_folder}${locale}-${domain}.po;
|
||||
msgfmt -o "${base_folder}/includes/locale/${locale}/LC_MESSAGES/${domain}.mo" "${base_folder}${po_folder}${locale}-${domain}.po";
|
||||
done;
|
||||
|
||||
rx_msgid_empty="^msgid \"\"";
|
||||
@@ -62,7 +65,7 @@ rx_msgstr="^msgstr \""
|
||||
# quick copy string at the end
|
||||
quick_copy='';
|
||||
|
||||
for language in ${language_list[*]}; do
|
||||
for language in "${language_list[@]}"; do
|
||||
# I don't know which one must be set, but I think at least LANGUAGE
|
||||
case ${language} in
|
||||
ja)
|
||||
@@ -79,7 +82,8 @@ for language in ${language_list[*]}; do
|
||||
esac;
|
||||
# write only one for language and then symlink files
|
||||
template_file=$(echo ${template_file_stump} | sed -e "s/##SUFFIX##//" | sed -e "s/##LANGUAGE##/${LANG}/");
|
||||
original_file=$(echo ${template_file} | sed -e 's/\.TMP//g');
|
||||
# original_file=$(echo ${template_file} | sed -e 's/\.TMP//g');
|
||||
original_file=${template_file//.TMP/};
|
||||
if [ "${FILE_MOVE}" -eq 0 ]; then
|
||||
file=${target_folder}${template_file};
|
||||
else
|
||||
@@ -88,16 +92,18 @@ for language in ${language_list[*]}; do
|
||||
echo "===> Write translation file ${file}";
|
||||
echo ". = normal, : = escape, x = skip";
|
||||
# init line [aka don't touch this file]
|
||||
echo "// AUTO FILL, changes will be overwritten" > $file;
|
||||
echo "// source: ${suffix}, language: ${language}" >> $file;
|
||||
echo "// Translation strings in the format" >> $file;
|
||||
echo "// \"Original\":\"Translated\""$'\n' >> $file;
|
||||
echo "var i18n = {" >> $file;
|
||||
echo "// AUTO FILL, changes will be overwritten" > "$file";
|
||||
{
|
||||
echo "// source: ${suffix}, language: ${language}";
|
||||
echo "// Translation strings in the format";
|
||||
echo "// \"Original\":\"Translated\""$'\n'
|
||||
echo "var i18n = {"
|
||||
} >> "$file"
|
||||
# translations stuff
|
||||
# read the po file
|
||||
pos=0; # do we add a , for the next line
|
||||
cat "${base_folder}${po_folder}${language}-${TEXTDOMAIN}.po" |
|
||||
while read str; do
|
||||
while read -r str; do
|
||||
# echo "S: ${str}";
|
||||
# skip empty
|
||||
if [[ "${str}" =~ ${rx_msgid_empty} ]]; then
|
||||
@@ -112,12 +118,13 @@ for language in ${language_list[*]}; do
|
||||
str_source=$(echo "${str}" | sed -e "s/^msgid \"//" | sed -e "s/\"$//");
|
||||
# close right side, if not last add ,
|
||||
if [ "${pos}" -eq 1 ]; then
|
||||
echo -n "," >> $file;
|
||||
echo -n "," >> "$file";
|
||||
fi;
|
||||
# all " inside string need to be escaped
|
||||
str_source=$(echo "${str_source}" | sed -e 's/"/\\"/g');
|
||||
# str_source=$(echo "${str_source}" | sed -e 's/"/\\"/g');
|
||||
str_source=${str_source//\"/\\\"}
|
||||
# fix with proper layout
|
||||
echo -n "\"$str_source\":\"$(TEXTDOMAINDIR=${TEXTDOMAINDIR} LANGUAGE=${language} LANG=${LANG} gettext ${TEXTDOMAIN} "${str_source}")\"" >> $file;
|
||||
echo -n "\"$str_source\":\"$(TEXTDOMAINDIR=${TEXTDOMAINDIR} LANGUAGE=${language} LANG=${LANG} gettext "${TEXTDOMAIN}" "${str_source}")\"" >> "$file";
|
||||
pos=1;
|
||||
elif [[ "${str}" =~ ${rx_msgstr} ]]; then
|
||||
# open right side (ignore)
|
||||
@@ -128,8 +135,8 @@ for language in ${language_list[*]}; do
|
||||
fi;
|
||||
done;
|
||||
|
||||
echo "" >> $file;
|
||||
echo "};" >> $file;
|
||||
echo "" >> "$file";
|
||||
echo "};" >> "$file";
|
||||
echo " [DONE]";
|
||||
|
||||
# on no move
|
||||
@@ -140,19 +147,19 @@ for language in ${language_list[*]}; do
|
||||
fi;
|
||||
|
||||
# symlink to master file
|
||||
for suffix in ${source_list[*]}; do
|
||||
for suffix in "${source_list[@]}"; do
|
||||
# symlink with full lang name
|
||||
symlink_file[0]=$(echo ${template_file_stump} | sed -e "s/##SUFFIX##/${suffix}_/" | sed -e "s/##LANGUAGE##/${LANG}/" | sed -e 's/\.TMP//g');
|
||||
# create second one with lang (no country) + encoding
|
||||
symlink_file[1]=$(echo ${template_file_stump} | sed -e "s/##SUFFIX##/${suffix}_/" | sed -e "s/##LANGUAGE##/${LANGUAGE}\.${ENCODING}/" | sed -e 's/\.TMP//g');
|
||||
for template_file in ${symlink_file[@]}; do
|
||||
for template_file in "${symlink_file[@]}"; do
|
||||
# if this is not symlink, create them
|
||||
if [ ! -h "${template_file}" ]; then
|
||||
echo "Create symlink: ${template_file}";
|
||||
# symlik to original
|
||||
cd "${target_folder}";
|
||||
cd "${target_folder}" || exit;
|
||||
ln -sf "${original_file}" "${template_file}";
|
||||
cd - >/dev/null;
|
||||
cd - >/dev/null || exit;
|
||||
fi;
|
||||
done;
|
||||
done;
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
base="/storage/var/www/html/developers/clemens/core_data/php_libraries/trunk/";
|
||||
# must be run in ${base}www/
|
||||
phan --progress-bar -C --analyze-twice
|
||||
# must be run in ${base}
|
||||
cd $base || exit;
|
||||
${base}tools/phan --progress-bar -C --analyze-twice;
|
||||
cd ~ || exit;
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
base="/storage/var/www/html/developers/clemens/core_data/php_libraries/trunk/";
|
||||
# must be run in ${base}www/
|
||||
phpstan
|
||||
# must be run in ${base}
|
||||
cd $base || exit;
|
||||
${base}tools/phpstan;
|
||||
cd ~ || exit;
|
||||
|
||||
@@ -1,46 +1,96 @@
|
||||
#!/bin/env bash
|
||||
|
||||
base="/storage/var/www/html/developers/clemens/core_data/php_libraries/trunk/";
|
||||
function error() {
|
||||
if [ -t 1 ]; then echo "[MAK] ERROR: $*" >&2; fi; exit 0;
|
||||
}
|
||||
|
||||
usage() {
|
||||
cat <<EOF
|
||||
Usage: $(basename "${BASH_SOURCE[0]}") [-h] [-t] [-v] [-p VERSION]
|
||||
|
||||
Runs all the PHP unit tests.
|
||||
|
||||
If -p is not set, the default intalled PHP is used.
|
||||
|
||||
Available options:
|
||||
|
||||
-h, --help Print this help and exit
|
||||
-t, --testdox Enable testdox output for phpunit
|
||||
-v, --verbose Enable verbose output for PHPunit
|
||||
-p, --php VERSION Chose PHP version in the form of "N.N", if not found will exit
|
||||
EOF
|
||||
exit
|
||||
}
|
||||
|
||||
# set base variables
|
||||
BASE_PATH="/storage/var/www/html/developers/clemens/core_data/php_libraries/trunk/";
|
||||
PHPUNIT_CONFIG="${BASE_PATH}phpunit.xml";
|
||||
PHP_BIN_PATH=$(which php);
|
||||
if [ -z "${PHP_BIN_PATH}" ]; then
|
||||
echo "Cannot find php binary";
|
||||
exit;
|
||||
fi;
|
||||
DEFAULT_PHP_VERSION=$(${PHP_BIN_PATH} -r "echo PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION;");
|
||||
if [ -z "${DEFAULT_PHP_VERSION}" ]; then
|
||||
echo "Cannot set default PHP version";
|
||||
exit;
|
||||
fi;
|
||||
# -c phpunit.xml
|
||||
# --testdox
|
||||
# call with "t" to give verbose testdox output
|
||||
# call with "-tt" to give verbose testdox output
|
||||
# SUPPORTED: https://www.php.net/supported-versions.php
|
||||
# call with php version number to force a certain php version
|
||||
# call with -p <php version number> to force a certain php version
|
||||
|
||||
opt_testdox="";
|
||||
if [ "${1}" = "t" ] || [ "${2}" = "t" ]; then
|
||||
opt_testdox="--testdox";
|
||||
fi;
|
||||
php_bin="";
|
||||
if [ ! -z "${1}" ]; then
|
||||
opt_verbose="";
|
||||
php_version="";
|
||||
no_php_version=0;
|
||||
while [ -n "${1-}" ]; do
|
||||
case "${1}" in
|
||||
# "7.3") php_bin="/usr/bin/php7.3 "; ;;
|
||||
# "7.4") php_bin="/usr/bin/php7.4 "; ;;
|
||||
# "8.0") php_bin="/usr/bin/php8.0 "; ;;
|
||||
"8.1") php_bin="/usr/bin/php8.1 "; ;;
|
||||
"8.2") php_bin="/usr/bin/php8.2 "; ;;
|
||||
*) echo "Not support PHP: ${1}"; exit; ;;
|
||||
esac;
|
||||
fi;
|
||||
if [ ! -z "${2}" ] && [ -z "${php_bin}" ]; then
|
||||
case "${2}" in
|
||||
# "7.3") php_bin="/usr/bin/php7.3 "; ;;
|
||||
# "7.4") php_bin="/usr/bin/php7.4 "; ;;
|
||||
# "8.0") php_bin="/usr/bin/php8.0 "; ;;
|
||||
"8.1") php_bin="/usr/bin/php8.1 "; ;;
|
||||
"8.2") php_bin="/usr/bin/php8.2 "; ;;
|
||||
*) echo "Not support PHP: ${1}"; exit; ;;
|
||||
esac;
|
||||
fi;
|
||||
-t | --testdox)
|
||||
opt_testdox="--testdox";
|
||||
;;
|
||||
-v | --verbose)
|
||||
opt_verbose="--verbose";
|
||||
;;
|
||||
-p | --php)
|
||||
php_version="${2-}";
|
||||
shift
|
||||
;;
|
||||
-h | --help)
|
||||
usage
|
||||
;;
|
||||
# invalid option
|
||||
-?*)
|
||||
error "[!] Unknown option: '$1'."
|
||||
;;
|
||||
esac
|
||||
shift;
|
||||
done;
|
||||
|
||||
phpunit_call="${php_bin}${base}www/vendor/bin/phpunit ${opt_testdox} -c ${base}phpunit.xml ${base}4dev/tests/";
|
||||
if [ -z "${php_version}" ]; then
|
||||
php_version="${DEFAULT_PHP_VERSION}";
|
||||
no_php_version=1;
|
||||
fi;
|
||||
php_bin="${PHP_BIN_PATH}${php_version}";
|
||||
echo "Use PHP Version: ${php_version}";
|
||||
|
||||
if [ ! -f "${php_bin}" ]; then
|
||||
echo "Set php ${php_bin} does not exist";
|
||||
exit;
|
||||
fi;
|
||||
php_bin="${php_bin} ";
|
||||
|
||||
# Note 4dev/tests/bootstrap.php has to be set as bootstrap file in phpunit.xml
|
||||
phpunit_call="${php_bin}${BASE_PATH}vendor/bin/phpunit ${opt_testdox} ${opt_verbose} -c ${PHPUNIT_CONFIG} ${BASE_PATH}4dev/tests/";
|
||||
|
||||
${phpunit_call};
|
||||
|
||||
if [ ! -z "${php_bin}" ]; then
|
||||
echo "CALLED WITH PHP: ${php_bin}"$(${php_bin} --version);
|
||||
echo -e "\nPHPUnit Config: ${PHPUNIT_CONFIG}";
|
||||
if [ "${no_php_version}" -eq 0 ]; then
|
||||
echo "CALLED WITH PHP: ${php_bin}$(${php_bin} --version)";
|
||||
else
|
||||
echo "Default PHP used: "$(php --version);
|
||||
echo "Default PHP used: $(php --version)";
|
||||
fi;
|
||||
|
||||
# __END__
|
||||
|
||||
@@ -13,7 +13,7 @@ if [ "${GO}" != "go" ]; then
|
||||
fi;
|
||||
|
||||
BASE="/storage/var/www/html/developers/clemens/core_data/";
|
||||
SOURCE="${BASE}php_libraries/trunk/"
|
||||
SOURCE="${BASE}php_libraries/master/"
|
||||
TARGET="${BASE}composer-packages/CoreLibs-Composer-All/"
|
||||
|
||||
rsync ${DRY_RUN}-Plzvrupt --stats --delete ${SOURCE}4dev/tests/ ${TARGET}test/phpunit/
|
||||
|
||||
@@ -5,9 +5,9 @@ RETURNS TRIGGER AS
|
||||
$$
|
||||
BEGIN
|
||||
IF TG_OP = 'INSERT' THEN
|
||||
NEW.date_created := 'now';
|
||||
NEW.date_created := clock_timestamp();
|
||||
ELSIF TG_OP = 'UPDATE' THEN
|
||||
NEW.date_updated := 'now';
|
||||
NEW.date_updated := clock_timestamp();
|
||||
END IF;
|
||||
RETURN NEW;
|
||||
END;
|
||||
|
||||
@@ -7,10 +7,11 @@ DECLARE
|
||||
random_length INT = 25; -- that should be long enough
|
||||
BEGIN
|
||||
IF TG_OP = 'INSERT' THEN
|
||||
NEW.date_created := 'now';
|
||||
NEW.date_created := clock_timestamp();
|
||||
NEW.cuid := random_string(random_length);
|
||||
NEW.cuuid := gen_random_uuid();
|
||||
ELSIF TG_OP = 'UPDATE' THEN
|
||||
NEW.date_updated := 'now';
|
||||
NEW.date_updated := clock_timestamp();
|
||||
END IF;
|
||||
RETURN NEW;
|
||||
END;
|
||||
|
||||
@@ -8,12 +8,12 @@ DECLARE
|
||||
random_length INT = 32; -- long for massive data
|
||||
BEGIN
|
||||
IF TG_OP = 'INSERT' THEN
|
||||
NEW.date_created := 'now';
|
||||
NEW.date_created := clock_timestamp();
|
||||
IF NEW.uid IS NULL THEN
|
||||
NEW.uid := random_string(random_length);
|
||||
END IF;
|
||||
ELSIF TG_OP = 'UPDATE' THEN
|
||||
NEW.date_updated := 'now';
|
||||
NEW.date_updated := clock_timestamp();
|
||||
END IF;
|
||||
RETURN NEW;
|
||||
END;
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
-- adds the created or updated date tags
|
||||
|
||||
-- OLD, DEPRECATED, use set_generic.sql
|
||||
|
||||
-- CREATE OR REPLACE FUNCTION set_generic()
|
||||
-- RETURNS TRIGGER AS
|
||||
-- $$
|
||||
-- BEGIN
|
||||
-- IF TG_OP = 'INSERT' THEN
|
||||
-- NEW.date_created := clock_timestamp();
|
||||
-- NEW.user_created := current_user;
|
||||
-- ELSIF TG_OP = 'UPDATE' THEN
|
||||
-- NEW.date_updated := clock_timestamp();
|
||||
-- NEW.user_updated := current_user;
|
||||
-- END IF;
|
||||
-- RETURN NEW;
|
||||
-- END;
|
||||
-- $$
|
||||
-- LANGUAGE 'plpgsql';
|
||||
110
4dev/database/function/upgrade_serial_to_identity.sql
Normal file
110
4dev/database/function/upgrade_serial_to_identity.sql
Normal file
@@ -0,0 +1,110 @@
|
||||
-- Upgrade serial to identity type
|
||||
--
|
||||
-- Original: https://www.enterprisedb.com/blog/postgresql-10-identity-columns-explained#section-6
|
||||
--
|
||||
-- @param reclass tbl The table where the column is located, prefix with 'schema.' if different schema
|
||||
-- @param name col The column to be changed
|
||||
-- @param varchar identity_type [default=a] Allowed a, d, assigned, default
|
||||
-- @param varchar col_type [default=''] Allowed smallint, int, bigint, int2, int4, int8
|
||||
-- @returns varchar status tring
|
||||
-- @raises EXCEPTON on column not found, no linked sequence, more than one linked sequence found, invalid col type
|
||||
--
|
||||
CREATE OR REPLACE FUNCTION upgrade_serial_to_identity(
|
||||
tbl regclass,
|
||||
col name,
|
||||
identity_type varchar = 'a',
|
||||
col_type varchar = ''
|
||||
)
|
||||
RETURNS varchar
|
||||
LANGUAGE plpgsql
|
||||
AS $$
|
||||
DECLARE
|
||||
colnum SMALLINT;
|
||||
seqid OID;
|
||||
count INT;
|
||||
col_type_oid INT;
|
||||
col_type_len INT;
|
||||
current_col_atttypid OID;
|
||||
current_col_attlen INT;
|
||||
status_string VARCHAR;
|
||||
BEGIN
|
||||
-- switch between always (default) or default identiy type
|
||||
IF identity_type NOT IN ('a', 'd', 'assigned', 'default') THEN
|
||||
identity_type := 'a';
|
||||
ELSE
|
||||
IF identity_type = 'default' THEN
|
||||
identity_type := 'd';
|
||||
ELSIF identity_type = 'assigned' THEN
|
||||
identity_type := 'a';
|
||||
END IF;
|
||||
END IF;
|
||||
-- find column number, attribute oid and attribute len
|
||||
SELECT attnum, atttypid, attlen
|
||||
INTO colnum, current_col_atttypid, current_col_attlen
|
||||
FROM pg_attribute
|
||||
WHERE attrelid = tbl AND attname = col;
|
||||
IF NOT FOUND THEN
|
||||
RAISE EXCEPTION 'column does not exist';
|
||||
END IF;
|
||||
|
||||
-- find sequence
|
||||
SELECT INTO seqid objid
|
||||
FROM pg_depend
|
||||
WHERE (refclassid, refobjid, refobjsubid) = ('pg_class'::regclass, tbl, colnum)
|
||||
AND classid = 'pg_class'::regclass AND objsubid = 0
|
||||
AND deptype = 'a';
|
||||
|
||||
GET DIAGNOSTICS count = ROW_COUNT;
|
||||
IF count < 1 THEN
|
||||
RAISE EXCEPTION 'no linked sequence found';
|
||||
ELSIF count > 1 THEN
|
||||
RAISE EXCEPTION 'more than one linked sequence found';
|
||||
END IF;
|
||||
|
||||
IF col_type <> '' AND col_type NOT IN ('smallint', 'int', 'bigint', 'int2', 'int4', 'int8') THEN
|
||||
RAISE EXCEPTION 'Invalid col type: %', col_type;
|
||||
END IF;
|
||||
|
||||
-- drop the default
|
||||
EXECUTE 'ALTER TABLE ' || tbl || ' ALTER COLUMN ' || quote_ident(col) || ' DROP DEFAULT';
|
||||
|
||||
-- change the dependency between column and sequence to internal
|
||||
UPDATE pg_depend
|
||||
SET deptype = 'i'
|
||||
WHERE (classid, objid, objsubid) = ('pg_class'::regclass, seqid, 0)
|
||||
AND deptype = 'a';
|
||||
|
||||
-- mark the column as identity column
|
||||
UPDATE pg_attribute
|
||||
-- set to 'd' for default
|
||||
SET attidentity = identity_type
|
||||
WHERE attrelid = tbl
|
||||
AND attname = col;
|
||||
status_string := 'Updated to identity for table "' || tbl || '" and columen "' || col || '" with type "' || identity_type || '"';
|
||||
|
||||
-- set type if requested and not empty
|
||||
IF col_type <> '' THEN
|
||||
-- rewrite smallint, int, bigint
|
||||
IF col_type = 'smallint' THEN
|
||||
col_type := 'int2';
|
||||
ELSIF col_type = 'int' THEN
|
||||
col_type := 'int4';
|
||||
ELSIF col_type = 'bigint' THEN
|
||||
col_type := 'int8';
|
||||
END IF;
|
||||
-- get the length and oid for selected
|
||||
SELECT oid, typlen INTO col_type_oid, col_type_len FROM pg_type WHERE typname = col_type;
|
||||
-- set only if diff or hight
|
||||
IF current_col_atttypid <> col_type_oid AND col_type_len > current_col_attlen THEN
|
||||
status_string := status_string || '. Change col type: ' || col_type;
|
||||
-- update type
|
||||
UPDATE pg_attribute
|
||||
SET
|
||||
atttypid = col_type_oid, attlen = col_type_len
|
||||
WHERE attrelid = tbl
|
||||
AND attname = col;
|
||||
END IF;
|
||||
END IF;
|
||||
RETURN status_string;
|
||||
END;
|
||||
$$;
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
-- DROP TABLE edit_access;
|
||||
CREATE TABLE edit_access (
|
||||
edit_access_id SERIAL PRIMARY KEY,
|
||||
edit_access_id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
|
||||
enabled SMALLINT NOT NULL DEFAULT 0,
|
||||
protected SMALLINT DEFAULT 0,
|
||||
deleted SMALLINT DEFAULT 0,
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
-- DROP TABLE edit_access_data;
|
||||
CREATE TABLE edit_access_data (
|
||||
edit_access_data_id SERIAL PRIMARY KEY,
|
||||
edit_access_data_id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
|
||||
edit_access_id INT NOT NULL,
|
||||
FOREIGN KEY (edit_access_id) REFERENCES edit_access (edit_access_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
enabled SMALLINT NOT NULL DEFAULT 0,
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
-- DROP TABLE edit_access_right;
|
||||
CREATE TABLE edit_access_right (
|
||||
edit_access_right_id SERIAL PRIMARY KEY,
|
||||
edit_access_right_id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
|
||||
name VARCHAR,
|
||||
level SMALLINT,
|
||||
type VARCHAR,
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
-- DROP TABLE edit_access_user;
|
||||
CREATE TABLE edit_access_user (
|
||||
edit_access_user_id SERIAL PRIMARY KEY,
|
||||
edit_access_user_id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
|
||||
edit_access_id INT NOT NULL,
|
||||
FOREIGN KEY (edit_access_id) REFERENCES edit_access (edit_access_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
edit_user_id INT NOT NULL,
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
-- DROP TABLE edit_generic;
|
||||
CREATE TABLE edit_generic (
|
||||
cuid VARCHAR,
|
||||
cuuid UUID DEFAULT gen_random_uuid(),
|
||||
date_created TIMESTAMP WITHOUT TIME ZONE DEFAULT clock_timestamp(),
|
||||
date_updated TIMESTAMP WITHOUT TIME ZONE
|
||||
);
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
-- DROP TABLE edit_group;
|
||||
CREATE TABLE edit_group (
|
||||
edit_group_id SERIAL PRIMARY KEY,
|
||||
edit_group_id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
|
||||
edit_scheme_id INT,
|
||||
FOREIGN KEY (edit_scheme_id) REFERENCES edit_scheme (edit_scheme_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
edit_access_right_id INT NOT NULL,
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
-- DROP TABLE edit_language;
|
||||
CREATE TABLE edit_language (
|
||||
edit_language_id SERIAL PRIMARY KEY,
|
||||
edit_language_id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
|
||||
enabled SMALLINT NOT NULL DEFAULT 0,
|
||||
lang_default SMALLINT NOT NULL DEFAULT 0,
|
||||
long_name VARCHAR,
|
||||
|
||||
@@ -7,35 +7,54 @@
|
||||
|
||||
-- DROP TABLE edit_log;
|
||||
CREATE TABLE edit_log (
|
||||
edit_log_id SERIAL PRIMARY KEY,
|
||||
edit_log_id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
|
||||
euid INT, -- this is a foreign key, but I don't nedd to reference to it
|
||||
FOREIGN KEY (euid) REFERENCES edit_user (edit_user_id) MATCH FULL ON UPDATE CASCADE ON DELETE SET NULL,
|
||||
username VARCHAR,
|
||||
password VARCHAR,
|
||||
eucuid VARCHAR,
|
||||
eucuuid UUID, -- this is the one we want to use, full UUIDv4 from the edit user table
|
||||
-- date_created equal, but can be overridden
|
||||
event_date TIMESTAMP WITHOUT TIME ZONE DEFAULT CURRENT_TIMESTAMP,
|
||||
ip VARCHAR,
|
||||
-- session ID if set
|
||||
session_id VARCHAR,
|
||||
-- username
|
||||
username VARCHAR,
|
||||
-- DEPRECATED [password]
|
||||
password VARCHAR,
|
||||
ip_address JSONB, -- REMOTE_IP and all other IPs (X_FORWARD, etc) as JSON block
|
||||
-- DEPRECATED [ip]
|
||||
ip VARCHAR, -- just the REMOTE_IP, full set see ip_address
|
||||
-- string blocks, general
|
||||
error TEXT,
|
||||
event TEXT,
|
||||
-- bytea or string type storage of any data
|
||||
data_binary BYTEA,
|
||||
data TEXT,
|
||||
-- set page name only
|
||||
page VARCHAR,
|
||||
action VARCHAR,
|
||||
action_id VARCHAR,
|
||||
action_yes VARCHAR,
|
||||
action_flag VARCHAR,
|
||||
action_menu VARCHAR,
|
||||
action_loaded VARCHAR,
|
||||
action_value VARCHAR,
|
||||
action_type VARCHAR,
|
||||
action_error VARCHAR,
|
||||
-- various info data sets
|
||||
user_agent VARCHAR,
|
||||
referer VARCHAR,
|
||||
script_name VARCHAR,
|
||||
query_string VARCHAR,
|
||||
request_scheme VARCHAR, -- http or https
|
||||
server_name VARCHAR,
|
||||
http_host VARCHAR,
|
||||
http_accept VARCHAR,
|
||||
http_accept_charset VARCHAR,
|
||||
http_accept_encoding VARCHAR,
|
||||
session_id VARCHAR
|
||||
http_data JSONB,
|
||||
-- DEPRECATED [http*]
|
||||
http_accept VARCHAR, -- in http_data
|
||||
http_accept_charset VARCHAR, -- in http_data
|
||||
http_accept_encoding VARCHAR, -- in http_data
|
||||
-- any action var, -> same set in action_data as JSON
|
||||
action_data JSONB,
|
||||
-- DEPRECATED [action*]
|
||||
action VARCHAR, -- in action_data
|
||||
action_id VARCHAR, -- in action_data
|
||||
action_sub_id VARCHAR, -- in action_data
|
||||
action_yes VARCHAR, -- in action_data
|
||||
action_flag VARCHAR, -- in action_data
|
||||
action_menu VARCHAR, -- in action_data
|
||||
action_loaded VARCHAR, -- in action_data
|
||||
action_value VARCHAR, -- in action_data
|
||||
action_type VARCHAR, -- in action_data
|
||||
action_error VARCHAR -- in action_data
|
||||
) INHERITS (edit_generic) WITHOUT OIDS;
|
||||
|
||||
@@ -7,10 +7,8 @@
|
||||
|
||||
-- DROP TABLE edit_menu_group;
|
||||
CREATE TABLE edit_menu_group (
|
||||
edit_menu_group_id SERIAL PRIMARY KEY,
|
||||
edit_menu_group_id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
|
||||
name VARCHAR,
|
||||
flag VARCHAR,
|
||||
order_number INT NOT NULL
|
||||
) INHERITS (edit_generic) WITHOUT OIDS;
|
||||
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
-- DROP TABLE edit_page;
|
||||
CREATE TABLE edit_page (
|
||||
edit_page_id SERIAL PRIMARY KEY,
|
||||
edit_page_id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
|
||||
content_alias_edit_page_id INT, -- alias for page content, if the page content is defined on a different page, ege for ajax backend pages
|
||||
FOREIGN KEY (content_alias_edit_page_id) REFERENCES edit_page (edit_page_id) MATCH FULL ON DELETE RESTRICT ON UPDATE CASCADE,
|
||||
filename VARCHAR,
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
-- DROP TABLE edit_page_access;
|
||||
CREATE TABLE edit_page_access (
|
||||
edit_page_access_id SERIAL PRIMARY KEY,
|
||||
edit_page_access_id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
|
||||
edit_group_id INT NOT NULL,
|
||||
FOREIGN KEY (edit_group_id) REFERENCES edit_group (edit_group_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
edit_page_id INT NOT NULL,
|
||||
@@ -16,5 +16,3 @@ CREATE TABLE edit_page_access (
|
||||
FOREIGN KEY (edit_access_right_id) REFERENCES edit_access_right (edit_access_right_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
enabled SMALLINT NOT NULL DEFAULT 0
|
||||
) INHERITS (edit_generic) WITHOUT OIDS;
|
||||
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
-- DROP TABLE edit_page_content;
|
||||
CREATE TABLE edit_page_content (
|
||||
edit_page_content_id SERIAL PRIMARY KEY,
|
||||
edit_page_content_id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
|
||||
edit_page_id INT NOT NULL,
|
||||
FOREIGN KEY (edit_page_id) REFERENCES edit_page (edit_page_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
edit_access_right_id INT NOT NULL,
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
-- DROP TABLE edit_query_string;
|
||||
CREATE TABLE edit_query_string (
|
||||
edit_query_string_id SERIAL PRIMARY KEY,
|
||||
edit_query_string_id SERIAINT GENERATED ALWAYS AS IDENTITYL PRIMARY KEY,
|
||||
edit_page_id INT NOT NULL,
|
||||
FOREIGN KEY (edit_page_id) REFERENCES edit_page (edit_page_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
enabled SMALLINT NOT NULL DEFAULT 0,
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
-- DROP TABLE edit_scheme;
|
||||
CREATE TABLE edit_scheme (
|
||||
edit_scheme_id SERIAL PRIMARY KEY,
|
||||
edit_scheme_id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
|
||||
enabled SMALLINT NOT NULL DEFAULT 0,
|
||||
name VARCHAR,
|
||||
header_color VARCHAR,
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
-- DROP TABLE edit_user;
|
||||
CREATE TABLE edit_user (
|
||||
edit_user_id SERIAL PRIMARY KEY,
|
||||
edit_user_id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
|
||||
connect_edit_user_id INT, -- possible reference to other user
|
||||
FOREIGN KEY (connect_edit_user_id) REFERENCES edit_user (edit_user_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
edit_language_id INT NOT NULL,
|
||||
@@ -35,11 +35,10 @@ CREATE TABLE edit_user (
|
||||
strict SMALLINT DEFAULT 0,
|
||||
locked SMALLINT DEFAULT 0,
|
||||
protected SMALLINT NOT NULL DEFAULT 0,
|
||||
-- legacy, debug flags
|
||||
debug SMALLINT NOT NULL DEFAULT 0,
|
||||
db_debug SMALLINT NOT NULL DEFAULT 0,
|
||||
-- is admin user
|
||||
admin SMALLINT NOT NULL DEFAULT 0,
|
||||
-- force lgout counter
|
||||
force_logout INT DEFAULT 0,
|
||||
-- last login log
|
||||
last_login TIMESTAMP WITHOUT TIME ZONE,
|
||||
-- login error
|
||||
@@ -76,9 +75,8 @@ COMMENT ON COLUMN edit_user.deleted IS 'Login is deleted (master switch), overri
|
||||
COMMENT ON COLUMN edit_user.strict IS 'If too many failed logins user will be locked, default off';
|
||||
COMMENT ON COLUMN edit_user.locked IS 'Locked from too many wrong password logins';
|
||||
COMMENT ON COLUMN edit_user.protected IS 'User can only be chnaged by admin user';
|
||||
COMMENT ON COLUMN edit_user.debug IS 'Turn debug flag on (legacy)';
|
||||
COMMENT ON COLUMN edit_user.db_debug IS 'Turn DB debug flag on (legacy)';
|
||||
COMMENT ON COLUMN edit_user.admin IS 'If set, this user is SUPER admin';
|
||||
COMMENT ON COLUMN edit_user.force_logout IS 'Counter for forced log out, if this one is higher than the session set one the session gets terminated';
|
||||
COMMENT ON COLUMN edit_user.last_login IS 'Last succesfull login tiemstamp';
|
||||
COMMENT ON COLUMN edit_user.login_error_count IS 'Number of failed logins, reset on successful login';
|
||||
COMMENT ON COLUMN edit_user.login_error_date_last IS 'Last login error date';
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
-- DROP TABLE edit_visible_group;
|
||||
CREATE TABLE edit_visible_group (
|
||||
edit_visible_group_id SERIAL PRIMARY KEY,
|
||||
edit_visible_group_id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
|
||||
name VARCHAR,
|
||||
flag VARCHAR
|
||||
) INHERITS (edit_generic) WITHOUT OIDS;
|
||||
|
||||
31
4dev/documentation/DB_Query_Params.md
Normal file
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
|
||||
65
4dev/tests/AAASetupData/requests/http_requests.php
Normal file
65
4dev/tests/AAASetupData/requests/http_requests.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php // phpcs:ignore PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* AUTHOR: Clemens Schwaighofer
|
||||
* CREATED: Ymd
|
||||
* DESCRIPTION:
|
||||
* DescriptionHere
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* build return json
|
||||
*
|
||||
* @param array<string,mixed> $http_headers
|
||||
* @param ?string $body
|
||||
* @return string
|
||||
*/
|
||||
function buildContent(array $http_headers, ?string $body): string
|
||||
{
|
||||
if (is_string($body) && !empty($body)) {
|
||||
$_body = json_decode($body, true);
|
||||
if (!is_array($_body)) {
|
||||
$body = [$body];
|
||||
} else {
|
||||
$body = $_body;
|
||||
}
|
||||
} elseif (is_string($body)) {
|
||||
$body = [];
|
||||
}
|
||||
return json_encode([
|
||||
'HEADERS' => $http_headers,
|
||||
"REQUEST_TYPE" => $_SERVER['REQUEST_METHOD'],
|
||||
"PARAMS" => $_GET,
|
||||
"BODY" => $body,
|
||||
]);
|
||||
}
|
||||
|
||||
$http_headers = array_filter($_SERVER, function ($value, $key) {
|
||||
if (str_starts_with($key, 'HTTP_')) {
|
||||
return true;
|
||||
}
|
||||
}, ARRAY_FILTER_USE_BOTH);
|
||||
|
||||
header("Content-Type: application/json; charset=UTF-8");
|
||||
|
||||
// if the header has Authorization and RunAuthTest then exit with 401
|
||||
if (!empty($http_headers['HTTP_AUTHORIZATION']) && !empty($http_headers['HTTP_RUNAUTHTEST'])) {
|
||||
header("HTTP/1.1 401 Unauthorized");
|
||||
print buildContent($http_headers, '{"code": 401, "content": {"Error": "Not Authorized"}}');
|
||||
exit;
|
||||
}
|
||||
|
||||
// if server request type is get set file_get to null -> no body
|
||||
if ($_SERVER['REQUEST_METHOD'] == "GET") {
|
||||
$file_get = null;
|
||||
} elseif (($file_get = file_get_contents('php://input')) === false) {
|
||||
header("HTTP/1.1 404 Not Found");
|
||||
print buildContent($http_headers, '{"code": 404, "content": {"Error": "file_get_contents failed"}}');
|
||||
exit;
|
||||
}
|
||||
|
||||
print buildContent($http_headers, $file_get);
|
||||
|
||||
// __END__
|
||||
@@ -22,8 +22,12 @@ Not yet covered tests:
|
||||
*/
|
||||
final class CoreLibsACLLoginTest extends TestCase
|
||||
{
|
||||
private static $db;
|
||||
private static $log;
|
||||
private static \CoreLibs\DB\IO $db;
|
||||
private static \CoreLibs\Logging\Logging $log;
|
||||
|
||||
private static string $edit_access_cuid;
|
||||
private static string $edit_user_cuid;
|
||||
private static string $edit_user_cuuid;
|
||||
|
||||
/**
|
||||
* start DB conneciton, setup DB, etc
|
||||
@@ -68,13 +72,10 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
|
||||
// logger is always needed
|
||||
// define basic connection set valid and one invalid
|
||||
self::$log = new \CoreLibs\Debug\Logging([
|
||||
self::$log = new \CoreLibs\Logging\Logging([
|
||||
// 'log_folder' => __DIR__ . DIRECTORY_SEPARATOR . 'log',
|
||||
'log_folder' => DIRECTORY_SEPARATOR . 'tmp',
|
||||
'file_id' => 'CoreLibs-ACL-Login-Test',
|
||||
'debug_all' => true,
|
||||
'echo_all' => false,
|
||||
'print_all' => true,
|
||||
'log_file_id' => 'CoreLibs-ACL-Login-Test',
|
||||
]);
|
||||
// test database we need to connect do, if not possible this test is skipped
|
||||
self::$db = new \CoreLibs\DB\IO(
|
||||
@@ -111,14 +112,40 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
self::$db->dbSetMaxQueryCall(-1);
|
||||
// insert additional content for testing (locked user, etc)
|
||||
$queries = [
|
||||
"INSERT INTO edit_access_data "
|
||||
. "(edit_access_id, name, value, enabled) VALUES "
|
||||
. "((SELECT edit_access_id FROM edit_access WHERE uid = 'AdminAccess'), "
|
||||
. "'test', 'value', 1)"
|
||||
<<<SQL
|
||||
INSERT INTO edit_access_data (
|
||||
edit_access_id, name, value, enabled
|
||||
) VALUES (
|
||||
(SELECT edit_access_id FROM edit_access WHERE uid = 'AdminAccess'),
|
||||
'test', 'value', 1
|
||||
)
|
||||
SQL
|
||||
];
|
||||
foreach ($queries as $query) {
|
||||
self::$db->dbExec($query);
|
||||
}
|
||||
// read edit access cuid, edit user cuid and edit user cuuid
|
||||
$row = self::$db->dbReturnRowParams(
|
||||
"SELECT cuid FROM edit_access WHERE uid = $1",
|
||||
["AdminAccess"]
|
||||
);
|
||||
self::$edit_access_cuid = $row['cuid'] ?? '';
|
||||
if (empty(self::$edit_access_cuid)) {
|
||||
self::markTestIncomplete(
|
||||
'Cannot read edit access cuid for "AdminAccess".'
|
||||
);
|
||||
}
|
||||
$row = self::$db->dbReturnRowParams(
|
||||
"SELECT cuid, cuuid FROM edit_user WHERE username = $1",
|
||||
["admin"]
|
||||
);
|
||||
self::$edit_user_cuid = $row['cuid'] ?? '';
|
||||
self::$edit_user_cuuid = $row['cuuid'] ?? '';
|
||||
if (empty(self::$edit_user_cuid) || empty(self::$edit_user_cuuid)) {
|
||||
self::markTestIncomplete(
|
||||
'Cannot read edit user cuid or cuuid for "admin".'
|
||||
);
|
||||
}
|
||||
|
||||
// define mandatory constant
|
||||
// must set
|
||||
@@ -170,8 +197,10 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
// change_password, pw_username, pw_old_password, pw_new_password,
|
||||
// pw_new_password_confirm
|
||||
// 3[session]: override session set
|
||||
// 4[error] : expected error code, 0 for all ok, 3000 for login page view
|
||||
// note that 1000 (no db), 2000 (no session) must be tested too
|
||||
// 4[error] : expected error code, 0 for all ok, 100 for login page view
|
||||
// note that 1000 (no db), 2000 (no session), 3000 (options set error)
|
||||
// must be tested too
|
||||
// <1000 info, >=1000 critical error
|
||||
// 5[return] : expected return array, eg login_error code,
|
||||
// or other info data to match
|
||||
$tests = [
|
||||
@@ -183,7 +212,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
3000,
|
||||
100,
|
||||
[
|
||||
'login_error' => 0,
|
||||
'error_string' => 'Success: <b>No error</b>',
|
||||
@@ -201,7 +230,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
3000,
|
||||
100,
|
||||
[
|
||||
'login_error' => 0,
|
||||
'error_string' => 'Success: <b>No error</b>',
|
||||
@@ -224,7 +253,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
3000,
|
||||
100,
|
||||
[
|
||||
'login_error' => 0,
|
||||
'error_string' => 'Success: <b>No error</b>',
|
||||
@@ -236,22 +265,25 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
'ajax_post_action' => 'login',
|
||||
],
|
||||
],
|
||||
'load, session euid set only, php error' => [
|
||||
'load, session eucuuid set only, php error' => [
|
||||
[
|
||||
'page_name' => 'edit_users.php',
|
||||
],
|
||||
[],
|
||||
[],
|
||||
[
|
||||
'EUID' => 1,
|
||||
'LOGIN_EUID' => 1,
|
||||
'LOGIN_EUCUID' => 'abc',
|
||||
'LOGIN_EUCUUID' => '1233456-1234-1234-1234-123456789012',
|
||||
],
|
||||
2,
|
||||
[],
|
||||
],
|
||||
'load, session euid set, all set' => [
|
||||
'load, session eucuuid set, all set' => [
|
||||
[
|
||||
'page_name' => 'edit_users.php',
|
||||
'edit_access_id' => 1,
|
||||
'edit_access_cuid' => 'SET_EDIT_ACCESS_CUID_IN_TEST',
|
||||
'edit_access_uid' => 'AdminAccess',
|
||||
'edit_access_data' => 'test',
|
||||
'base_access' => 'list',
|
||||
@@ -260,20 +292,23 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
[],
|
||||
[],
|
||||
[
|
||||
'EUID' => 1,
|
||||
'USER_NAME' => '',
|
||||
'GROUP_NAME' => '',
|
||||
'ADMIN' => 1,
|
||||
'GROUP_ACL_LEVEL' => -1,
|
||||
'PAGES_ACL_LEVEL' => [],
|
||||
'USER_ACL_LEVEL' => -1,
|
||||
'USER_ADDITIONAL_ACL' => [],
|
||||
'GROUP_ADDITIONAL_ACL' => [],
|
||||
'UNIT_UID' => [
|
||||
'AdminAccess' => 1,
|
||||
'LOGIN_EUID' => 1,
|
||||
'LOGIN_EUCUID' => 'abc',
|
||||
'LOGIN_EUCUUID' => 'SET_EUCUUID_IN_TEST',
|
||||
'LOGIN_USER_NAME' => '',
|
||||
'LOGIN_GROUP_NAME' => '',
|
||||
'LOGIN_ADMIN' => 1,
|
||||
'LOGIN_GROUP_ACL_LEVEL' => -1,
|
||||
'LOGIN_PAGES_ACL_LEVEL' => [],
|
||||
'LOGIN_USER_ACL_LEVEL' => -1,
|
||||
'LOGIN_USER_ADDITIONAL_ACL' => [],
|
||||
'LOGIN_GROUP_ADDITIONAL_ACL' => [],
|
||||
'LOGIN_UNIT_UID' => [
|
||||
'AdminAccess' => '123456789012',
|
||||
],
|
||||
'UNIT' => [
|
||||
1 => [
|
||||
'LOGIN_UNIT' => [
|
||||
'123456789012' => [
|
||||
'id' => 1,
|
||||
'acl_level' => 80,
|
||||
'name' => 'Admin Access',
|
||||
'uid' => 'AdminAccess',
|
||||
@@ -285,8 +320,8 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
'additional_acl' => []
|
||||
],
|
||||
],
|
||||
// 'UNIT_DEFAULT' => '',
|
||||
// 'DEFAULT_ACL_LIST' => [],
|
||||
// 'LOGIN_UNIT_DEFAULT' => '',
|
||||
// 'LOGIN_DEFAULT_ACL_LIST' => [],
|
||||
],
|
||||
0,
|
||||
[
|
||||
@@ -294,6 +329,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
'admin_flag' => true,
|
||||
'check_access' => true,
|
||||
'check_access_id' => 1,
|
||||
'check_access_cuid' => 'SET_EDIT_ACCESS_CUID_IN_TEST',
|
||||
'check_access_data' => 'value',
|
||||
'base_access' => true,
|
||||
'page_access' => true,
|
||||
@@ -311,7 +347,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
'login_password' => '',
|
||||
],
|
||||
[],
|
||||
3000,
|
||||
100,
|
||||
[
|
||||
'login_error' => 102,
|
||||
'error_string' => '<span style="color: red;">Fatal Error:</span> '
|
||||
@@ -332,7 +368,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
'login_password' => 'abc',
|
||||
],
|
||||
[],
|
||||
3000,
|
||||
100,
|
||||
[
|
||||
'login_error' => 102,
|
||||
'error_string' => '<span style="color: red;">Fatal Error:</span> '
|
||||
@@ -353,7 +389,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
'login_password' => '',
|
||||
],
|
||||
[],
|
||||
3000,
|
||||
100,
|
||||
[
|
||||
'login_error' => 102,
|
||||
'error_string' => '<span style="color: red;">Fatal Error:</span> '
|
||||
@@ -374,7 +410,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
'login_password' => 'abc',
|
||||
],
|
||||
[],
|
||||
3000,
|
||||
100,
|
||||
[
|
||||
'login_error' => 1010,
|
||||
'error_string' => '<span style="color: red;">Fatal Error:</span> '
|
||||
@@ -398,7 +434,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
'login_password' => 'abc',
|
||||
],
|
||||
[],
|
||||
3000,
|
||||
100,
|
||||
[
|
||||
// default password is plain text
|
||||
'login_error' => 1012,
|
||||
@@ -413,6 +449,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
[
|
||||
'page_name' => 'edit_users.php',
|
||||
'edit_access_id' => 1,
|
||||
'edit_access_cuid' => 'SET_EDIT_ACCESS_CUID_IN_TEST',
|
||||
'base_access' => 'list',
|
||||
'page_access' => 'list',
|
||||
'test_deleted' => true
|
||||
@@ -424,7 +461,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
'login_password' => 'admin',
|
||||
],
|
||||
[],
|
||||
3000,
|
||||
100,
|
||||
[
|
||||
'login_error' => 106,
|
||||
'error_string' => '<span style="color: red;">Fatal Error:</span> '
|
||||
@@ -438,6 +475,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
[
|
||||
'page_name' => 'edit_users.php',
|
||||
'edit_access_id' => 1,
|
||||
'edit_access_cuid' => 'SET_EDIT_ACCESS_CUID_IN_TEST',
|
||||
'base_access' => 'list',
|
||||
'page_access' => 'list',
|
||||
'test_enabled' => true
|
||||
@@ -449,7 +487,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
'login_password' => 'admin',
|
||||
],
|
||||
[],
|
||||
3000,
|
||||
100,
|
||||
[
|
||||
'login_error' => 104,
|
||||
'error_string' => '<span style="color: red;">Fatal Error:</span> '
|
||||
@@ -463,6 +501,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
[
|
||||
'page_name' => 'edit_users.php',
|
||||
'edit_access_id' => 1,
|
||||
'edit_access_cuid' => 'SET_EDIT_ACCESS_CUID_IN_TEST',
|
||||
'base_access' => 'list',
|
||||
'page_access' => 'list',
|
||||
'test_locked' => true
|
||||
@@ -474,7 +513,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
'login_password' => 'admin',
|
||||
],
|
||||
[],
|
||||
3000,
|
||||
100,
|
||||
[
|
||||
'login_error' => 105,
|
||||
'error_string' => '<span style="color: red;">Fatal Error:</span> '
|
||||
@@ -488,6 +527,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
[
|
||||
'page_name' => 'edit_users.php',
|
||||
'edit_access_id' => 1,
|
||||
'edit_access_cuid' => 'SET_EDIT_ACCESS_CUID_IN_TEST',
|
||||
'base_access' => 'list',
|
||||
'page_access' => 'list',
|
||||
'test_get_locked' => true,
|
||||
@@ -512,6 +552,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
[
|
||||
'page_name' => 'edit_users.php',
|
||||
'edit_access_id' => 1,
|
||||
'edit_access_cuid' => 'SET_EDIT_ACCESS_CUID_IN_TEST',
|
||||
'base_access' => 'list',
|
||||
'page_access' => 'list',
|
||||
'test_locked_period_until' => 'on'
|
||||
@@ -523,7 +564,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
'login_password' => 'admin',
|
||||
],
|
||||
[],
|
||||
3000,
|
||||
100,
|
||||
[
|
||||
'login_error' => 107,
|
||||
'error_string' => '<span style="color: red;">Fatal Error:</span> '
|
||||
@@ -537,6 +578,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
[
|
||||
'page_name' => 'edit_users.php',
|
||||
'edit_access_id' => 1,
|
||||
'edit_access_cuid' => 'SET_EDIT_ACCESS_CUID_IN_TEST',
|
||||
'edit_access_uid' => 'AdminAccess',
|
||||
'edit_access_data' => 'test',
|
||||
'base_access' => 'list',
|
||||
@@ -556,6 +598,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
'admin_flag' => true,
|
||||
'check_access' => true,
|
||||
'check_access_id' => 1,
|
||||
'check_access_cuid' => 'SET_EDIT_ACCESS_CUID_IN_TEST',
|
||||
'check_access_data' => 'value',
|
||||
'base_access' => true,
|
||||
'page_access' => true,
|
||||
@@ -566,6 +609,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
[
|
||||
'page_name' => 'edit_users.php',
|
||||
'edit_access_id' => 1,
|
||||
'edit_access_cuid' => 'SET_EDIT_ACCESS_CUID_IN_TEST',
|
||||
'base_access' => 'list',
|
||||
'page_access' => 'list',
|
||||
'test_locked_period_after' => 'on'
|
||||
@@ -577,7 +621,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
'login_password' => 'admin',
|
||||
],
|
||||
[],
|
||||
3000,
|
||||
100,
|
||||
[
|
||||
'login_error' => 107,
|
||||
'error_string' => '<span style="color: red;">Fatal Error:</span> '
|
||||
@@ -591,6 +635,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
[
|
||||
'page_name' => 'edit_users.php',
|
||||
'edit_access_id' => 1,
|
||||
'edit_access_cuid' => 'SET_EDIT_ACCESS_CUID_IN_TEST',
|
||||
'base_access' => 'list',
|
||||
'page_access' => 'list',
|
||||
'test_locked_period_until' => 'on',
|
||||
@@ -603,7 +648,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
'login_password' => 'admin',
|
||||
],
|
||||
[],
|
||||
3000,
|
||||
100,
|
||||
[
|
||||
'login_error' => 107,
|
||||
'error_string' => '<span style="color: red;">Fatal Error:</span> '
|
||||
@@ -617,6 +662,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
[
|
||||
'page_name' => 'edit_users.php',
|
||||
'edit_access_id' => 1,
|
||||
'edit_access_cuid' => 'SET_EDIT_ACCESS_CUID_IN_TEST',
|
||||
'base_access' => 'list',
|
||||
'page_access' => 'list',
|
||||
'test_login_user_id_locked' => true
|
||||
@@ -628,7 +674,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
'login_password' => 'admin',
|
||||
],
|
||||
[],
|
||||
3000,
|
||||
100,
|
||||
[
|
||||
'login_error' => 108,
|
||||
'error_string' => '<span style="color: red;">Fatal Error:</span> '
|
||||
@@ -642,6 +688,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
[
|
||||
'page_name' => 'edit_users.php',
|
||||
'edit_access_id' => 1,
|
||||
'edit_access_cuid' => 'SET_EDIT_ACCESS_CUID_IN_TEST',
|
||||
'edit_access_uid' => 'AdminAccess',
|
||||
'edit_access_data' => 'test',
|
||||
'base_access' => 'list',
|
||||
@@ -660,6 +707,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
'admin_flag' => true,
|
||||
'check_access' => true,
|
||||
'check_access_id' => 1,
|
||||
'check_access_cuid' => 'SET_EDIT_ACCESS_CUID_IN_TEST',
|
||||
'check_access_data' => 'value',
|
||||
'base_access' => true,
|
||||
'page_access' => true,
|
||||
@@ -670,6 +718,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
[
|
||||
'page_name' => 'edit_users.php',
|
||||
'edit_access_id' => 1,
|
||||
'edit_access_cuid' => 'SET_EDIT_ACCESS_CUID_IN_TEST',
|
||||
'edit_access_uid' => 'AdminAccess',
|
||||
'edit_access_data' => 'test',
|
||||
'base_access' => 'list',
|
||||
@@ -689,6 +738,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
'admin_flag' => true,
|
||||
'check_access' => true,
|
||||
'check_access_id' => 1,
|
||||
'check_access_cuid' => 'SET_EDIT_ACCESS_CUID_IN_TEST',
|
||||
'check_access_data' => 'value',
|
||||
'base_access' => true,
|
||||
'page_access' => true,
|
||||
@@ -699,6 +749,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
[
|
||||
'page_name' => 'edit_users.php',
|
||||
'edit_access_id' => 1,
|
||||
'edit_access_cuid' => 'SET_EDIT_ACCESS_CUID_IN_TEST',
|
||||
'edit_access_uid' => 'AdminAccess',
|
||||
'edit_access_data' => 'test',
|
||||
'base_access' => 'list',
|
||||
@@ -718,6 +769,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
'admin_flag' => true,
|
||||
'check_access' => true,
|
||||
'check_access_id' => 1,
|
||||
'check_access_cuid' => 'SET_EDIT_ACCESS_CUID_IN_TEST',
|
||||
'check_access_data' => 'value',
|
||||
'base_access' => true,
|
||||
'page_access' => true,
|
||||
@@ -728,6 +780,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
[
|
||||
'page_name' => 'edit_users.php',
|
||||
'edit_access_id' => 1,
|
||||
'edit_access_cuid' => 'SET_EDIT_ACCESS_CUID_IN_TEST',
|
||||
'edit_access_uid' => 'AdminAccess',
|
||||
'edit_access_data' => 'test',
|
||||
'base_access' => 'list',
|
||||
@@ -747,6 +800,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
'admin_flag' => true,
|
||||
'check_access' => true,
|
||||
'check_access_id' => 1,
|
||||
'check_access_cuid' => 'SET_EDIT_ACCESS_CUID_IN_TEST',
|
||||
'check_access_data' => 'value',
|
||||
'base_access' => true,
|
||||
'page_access' => true,
|
||||
@@ -764,7 +818,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
],
|
||||
[],
|
||||
[],
|
||||
3000,
|
||||
100,
|
||||
[
|
||||
'login_error' => 1010,
|
||||
'error_string' => '<span style="color: red;">Fatal Error:</span> '
|
||||
@@ -778,6 +832,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
[
|
||||
'page_name' => 'edit_users.php',
|
||||
'edit_access_id' => 1,
|
||||
'edit_access_cuid' => 'SET_EDIT_ACCESS_CUID_IN_TEST',
|
||||
'edit_access_uid' => 'AdminAccess',
|
||||
'edit_access_data' => 'test',
|
||||
'base_access' => 'list',
|
||||
@@ -801,6 +856,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
'admin_flag' => true,
|
||||
'check_access' => true,
|
||||
'check_access_id' => 1,
|
||||
'check_access_cuid' => 'SET_EDIT_ACCESS_CUID_IN_TEST',
|
||||
'check_access_data' => 'value',
|
||||
'base_access' => true,
|
||||
'page_access' => true,
|
||||
@@ -811,6 +867,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
[
|
||||
'page_name' => 'edit_users.php',
|
||||
'edit_access_id' => 1,
|
||||
'edit_access_cuid' => 'SET_EDIT_ACCESS_CUID_IN_TEST',
|
||||
'edit_access_uid' => 'AdminAccess',
|
||||
'edit_access_data' => 'test',
|
||||
'base_access' => 'list',
|
||||
@@ -834,6 +891,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
'admin_flag' => true,
|
||||
'check_access' => true,
|
||||
'check_access_id' => 1,
|
||||
'check_access_cuid' => 'SET_EDIT_ACCESS_CUID_IN_TEST',
|
||||
'check_access_data' => 'value',
|
||||
'base_access' => true,
|
||||
'page_access' => true,
|
||||
@@ -844,6 +902,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
[
|
||||
'page_name' => 'edit_users.php',
|
||||
'edit_access_id' => 1,
|
||||
'edit_access_cuid' => 'SET_EDIT_ACCESS_CUID_IN_TEST',
|
||||
'base_access' => 'list',
|
||||
'page_access' => 'list',
|
||||
'test_login_user_id_revalidate_after' => 'on',
|
||||
@@ -856,7 +915,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
],
|
||||
[],
|
||||
[],
|
||||
3000,
|
||||
100,
|
||||
[
|
||||
'login_error' => 1101,
|
||||
'error_string' => '<span style="color: red;">Fatal Error:</span> '
|
||||
@@ -870,6 +929,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
[
|
||||
'page_name' => 'edit_users.php',
|
||||
'edit_access_id' => 1,
|
||||
'edit_access_cuid' => 'SET_EDIT_ACCESS_CUID_IN_TEST',
|
||||
'edit_access_uid' => 'AdminAccess',
|
||||
'edit_access_data' => 'test',
|
||||
'base_access' => 'list',
|
||||
@@ -890,6 +950,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
'admin_flag' => true,
|
||||
'check_access' => true,
|
||||
'check_access_id' => 1,
|
||||
'check_access_cuid' => 'SET_EDIT_ACCESS_CUID_IN_TEST',
|
||||
'check_access_data' => 'value',
|
||||
'base_access' => true,
|
||||
'page_access' => true,
|
||||
@@ -900,6 +961,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
[
|
||||
'page_name' => 'edit_users.php',
|
||||
'edit_access_id' => 1,
|
||||
'edit_access_cuid' => 'SET_EDIT_ACCESS_CUID_IN_TEST',
|
||||
'base_access' => 'list',
|
||||
'page_access' => 'list',
|
||||
'test_login_user_id_valid_from' => 'on',
|
||||
@@ -912,7 +974,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
],
|
||||
[],
|
||||
[],
|
||||
3000,
|
||||
100,
|
||||
[
|
||||
'login_error' => 1102,
|
||||
'error_string' => '<span style="color: red;">Fatal Error:</span> '
|
||||
@@ -926,6 +988,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
[
|
||||
'page_name' => 'edit_users.php',
|
||||
'edit_access_id' => 1,
|
||||
'edit_access_cuid' => 'SET_EDIT_ACCESS_CUID_IN_TEST',
|
||||
'edit_access_uid' => 'AdminAccess',
|
||||
'edit_access_data' => 'test',
|
||||
'base_access' => 'list',
|
||||
@@ -946,6 +1009,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
'admin_flag' => true,
|
||||
'check_access' => true,
|
||||
'check_access_id' => 1,
|
||||
'check_access_cuid' => 'SET_EDIT_ACCESS_CUID_IN_TEST',
|
||||
'check_access_data' => 'value',
|
||||
'base_access' => true,
|
||||
'page_access' => true,
|
||||
@@ -956,6 +1020,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
[
|
||||
'page_name' => 'edit_users.php',
|
||||
'edit_access_id' => 1,
|
||||
'edit_access_cuid' => 'SET_EDIT_ACCESS_CUID_IN_TEST',
|
||||
'base_access' => 'list',
|
||||
'page_access' => 'list',
|
||||
'test_login_user_id_valid_until' => 'on',
|
||||
@@ -968,7 +1033,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
],
|
||||
[],
|
||||
[],
|
||||
3000,
|
||||
100,
|
||||
[
|
||||
'login_error' => 1102,
|
||||
'error_string' => '<span style="color: red;">Fatal Error:</span> '
|
||||
@@ -982,6 +1047,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
[
|
||||
'page_name' => 'edit_users.php',
|
||||
'edit_access_id' => 1,
|
||||
'edit_access_cuid' => 'SET_EDIT_ACCESS_CUID_IN_TEST',
|
||||
'base_access' => 'list',
|
||||
'page_access' => 'list',
|
||||
'test_login_user_id_valid_from' => 'on',
|
||||
@@ -995,7 +1061,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
],
|
||||
[],
|
||||
[],
|
||||
3000,
|
||||
100,
|
||||
[
|
||||
'login_error' => 1102,
|
||||
'error_string' => '<span style="color: red;">Fatal Error:</span> '
|
||||
@@ -1009,6 +1075,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
[
|
||||
'page_name' => 'edit_users.php',
|
||||
'edit_access_id' => 1,
|
||||
'edit_access_cuid' => 'SET_EDIT_ACCESS_CUID_IN_TEST',
|
||||
'edit_access_uid' => 'AdminAccess',
|
||||
'edit_access_data' => 'test',
|
||||
'base_access' => 'list',
|
||||
@@ -1039,6 +1106,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
'admin_flag' => true,
|
||||
'check_access' => true,
|
||||
'check_access_id' => 1,
|
||||
'check_access_cuid' => 'SET_EDIT_ACCESS_CUID_IN_TEST',
|
||||
'check_access_data' => 'value',
|
||||
'base_access' => true,
|
||||
'page_access' => true,
|
||||
@@ -1086,9 +1154,9 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
/** @var \CoreLibs\Create\Session&MockObject */
|
||||
$session_mock = $this->createPartialMock(
|
||||
\CoreLibs\Create\Session::class,
|
||||
['startSession', 'checkActiveSession', 'sessionDestroy']
|
||||
['getSessionId', 'checkActiveSession', 'sessionDestroy']
|
||||
);
|
||||
$session_mock->method('startSession')->willReturn('ACLLOGINTEST12');
|
||||
$session_mock->method('getSessionId')->willReturn('ACLLOGINTEST12');
|
||||
$session_mock->method('checkActiveSession')->willReturn(true);
|
||||
$session_mock->method('sessionDestroy')->will(
|
||||
$this->returnCallback(function () {
|
||||
@@ -1108,11 +1176,15 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
$_POST[$post_var] = $post_value;
|
||||
}
|
||||
|
||||
// set ingoing session cuuid if requested
|
||||
if (isset($session['LOGIN_EUCUUID']) && $session['LOGIN_EUCUUID'] == 'SET_EUCUUID_IN_TEST') {
|
||||
$session['LOGIN_EUCUUID'] = self::$edit_user_cuuid;
|
||||
}
|
||||
|
||||
// set _SESSION data
|
||||
foreach ($session as $session_var => $session_value) {
|
||||
$_SESSION[$session_var] = $session_value;
|
||||
}
|
||||
|
||||
/** @var \CoreLibs\ACL\Login&MockObject */
|
||||
$login_mock = $this->getMockBuilder(\CoreLibs\ACL\Login::class)
|
||||
->setConstructorArgs([
|
||||
@@ -1131,12 +1203,12 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
. 'locale' . DIRECTORY_SEPARATOR,
|
||||
]
|
||||
])
|
||||
->onlyMethods(['loginTerminate', 'loginReadPageName', 'loginPrintLogin'])
|
||||
->onlyMethods(['loginTerminate', 'loginReadPageName', 'loginPrintLogin', 'loginEnhanceHttpSecurity'])
|
||||
->getMock();
|
||||
$login_mock->expects($this->any())
|
||||
->method('loginTerminate')
|
||||
->will(
|
||||
$this->returnCallback(function ($code) {
|
||||
$this->returnCallback(function ($message, $code) {
|
||||
throw new \Exception('', $code);
|
||||
})
|
||||
);
|
||||
@@ -1149,6 +1221,10 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
->method('loginPrintLogin')
|
||||
->willReturnCallback(function () {
|
||||
});
|
||||
$login_mock->expects($this->any())
|
||||
->method('loginEnhanceHttpSecurity')
|
||||
->willReturnCallback(function () {
|
||||
});
|
||||
|
||||
// if mock_settings: enabled OFF
|
||||
// run DB update and set off
|
||||
@@ -1230,7 +1306,11 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
$login_mock->loginSetMaxLoginErrorCount($mock_settings['max_login_error_count']);
|
||||
// temporary wrong password
|
||||
$_POST['login_password'] = 'wrong';
|
||||
for ($run = 1, $max_run = $login_mock->loginGetMaxLoginErrorCount(); $run <= $max_run; $run++) {
|
||||
for (
|
||||
$run = 1, $max_run = $login_mock->loginGetMaxLoginErrorCount();
|
||||
$run <= $max_run;
|
||||
$run++
|
||||
) {
|
||||
try {
|
||||
$login_mock->loginMainCall();
|
||||
} catch (\Exception $e) {
|
||||
@@ -1362,6 +1442,19 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
|
||||
// run test
|
||||
try {
|
||||
// preset, we cannot set that in the provider
|
||||
if (
|
||||
isset($expected['check_access_cuid']) &&
|
||||
$expected['check_access_cuid'] == 'SET_EDIT_ACCESS_CUID_IN_TEST'
|
||||
) {
|
||||
$expected['check_access_cuid'] = self::$edit_access_cuid;
|
||||
}
|
||||
if (
|
||||
isset($mock_settings['edit_access_cuid']) &&
|
||||
$mock_settings['edit_access_cuid'] == 'SET_EDIT_ACCESS_CUID_IN_TEST'
|
||||
) {
|
||||
$mock_settings['edit_access_cuid'] = self::$edit_access_cuid;
|
||||
}
|
||||
// if ajax call
|
||||
// check if parameter, or globals (old type)
|
||||
// else normal call
|
||||
@@ -1420,6 +1513,31 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
$login_mock->loginCheckAccessPage($mock_settings['page_access']),
|
||||
'Assert page access'
|
||||
);
|
||||
// - loginCheckEditAccessCuid
|
||||
$this->assertEquals(
|
||||
$expected['check_access'],
|
||||
$login_mock->loginCheckEditAccessCuid($mock_settings['edit_access_cuid']),
|
||||
'Assert check access'
|
||||
);
|
||||
// - loginCheckEditAccessValidCuid
|
||||
$this->assertEquals(
|
||||
$expected['check_access_cuid'],
|
||||
$login_mock->loginCheckEditAccessValidCuid($mock_settings['edit_access_cuid']),
|
||||
'Assert check access cuid valid'
|
||||
);
|
||||
// - loginGetEditAccessCuidFromUid
|
||||
$this->assertEquals(
|
||||
$expected['check_access_cuid'],
|
||||
$login_mock->loginGetEditAccessCuidFromUid($mock_settings['edit_access_uid']),
|
||||
'Assert check access uid to cuid valid'
|
||||
);
|
||||
// - loginGetEditAccessCuidFromId
|
||||
$this->assertEquals(
|
||||
$expected['check_access_cuid'],
|
||||
$login_mock->loginGetEditAccessCuidFromUid($mock_settings['edit_access_id']),
|
||||
'Assert check access id to cuid valid'
|
||||
);
|
||||
// Deprecated
|
||||
// - loginCheckEditAccess
|
||||
$this->assertEquals(
|
||||
$expected['check_access'],
|
||||
@@ -1442,7 +1560,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
$this->assertEquals(
|
||||
$expected['check_access_data'],
|
||||
$login_mock->loginGetEditAccessData(
|
||||
$mock_settings['edit_access_id'],
|
||||
$mock_settings['edit_access_uid'],
|
||||
$mock_settings['edit_access_data']
|
||||
),
|
||||
'Assert check access id data value valid'
|
||||
@@ -1473,15 +1591,16 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
// - loginCheckPermissions
|
||||
// - loginGetPermissionOkay
|
||||
} catch (\Exception $e) {
|
||||
// print "[E]: " . $e->getCode() . ", ERROR: " . $login_mock->loginGetLastErrorCode() . "/"
|
||||
// . ($expected['login_error'] ?? 0) . "\n";
|
||||
// print "AJAX: " . $login_mock->loginGetAjaxFlag() . "\n";
|
||||
// print "AJAX GLOBAL: " . ($GLOBALS['AJAX_PAGE'] ?? '{f}') . "\n";
|
||||
// print "Login error expext: " . ($expected['login_error'] ?? '{0}') . "\n";
|
||||
// if this is 3000, then we do further error checks
|
||||
/* print "[E]: " . $e->getCode() . ", ERROR: " . $login_mock->loginGetLastErrorCode() . "/"
|
||||
. ($expected['login_error'] ?? 0) . "\n";
|
||||
print "AJAX: " . $login_mock->loginGetAjaxFlag() . "\n";
|
||||
print "AJAX GLOBAL: " . ($GLOBALS['AJAX_PAGE'] ?? '{f}') . "\n";
|
||||
print "Login error expext: " . ($expected['login_error'] ?? '{0}') . "\n";
|
||||
print "POST exit: " . ($_POST['login_exit'] ?? '{0}') . "\n"; */
|
||||
// if this is 100, then we do further error checks
|
||||
if (
|
||||
$e->getCode() == 3000 ||
|
||||
!empty($_POST['login_exit']) && $_POST['login_exit'] == 3000
|
||||
$e->getCode() == 100 ||
|
||||
!empty($_POST['login_exit']) && $_POST['login_exit'] == 100
|
||||
) {
|
||||
$this->assertEquals(
|
||||
$expected['login_error'],
|
||||
@@ -1785,9 +1904,9 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
/** @var \CoreLibs\Create\Session&MockObject */
|
||||
$session_mock = $this->createPartialMock(
|
||||
\CoreLibs\Create\Session::class,
|
||||
['startSession', 'checkActiveSession', 'sessionDestroy']
|
||||
['getSessionId', 'checkActiveSession', 'sessionDestroy']
|
||||
);
|
||||
$session_mock->method('startSession')->willReturn('ACLLOGINTEST34');
|
||||
$session_mock->method('getSessionId')->willReturn('ACLLOGINTEST34');
|
||||
$session_mock->method('checkActiveSession')->willReturn(true);
|
||||
$session_mock->method('sessionDestroy')->will(
|
||||
$this->returnCallback(function () {
|
||||
@@ -1819,7 +1938,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
$login_mock->expects($this->any())
|
||||
->method('loginTerminate')
|
||||
->will(
|
||||
$this->returnCallback(function ($code) {
|
||||
$this->returnCallback(function ($message, $code) {
|
||||
throw new \Exception('', $code);
|
||||
})
|
||||
);
|
||||
@@ -1899,9 +2018,9 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
/** @var \CoreLibs\Create\Session&MockObject */
|
||||
$session_mock = $this->createPartialMock(
|
||||
\CoreLibs\Create\Session::class,
|
||||
['startSession', 'checkActiveSession', 'sessionDestroy']
|
||||
['getSessionId', 'checkActiveSession', 'sessionDestroy']
|
||||
);
|
||||
$session_mock->method('startSession')->willReturn('ACLLOGINTEST34');
|
||||
$session_mock->method('getSessionId')->willReturn('ACLLOGINTEST34');
|
||||
$session_mock->method('checkActiveSession')->willReturn(true);
|
||||
$session_mock->method('sessionDestroy')->will(
|
||||
$this->returnCallback(function () {
|
||||
@@ -1933,7 +2052,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
$login_mock->expects($this->any())
|
||||
->method('loginTerminate')
|
||||
->will(
|
||||
$this->returnCallback(function ($code) {
|
||||
$this->returnCallback(function ($message, $code) {
|
||||
throw new \Exception('', $code);
|
||||
})
|
||||
);
|
||||
@@ -1987,9 +2106,9 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
/** @var \CoreLibs\Create\Session&MockObject */
|
||||
$session_mock = $this->createPartialMock(
|
||||
\CoreLibs\Create\Session::class,
|
||||
['startSession', 'checkActiveSession', 'sessionDestroy']
|
||||
['getSessionId', 'checkActiveSession', 'sessionDestroy']
|
||||
);
|
||||
$session_mock->method('startSession')->willReturn('ACLLOGINTEST34');
|
||||
$session_mock->method('getSessionId')->willReturn('ACLLOGINTEST34');
|
||||
$session_mock->method('checkActiveSession')->willReturn(true);
|
||||
$session_mock->method('sessionDestroy')->will(
|
||||
$this->returnCallback(function () {
|
||||
@@ -2021,7 +2140,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
$login_mock->expects($this->any())
|
||||
->method('loginTerminate')
|
||||
->will(
|
||||
$this->returnCallback(function ($code) {
|
||||
$this->returnCallback(function ($message, $code) {
|
||||
throw new \Exception('', $code);
|
||||
})
|
||||
);
|
||||
@@ -2083,9 +2202,9 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
/** @var \CoreLibs\Create\Session&MockObject */
|
||||
$session_mock = $this->createPartialMock(
|
||||
\CoreLibs\Create\Session::class,
|
||||
['startSession', 'checkActiveSession', 'sessionDestroy']
|
||||
['getSessionId', 'checkActiveSession', 'sessionDestroy']
|
||||
);
|
||||
$session_mock->method('startSession')->willReturn('ACLLOGINTEST34');
|
||||
$session_mock->method('getSessionId')->willReturn('ACLLOGINTEST34');
|
||||
$session_mock->method('checkActiveSession')->willReturn(true);
|
||||
$session_mock->method('sessionDestroy')->will(
|
||||
$this->returnCallback(function () {
|
||||
@@ -2117,7 +2236,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
$login_mock->expects($this->any())
|
||||
->method('loginTerminate')
|
||||
->will(
|
||||
$this->returnCallback(function ($code) {
|
||||
$this->returnCallback(function ($message, $code) {
|
||||
throw new \Exception('', $code);
|
||||
})
|
||||
);
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -13,6 +13,11 @@ use PHPUnit\Framework\TestCase;
|
||||
*/
|
||||
final class CoreLibsCheckColorsTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array<mixed>
|
||||
*/
|
||||
public function validateColorProvider(): array
|
||||
{
|
||||
/*
|
||||
@@ -321,7 +326,7 @@ final class CoreLibsCheckColorsTest extends TestCase
|
||||
*/
|
||||
public function testValidateColorException(int $flag): void
|
||||
{
|
||||
$this->expectException(\Exception::class);
|
||||
$this->expectException(\UnexpectedValueException::class);
|
||||
\CoreLibs\Check\Colors::validateColor('#ffffff', $flag);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,10 +28,10 @@ final class CoreLibsCheckFileTest extends TestCase
|
||||
public function filesList(): array
|
||||
{
|
||||
return [
|
||||
['filename.txt', 'txt', 5],
|
||||
['filename.csv', 'csv', 15],
|
||||
['filename.tsv', 'tsv', 0],
|
||||
['file_does_not_exits', '', -1],
|
||||
['filename.txt', 'txt', 5, 'text/plain'],
|
||||
['filename.csv', 'csv', 15, 'text/csv'],
|
||||
['filename.tsv', 'tsv', 0, 'text/plain'],
|
||||
['file_does_not_exits', '', -1, ''],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -63,6 +63,15 @@ final class CoreLibsCheckFileTest extends TestCase
|
||||
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
|
||||
*
|
||||
@@ -115,6 +124,51 @@ final class CoreLibsCheckFileTest extends TestCase
|
||||
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__
|
||||
|
||||
@@ -31,6 +31,7 @@ final class CoreLibsCombinedArrayHandlerTest extends TestCase
|
||||
4,
|
||||
'b',
|
||||
'c' => 'test',
|
||||
'single' => 'single',
|
||||
'same' => 'same',
|
||||
'deep' => [
|
||||
'sub' => [
|
||||
@@ -288,6 +289,188 @@ final class CoreLibsCombinedArrayHandlerTest extends TestCase
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function arraySearchKeyProvider(): array
|
||||
{
|
||||
/*
|
||||
0: search in array
|
||||
1: search keys
|
||||
2: flat flag
|
||||
3: prefix flag
|
||||
4: expected array
|
||||
*/
|
||||
return [
|
||||
// single
|
||||
'find single, standard' => [
|
||||
0 => self::$array,
|
||||
1 => ['single'],
|
||||
2 => null,
|
||||
3 => null,
|
||||
4 => [
|
||||
0 => [
|
||||
'value' => 'single',
|
||||
'path' => ['single'],
|
||||
],
|
||||
],
|
||||
],
|
||||
'find single, prefix' => [
|
||||
0 => self::$array,
|
||||
1 => ['single'],
|
||||
2 => null,
|
||||
3 => true,
|
||||
4 => [
|
||||
'single' => [
|
||||
0 => [
|
||||
'value' => 'single',
|
||||
'path' => ['single'],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
'find single, flat' => [
|
||||
0 => self::$array,
|
||||
1 => ['single'],
|
||||
2 => true,
|
||||
3 => null,
|
||||
4 => [
|
||||
'single',
|
||||
],
|
||||
],
|
||||
'find single, flat, prefix' => [
|
||||
0 => self::$array,
|
||||
1 => ['single'],
|
||||
2 => true,
|
||||
3 => true,
|
||||
4 => [
|
||||
'single' => [
|
||||
'single',
|
||||
],
|
||||
],
|
||||
],
|
||||
// not found
|
||||
'not found, standard' => [
|
||||
0 => self::$array,
|
||||
1 => ['NOT FOUND'],
|
||||
2 => null,
|
||||
3 => null,
|
||||
4 => [],
|
||||
],
|
||||
'not found, standard, prefix' => [
|
||||
0 => self::$array,
|
||||
1 => ['NOT FOUND'],
|
||||
2 => null,
|
||||
3 => true,
|
||||
4 => [
|
||||
'NOT FOUND' => [],
|
||||
],
|
||||
],
|
||||
'not found, flat' => [
|
||||
0 => self::$array,
|
||||
1 => ['NOT FOUND'],
|
||||
2 => true,
|
||||
3 => null,
|
||||
4 => [],
|
||||
],
|
||||
'not found, flat, prefix' => [
|
||||
0 => self::$array,
|
||||
1 => ['NOT FOUND'],
|
||||
2 => true,
|
||||
3 => true,
|
||||
4 => [
|
||||
'NOT FOUND' => [],
|
||||
],
|
||||
],
|
||||
// multi
|
||||
'multiple found, standard' => [
|
||||
0 => self::$array,
|
||||
1 => ['same'],
|
||||
2 => null,
|
||||
3 => null,
|
||||
4 => [
|
||||
[
|
||||
'value' => 'same',
|
||||
'path' => ['a', 'same', ],
|
||||
],
|
||||
[
|
||||
'value' => 'same',
|
||||
'path' => ['same', ],
|
||||
],
|
||||
[
|
||||
'value' => 'same',
|
||||
'path' => ['deep', 'sub', 'same', ],
|
||||
],
|
||||
]
|
||||
],
|
||||
'multiple found, flat' => [
|
||||
0 => self::$array,
|
||||
1 => ['same'],
|
||||
2 => true,
|
||||
3 => null,
|
||||
4 => ['same', 'same', 'same', ],
|
||||
],
|
||||
// search with multiple
|
||||
'search multiple, standard' => [
|
||||
0 => self::$array,
|
||||
1 => ['single', 'nested'],
|
||||
2 => null,
|
||||
3 => null,
|
||||
4 => [
|
||||
[
|
||||
'value' => 'single',
|
||||
'path' => ['single'],
|
||||
],
|
||||
[
|
||||
'value' => 'bar',
|
||||
'path' => ['deep', 'sub', 'nested', ],
|
||||
],
|
||||
],
|
||||
],
|
||||
'search multiple, prefix' => [
|
||||
0 => self::$array,
|
||||
1 => ['single', 'nested'],
|
||||
2 => null,
|
||||
3 => true,
|
||||
4 => [
|
||||
'single' => [
|
||||
[
|
||||
'value' => 'single',
|
||||
'path' => ['single'],
|
||||
],
|
||||
],
|
||||
'nested' => [
|
||||
[
|
||||
'value' => 'bar',
|
||||
'path' => ['deep', 'sub', 'nested', ],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
'search multiple, flat' => [
|
||||
0 => self::$array,
|
||||
1 => ['single', 'nested'],
|
||||
2 => true,
|
||||
3 => null,
|
||||
4 => [
|
||||
'single', 'bar',
|
||||
],
|
||||
],
|
||||
'search multiple, flat, prefix' => [
|
||||
0 => self::$array,
|
||||
1 => ['single', 'nested'],
|
||||
2 => true,
|
||||
3 => true,
|
||||
4 => [
|
||||
'single' => ['single', ],
|
||||
'nested' => ['bar', ],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* provides array listing for the merge test
|
||||
*
|
||||
@@ -335,17 +518,20 @@ final class CoreLibsCombinedArrayHandlerTest extends TestCase
|
||||
return [
|
||||
// error <2 arguments
|
||||
'too view arguments' => [
|
||||
'ArgumentCountError',
|
||||
'arrayMergeRecursive needs two or more array arguments',
|
||||
[1]
|
||||
],
|
||||
// error <2 arrays
|
||||
'only one array' => [
|
||||
'ArgumentCountError',
|
||||
'arrayMergeRecursive needs two or more array arguments',
|
||||
[1],
|
||||
true,
|
||||
],
|
||||
// error element is not array
|
||||
'non array between array' => [
|
||||
'TypeError',
|
||||
'arrayMergeRecursive encountered a non array argument',
|
||||
[1],
|
||||
'string',
|
||||
@@ -691,6 +877,44 @@ final class CoreLibsCombinedArrayHandlerTest extends TestCase
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers::arraySearchKey
|
||||
* @dataProvider arraySearchKeyProvider
|
||||
* @testdox arraySearchKey Search array with keys and flat: $flat, prefix: $prefix [$_dataName]
|
||||
*
|
||||
* @param array $input
|
||||
* @param array $needles
|
||||
* @param bool|null $flat
|
||||
* @param bool|null $prefix
|
||||
* @param array $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testArraySearchKey(
|
||||
array $input,
|
||||
array $needles,
|
||||
?bool $flat,
|
||||
?bool $prefix,
|
||||
array $expected
|
||||
): void {
|
||||
if ($flat === null && $prefix === null) {
|
||||
$result = \CoreLibs\Combined\ArrayHandler::arraySearchKey($input, $needles);
|
||||
} elseif ($flat === null) {
|
||||
$result = \CoreLibs\Combined\ArrayHandler::arraySearchKey($input, $needles, prefix: $prefix);
|
||||
} elseif ($prefix === null) {
|
||||
$result = \CoreLibs\Combined\ArrayHandler::arraySearchKey($input, $needles, flat: $flat);
|
||||
} else {
|
||||
$result = \CoreLibs\Combined\ArrayHandler::arraySearchKey($input, $needles, $flat, $prefix);
|
||||
}
|
||||
// print "E: " . print_r($expected, true) . "\n";
|
||||
// print "R: " . print_r($result, true) . "\n";
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$result
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
@@ -726,18 +950,20 @@ final class CoreLibsCombinedArrayHandlerTest extends TestCase
|
||||
*/
|
||||
public function testArrayMergeRecursiveWarningA(): void
|
||||
{
|
||||
set_error_handler(
|
||||
static function (int $errno, string $errstr): never {
|
||||
throw new Exception($errstr, $errno);
|
||||
},
|
||||
E_USER_WARNING
|
||||
);
|
||||
// set_error_handler(
|
||||
// static function (int $errno, string $errstr): never {
|
||||
// throw new Exception($errstr, $errno);
|
||||
// },
|
||||
// E_USER_WARNING
|
||||
// );
|
||||
|
||||
$arrays = func_get_args();
|
||||
// first is expected warning
|
||||
$exception = array_shift($arrays);
|
||||
$warning = array_shift($arrays);
|
||||
|
||||
// phpunit 10.0 compatible
|
||||
$this->expectException($exception);
|
||||
$this->expectExceptionMessage($warning);
|
||||
|
||||
\CoreLibs\Combined\ArrayHandler::arrayMergeRecursive(...$arrays);
|
||||
@@ -872,16 +1098,194 @@ final class CoreLibsCombinedArrayHandlerTest extends TestCase
|
||||
* @testdox arrayFlatForKey array $input will be $expected [$_dataName]
|
||||
*
|
||||
* @param array $input
|
||||
* @param string $search
|
||||
* @param array $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testArrayFlatForKey(array $input, $search, array $expected): void
|
||||
public function testArrayFlatForKey(array $input, string $search, array $expected): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\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'
|
||||
);
|
||||
}
|
||||
|
||||
public function providerReturnMatchingKeyOnley(): array
|
||||
{
|
||||
return [
|
||||
'limited entries' => [
|
||||
[
|
||||
'a' => 'foo',
|
||||
'b' => 'bar',
|
||||
'c' => 'foobar'
|
||||
],
|
||||
[
|
||||
'a', 'b'
|
||||
],
|
||||
[
|
||||
'a' => 'foo',
|
||||
'b' => 'bar',
|
||||
],
|
||||
],
|
||||
'limited entries, with one wrong key' => [
|
||||
[
|
||||
'a' => 'foo',
|
||||
'b' => 'bar',
|
||||
'c' => 'foobar'
|
||||
],
|
||||
[
|
||||
'a', 'b', 'f'
|
||||
],
|
||||
[
|
||||
'a' => 'foo',
|
||||
'b' => 'bar',
|
||||
],
|
||||
],
|
||||
'wrong keys only' => [
|
||||
[
|
||||
'a' => 'foo',
|
||||
'b' => 'bar',
|
||||
'c' => 'foobar'
|
||||
],
|
||||
[
|
||||
'f', 'f'
|
||||
],
|
||||
[
|
||||
],
|
||||
],
|
||||
'empty keys' => [
|
||||
[
|
||||
'a' => 'foo',
|
||||
'b' => 'bar',
|
||||
'c' => 'foobar'
|
||||
],
|
||||
[],
|
||||
[
|
||||
'a' => 'foo',
|
||||
'b' => 'bar',
|
||||
'c' => 'foobar'
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::arrayReturnMatchingKeyOnly
|
||||
* @dataProvider providerReturnMatchingKeyOnley
|
||||
* @testdox arrayReturnMatchingKeyOnly get only selected key entries from array [$_dataName]
|
||||
*
|
||||
* @param array $input
|
||||
* @param array $key_list
|
||||
* @param array $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testArrayReturnMatchingKeyOnly(
|
||||
array $input,
|
||||
array $key_list,
|
||||
array $expected
|
||||
): void {
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Combined\ArrayHandler::arrayReturnMatchingKeyOnly(
|
||||
$input,
|
||||
$key_list
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// __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
|
||||
*
|
||||
@@ -74,6 +102,11 @@ final class CoreLibsCombinedDateTimeTest extends TestCase
|
||||
public function intervalProvider(): array
|
||||
{
|
||||
return [
|
||||
'on hour' => [
|
||||
3600,
|
||||
false,
|
||||
'1h 0m 0s'
|
||||
],
|
||||
'interval no microtime' => [
|
||||
1641515890,
|
||||
false,
|
||||
@@ -82,7 +115,7 @@ final class CoreLibsCombinedDateTimeTest extends TestCase
|
||||
'interval with microtime' => [
|
||||
1641515890,
|
||||
true,
|
||||
'18999d 0h 38m 10s',
|
||||
'18999d 0h 38m 10s 0ms',
|
||||
],
|
||||
'micro interval no microtime' => [
|
||||
1641515890.123456,
|
||||
@@ -92,7 +125,7 @@ final class CoreLibsCombinedDateTimeTest extends TestCase
|
||||
'micro interval with microtime' => [
|
||||
1641515890.123456,
|
||||
true,
|
||||
'18999d 0h 38m 10s 1235ms',
|
||||
'18999d 0h 38m 10s 124ms',
|
||||
],
|
||||
'negative interval no microtime' => [
|
||||
-1641515890,
|
||||
@@ -103,27 +136,27 @@ final class CoreLibsCombinedDateTimeTest extends TestCase
|
||||
'microtime only' => [
|
||||
0.123456,
|
||||
true,
|
||||
'0s 1235ms',
|
||||
'0s 123ms',
|
||||
],
|
||||
'seconds only' => [
|
||||
30.123456,
|
||||
true,
|
||||
'30s 1235ms',
|
||||
'30s 123ms',
|
||||
],
|
||||
'minutes only' => [
|
||||
90.123456,
|
||||
true,
|
||||
'1m 30s 1235ms',
|
||||
'1m 30s 123ms',
|
||||
],
|
||||
'hours only' => [
|
||||
3690.123456,
|
||||
true,
|
||||
'1h 1m 30s 1235ms',
|
||||
'1h 1m 30s 123ms',
|
||||
],
|
||||
'days only' => [
|
||||
90090.123456,
|
||||
true,
|
||||
'1d 1h 1m 30s 1235ms',
|
||||
'1d 1h 1m 30s 123ms',
|
||||
],
|
||||
'already set' => [
|
||||
'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
|
||||
*
|
||||
@@ -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
|
||||
*
|
||||
@@ -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
|
||||
*
|
||||
@@ -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
|
||||
*
|
||||
@@ -309,45 +699,104 @@ final class CoreLibsCombinedDateTimeTest extends TestCase
|
||||
'2020-12-12',
|
||||
'2021-12-12',
|
||||
-1,
|
||||
null,
|
||||
null,
|
||||
],
|
||||
'dates equal' => [
|
||||
'2020-12-12',
|
||||
'2020-12-12',
|
||||
0,
|
||||
null,
|
||||
null,
|
||||
],
|
||||
'second date smaller' => [
|
||||
'2021-12-12',
|
||||
'2020-12-12',
|
||||
1
|
||||
1,
|
||||
null,
|
||||
null,
|
||||
],
|
||||
'dates equal with different time' => [
|
||||
'2020-12-12 12:12:12',
|
||||
'2020-12-12 13:13:13',
|
||||
0,
|
||||
null,
|
||||
null,
|
||||
],
|
||||
'invalid dates --' => [
|
||||
'--',
|
||||
'--',
|
||||
false
|
||||
false,
|
||||
'UnexpectedValueException',
|
||||
1,
|
||||
],
|
||||
'empty dates' => [
|
||||
'',
|
||||
'',
|
||||
false
|
||||
false,
|
||||
'UnexpectedValueException',
|
||||
1
|
||||
],
|
||||
'invalid dates' => [
|
||||
'not a date',
|
||||
'not a date either',
|
||||
false,
|
||||
'UnexpectedValueException',
|
||||
2
|
||||
],
|
||||
'invalid end date' => [
|
||||
'1990-01-01',
|
||||
'not a date either',
|
||||
false,
|
||||
'UnexpectedValueException',
|
||||
3
|
||||
],
|
||||
'out of bound dates' => [
|
||||
'1900-1-1',
|
||||
'9999-12-31',
|
||||
-1
|
||||
-1,
|
||||
null,
|
||||
null,
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
* @return array<mixed>
|
||||
*/
|
||||
public function dateTimeCompareProvider(): array
|
||||
{
|
||||
return [
|
||||
@@ -355,55 +804,120 @@ final class CoreLibsCombinedDateTimeTest extends TestCase
|
||||
'2020-12-12',
|
||||
'2021-12-12',
|
||||
-1,
|
||||
null,
|
||||
null,
|
||||
],
|
||||
'dates equal no timestamp' => [
|
||||
'2020-12-12',
|
||||
'2020-12-12',
|
||||
0,
|
||||
null,
|
||||
null,
|
||||
],
|
||||
'second date smaller no timestamp' => [
|
||||
'2021-12-12',
|
||||
'2020-12-12',
|
||||
1
|
||||
1,
|
||||
null,
|
||||
null,
|
||||
],
|
||||
'date equal first time smaller' => [
|
||||
'2020-12-12 12:12:12',
|
||||
'2020-12-12 13:13:13',
|
||||
-1,
|
||||
null,
|
||||
null,
|
||||
],
|
||||
'date equal time equal' => [
|
||||
'2020-12-12 12:12:12',
|
||||
'2020-12-12 12:12:12',
|
||||
0,
|
||||
null,
|
||||
null,
|
||||
],
|
||||
'date equal second time smaller' => [
|
||||
'2020-12-12 13:13:13',
|
||||
'2020-12-12 12:12:12',
|
||||
1,
|
||||
null,
|
||||
null,
|
||||
],
|
||||
'valid date invalid time' => [
|
||||
'2020-12-12 13:99:13',
|
||||
'2020-12-12 12:12:99',
|
||||
false,
|
||||
'UnexpectedValueException',
|
||||
2
|
||||
],
|
||||
'valid date invalid end time' => [
|
||||
'2020-12-12 13:12:13',
|
||||
'2020-12-12 12:12:99',
|
||||
false,
|
||||
'UnexpectedValueException',
|
||||
3
|
||||
],
|
||||
'invalid datetimes --' => [
|
||||
'--',
|
||||
'--',
|
||||
false,
|
||||
'UnexpectedValueException',
|
||||
1
|
||||
],
|
||||
'empty datetimess' => [
|
||||
'',
|
||||
'',
|
||||
false,
|
||||
'UnexpectedValueException',
|
||||
1
|
||||
],
|
||||
'invalid datetimes' => [
|
||||
'invalid date times' => [
|
||||
'not a date',
|
||||
'not a date either',
|
||||
false,
|
||||
'UnexpectedValueException',
|
||||
2
|
||||
],
|
||||
'invalid end date time' => [
|
||||
'1990-01-01 12:12:12',
|
||||
'not a date either',
|
||||
false,
|
||||
'UnexpectedValueException',
|
||||
3
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
@@ -458,151 +972,6 @@ 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 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
|
||||
* @return void
|
||||
*/
|
||||
public function testCompareDate(string $input_a, string $input_b, $expected): void
|
||||
{
|
||||
$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
|
||||
* @return void
|
||||
*/
|
||||
public function testCompareDateTime(string $input_a, string $input_b, $expected): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Combined\DateTime::compareDateTime($input_a, $input_b)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
@@ -780,6 +1149,70 @@ final class CoreLibsCombinedDateTimeTest extends TestCase
|
||||
$output
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
* @covers ::dateRangeHasWeekend
|
||||
* @dataProvider dateRangeHasWeekendProvider
|
||||
* @testdox dateRangeHasWeekend $start_date and $end_date are expected weekend $expected [$_dataName]
|
||||
*
|
||||
* @param string $start_date
|
||||
* @param string $end_date
|
||||
* @param bool $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testDateRangeHasWeekend(
|
||||
string $start_date,
|
||||
string $end_date,
|
||||
bool $expected
|
||||
): void {
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Combined\DateTime::dateRangeHasWeekend($start_date, $end_date)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
|
||||
@@ -253,7 +253,8 @@ final class CoreLibsConvertByteTest extends TestCase
|
||||
*/
|
||||
public function testHumanReadableByteFormatException(int $flag): void
|
||||
{
|
||||
$this->expectException(\Exception::class);
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
$this->expectExceptionCode(1);
|
||||
\CoreLibs\Convert\Byte::humanReadableByteFormat(12, $flag);
|
||||
}
|
||||
|
||||
@@ -272,7 +273,8 @@ final class CoreLibsConvertByteTest extends TestCase
|
||||
*/
|
||||
public function testStringByteFormatException(int $flag): void
|
||||
{
|
||||
$this->expectException(\Exception::class);
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
$this->expectExceptionCode(1);
|
||||
\CoreLibs\Convert\Byte::stringByteFormat(12, $flag);
|
||||
}
|
||||
}
|
||||
|
||||
1186
4dev/tests/Convert/CoreLibsConvertColorTest.php
Normal file
1186
4dev/tests/Convert/CoreLibsConvertColorTest.php
Normal file
File diff suppressed because it is too large
Load Diff
@@ -9,7 +9,7 @@ use PHPUnit\Framework\TestCase;
|
||||
/**
|
||||
* Test class for Convert\Colors
|
||||
* @coversDefaultClass \CoreLibs\Convert\Colors
|
||||
* @testdox \CoreLibs\Convert\Colors method tests
|
||||
* @testdox \CoreLibs\Convert\Colors legacy method tests
|
||||
*/
|
||||
final class CoreLibsConvertColorsTest extends TestCase
|
||||
{
|
||||
@@ -21,7 +21,7 @@ final class CoreLibsConvertColorsTest extends TestCase
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rgb2hexColorProvider(): array
|
||||
public function providerRgb2hexColor(): array
|
||||
{
|
||||
return [
|
||||
'color' => [
|
||||
@@ -59,6 +59,27 @@ final class CoreLibsConvertColorsTest extends TestCase
|
||||
3 => false,
|
||||
4 => false
|
||||
],
|
||||
'invalid color red ' => [
|
||||
0 => -12,
|
||||
1 => 12,
|
||||
2 => 12,
|
||||
3 => false,
|
||||
4 => false
|
||||
],
|
||||
'invalid color green ' => [
|
||||
0 => 12,
|
||||
1 => -12,
|
||||
2 => 12,
|
||||
3 => false,
|
||||
4 => false
|
||||
],
|
||||
'invalid color blue ' => [
|
||||
0 => 12,
|
||||
1 => 12,
|
||||
2 => -12,
|
||||
3 => false,
|
||||
4 => false
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -67,7 +88,7 @@ final class CoreLibsConvertColorsTest extends TestCase
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function hex2rgbColorProvider(): array
|
||||
public function providerHex2rgbColor(): array
|
||||
{
|
||||
return [
|
||||
'color' => [
|
||||
@@ -150,10 +171,40 @@ final class CoreLibsConvertColorsTest extends TestCase
|
||||
'valid' => true,
|
||||
],
|
||||
// invalid values
|
||||
'invalid color' => [
|
||||
'rgb' => [-12, 300, 12],
|
||||
'hsb' => [-12, 300, 12],
|
||||
'hsl' => [-12, 300, 12],
|
||||
'invalid color r/h/h low' => [
|
||||
'rgb' => [-1, 12, 12],
|
||||
'hsb' => [-1, 50, 50],
|
||||
'hsl' => [-1, 50, 50],
|
||||
'valid' => false,
|
||||
],
|
||||
'invalid color r/h/h high' => [
|
||||
'rgb' => [256, 12, 12],
|
||||
'hsb' => [361, 50, 50],
|
||||
'hsl' => [361, 50, 50],
|
||||
'valid' => false,
|
||||
],
|
||||
'invalid color g/s/s low' => [
|
||||
'rgb' => [12, -1, 12],
|
||||
'hsb' => [1, -1, 50],
|
||||
'hsl' => [1, -1, 50],
|
||||
'valid' => false,
|
||||
],
|
||||
'invalid color g/s/s high' => [
|
||||
'rgb' => [12, 256, 12],
|
||||
'hsb' => [1, 101, 50],
|
||||
'hsl' => [1, 101, 50],
|
||||
'valid' => false,
|
||||
],
|
||||
'invalid color b/b/l low' => [
|
||||
'rgb' => [12, 12, -1],
|
||||
'hsb' => [1, 50, -1],
|
||||
'hsl' => [1, 50, -1],
|
||||
'valid' => false,
|
||||
],
|
||||
'invalid color b/b/l high' => [
|
||||
'rgb' => [12, 12, 256],
|
||||
'hsb' => [1, 50, 101],
|
||||
'hsl' => [1, 50, 101],
|
||||
'valid' => false,
|
||||
],
|
||||
];
|
||||
@@ -164,7 +215,7 @@ final class CoreLibsConvertColorsTest extends TestCase
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rgb2hsbColorProvider(): array
|
||||
public function providerRgb2hsbColor(): array
|
||||
{
|
||||
$list = [];
|
||||
foreach ($this->rgb2hslAndhsbList() as $name => $values) {
|
||||
@@ -183,7 +234,7 @@ final class CoreLibsConvertColorsTest extends TestCase
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function hsb2rgbColorProvider(): array
|
||||
public function providerHsb2rgbColor(): array
|
||||
{
|
||||
$list = [];
|
||||
foreach ($this->rgb2hslAndhsbList() as $name => $values) {
|
||||
@@ -202,7 +253,7 @@ final class CoreLibsConvertColorsTest extends TestCase
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rgb2hslColorProvider(): array
|
||||
public function providerRgb2hslColor(): array
|
||||
{
|
||||
$list = [];
|
||||
foreach ($this->rgb2hslAndhsbList() as $name => $values) {
|
||||
@@ -221,7 +272,7 @@ final class CoreLibsConvertColorsTest extends TestCase
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function hsl2rgbColorProvider(): array
|
||||
public function providerHsl2rgbColor(): array
|
||||
{
|
||||
$list = [];
|
||||
foreach ($this->rgb2hslAndhsbList() as $name => $values) {
|
||||
@@ -240,17 +291,28 @@ final class CoreLibsConvertColorsTest extends TestCase
|
||||
* TODO: add cross convert check
|
||||
*
|
||||
* @covers ::rgb2hex
|
||||
* @dataProvider rgb2hexColorProvider
|
||||
* @dataProvider providerRgb2hexColor
|
||||
* @testdox rgb2hex $input_r,$input_g,$input_b will be $expected [$_dataName]
|
||||
*
|
||||
* @param int $input_r
|
||||
* @param int $input_g
|
||||
* @param int $input_b
|
||||
* @param string|bool $expected_hash
|
||||
* @param string|bool $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testRgb2hex(int $input_r, int $input_g, int $input_b, $expected_hash, $expected)
|
||||
{
|
||||
public function testRgb2hex(
|
||||
int $input_r,
|
||||
int $input_g,
|
||||
int $input_b,
|
||||
string|bool $expected_hash,
|
||||
string|bool $expected
|
||||
) {
|
||||
// if expected hash is or expected is false, we need to check for
|
||||
// LengthException
|
||||
if ($expected_hash === false || $expected === false) {
|
||||
$this->expectException(\LengthException::class);
|
||||
}
|
||||
// with #
|
||||
$this->assertEquals(
|
||||
$expected_hash,
|
||||
@@ -280,7 +342,7 @@ final class CoreLibsConvertColorsTest extends TestCase
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::hex2rgb
|
||||
* @dataProvider hex2rgbColorProvider
|
||||
* @dataProvider providerHex2rgbColor
|
||||
* @testdox hex2rgb $input will be $expected, $expected_str str[,], $expected_str_sep str[$separator] [$_dataName]
|
||||
*
|
||||
* @param string $input
|
||||
@@ -292,11 +354,19 @@ final class CoreLibsConvertColorsTest extends TestCase
|
||||
*/
|
||||
public function testHex2rgb(
|
||||
string $input,
|
||||
$expected,
|
||||
$expected_str,
|
||||
array|bool $expected,
|
||||
string|bool $expected_str,
|
||||
string $separator,
|
||||
$expected_str_sep
|
||||
string|bool $expected_str_sep
|
||||
): void {
|
||||
if ($expected === false || $expected_str === false || $expected_str_sep === false) {
|
||||
$hex_string = preg_replace("/[^0-9A-Fa-f]/", '', $input);
|
||||
if (!is_string($hex_string)) {
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
} else {
|
||||
$this->expectException(\UnexpectedValueException::class);
|
||||
}
|
||||
}
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Convert\Colors::hex2rgb($input)
|
||||
@@ -315,7 +385,7 @@ final class CoreLibsConvertColorsTest extends TestCase
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::rgb2hsb
|
||||
* @dataProvider rgb2hsbColorProvider
|
||||
* @dataProvider providerRgb2hsbColor
|
||||
* @testdox rgb2hsb $input_r,$input_g,$input_b will be $expected [$_dataName]
|
||||
*
|
||||
* @param integer $input_r
|
||||
@@ -324,8 +394,11 @@ final class CoreLibsConvertColorsTest extends TestCase
|
||||
* @param array|bool $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testRgb2hsb(int $input_r, int $input_g, int $input_b, $expected): void
|
||||
public function testRgb2hsb(int $input_r, int $input_g, int $input_b, array|bool $expected): void
|
||||
{
|
||||
if ($expected === false) {
|
||||
$this->expectException(\LengthException::class);
|
||||
}
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Convert\Colors::rgb2hsb($input_r, $input_g, $input_b)
|
||||
@@ -336,7 +409,7 @@ final class CoreLibsConvertColorsTest extends TestCase
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::hsb2rgb
|
||||
* @dataProvider hsb2rgbColorProvider
|
||||
* @dataProvider providerHsb2rgbColor
|
||||
* @testdox hsb2rgb $input_h,$input_s,$input_b will be $expected [$_dataName]
|
||||
*
|
||||
* @param float $input_h
|
||||
@@ -345,8 +418,12 @@ final class CoreLibsConvertColorsTest extends TestCase
|
||||
* @param array|bool $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testHsb2rgb(float $input_h, float $input_s, float $input_b, $expected): void
|
||||
public function testHsb2rgb(float $input_h, float $input_s, float $input_b, array|bool $expected): void
|
||||
{
|
||||
if ($expected === false) {
|
||||
$this->expectException(\LengthException::class);
|
||||
$expected = [];
|
||||
}
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Convert\Colors::hsb2rgb($input_h, $input_s, $input_b)
|
||||
@@ -357,7 +434,7 @@ final class CoreLibsConvertColorsTest extends TestCase
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::rgb2hsl
|
||||
* @dataProvider rgb2hslColorProvider
|
||||
* @dataProvider providerRgb2hslColor
|
||||
* @testdox rgb2hsl $input_r,$input_g,$input_b will be $expected [$_dataName]
|
||||
*
|
||||
* @param integer $input_r
|
||||
@@ -366,8 +443,11 @@ final class CoreLibsConvertColorsTest extends TestCase
|
||||
* @param array|bool $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testRgb2hsl(int $input_r, int $input_g, int $input_b, $expected): void
|
||||
public function testRgb2hsl(int $input_r, int $input_g, int $input_b, array|bool $expected): void
|
||||
{
|
||||
if ($expected === false) {
|
||||
$this->expectException(\LengthException::class);
|
||||
}
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Convert\Colors::rgb2hsl($input_r, $input_g, $input_b)
|
||||
@@ -378,7 +458,7 @@ final class CoreLibsConvertColorsTest extends TestCase
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::hsl2rgb
|
||||
* @dataProvider hsl2rgbColorProvider
|
||||
* @dataProvider providerHsl2rgbColor
|
||||
* @testdox hsl2rgb $input_h,$input_s,$input_l will be $expected [$_dataName]
|
||||
*
|
||||
* @param integer|float $input_h
|
||||
@@ -387,8 +467,11 @@ final class CoreLibsConvertColorsTest extends TestCase
|
||||
* @param array|bool $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testHsl2rgb($input_h, float $input_s, float $input_l, $expected): void
|
||||
public function testHsl2rgb(int|float $input_h, float $input_s, float $input_l, array|bool $expected): void
|
||||
{
|
||||
if ($expected === false) {
|
||||
$this->expectException(\LengthException::class);
|
||||
}
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Convert\Colors::hsl2rgb($input_h, $input_s, $input_l)
|
||||
@@ -406,11 +489,11 @@ final class CoreLibsConvertColorsTest extends TestCase
|
||||
*/
|
||||
public function testHslHsb360hue(): void
|
||||
{
|
||||
$this->assertNotFalse(
|
||||
$this->assertIsArray(
|
||||
\CoreLibs\Convert\Colors::hsl2rgb(360.0, 90.5, 41.2),
|
||||
'HSL to RGB with 360 hue'
|
||||
);
|
||||
$this->assertNotFalse(
|
||||
$this->assertIsArray(
|
||||
\CoreLibs\Convert\Colors::hsb2rgb(360, 95, 78.0),
|
||||
'HSB to RGB with 360 hue'
|
||||
);
|
||||
|
||||
@@ -16,7 +16,7 @@ final class CoreLibsConvertJsonTest extends TestCase
|
||||
/**
|
||||
* test list for json convert tests
|
||||
*
|
||||
* @return array
|
||||
* @return array<mixed>
|
||||
*/
|
||||
public function jsonProvider(): array
|
||||
{
|
||||
@@ -54,10 +54,36 @@ final class CoreLibsConvertJsonTest extends TestCase
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array<mixed>
|
||||
*/
|
||||
public function jsonArrayProvider(): array
|
||||
{
|
||||
return [
|
||||
'valid json' => [
|
||||
[
|
||||
'm' => 2,
|
||||
'f' => 'sub_2'
|
||||
],
|
||||
'{"m":2,"f":"sub_2"}',
|
||||
],
|
||||
'empty json array' => [
|
||||
[],
|
||||
'[]'
|
||||
],
|
||||
'empty json hash' => [
|
||||
['' => ''],
|
||||
'{"":""}'
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* json error list
|
||||
*
|
||||
* @return array JSON error list
|
||||
* @return array<mixed> JSON error list
|
||||
*/
|
||||
public function jsonErrorProvider(): array
|
||||
{
|
||||
@@ -127,7 +153,7 @@ final class CoreLibsConvertJsonTest extends TestCase
|
||||
*
|
||||
* @param string|null $input
|
||||
* @param bool $flag
|
||||
* @param array $expected
|
||||
* @param array<mixed> $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testJsonConvertToArray(?string $input, bool $flag, array $expected): void
|
||||
@@ -146,7 +172,8 @@ final class CoreLibsConvertJsonTest extends TestCase
|
||||
* @testdox jsonGetLastError $input will be $expected_i/$expected_s [$_dataName]
|
||||
*
|
||||
* @param string|null $input
|
||||
* @param string $expected
|
||||
* @param int $expected_i
|
||||
* @param string $expected_s
|
||||
* @return void
|
||||
*/
|
||||
public function testJsonGetLastError(?string $input, int $expected_i, string $expected_s): void
|
||||
@@ -161,6 +188,25 @@ final class CoreLibsConvertJsonTest extends TestCase
|
||||
\CoreLibs\Convert\Json::jsonGetLastError(true)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::jsonConvertArrayTo
|
||||
* @dataProvider jsonArrayProvider
|
||||
* @testdox jsonConvertArrayTo $input (Override: $flag) will be $expected [$_dataName]
|
||||
*
|
||||
* @param array<mixed> $input
|
||||
* @param string $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testJsonConvertArrayto(array $input, string $expected): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Convert\Json::jsonConvertArrayTo($input)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
|
||||
@@ -18,7 +18,7 @@ final class CoreLibsConvertMathTest extends TestCase
|
||||
*
|
||||
* @return array<mixed>
|
||||
*/
|
||||
public function fceilProvider(): array
|
||||
public function providerFceil(): array
|
||||
{
|
||||
return [
|
||||
'5.5 must be 6' => [5.5, 6],
|
||||
@@ -31,7 +31,7 @@ final class CoreLibsConvertMathTest extends TestCase
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::fceil
|
||||
* @dataProvider fceilProvider
|
||||
* @dataProvider providerFceil
|
||||
* @testdox fceil: Input $input must be $expected
|
||||
*
|
||||
* @param float $input
|
||||
@@ -51,7 +51,7 @@ final class CoreLibsConvertMathTest extends TestCase
|
||||
*
|
||||
* @return array<mixed>
|
||||
*/
|
||||
public function floorProvider(): array
|
||||
public function providerFloor(): array
|
||||
{
|
||||
return [
|
||||
'5123456 with -3 must be 5123000' => [5123456, -3, 5123000],
|
||||
@@ -63,7 +63,7 @@ final class CoreLibsConvertMathTest extends TestCase
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::floorp
|
||||
* @dataProvider floorProvider
|
||||
* @dataProvider providerFloor
|
||||
* @testdox floor: Input $input with cutoff $cutoff must be $expected
|
||||
*
|
||||
* @param int $input
|
||||
@@ -84,7 +84,7 @@ final class CoreLibsConvertMathTest extends TestCase
|
||||
*
|
||||
* @return array<mixed>
|
||||
*/
|
||||
public function initNumericProvider(): array
|
||||
public function providerInitNumeric(): array
|
||||
{
|
||||
return [
|
||||
'5 must be 5' => [5, 5, 'int'],
|
||||
@@ -98,7 +98,7 @@ final class CoreLibsConvertMathTest extends TestCase
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::initNumeric
|
||||
* @dataProvider initNumericProvider
|
||||
* @dataProvider providerInitNumeric
|
||||
* @testdox initNumeric: Input $info $input must match $expected [$_dataName]
|
||||
*
|
||||
* @param int|float|string $input
|
||||
@@ -113,6 +113,388 @@ final class CoreLibsConvertMathTest extends TestCase
|
||||
\CoreLibs\Convert\Math::initNumeric($input)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function providerCbrt(): array
|
||||
{
|
||||
return [
|
||||
'cube root of 2' => [2, 1.25992, 5],
|
||||
'cube root of 3' => [3, 1.44225, 5],
|
||||
'cube root of -1' => [-1, 'NAN', 0],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::cbrt
|
||||
* @dataProvider providerCbrt
|
||||
* @testdox initNumeric: Input $input must match $expected [$_dataName]
|
||||
*
|
||||
* @param float|int $number
|
||||
* @param float $expected
|
||||
* @param int $round_to
|
||||
* @return void
|
||||
*/
|
||||
public function testCbrt(float|int $number, float|string $expected, int $round_to): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
round(\CoreLibs\Convert\Math::cbrt($number), $round_to)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function providerMultiplyMatrices(): array
|
||||
{
|
||||
return [
|
||||
'[3] x [3] => [3x1]' => [
|
||||
[1, 2, 3],
|
||||
[1, 2, 3],
|
||||
[14]
|
||||
],
|
||||
'[3] x [3x1]' => [
|
||||
[1, 2, 3],
|
||||
[[1], [2], [3]],
|
||||
[14]
|
||||
],
|
||||
'[3] x [3x1]' => [
|
||||
[1, 2, 3],
|
||||
[[1], [2], [3]],
|
||||
[14]
|
||||
],
|
||||
'[1x3L] x [3x1]' => [
|
||||
[[1, 2, 3]],
|
||||
[[1], [2], [3]],
|
||||
[14]
|
||||
],
|
||||
'[1x3] x [3x1]' => [
|
||||
[[1], [2], [3]],
|
||||
[[1], [2], [3]],
|
||||
[1, 2, 3]
|
||||
],
|
||||
'[2x3] x [3] => [3x1]' => [
|
||||
[
|
||||
[1, 2, 3],
|
||||
[1, 2, 3]
|
||||
],
|
||||
[1, 2, 3],
|
||||
[
|
||||
14,
|
||||
14
|
||||
]
|
||||
],
|
||||
'[2x3] x [3x1]' => [
|
||||
[
|
||||
[1, 2, 3],
|
||||
[1, 2, 3]
|
||||
],
|
||||
[[1], [2], [3]],
|
||||
[
|
||||
14,
|
||||
14
|
||||
]
|
||||
],
|
||||
'[2x3] x [2x3] => [3x3]' => [
|
||||
[
|
||||
[1, 2, 3],
|
||||
[1, 2, 3],
|
||||
],
|
||||
[
|
||||
[1, 2, 3],
|
||||
[1, 2, 3],
|
||||
],
|
||||
[
|
||||
[3, 6, 9],
|
||||
[3, 6, 9]
|
||||
]
|
||||
],
|
||||
'[2x3] x [3x3]' => [
|
||||
[
|
||||
[1, 2, 3],
|
||||
[1, 2, 3],
|
||||
],
|
||||
[
|
||||
[1, 2, 3],
|
||||
[1, 2, 3],
|
||||
[0, 0, 0],
|
||||
],
|
||||
[
|
||||
[3, 6, 9],
|
||||
[3, 6, 9]
|
||||
]
|
||||
],
|
||||
'[2x3] x [3x2]' => [
|
||||
'a' => [
|
||||
[1, 2, 3],
|
||||
[1, 2, 3],
|
||||
],
|
||||
'b' => [
|
||||
[1, 1],
|
||||
[2, 2],
|
||||
[3, 3],
|
||||
],
|
||||
'prod' => [
|
||||
[14, 14],
|
||||
[14, 14],
|
||||
]
|
||||
],
|
||||
'[3x3] x [3] => [1x3]' => [
|
||||
[
|
||||
[1, 2, 3],
|
||||
[1, 2, 3],
|
||||
[1, 2, 3],
|
||||
],
|
||||
[1, 2, 3],
|
||||
[
|
||||
14,
|
||||
14,
|
||||
14
|
||||
]
|
||||
],
|
||||
'[3x3] x [2x3] => [3x3]' => [
|
||||
[
|
||||
[1, 2, 3],
|
||||
[1, 2, 3],
|
||||
[1, 2, 3],
|
||||
],
|
||||
[
|
||||
[1, 2, 3],
|
||||
[1, 2, 3],
|
||||
],
|
||||
[
|
||||
[3, 6, 9],
|
||||
[3, 6, 9],
|
||||
[3, 6, 9],
|
||||
]
|
||||
],
|
||||
'[3x3] x [3x3]' => [
|
||||
[
|
||||
[1, 2, 3],
|
||||
[1, 2, 3],
|
||||
[1, 2, 3],
|
||||
],
|
||||
[
|
||||
[1, 2, 3],
|
||||
[1, 2, 3],
|
||||
// [0, 0, 0],
|
||||
],
|
||||
[
|
||||
[3, 6, 9],
|
||||
[3, 6, 9],
|
||||
[3, 6, 9],
|
||||
]
|
||||
],
|
||||
'[3] x [3x3]' => [
|
||||
[1, 2, 3],
|
||||
[
|
||||
[1, 2, 3],
|
||||
[1, 2, 3],
|
||||
[1, 2, 3],
|
||||
],
|
||||
[
|
||||
[6, 12, 18],
|
||||
]
|
||||
],
|
||||
'[2x3] x [3x3]' => [
|
||||
[
|
||||
[1, 2, 3],
|
||||
[1, 2, 3],
|
||||
],
|
||||
[
|
||||
[1, 2, 3],
|
||||
[1, 2, 3],
|
||||
[1, 2, 3],
|
||||
],
|
||||
[
|
||||
[6, 12, 18],
|
||||
[6, 12, 18],
|
||||
]
|
||||
],
|
||||
'inblanaced [2x2,3] x [3x2]' => [
|
||||
'a' => [
|
||||
[1, 2, 3],
|
||||
[4, 5]
|
||||
],
|
||||
'b' => [
|
||||
[6, 7],
|
||||
[8, 9],
|
||||
[10, 11]
|
||||
],
|
||||
'result' => [
|
||||
[52, 58],
|
||||
[64, 73],
|
||||
]
|
||||
],
|
||||
'inblanaced [2x3] x [3x1,2]' => [
|
||||
'a' => [
|
||||
[1, 2, 3],
|
||||
[4, 5, 7]
|
||||
],
|
||||
'b' => [
|
||||
[7, 8],
|
||||
[9, 10],
|
||||
[11]
|
||||
],
|
||||
'result' => [
|
||||
[58, 28],
|
||||
[150, 82],
|
||||
]
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::multiplyMatrices
|
||||
* @dataProvider providerMultiplyMatrices
|
||||
* @testdox initNumeric: Input $input_a x $input_b must match $expected [$_dataName]
|
||||
*
|
||||
* @param array $input_a
|
||||
* @param array $input_b
|
||||
* @param array $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testMultiplyMatrices(array $input_a, array $input_b, array $expected): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Convert\Math::multiplyMatrices($input_a, $input_b)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function providerEqualWithEpsilon(): array
|
||||
{
|
||||
return [
|
||||
'equal' => [
|
||||
'a' => 0.000000000000000222,
|
||||
'b' => 0.000000000000000222,
|
||||
'epsilon' => PHP_FLOAT_EPSILON,
|
||||
'equal' => true,
|
||||
],
|
||||
'almost equal' => [
|
||||
'a' => 0.000000000000000222,
|
||||
'b' => 0.000000000000000232,
|
||||
'epsilon' => PHP_FLOAT_EPSILON,
|
||||
'equal' => true,
|
||||
],
|
||||
'not equal' => [
|
||||
'a' => 0.000000000000000222,
|
||||
'b' => 0.000000000000004222,
|
||||
'epsilon' => PHP_FLOAT_EPSILON,
|
||||
'equal' => false,
|
||||
],
|
||||
'equal, different epsilon' => [
|
||||
'a' => 0.000000000000000222,
|
||||
'b' => 0.000000000000004222,
|
||||
'epsilon' => 0.0001,
|
||||
'equal' => true,
|
||||
],
|
||||
'not equal, different epsilon' => [
|
||||
'a' => 0.0001,
|
||||
'b' => 0.0002,
|
||||
'epsilon' => 0.0001,
|
||||
'equal' => false,
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::equalWithEpsilon
|
||||
* @dataProvider providerEqualWithEpsilon
|
||||
* @testdox equalWithEpsilon with $a and $b and Epsilon: $epsilon must be equal: $equal [$_dataName]
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testEqualWithEpsilon(float $a, float $b, float $epsilon, bool $equal): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$equal,
|
||||
\CoreLibs\Convert\Math::equalWithEpsilon($a, $b, $epsilon)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function providerCompareWithEpsilon(): array
|
||||
{
|
||||
return [
|
||||
'smaller, true' => [
|
||||
'value' => 0.0001,
|
||||
'compare' => '<',
|
||||
'limit' => 0.0002,
|
||||
'epsilon' => 0.00001,
|
||||
'match' => true,
|
||||
],
|
||||
'smaller, false' => [
|
||||
'value' => 0.0001,
|
||||
'compare' => '<',
|
||||
'limit' => 0.0001,
|
||||
'epsilon' => 0.00001,
|
||||
'match' => false,
|
||||
],
|
||||
'bigger, true' => [
|
||||
'value' => 0.0002,
|
||||
'compare' => '>',
|
||||
'limit' => 0.0001,
|
||||
'epsilon' => 0.00001,
|
||||
'match' => true,
|
||||
],
|
||||
'bigger, false' => [
|
||||
'value' => 0.0001,
|
||||
'compare' => '>',
|
||||
'limit' => 0.0001,
|
||||
'epsilon' => 0.00001,
|
||||
'match' => false,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::compareWithEpsilon
|
||||
* @dataProvider providerCompareWithEpsilon
|
||||
* @testdox compareWithEpsilon $value $compare $limit with $epsilon must match: $match [$_dataName]
|
||||
*
|
||||
* @param float $value
|
||||
* @param string $compare
|
||||
* @param float $limit
|
||||
* @param float $epslion
|
||||
* @param bool $match
|
||||
* @return void
|
||||
*/
|
||||
public function testCompareWithEpsilon(
|
||||
float $value,
|
||||
string $compare,
|
||||
float $limit,
|
||||
float $epsilon,
|
||||
bool $match
|
||||
): void {
|
||||
$this->assertEquals(
|
||||
$match,
|
||||
\CoreLibs\Convert\Math::compareWithEpsilon($value, $compare, $limit, $epsilon)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
|
||||
@@ -33,15 +33,14 @@ final class CoreLibsConvertMimeEncodeTest extends TestCase
|
||||
'The quick brown fox jumps over the lazy sheep that sleeps in the ravine '
|
||||
. 'and has no idea what is going on here',
|
||||
'UTF-8',
|
||||
'The quick brown fox jumps over the lazy sheep that sleeps in the ravine '
|
||||
. 'and has no idea what is going on here'
|
||||
"The quick brown fox jumps over the lazy sheep that sleeps in the ravine and\r\n"
|
||||
. ' has no idea what is going on here'
|
||||
],
|
||||
'standard with special chars UTF-8' => [
|
||||
'This is ümläßtと漢字もカタカナ!!^$%&',
|
||||
'UTF-8',
|
||||
'This is =?UTF-8?B?w7xtbMOkw59044Go5ryi5a2X44KC44Kr44K/44Kr44OK77yBIV4k?='
|
||||
. "\r\n"
|
||||
. ' =?UTF-8?B?JQ==?=&'
|
||||
"This is =?UTF-8?B?w7xtbMOkw59044Go5ryi5a2X44KC44Kr44K/44Kr44OK77yBIV4k?=\r\n"
|
||||
. ' =?UTF-8?B?JSY=?='
|
||||
],
|
||||
'35 chars and space at the end UTF-8' => [
|
||||
'12345678901234567890123456789012345 '
|
||||
@@ -62,9 +61,8 @@ final class CoreLibsConvertMimeEncodeTest extends TestCase
|
||||
. 'is there a space?',
|
||||
'UTF-8',
|
||||
"=?UTF-8?B?44Kr44K/44Kr44OK44Kr44K/44Kr44OK44GL44Gq44Kr44K/44Kr44OK44Kr?=\r\n"
|
||||
. " =?UTF-8?B?44K/44Kr44OK?=\r\n"
|
||||
. " =?UTF-8?B?44GL44Gq44Kr44K/44Kr44OK44Kr44K/44Kr44OK44GL44Gq44Kr44K/44Kr?=\r\n"
|
||||
. " =?UTF-8?B?44OK44Kr44K/?= is there a =?UTF-8?B?c3BhY2U/?="
|
||||
. " =?UTF-8?B?44K/44Kr44OK44GL44Gq44Kr44K/44Kr44OK44Kr44K/44Kr44OK44GL44Gq?=\r\n"
|
||||
. " =?UTF-8?B?44Kr44K/44Kr44OK44Kr44K/IGlzIHRoZXJlIGEgc3BhY2U/?="
|
||||
]
|
||||
];
|
||||
}
|
||||
@@ -85,16 +83,28 @@ final class CoreLibsConvertMimeEncodeTest extends TestCase
|
||||
// print "MIME: -" . $encoded . "-\n";
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$encoded
|
||||
$encoded,
|
||||
"__mbMimeEncode"
|
||||
);
|
||||
$decoded = mb_decode_mimeheader($encoded);
|
||||
// print "INPUT : " . $input . "\n";
|
||||
// print "DECODED: " . $decoded . "\n";
|
||||
// print "ENCODED: " . $encoded . "\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
|
||||
$this->assertEquals(
|
||||
$input,
|
||||
$decoded
|
||||
$decoded,
|
||||
"mb_decode_mimeheader"
|
||||
);
|
||||
|
||||
// $this->assertEquals(
|
||||
// $input,
|
||||
// $test_dec,
|
||||
// 'mb_encode_to_decode'
|
||||
// );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -43,12 +43,17 @@ final class CoreLibsConvertSetVarTypeNullTest extends TestCase
|
||||
'int, no override' => [
|
||||
1,
|
||||
null,
|
||||
null
|
||||
'1'
|
||||
],
|
||||
'int, override set' => [
|
||||
1,
|
||||
'not int',
|
||||
'not int'
|
||||
'1'
|
||||
],
|
||||
'array, override set' => [
|
||||
[1, 2],
|
||||
null,
|
||||
null
|
||||
]
|
||||
];
|
||||
}
|
||||
@@ -201,7 +206,7 @@ final class CoreLibsConvertSetVarTypeNullTest extends TestCase
|
||||
'float' => [
|
||||
1.5,
|
||||
null,
|
||||
null
|
||||
1
|
||||
]
|
||||
];
|
||||
}
|
||||
@@ -349,7 +354,7 @@ final class CoreLibsConvertSetVarTypeNullTest extends TestCase
|
||||
'int' => [
|
||||
1,
|
||||
null,
|
||||
null
|
||||
1.0
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
@@ -43,11 +43,16 @@ final class CoreLibsConvertSetVarTypeTest extends TestCase
|
||||
'int, no override' => [
|
||||
1,
|
||||
null,
|
||||
''
|
||||
'1'
|
||||
],
|
||||
'int, override set' => [
|
||||
1,
|
||||
'not int',
|
||||
'1'
|
||||
],
|
||||
'array, override set' => [
|
||||
[1, 2],
|
||||
'not int',
|
||||
'not int'
|
||||
]
|
||||
];
|
||||
@@ -189,7 +194,7 @@ final class CoreLibsConvertSetVarTypeTest extends TestCase
|
||||
'float' => [
|
||||
1.5,
|
||||
null,
|
||||
0
|
||||
1
|
||||
]
|
||||
];
|
||||
}
|
||||
@@ -330,7 +335,7 @@ final class CoreLibsConvertSetVarTypeTest extends TestCase
|
||||
'int' => [
|
||||
1,
|
||||
null,
|
||||
0.0
|
||||
1.0
|
||||
]
|
||||
];
|
||||
}
|
||||
@@ -341,7 +346,7 @@ final class CoreLibsConvertSetVarTypeTest extends TestCase
|
||||
* @dataProvider varSetTypeFloatProvider
|
||||
* @testdox setFloat $input with override $default will be $expected [$_dataName]
|
||||
*
|
||||
* @param mixed $input
|
||||
* @param mixed $input
|
||||
* @param float|null $default
|
||||
* @param float $expected
|
||||
* @return void
|
||||
|
||||
@@ -13,6 +13,8 @@ use PHPUnit\Framework\TestCase;
|
||||
*/
|
||||
final class CoreLibsConvertStringsTest extends TestCase
|
||||
{
|
||||
private const DATA_FOLDER = __DIR__ . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR;
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
@@ -256,6 +258,126 @@ final class CoreLibsConvertStringsTest extends TestCase
|
||||
$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)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function providerStripUTF8BomBytes(): array
|
||||
{
|
||||
return [
|
||||
"utf8-bom" => [
|
||||
"file" => "UTF8BOM.csv",
|
||||
"expect" => "Asset Type,Epic,File Name\n",
|
||||
],
|
||||
"utf8" => [
|
||||
"file" => "UTF8.csv",
|
||||
"expect" => "Asset Type,Epic,File Name\n",
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* test utf8 bom remove
|
||||
*
|
||||
* @covers ::stripUTF8BomBytes
|
||||
* @dataProvider providerStripUTF8BomBytes
|
||||
* @testdox stripUTF8BomBytes $file will be $expected [$_dataName]
|
||||
*
|
||||
* @param string $file
|
||||
* @param string $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testStripUTF8BomBytes(string $file, string $expected): void
|
||||
{
|
||||
// load sample file
|
||||
if (!is_file(self::DATA_FOLDER . $file)) {
|
||||
$this->markTestSkipped('File: ' . $file . ' could not be opened');
|
||||
}
|
||||
$file = file_get_contents(self::DATA_FOLDER . $file);
|
||||
if ($file === false) {
|
||||
$this->markTestSkipped('File: ' . $file . ' could not be read');
|
||||
}
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Convert\Strings::stripUTF8BomBytes($file)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
|
||||
1
4dev/tests/Convert/data/UTF8.csv
Normal file
1
4dev/tests/Convert/data/UTF8.csv
Normal file
@@ -0,0 +1 @@
|
||||
Asset Type,Epic,File Name
|
||||
|
1
4dev/tests/Convert/data/UTF8BOM.csv
Normal file
1
4dev/tests/Convert/data/UTF8BOM.csv
Normal file
@@ -0,0 +1 @@
|
||||
Asset Type,Epic,File Name
|
||||
|
@@ -22,12 +22,9 @@ final class CoreLibsCreateEmailTest extends TestCase
|
||||
*/
|
||||
public static function setUpBeforeClass(): void
|
||||
{
|
||||
self::$log = new \CoreLibs\Debug\Logging([
|
||||
self::$log = new \CoreLibs\Logging\Logging([
|
||||
'log_folder' => DIRECTORY_SEPARATOR . 'tmp',
|
||||
'file_id' => 'CoreLibs-Create-Email-Test',
|
||||
'debug_all' => true,
|
||||
'echo_all' => false,
|
||||
'print_all' => true,
|
||||
'log_file_id' => 'CoreLibs-Create-Email-Test',
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -624,7 +621,7 @@ final class CoreLibsCreateEmailTest extends TestCase
|
||||
// force new set for each run
|
||||
self::$log->setLogUniqueId(true);
|
||||
// set on of unique log id
|
||||
self::$log->setLogPer('run', true);
|
||||
self::$log->setLogFlag(\CoreLibs\Logging\Logger\Flag::per_run);
|
||||
// init logger
|
||||
$status = \CoreLibs\Create\Email::sendEmail(
|
||||
$subject,
|
||||
@@ -646,7 +643,9 @@ final class CoreLibsCreateEmailTest extends TestCase
|
||||
// assert content: must load JSON from log file
|
||||
if ($status == 2) {
|
||||
// open file, get last entry with 'SEND EMAIL JSON' key
|
||||
$file = file_get_contents(self::$log->getLogFileName());
|
||||
$file = file_get_contents(
|
||||
self::$log->getLogFolder() . self::$log->getLogFile()
|
||||
);
|
||||
if ($file !== false) {
|
||||
// extract SEND EMAIL JSON line
|
||||
$found = preg_match_all("/^.* <SEND EMAIL JSON> - (.*)$/m", $file, $matches);
|
||||
|
||||
@@ -22,7 +22,6 @@ final class CoreLibsCreateSessionTest extends TestCase
|
||||
public function sessionProvider(): array
|
||||
{
|
||||
// 0: session name as parameter or for GLOBAL value
|
||||
// 1: type p: parameter, g: global, d: php.ini default
|
||||
// 2: mock data as array
|
||||
// checkCliStatus: true/false,
|
||||
// getSessionStatus: PHP_SESSION_DISABLED for abort,
|
||||
@@ -30,12 +29,11 @@ final class CoreLibsCreateSessionTest extends TestCase
|
||||
// setSessionName: true/false,
|
||||
// checkActiveSession: true/false, [1st call, 2nd call]
|
||||
// getSessionId: string or false
|
||||
// 3: exepcted name (session)
|
||||
// 4: expected error string
|
||||
// 3: exepcted name (session)]
|
||||
// 4: auto write close flag
|
||||
return [
|
||||
'session parameter' => [
|
||||
'sessionNameParameter',
|
||||
'p',
|
||||
[
|
||||
'checkCliStatus' => false,
|
||||
'getSessionStatus' => PHP_SESSION_NONE,
|
||||
@@ -44,11 +42,10 @@ final class CoreLibsCreateSessionTest extends TestCase
|
||||
'getSessionId' => '1234abcd4567'
|
||||
],
|
||||
'sessionNameParameter',
|
||||
''
|
||||
null,
|
||||
],
|
||||
'session globals' => [
|
||||
'sessionNameGlobals',
|
||||
'g',
|
||||
[
|
||||
'checkCliStatus' => false,
|
||||
'getSessionStatus' => PHP_SESSION_NONE,
|
||||
@@ -57,11 +54,12 @@ final class CoreLibsCreateSessionTest extends TestCase
|
||||
'getSessionId' => '1234abcd4567'
|
||||
],
|
||||
'sessionNameGlobals',
|
||||
''
|
||||
[
|
||||
'auto_write_close' => false,
|
||||
],
|
||||
],
|
||||
'session name default' => [
|
||||
'',
|
||||
'd',
|
||||
'auto write close' => [
|
||||
'sessionNameAutoWriteClose',
|
||||
[
|
||||
'checkCliStatus' => false,
|
||||
'getSessionStatus' => PHP_SESSION_NONE,
|
||||
@@ -69,95 +67,10 @@ final class CoreLibsCreateSessionTest extends TestCase
|
||||
'checkActiveSession' => [false, true],
|
||||
'getSessionId' => '1234abcd4567'
|
||||
],
|
||||
'',
|
||||
''
|
||||
],
|
||||
// error checks
|
||||
// 1: we are in cli
|
||||
'on cli error' => [
|
||||
'',
|
||||
'd',
|
||||
'sessionNameAutoWriteClose',
|
||||
[
|
||||
'checkCliStatus' => true,
|
||||
'getSessionStatus' => PHP_SESSION_NONE,
|
||||
'setSessionName' => true,
|
||||
'checkActiveSession' => [false, true],
|
||||
'getSessionId' => '1234abcd4567'
|
||||
'auto_write_close' => true,
|
||||
],
|
||||
'',
|
||||
'[SESSION] No sessions in php cli'
|
||||
],
|
||||
// 2: session disabled
|
||||
'session disabled error' => [
|
||||
'',
|
||||
'd',
|
||||
[
|
||||
'checkCliStatus' => false,
|
||||
'getSessionStatus' => PHP_SESSION_DISABLED,
|
||||
'setSessionName' => true,
|
||||
'checkActiveSession' => [false, true],
|
||||
'getSessionId' => '1234abcd4567'
|
||||
],
|
||||
'',
|
||||
'[SESSION] Sessions are disabled'
|
||||
],
|
||||
// 3: invalid session name: string
|
||||
'invalid name chars error' => [
|
||||
'1invalid$session#;',
|
||||
'p',
|
||||
[
|
||||
'checkCliStatus' => false,
|
||||
'getSessionStatus' => PHP_SESSION_NONE,
|
||||
'setSessionName' => false,
|
||||
'checkActiveSession' => [false, true],
|
||||
'getSessionId' => '1234abcd4567'
|
||||
],
|
||||
'',
|
||||
'[SESSION] Invalid session name: 1invalid$session#;'
|
||||
],
|
||||
// 3: invalid session name: only numbers
|
||||
'invalid name numbers only error' => [
|
||||
'123',
|
||||
'p',
|
||||
[
|
||||
'checkCliStatus' => false,
|
||||
'getSessionStatus' => PHP_SESSION_NONE,
|
||||
'setSessionName' => false,
|
||||
'checkActiveSession' => [false, true],
|
||||
'getSessionId' => '1234abcd4567'
|
||||
],
|
||||
'',
|
||||
'[SESSION] Invalid session name: 123'
|
||||
],
|
||||
// 3: invalid session name: invalid name short
|
||||
// 3: invalid session name: too long (128)
|
||||
// 4: failed to start session (2nd false on check active session)
|
||||
'invalid name numbers only error' => [
|
||||
'',
|
||||
'd',
|
||||
[
|
||||
'checkCliStatus' => false,
|
||||
'getSessionStatus' => PHP_SESSION_NONE,
|
||||
'setSessionName' => true,
|
||||
'checkActiveSession' => [false, false],
|
||||
'getSessionId' => '1234abcd4567'
|
||||
],
|
||||
'',
|
||||
'[SESSION] Failed to activate session'
|
||||
],
|
||||
// 5: get session id return false
|
||||
'invalid name numbers only error' => [
|
||||
'',
|
||||
'd',
|
||||
[
|
||||
'checkCliStatus' => false,
|
||||
'getSessionStatus' => PHP_SESSION_NONE,
|
||||
'setSessionName' => true,
|
||||
'checkActiveSession' => [false, true],
|
||||
'getSessionId' => false
|
||||
],
|
||||
'',
|
||||
'[SESSION] getSessionId did not return a session id'
|
||||
],
|
||||
];
|
||||
}
|
||||
@@ -170,29 +83,24 @@ final class CoreLibsCreateSessionTest extends TestCase
|
||||
* @testdox startSession $input name for $type will be $expected (error: $expected_error) [$_dataName]
|
||||
*
|
||||
* @param string $input
|
||||
* @param string $type
|
||||
* @param array<mixed> $mock_data
|
||||
* @param string $expected
|
||||
* @param string $expected_error
|
||||
* @param array<string,mixed> $options
|
||||
* @return void
|
||||
*/
|
||||
public function testStartSession(
|
||||
string $input,
|
||||
string $type,
|
||||
array $mock_data,
|
||||
string $expected,
|
||||
string $expected_error
|
||||
?array $options,
|
||||
): void {
|
||||
// override expected
|
||||
if ($type == 'd') {
|
||||
$expected = ini_get('session.name');
|
||||
}
|
||||
/** @var \CoreLibs\Create\Session&MockObject $session_mock */
|
||||
$session_mock = $this->createPartialMock(
|
||||
\CoreLibs\Create\Session::class,
|
||||
[
|
||||
'checkCliStatus', 'getSessionStatus', 'checkActiveSession',
|
||||
'setSessionName', 'startSessionCall', 'getSessionId',
|
||||
'checkCliStatus',
|
||||
'getSessionStatus', 'checkActiveSession',
|
||||
'getSessionId',
|
||||
'getSessionName'
|
||||
]
|
||||
);
|
||||
@@ -211,12 +119,8 @@ final class CoreLibsCreateSessionTest extends TestCase
|
||||
$mock_data['checkActiveSession'][0],
|
||||
$mock_data['checkActiveSession'][1],
|
||||
);
|
||||
// dummy set for session name
|
||||
$session_mock->method('setSessionName')->with($input)->willReturn($mock_data['setSessionName']);
|
||||
// set session name & return bsed on request data
|
||||
$session_mock->method('getSessionName')->willReturn($expected);
|
||||
// will not return anything
|
||||
$session_mock->method('startSessionCall');
|
||||
// in test case only return string
|
||||
// false: will return false
|
||||
$session_mock->method('getSessionId')->willReturn($mock_data['getSessionId']);
|
||||
@@ -224,20 +128,7 @@ final class CoreLibsCreateSessionTest extends TestCase
|
||||
// regex for session id
|
||||
$ression_id_regex = "/^\w+$/";
|
||||
|
||||
unset($GLOBALS['SET_SESSION_NAME']);
|
||||
$session_id = '';
|
||||
switch ($type) {
|
||||
case 'p':
|
||||
$session_id = $session_mock->startSession($input);
|
||||
break;
|
||||
case 'g':
|
||||
$GLOBALS['SET_SESSION_NAME'] = $input;
|
||||
$session_id = $session_mock->startSession();
|
||||
break;
|
||||
case 'd':
|
||||
$session_id = $session_mock->startSession();
|
||||
break;
|
||||
}
|
||||
$session_id = $session_mock->getSessionId();
|
||||
// asert checks
|
||||
if (!empty($session_id)) {
|
||||
$this->assertMatchesRegularExpression(
|
||||
@@ -253,16 +144,82 @@ final class CoreLibsCreateSessionTest extends TestCase
|
||||
$expected,
|
||||
$session_mock->getSessionName()
|
||||
);
|
||||
} else {
|
||||
// false checks
|
||||
$this->assertEquals(
|
||||
$expected_error,
|
||||
$session_mock->getErrorStr(),
|
||||
'error assert'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function providerSessionException(): array
|
||||
{
|
||||
return [
|
||||
'not cli' => [
|
||||
'TEST_EXCEPTION',
|
||||
\RuntimeException::class,
|
||||
1,
|
||||
'/^\[SESSION\] No sessions in php cli$/',
|
||||
],
|
||||
/* 'session disabled ' => [
|
||||
'TEST_EXCEPTION',
|
||||
\RuntimeException::class,
|
||||
2,
|
||||
'/^\[SESSION\] Sessions are disabled/'
|
||||
],
|
||||
'invalid session name' => [
|
||||
'--#as^-292p-',
|
||||
\UnexpectedValueException::class,
|
||||
3,
|
||||
'/^\[SESSION\] Invalid session name: /'
|
||||
],
|
||||
'failed to activate session' => [
|
||||
'TEST_EXCEPTION',
|
||||
\RuntimeException::class,
|
||||
4,
|
||||
'/^\[SESSION\] Failed to activate session/'
|
||||
],
|
||||
'expired session' => [
|
||||
\RuntimeException::class,
|
||||
5,
|
||||
'/^\[SESSION\] Expired session found/'
|
||||
],
|
||||
'not a valid session id returned' => [
|
||||
\UnexpectedValueException::class,
|
||||
6,
|
||||
'/^\[SESSION\] getSessionId did not return a session id/'
|
||||
], */
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* exception checks
|
||||
*
|
||||
* @covers ::initSession
|
||||
* @dataProvider providerSessionException
|
||||
* @testdox create session $session_name with exception $exception ($exception_code) [$_dataName]
|
||||
*
|
||||
* @param string $session_name
|
||||
* @param string $exception
|
||||
* @param int $exception_code
|
||||
* @param string $expected_error
|
||||
* @return void
|
||||
*/
|
||||
public function testSessionException(
|
||||
string $session_name,
|
||||
string $exception,
|
||||
int $exception_code,
|
||||
string $expected_error,
|
||||
): void {
|
||||
//
|
||||
// throws only on new Object creation
|
||||
$this->expectException($exception);
|
||||
$this->expectExceptionCode($exception_code);
|
||||
$this->expectExceptionMessageMatches($expected_error);
|
||||
// cannot set ini after header sent, plus we are on command line there are no headers
|
||||
new \CoreLibs\Create\Session($session_name, ['session_strict' => false]);
|
||||
}
|
||||
|
||||
/**
|
||||
* provider for session name check
|
||||
*
|
||||
@@ -326,109 +283,147 @@ final class CoreLibsCreateSessionTest extends TestCase
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function sessionDataProvider(): array
|
||||
public function providerSessionData(): array
|
||||
{
|
||||
return [
|
||||
'test' => [
|
||||
'foo',
|
||||
'bar',
|
||||
'bar',
|
||||
null,
|
||||
],
|
||||
'int key test' => [
|
||||
123,
|
||||
'bar',
|
||||
'bar',
|
||||
\UnexpectedValueException::class
|
||||
],
|
||||
// more complex value tests
|
||||
'array values' => [
|
||||
'array',
|
||||
[1, 2, 3],
|
||||
[1, 2, 3],
|
||||
null,
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
// NOTE: with auto start session, we cannot test this in the command line
|
||||
|
||||
/**
|
||||
* method call test
|
||||
*
|
||||
* @covers ::setS
|
||||
* @covers ::getS
|
||||
* @covers ::issetS
|
||||
* @covers ::unsetS
|
||||
* @dataProvider sessionDataProvider
|
||||
* @testdox setS/getS/issetS/unsetS $name with $input is $expected [$_dataName]
|
||||
* @covers ::set
|
||||
* @covers ::get
|
||||
* @covers ::isset
|
||||
* @covers ::unset
|
||||
* @dataProvider providerSessionData
|
||||
* @testdox set/get/isset/unset $name with $input is $expected ($exception) [$_dataName]
|
||||
*
|
||||
* @param string|int $name
|
||||
* @param mixed $input
|
||||
* @param mixed $expected
|
||||
* @param ?mixed $exception
|
||||
* @return void
|
||||
*/
|
||||
public function testMethodSetGet($name, $input, $expected): void
|
||||
public function testMethodSetGet($name, $input, $expected, $exception): void
|
||||
{
|
||||
$session = new \CoreLibs\Create\Session();
|
||||
$session->setS($name, $input);
|
||||
if (\CoreLibs\Get\System::checkCLI()) {
|
||||
$this->markTestSkipped('Cannot run testMethodSetGet in CLI');
|
||||
}
|
||||
$session = new \CoreLibs\Create\Session('TEST_METHOD');
|
||||
if ($expected !== null) {
|
||||
$this->expectException($exception);
|
||||
}
|
||||
$session->set($name, $input);
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$session->getS($name),
|
||||
$session->get($name),
|
||||
'method set assert'
|
||||
);
|
||||
// isset true
|
||||
$this->assertTrue(
|
||||
$session->issetS($name),
|
||||
$session->isset($name),
|
||||
'method isset assert ok'
|
||||
);
|
||||
$session->unsetS($name);
|
||||
$session->unset($name);
|
||||
$this->assertEquals(
|
||||
'',
|
||||
$session->getS($name),
|
||||
$session->get($name),
|
||||
'method unset assert'
|
||||
);
|
||||
// iset false
|
||||
// isset false
|
||||
$this->assertFalse(
|
||||
$session->issetS($name),
|
||||
$session->isset($name),
|
||||
'method isset assert false'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* magic call test
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::__set
|
||||
* @covers ::__get
|
||||
* @covers ::__isset
|
||||
* @covers ::__unset
|
||||
* @dataProvider sessionDataProvider
|
||||
* @testdox __set/__get/__iseet/__unset $name with $input is $expected [$_dataName]
|
||||
* @return array
|
||||
*/
|
||||
public function providerSessionDataMany(): array
|
||||
{
|
||||
return [
|
||||
'valid set' => [
|
||||
[
|
||||
'foo 1' => 'bar 1',
|
||||
'foo 2' => 'bar 1',
|
||||
],
|
||||
[
|
||||
'foo 1' => 'bar 1',
|
||||
'foo 2' => 'bar 1',
|
||||
],
|
||||
null,
|
||||
],
|
||||
'invalid entry' => [
|
||||
[
|
||||
'foo 1' => 'bar 1',
|
||||
123 => 'bar 1',
|
||||
],
|
||||
[
|
||||
'foo 1' => 'bar 1',
|
||||
],
|
||||
\UnexpectedValueException::class
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @param string|int $name
|
||||
* @param mixed $input
|
||||
* @param mixed $expected
|
||||
* @covers ::setMany
|
||||
* @covers ::getMany
|
||||
* @dataProvider providerSessionDataMany
|
||||
* @testdox setMany/getMany/unsetMany $set is $expected ($exception) [$_dataName]
|
||||
*
|
||||
* @param array<string|int,mixed> $set
|
||||
* @param array<string,mixed> $expected
|
||||
* @param ?mixed $exception
|
||||
* @return void
|
||||
*/
|
||||
public function testMagicSetGet($name, $input, $expected): void
|
||||
public function testMany($set, $expected, $exception): void
|
||||
{
|
||||
$session = new \CoreLibs\Create\Session();
|
||||
$session->$name = $input;
|
||||
if (\CoreLibs\Get\System::checkCLI()) {
|
||||
$this->markTestSkipped('Cannot run testMethodSetGet in CLI');
|
||||
}
|
||||
$session = new \CoreLibs\Create\Session('TEST_METHOD');
|
||||
if ($expected !== null) {
|
||||
$this->expectException($exception);
|
||||
}
|
||||
$session->setMany($set);
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$session->$name,
|
||||
'magic set assert'
|
||||
$session->getMany(array_keys($set)),
|
||||
'set many failed'
|
||||
);
|
||||
// isset true
|
||||
$this->assertTrue(
|
||||
isset($session->$name),
|
||||
'magic isset assert ok'
|
||||
);
|
||||
unset($session->$name);
|
||||
$session->unsetMany(array_keys($set));
|
||||
$this->assertEquals(
|
||||
'',
|
||||
$session->$name,
|
||||
'magic unset assert'
|
||||
);
|
||||
// isset true
|
||||
$this->assertFalse(
|
||||
isset($session->$name),
|
||||
'magic isset assert false'
|
||||
[],
|
||||
$session->getMany(array_keys($set)),
|
||||
'unset many failed'
|
||||
);
|
||||
}
|
||||
|
||||
@@ -442,27 +437,30 @@ final class CoreLibsCreateSessionTest extends TestCase
|
||||
*/
|
||||
public function testUnsetAll(): void
|
||||
{
|
||||
if (\CoreLibs\Get\System::checkCLI()) {
|
||||
$this->markTestSkipped('Cannot run testUnsetAll in CLI');
|
||||
}
|
||||
$test_values = [
|
||||
'foo' => 'abc',
|
||||
'bar' => '123'
|
||||
];
|
||||
$session = new \CoreLibs\Create\Session();
|
||||
$session = new \CoreLibs\Create\Session('TEST_UNSET');
|
||||
foreach ($test_values as $name => $value) {
|
||||
$session->setS($name, $value);
|
||||
$session->set($name, $value);
|
||||
// confirm set
|
||||
$this->assertEquals(
|
||||
$value,
|
||||
$session->getS($name),
|
||||
$session->get($name),
|
||||
'set assert: ' . $name
|
||||
);
|
||||
}
|
||||
// unset all
|
||||
$session->unsetAllS();
|
||||
$session->clear();
|
||||
// check unset
|
||||
foreach (array_keys($test_values) as $name) {
|
||||
$this->assertEquals(
|
||||
'',
|
||||
$session->getS($name),
|
||||
$session->get($name),
|
||||
'unsert assert: ' . $name
|
||||
);
|
||||
}
|
||||
|
||||
@@ -21,45 +21,83 @@ final class CoreLibsCreateUidsTest extends TestCase
|
||||
public function uniqIdProvider(): array
|
||||
{
|
||||
return [
|
||||
// number length
|
||||
'too short' => [
|
||||
0 => 1,
|
||||
1 => 4,
|
||||
2 => null
|
||||
],
|
||||
'valid length: 10' => [
|
||||
0 => 10,
|
||||
1 => 10,
|
||||
2 => null
|
||||
],
|
||||
'valid length: 9, auto length' => [
|
||||
0 => 9,
|
||||
1 => 8,
|
||||
2 => null
|
||||
],
|
||||
'valid length: 9, force length' => [
|
||||
0 => 9,
|
||||
1 => 9,
|
||||
2 => true,
|
||||
],
|
||||
'very long: 512' => [
|
||||
0 => 512,
|
||||
1 => 512,
|
||||
2 => null
|
||||
],
|
||||
// below is all legacy
|
||||
'md5 hash' => [
|
||||
0 => 'md5',
|
||||
1 => 32,
|
||||
2 => null
|
||||
],
|
||||
'sha256 hash' => [
|
||||
0 => 'sha256',
|
||||
1 => 64
|
||||
1 => 64,
|
||||
2 => null
|
||||
],
|
||||
'ripemd160 hash' => [
|
||||
0 => 'ripemd160',
|
||||
1 => 40
|
||||
1 => 40,
|
||||
2 => null
|
||||
],
|
||||
'adler32 hash' => [
|
||||
0 => 'adler32',
|
||||
1 => 8
|
||||
1 => 8,
|
||||
2 => null
|
||||
],
|
||||
'not in list hash but valid' => [
|
||||
'not in list, set default length' => [
|
||||
0 => 'sha3-512',
|
||||
1 => strlen(hash('sha3-512', 'A'))
|
||||
1 => 64,
|
||||
2 => null
|
||||
],
|
||||
'default hash not set' => [
|
||||
0 => null,
|
||||
1 => 64,
|
||||
2 => null
|
||||
],
|
||||
'invalid name' => [
|
||||
0 => 'iamnotavalidhash',
|
||||
1 => 64,
|
||||
2 => null
|
||||
],
|
||||
'auto: ' . \CoreLibs\Create\Uids::DEFAULT_HASH => [
|
||||
0 => \CoreLibs\Create\Uids::DEFAULT_HASH,
|
||||
1 => strlen(hash(\CoreLibs\Create\Uids::DEFAULT_HASH, 'A'))
|
||||
// auto calls
|
||||
'auto: ' . \CoreLibs\Create\Uids::DEFAULT_UNNIQ_ID_LENGTH => [
|
||||
0 => \CoreLibs\Create\Uids::DEFAULT_UNNIQ_ID_LENGTH,
|
||||
1 => 64,
|
||||
2 => null
|
||||
],
|
||||
'auto: ' . \CoreLibs\Create\Uids::STANDARD_HASH_LONG => [
|
||||
0 => \CoreLibs\Create\Uids::STANDARD_HASH_LONG,
|
||||
1 => strlen(hash(\CoreLibs\Create\Uids::STANDARD_HASH_LONG, 'A'))
|
||||
1 => strlen(hash(\CoreLibs\Create\Uids::STANDARD_HASH_LONG, 'A')),
|
||||
2 => null
|
||||
],
|
||||
'auto: ' . \CoreLibs\Create\Uids::STANDARD_HASH_SHORT => [
|
||||
0 => \CoreLibs\Create\Uids::STANDARD_HASH_SHORT,
|
||||
1 => strlen(hash(\CoreLibs\Create\Uids::STANDARD_HASH_SHORT, 'A'))
|
||||
1 => strlen(hash(\CoreLibs\Create\Uids::STANDARD_HASH_SHORT, 'A')),
|
||||
2 => null
|
||||
],
|
||||
];
|
||||
}
|
||||
@@ -83,6 +121,7 @@ final class CoreLibsCreateUidsTest extends TestCase
|
||||
* must match 7e78fe0d-59b8-4637-af7f-e88d221a7d1e
|
||||
*
|
||||
* @covers ::uuidv4
|
||||
* @covers ::validateUuidv4
|
||||
* @testdox uuidv4 check that return is matching regex [$_dataName]
|
||||
*
|
||||
* @return void
|
||||
@@ -91,13 +130,18 @@ final class CoreLibsCreateUidsTest extends TestCase
|
||||
{
|
||||
$uuid = \CoreLibs\Create\Uids::uuidv4();
|
||||
$this->assertMatchesRegularExpression(
|
||||
'/^[a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12}$/',
|
||||
$uuid
|
||||
'/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/',
|
||||
$uuid,
|
||||
'Failed regex check'
|
||||
);
|
||||
$this->assertTrue(
|
||||
\CoreLibs\Create\Uids::validateUuuidv4($uuid),
|
||||
'Failed validate regex method'
|
||||
);
|
||||
$this->assertFalse(
|
||||
\CoreLibs\Create\Uids::validateUuuidv4('not-a-uuidv4'),
|
||||
'Failed wrong uuid validated as true'
|
||||
);
|
||||
// $this->assertStringMatchesFormat(
|
||||
// '%4s%4s-%4s-%4s-%4s-%4s%4s%4s',
|
||||
// $uuid
|
||||
// );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -105,25 +149,26 @@ final class CoreLibsCreateUidsTest extends TestCase
|
||||
*
|
||||
* @covers ::uniqId
|
||||
* @dataProvider uniqIdProvider
|
||||
* @testdox uniqId $input will be length $expected [$_dataName]
|
||||
* @testdox uniqId $input will be length $expected (Force $flag) [$_dataName]
|
||||
*
|
||||
* @param string|null $input
|
||||
* @param int|string|null $input
|
||||
* @param string $expected
|
||||
* @param bool|null $flag
|
||||
* @return void
|
||||
*/
|
||||
public function testUniqId(?string $input, int $expected): void
|
||||
public function testUniqId(int|string|null $input, int $expected, ?bool $flag): void
|
||||
{
|
||||
if ($input === null) {
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
strlen(\CoreLibs\Create\Uids::uniqId())
|
||||
);
|
||||
$uniq_id_length = strlen(\CoreLibs\Create\Uids::uniqId());
|
||||
} elseif ($flag === null) {
|
||||
$uniq_id_length = strlen(\CoreLibs\Create\Uids::uniqId($input));
|
||||
} else {
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
strlen(\CoreLibs\Create\Uids::uniqId($input))
|
||||
);
|
||||
$uniq_id_length = strlen(\CoreLibs\Create\Uids::uniqId($input, $flag));
|
||||
}
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$uniq_id_length
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -10,7 +10,6 @@ use PHPUnit\Framework\TestCase;
|
||||
* Test class for DB\Extended\ArrayIO
|
||||
* This will only test the PgSQL parts
|
||||
* @coversDefaultClass \CoreLibs\DB\Extended\ArrayIO
|
||||
* @coversDefaultClass \CoreLibs\DB\Extended\ArrayIO
|
||||
* @testdox \CoreLibs\Extended\ArrayIO method tests for extended DB interface
|
||||
*/
|
||||
final class CoreLibsDBExtendedArrayIOTest extends TestCase
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -10,12 +10,13 @@ use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Test class for Debug\Logging
|
||||
* @coversDefaultClass \CoreLibs\Debug\Logging
|
||||
* @testdox \CoreLibs\Debug\Logging method tests
|
||||
* @coversDefaultClass \CoreLibs\Debug\LoggingLegacy
|
||||
* @testdox \CoreLibs\Debug\LoggingLegacy method tests
|
||||
*/
|
||||
final class CoreLibsDebugLoggingTest extends TestCase
|
||||
final class CoreLibsDebugLoggingLegacyTest extends TestCase
|
||||
{
|
||||
private const LOG_FOLDER = __DIR__ . DIRECTORY_SEPARATOR . 'log' . DIRECTORY_SEPARATOR;
|
||||
|
||||
/**
|
||||
* test set for options BASIC
|
||||
*
|
||||
@@ -24,7 +25,7 @@ final class CoreLibsDebugLoggingTest extends TestCase
|
||||
* 1: expected
|
||||
* 2: override
|
||||
* override:
|
||||
* - constant for COSNTANTS
|
||||
* - constant for CONSTANTS
|
||||
* - global for _GLOBALS
|
||||
*
|
||||
* @return array
|
||||
@@ -138,7 +139,7 @@ final class CoreLibsDebugLoggingTest extends TestCase
|
||||
// catch this with the message
|
||||
$this->expectExceptionMessage($deprecation_message);
|
||||
}
|
||||
$log = new \CoreLibs\Debug\Logging($options);
|
||||
$log = new \CoreLibs\Debug\LoggingLegacy($options);
|
||||
// reset error handler
|
||||
restore_error_handler();
|
||||
// check that settings match
|
||||
@@ -308,7 +309,7 @@ final class CoreLibsDebugLoggingTest extends TestCase
|
||||
// catch this with the message
|
||||
$this->expectExceptionMessage($deprecation_message);
|
||||
}
|
||||
$log = new \CoreLibs\Debug\Logging($options);
|
||||
$log = new \CoreLibs\Debug\LoggingLegacy($options);
|
||||
// reset error handler
|
||||
restore_error_handler();
|
||||
// check current
|
||||
@@ -385,7 +386,7 @@ final class CoreLibsDebugLoggingTest extends TestCase
|
||||
bool $expected_get
|
||||
): void {
|
||||
// neutral start with default
|
||||
$log = new \CoreLibs\Debug\Logging([
|
||||
$log = new \CoreLibs\Debug\LoggingLegacy([
|
||||
'file_id' => 'testSetGetLogLevelAll',
|
||||
'log_folder' => self::LOG_FOLDER
|
||||
]);
|
||||
@@ -510,7 +511,7 @@ final class CoreLibsDebugLoggingTest extends TestCase
|
||||
$expected_get
|
||||
): void {
|
||||
// neutral start with default
|
||||
$log = new \CoreLibs\Debug\Logging([
|
||||
$log = new \CoreLibs\Debug\LoggingLegacy([
|
||||
'file_id' => 'testSetGetLogLevel',
|
||||
'log_folder' => self::LOG_FOLDER
|
||||
]);
|
||||
@@ -592,7 +593,7 @@ final class CoreLibsDebugLoggingTest extends TestCase
|
||||
bool $expected_get
|
||||
): void {
|
||||
// neutral start with default
|
||||
$log = new \CoreLibs\Debug\Logging([
|
||||
$log = new \CoreLibs\Debug\LoggingLegacy([
|
||||
'file_id' => 'testSetGetLogPer',
|
||||
'log_folder' => self::LOG_FOLDER
|
||||
]);
|
||||
@@ -624,7 +625,7 @@ final class CoreLibsDebugLoggingTest extends TestCase
|
||||
public function testSetGetLogPrintFileDate(bool $input, bool $expected_set, bool $expected_get): void
|
||||
{
|
||||
// neutral start with default
|
||||
$log = new \CoreLibs\Debug\Logging([
|
||||
$log = new \CoreLibs\Debug\LoggingLegacy([
|
||||
'file_id' => 'testSetGetLogPrintFileDate',
|
||||
'log_folder' => self::LOG_FOLDER
|
||||
]);
|
||||
@@ -693,7 +694,7 @@ final class CoreLibsDebugLoggingTest extends TestCase
|
||||
*/
|
||||
public function testPrAr(array $input, string $expected): void
|
||||
{
|
||||
$log = new \CoreLibs\Debug\Logging([
|
||||
$log = new \CoreLibs\Debug\LoggingLegacy([
|
||||
'file_id' => 'testPrAr',
|
||||
'log_folder' => self::LOG_FOLDER
|
||||
]);
|
||||
@@ -757,7 +758,7 @@ final class CoreLibsDebugLoggingTest extends TestCase
|
||||
*/
|
||||
public function testPrBl(bool $input, ?string $true, ?string $false, string $expected): void
|
||||
{
|
||||
$log = new \CoreLibs\Debug\Logging([
|
||||
$log = new \CoreLibs\Debug\LoggingLegacy([
|
||||
'file_id' => 'testPrBl',
|
||||
'log_folder' => self::LOG_FOLDER
|
||||
]);
|
||||
@@ -932,7 +933,7 @@ final class CoreLibsDebugLoggingTest extends TestCase
|
||||
// remove any files named /tmp/error_log_TestDebug*.log
|
||||
array_map('unlink', glob($options['log_folder'] . 'error_msg_' . $options['file_id'] . '*.log'));
|
||||
// init logger
|
||||
$log = new \CoreLibs\Debug\Logging($options);
|
||||
$log = new \CoreLibs\Debug\LoggingLegacy($options);
|
||||
// * debug (A/B)
|
||||
// NULL check for strip/prefix
|
||||
$this->assertEquals(
|
||||
@@ -1046,13 +1047,13 @@ final class CoreLibsDebugLoggingTest extends TestCase
|
||||
public function testLogUniqueId(bool $option, bool $override): void
|
||||
{
|
||||
if ($option === true) {
|
||||
$log = new \CoreLibs\Debug\Logging([
|
||||
$log = new \CoreLibs\Debug\LoggingLegacy([
|
||||
'file_id' => 'testLogUniqueId',
|
||||
'log_folder' => self::LOG_FOLDER,
|
||||
'per_run' => $option
|
||||
]);
|
||||
} else {
|
||||
$log = new \CoreLibs\Debug\Logging([
|
||||
$log = new \CoreLibs\Debug\LoggingLegacy([
|
||||
'file_id' => 'testLogUniqueId',
|
||||
'log_folder' => self::LOG_FOLDER
|
||||
]);
|
||||
@@ -5,6 +5,7 @@ declare(strict_types=1);
|
||||
namespace tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use CoreLibs\Debug\Support;
|
||||
|
||||
/**
|
||||
* Test class for Debug\Support
|
||||
@@ -40,6 +41,32 @@ final class CoreLibsDebugSupportTest extends TestCase
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @cover ::printTime
|
||||
* @dataProvider printTimeProvider
|
||||
* @testdox printTime test with $microtime and match to regex [$_dataName]
|
||||
*
|
||||
* @param int|null $mircrotime
|
||||
* @param string $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testPrintTime(?int $microtime, string $regex): void
|
||||
{
|
||||
if ($microtime === null) {
|
||||
$this->assertMatchesRegularExpression(
|
||||
$regex,
|
||||
Support::printTime()
|
||||
);
|
||||
} else {
|
||||
$this->assertMatchesRegularExpression(
|
||||
$regex,
|
||||
Support::printTime($microtime)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
@@ -50,18 +77,55 @@ final class CoreLibsDebugSupportTest extends TestCase
|
||||
return [
|
||||
'empty array' => [
|
||||
0 => [],
|
||||
1 => "<pre>Array\n(\n)\n</pre>"
|
||||
1 => "<pre>Array\n(\n)\n</pre>",
|
||||
2 => "Array\n(\n)\n",
|
||||
],
|
||||
'simple array' => [
|
||||
0 => ['a', 'b'],
|
||||
1 => "<pre>Array\n(\n"
|
||||
. " [0] => a\n"
|
||||
. " [1] => b\n"
|
||||
. ")\n</pre>"
|
||||
. ")\n</pre>",
|
||||
2 => "Array\n(\n"
|
||||
. " [0] => a\n"
|
||||
. " [1] => b\n"
|
||||
. ")\n",
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @cover ::printAr
|
||||
* @cover ::printArray
|
||||
* @dataProvider printArrayProvider
|
||||
* @testdox printAr/printArray $input will be $expected [$_dataName]
|
||||
*
|
||||
* @param array $input
|
||||
* @param string $expected
|
||||
* @param string $expected_strip
|
||||
* @return void
|
||||
*/
|
||||
public function testPrintAr(array $input, string $expected, string $expected_strip): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
Support::printAr($input),
|
||||
'assert printAr'
|
||||
);
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
Support::printArray($input),
|
||||
'assert printArray'
|
||||
);
|
||||
$this->assertEquals(
|
||||
$expected_strip,
|
||||
Support::prAr($input),
|
||||
'assert prAr'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
@@ -73,27 +137,31 @@ final class CoreLibsDebugSupportTest extends TestCase
|
||||
'true input default' => [
|
||||
0 => true,
|
||||
1 => [],
|
||||
2 => 'true'
|
||||
2 => 'true',
|
||||
3 => 'true',
|
||||
],
|
||||
'false input default' => [
|
||||
0 => false,
|
||||
1 => [],
|
||||
2 => 'false'
|
||||
2 => 'false',
|
||||
3 => 'false'
|
||||
],
|
||||
'false input param name' => [
|
||||
0 => false,
|
||||
1 => [
|
||||
'name' => 'param test'
|
||||
],
|
||||
2 => '<b>param test</b>: false'
|
||||
2 => '<b>param test</b>: false',
|
||||
3 => 'false'
|
||||
],
|
||||
'true input param name, true override' => [
|
||||
0 => true,
|
||||
1 => [
|
||||
'name' => 'param test',
|
||||
'true' => 'ok'
|
||||
'true' => 'ok',
|
||||
],
|
||||
2 => '<b>param test</b>: ok'
|
||||
2 => '<b>param test</b>: ok',
|
||||
3 => 'ok',
|
||||
],
|
||||
'false input param name, true override, false override' => [
|
||||
0 => false,
|
||||
@@ -102,11 +170,77 @@ final class CoreLibsDebugSupportTest extends TestCase
|
||||
'true' => 'ok',
|
||||
'false' => 'not',
|
||||
],
|
||||
2 => '<b>param test</b>: not'
|
||||
2 => '<b>param test</b>: not',
|
||||
3 => 'not'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @cover ::printBool
|
||||
* @dataProvider printBoolProvider
|
||||
* @testdox printBool $input will be $expected [$_dataName]
|
||||
*
|
||||
* @param bool $input
|
||||
* @param array $params
|
||||
* @param string $expected
|
||||
* @param string $expected_strip
|
||||
* @return void
|
||||
*/
|
||||
public function testPrintBool(bool $input, array $params, string $expected, string $expected_strip): void
|
||||
{
|
||||
if (
|
||||
isset($params['name']) &&
|
||||
isset($params['true']) &&
|
||||
isset($params['false'])
|
||||
) {
|
||||
$string = Support::printBool(
|
||||
$input,
|
||||
$params['name'],
|
||||
$params['true'],
|
||||
$params['false']
|
||||
);
|
||||
$string_strip = Support::prBl(
|
||||
$input,
|
||||
$params['true'],
|
||||
$params['false']
|
||||
);
|
||||
} elseif (isset($params['name']) && isset($params['true'])) {
|
||||
$string = Support::printBool(
|
||||
$input,
|
||||
$params['name'],
|
||||
$params['true']
|
||||
);
|
||||
$string_strip = Support::prBl(
|
||||
$input,
|
||||
$params['true'],
|
||||
);
|
||||
} elseif (isset($params['name'])) {
|
||||
$string = Support::printBool(
|
||||
$input,
|
||||
$params['name']
|
||||
);
|
||||
$string_strip = Support::prBl(
|
||||
$input
|
||||
);
|
||||
} else {
|
||||
$string = Support::printBool($input);
|
||||
$string_strip = Support::prBl($input);
|
||||
}
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$string,
|
||||
'assert printBool'
|
||||
);
|
||||
$this->assertEquals(
|
||||
$expected_strip,
|
||||
$string_strip,
|
||||
'assert prBl'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
@@ -169,12 +303,10 @@ final class CoreLibsDebugSupportTest extends TestCase
|
||||
'an array, no html' => [
|
||||
['a', 'b'],
|
||||
true,
|
||||
"##HTMLPRE##"
|
||||
. "Array\n(\n"
|
||||
"Array\n(\n"
|
||||
. " [0] => a\n"
|
||||
. " [1] => b\n"
|
||||
. ")\n"
|
||||
. "##/HTMLPRE##",
|
||||
. ")\n",
|
||||
],
|
||||
// resource
|
||||
'a resource' => [
|
||||
@@ -191,6 +323,333 @@ final class CoreLibsDebugSupportTest extends TestCase
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @cover ::printToString
|
||||
* @dataProvider printToStringProvider
|
||||
* @testdox printToString $input with $flag will be $expected [$_dataName]
|
||||
*
|
||||
* @param mixed $input anything
|
||||
* @param boolean|null $flag html flag, only for string and array
|
||||
* @param string $expected always string
|
||||
* @return void
|
||||
*/
|
||||
public function testPrintToString(mixed $input, ?bool $flag, string $expected): void
|
||||
{
|
||||
if ($flag === null) {
|
||||
// if expected starts with / and ends with / then this is a regex compare
|
||||
if (
|
||||
substr($expected, 0, 1) == '/' &&
|
||||
substr($expected, -1, 1) == '/'
|
||||
) {
|
||||
$this->assertMatchesRegularExpression(
|
||||
$expected,
|
||||
Support::printToString($input)
|
||||
);
|
||||
} else {
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
Support::printToString($input)
|
||||
);
|
||||
}
|
||||
} else {
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
Support::printToString($input, $flag)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function providerDumpExportVar(): array
|
||||
{
|
||||
return [
|
||||
'string' => [
|
||||
'input' => 'string',
|
||||
'flag' => null,
|
||||
'expected_dump' => 'string(6) "string"' . "\n",
|
||||
'expected_export' => "<pre>'string'</pre>",
|
||||
],
|
||||
'string, no html' => [
|
||||
'input' => 'string',
|
||||
'flag' => true,
|
||||
'expected_dump' => 'string(6) "string"' . "\n",
|
||||
'expected_export' => "'string'",
|
||||
],
|
||||
// int
|
||||
'int' => [
|
||||
'input' => 6,
|
||||
'flag' => null,
|
||||
'expected_dump' => 'int(6)' . "\n",
|
||||
'expected_export' => "<pre>6</pre>",
|
||||
],
|
||||
// float
|
||||
'float' => [
|
||||
'input' => 1.6,
|
||||
'flag' => null,
|
||||
'expected_dump' => 'float(1.6)' . "\n",
|
||||
'expected_export' => "<pre>1.6</pre>",
|
||||
],
|
||||
// bool
|
||||
'bool' => [
|
||||
'input' => true,
|
||||
'flag' => null,
|
||||
'expected_dump' => 'bool(true)' . "\n",
|
||||
'expected_export' => "<pre>true</pre>",
|
||||
],
|
||||
// array
|
||||
'array' => [
|
||||
'input' => ['string', true],
|
||||
'flag' => null,
|
||||
'expected_dump' => "array(2) {\n"
|
||||
. " [0]=>\n"
|
||||
. " string(6) \"string\"\n"
|
||||
. " [1]=>\n"
|
||||
. " bool(true)\n"
|
||||
. "}\n",
|
||||
'expected_export' => "<pre>array (\n"
|
||||
. " 0 => 'string',\n"
|
||||
. " 1 => true,\n"
|
||||
. ")</pre>",
|
||||
],
|
||||
// more
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @cover ::dumpVar
|
||||
* @cover ::exportVar
|
||||
* @dataProvider providerDumpExportVar
|
||||
* @testdox dump/exportVar $input with $flag will be $expected_dump / $expected_export [$_dataName]
|
||||
*
|
||||
* @param mixed $input
|
||||
* @param bool|null $flag
|
||||
* @param string $expected_dump
|
||||
* @param string $expected_export
|
||||
* @return void
|
||||
*/
|
||||
public function testDumpExportVar(mixed $input, ?bool $flag, string $expected_dump, string $expected_export): void
|
||||
{
|
||||
if ($flag === null) {
|
||||
$dump = Support::dumpVar($input);
|
||||
$export = Support::exportVar($input);
|
||||
} else {
|
||||
$dump = Support::dumpVar($input, $flag);
|
||||
$export = Support::exportVar($input, $flag);
|
||||
}
|
||||
$this->assertEquals(
|
||||
$expected_dump,
|
||||
$dump,
|
||||
'assert dumpVar'
|
||||
);
|
||||
$this->assertEquals(
|
||||
$expected_export,
|
||||
$export,
|
||||
'assert dumpVar'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @cover ::getCallerFileLine
|
||||
* @testWith ["vendor/phpunit/phpunit/src/Framework/TestCase.php:6434","phar:///home/clemens/.phive/phars/phpunit-9.6.13.phar/phpunit/Framework/TestCase.php:6434"]
|
||||
* @testdox getCallerFileLine check based on regex .../Framework/TestCase.php:\d+ [$_dataName]
|
||||
*
|
||||
* @param string $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testGetCallerFileLine(): void
|
||||
{
|
||||
// regex prefix with path "/../" and then fixed vendor + \d+
|
||||
// or phar start if phiev installed
|
||||
// phar:///home/clemens/.phive/phars/phpunit-9.6.13.phar/phpunit/Framework/TestCase.php
|
||||
$regex = "/^("
|
||||
. "\/.*\/vendor\/phpunit\/phpunit\/src"
|
||||
. "|"
|
||||
. "phar:\/\/\/.*\.phive\/phars\/phpunit-\d+\.\d+\.\d+\.phar\/phpunit"
|
||||
. ")"
|
||||
. "\/Framework\/TestCase.php:\d+$/";
|
||||
$this->assertMatchesRegularExpression(
|
||||
$regex,
|
||||
Support::getCallerFileLine()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @cover ::getCallerMethod
|
||||
* @testWith ["testGetCallerMethod"]
|
||||
* @testdox getCallerMethod check if it returns $expected [$_dataName]
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetCallerMethod(string $expected): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
Support::getCallerMethod()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @cover ::getCallerMethodList
|
||||
* @testWith [["main", "run", "run", "run", "run", "run", "run", "runBare", "runTest", "testGetCallerMethodList"]]
|
||||
* @testdox getCallerMethodList check if it returns $expected [$_dataName]
|
||||
*
|
||||
* @param array $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testGetCallerMethodList(array $expected): void
|
||||
{
|
||||
$compare = Support::getCallerMethodList();
|
||||
// 10: legacy
|
||||
// 11: direct
|
||||
// 12: full call
|
||||
switch (count($compare)) {
|
||||
case 10:
|
||||
// add nothing
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$compare,
|
||||
'assert expected 10'
|
||||
);
|
||||
break;
|
||||
case 11:
|
||||
if ($compare[0] == 'include') {
|
||||
// add include at first
|
||||
array_splice(
|
||||
$expected,
|
||||
0,
|
||||
0,
|
||||
['include']
|
||||
);
|
||||
} else {
|
||||
array_splice(
|
||||
$expected,
|
||||
6,
|
||||
0,
|
||||
['run']
|
||||
);
|
||||
}
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$compare,
|
||||
'assert expected 11'
|
||||
);
|
||||
break;
|
||||
case 12:
|
||||
// add two "run" before "runBare"
|
||||
array_splice(
|
||||
$expected,
|
||||
7,
|
||||
0,
|
||||
['run']
|
||||
);
|
||||
array_splice(
|
||||
$expected,
|
||||
0,
|
||||
0,
|
||||
['include']
|
||||
);
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$compare,
|
||||
'assert expected 12'
|
||||
);
|
||||
break;
|
||||
default:
|
||||
$this->assertTrue(true, 'Default fallback as true');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
*
|
||||
* @cover ::getCallerClass
|
||||
* @testWith ["tests\\CoreLibsDebugSupportTest"]
|
||||
* @testdox getCallerClass check if it returns $expected [$_dataName]
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetCallerClass(string $expected): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
Support::getCallerClass()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* test highest return (top level)
|
||||
*
|
||||
* @cover ::getCallerTopLevelClass
|
||||
* @testWith ["PHPUnit\\TextUI\\Command"]
|
||||
* @testdox getCallerTopLevelClass check if it returns $expected [$_dataName]
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetCallerTopLevelClass(string $expected): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
Support::getCallerTopLevelClass()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* test highest return (top level)
|
||||
*
|
||||
* @cover ::getCallerClassMethod
|
||||
* @testWith ["tests\\CoreLibsDebugSupportTest->testGetCallerClassMethod"]
|
||||
* @testdox getCallerClassMethod check if it returns $expected [$_dataName]
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetCallerClassMethod(string $expected): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
Support::getCallerClassMethod()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
@@ -236,205 +695,6 @@ final class CoreLibsDebugSupportTest extends TestCase
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @cover ::printTime
|
||||
* @dataProvider printTimeProvider
|
||||
* @testdox printTime test with $microtime and match to regex [$_dataName]
|
||||
*
|
||||
* @param int|null $mircrotime
|
||||
* @param string $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testPrintTime(?int $microtime, string $regex): void
|
||||
{
|
||||
if ($microtime === null) {
|
||||
$this->assertMatchesRegularExpression(
|
||||
$regex,
|
||||
\CoreLibs\Debug\Support::printTime()
|
||||
);
|
||||
} else {
|
||||
$this->assertMatchesRegularExpression(
|
||||
$regex,
|
||||
\CoreLibs\Debug\Support::printTime($microtime)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @cover ::printAr
|
||||
* @cover ::printArray
|
||||
* @dataProvider printArrayProvider
|
||||
* @testdox printAr/printArray $input will be $expected [$_dataName]
|
||||
*
|
||||
* @param array $input
|
||||
* @param string $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testPrintAr(array $input, string $expected): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Debug\Support::printAr($input),
|
||||
'assert printAr'
|
||||
);
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Debug\Support::printArray($input),
|
||||
'assert printArray'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @cover ::printBool
|
||||
* @dataProvider printBoolProvider
|
||||
* @testdox printBool $input will be $expected [$_dataName]
|
||||
*
|
||||
* @param bool $input
|
||||
* @param array $params
|
||||
* @param string $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testPrintBool(bool $input, array $params, string $expected): void
|
||||
{
|
||||
if (
|
||||
isset($params['name']) &&
|
||||
isset($params['true']) &&
|
||||
isset($params['false'])
|
||||
) {
|
||||
$string = \CoreLibs\Debug\Support::printBool(
|
||||
$input,
|
||||
$params['name'],
|
||||
$params['true'],
|
||||
$params['false']
|
||||
);
|
||||
} elseif (isset($params['name']) && isset($params['true'])) {
|
||||
$string = \CoreLibs\Debug\Support::printBool(
|
||||
$input,
|
||||
$params['name'],
|
||||
$params['true']
|
||||
);
|
||||
} elseif (isset($params['name'])) {
|
||||
$string = \CoreLibs\Debug\Support::printBool(
|
||||
$input,
|
||||
$params['name']
|
||||
);
|
||||
} else {
|
||||
$string = \CoreLibs\Debug\Support::printBool($input);
|
||||
}
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$string,
|
||||
'assert printBool'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @cover ::printToString
|
||||
* @dataProvider printToStringProvider
|
||||
* @testdox printToString $input with $flag will be $expected [$_dataName]
|
||||
*
|
||||
* @param mixed $input anything
|
||||
* @param boolean|null $flag html flag, only for string and array
|
||||
* @param string $expected always string
|
||||
* @return void
|
||||
*/
|
||||
public function testPrintToString(mixed $input, ?bool $flag, string $expected): void
|
||||
{
|
||||
if ($flag === null) {
|
||||
// if expected starts with / and ends with / then this is a regex compare
|
||||
if (
|
||||
substr($expected, 0, 1) == '/' &&
|
||||
substr($expected, -1, 1) == '/'
|
||||
) {
|
||||
$this->assertMatchesRegularExpression(
|
||||
$expected,
|
||||
\CoreLibs\Debug\Support::printToString($input)
|
||||
);
|
||||
} else {
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Debug\Support::printToString($input)
|
||||
);
|
||||
}
|
||||
} else {
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Debug\Support::printToString($input, $flag)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @cover ::getCallerMethod
|
||||
* @testWith ["testGetCallerMethod"]
|
||||
* @testdox getCallerMethod check if it returns $expected [$_dataName]
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetCallerMethod(string $expected): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Debug\Support::getCallerMethod()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @cover ::getCallerMethodList
|
||||
* @testWith [["main", "run", "run", "run", "run", "run", "run", "runBare", "runTest", "testGetCallerMethodList"],["include", "main", "run", "run", "run", "run", "run", "run", "run", "runBare", "runTest", "testGetCallerMethodList"]]
|
||||
* @testdox getCallerMethodList check if it returns $expected [$_dataName]
|
||||
*
|
||||
* @param array $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testGetCallerMethodList(array $expected, array $expected_group): void
|
||||
{
|
||||
$compare = \CoreLibs\Debug\Support::getCallerMethodList();
|
||||
// if we direct call we have 10, if we call as folder we get 11
|
||||
if (count($compare) == 10) {
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Debug\Support::getCallerMethodList(),
|
||||
'assert expected 10'
|
||||
);
|
||||
} else {
|
||||
$this->assertEquals(
|
||||
$expected_group,
|
||||
\CoreLibs\Debug\Support::getCallerMethodList(),
|
||||
'assert expected group'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @cover ::getCallerClass
|
||||
* @testWith ["PHPUnit\\TextUI\\Command"]
|
||||
* @testdox getCallerClass check if it returns $expected [$_dataName]
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetCallerClass(string $expected): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Debug\Support::getCallerClass()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
@@ -453,19 +713,19 @@ final class CoreLibsDebugSupportTest extends TestCase
|
||||
if ($replace === null && $flag === null) {
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Debug\Support::debugString($input),
|
||||
Support::debugString($input),
|
||||
'assert all default'
|
||||
);
|
||||
} elseif ($flag === null) {
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Debug\Support::debugString($input, $replace),
|
||||
Support::debugString($input, $replace),
|
||||
'assert flag default'
|
||||
);
|
||||
} else {
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Debug\Support::debugString($input, $replace, $flag),
|
||||
Support::debugString($input, $replace, $flag),
|
||||
'assert all set'
|
||||
);
|
||||
}
|
||||
|
||||
@@ -67,17 +67,17 @@ final class CoreLibsGetSystemTest extends TestCase
|
||||
'original set' => [
|
||||
0 => null,
|
||||
1 => 'NOHOST',
|
||||
2 => 'NOPORT',
|
||||
2 => 0,
|
||||
],
|
||||
'override set no port' => [
|
||||
0 => 'foo.org',
|
||||
1 => 'foo.org',
|
||||
2 => '80'
|
||||
2 => 80
|
||||
],
|
||||
'override set with port' => [
|
||||
0 => 'foo.org:443',
|
||||
1 => 'foo.org',
|
||||
2 => '443'
|
||||
2 => 443
|
||||
]
|
||||
];
|
||||
}
|
||||
@@ -99,7 +99,7 @@ final class CoreLibsGetSystemTest extends TestCase
|
||||
1 => 'phpunit',
|
||||
2 => 'phpunit',
|
||||
// NOTE: this can change, so it is a regex check
|
||||
3 => "/^(\/?.*\/?)?vendor\/bin\/phpunit$/",
|
||||
3 => "/^(\/?.*\/?)?(vendor\/bin|tools)\/phpunit$/",
|
||||
],
|
||||
'some path with extension' => [
|
||||
0 => '/some/path/to/file.txt',
|
||||
@@ -138,10 +138,10 @@ final class CoreLibsGetSystemTest extends TestCase
|
||||
*
|
||||
* @param string|null $input
|
||||
* @param string $expected_host
|
||||
* @param string $expected_port
|
||||
* @param int $expected_port
|
||||
* @return void
|
||||
*/
|
||||
public function testGetHostNanme(?string $input, string $expected_host, string $expected_port): void
|
||||
public function testGetHostNanme(?string $input, string $expected_host, int $expected_port): void
|
||||
{
|
||||
// print "HOSTNAME: " . $_SERVER['HTTP_HOST'] . "<br>";
|
||||
// print "SERVER: " . print_r($_SERVER, true) . "\n";
|
||||
@@ -216,6 +216,29 @@ final class CoreLibsGetSystemTest extends TestCase
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::getIpAddresses
|
||||
* @testdox getIpAddresses check
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetIpAddresses()
|
||||
{
|
||||
// response must have "REMOTE_ADDR" entry, others are optional
|
||||
// NOTE: we have no IP addresses on command line
|
||||
$this->assertTrue(
|
||||
true,
|
||||
"We do not have REMOTE_ADDR on command line"
|
||||
);
|
||||
// $this->assertContains(
|
||||
// 'REMOTE_ADDR',
|
||||
// array_keys(\CoreLibs\Get\System::getIpAddresses()),
|
||||
// 'failed REMOTE_ADDR assert'
|
||||
// );
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
|
||||
@@ -21,341 +21,6 @@ final class CoreLibsLanguageGetLocaleTest extends TestCase
|
||||
. 'includes' . DIRECTORY_SEPARATOR
|
||||
. 'locale' . DIRECTORY_SEPARATOR;
|
||||
|
||||
/**
|
||||
* set all constant variables that must be set before call
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function setUpBeforeClass(): void
|
||||
{
|
||||
// default web page encoding setting
|
||||
/* if (!defined('DEFAULT_ENCODING')) {
|
||||
define('DEFAULT_ENCODING', 'UTF-8');
|
||||
}
|
||||
if (!defined('DEFAULT_LOCALE')) {
|
||||
// default lang + encoding
|
||||
define('DEFAULT_LOCALE', 'en_US.UTF-8');
|
||||
}
|
||||
// site
|
||||
if (!defined('SITE_ENCODING')) {
|
||||
define('SITE_ENCODING', DEFAULT_ENCODING);
|
||||
}
|
||||
if (!defined('SITE_LOCALE')) {
|
||||
define('SITE_LOCALE', DEFAULT_LOCALE);
|
||||
} */
|
||||
// just set
|
||||
/* if (!defined('BASE')) {
|
||||
define('BASE', str_replace('/configs', '', __DIR__) . DIRECTORY_SEPARATOR);
|
||||
}
|
||||
if (!defined('INCLUDES')) {
|
||||
define('INCLUDES', 'includes' . DIRECTORY_SEPARATOR);
|
||||
}
|
||||
if (!defined('LANG')) {
|
||||
define('LANG', 'lang' . DIRECTORY_SEPARATOR);
|
||||
}
|
||||
if (!defined('LOCALE')) {
|
||||
define('LOCALE', 'locale' . DIRECTORY_SEPARATOR);
|
||||
}
|
||||
if (!defined('CONTENT_PATH')) {
|
||||
define('CONTENT_PATH', 'frontend' . DIRECTORY_SEPARATOR);
|
||||
} */
|
||||
// array session
|
||||
$_SESSION = [];
|
||||
global $_SESSION;
|
||||
}
|
||||
|
||||
/**
|
||||
* all the test data
|
||||
*
|
||||
* @return array<mixed>
|
||||
*/
|
||||
/* public function setLocaleProvider(): array
|
||||
{
|
||||
return [
|
||||
// 0: locale
|
||||
// 1: domain
|
||||
// 2: encoding
|
||||
// 3: path
|
||||
// 4: SESSION: DEFAULT_LOCALE
|
||||
// 5: SESSION: DEFAULT_CHARSET
|
||||
// 6: expected array
|
||||
// 7: deprecation message
|
||||
'no params, all default constants' => [
|
||||
// lang, domain, encoding, path
|
||||
null, null, null, null,
|
||||
// SESSION DEFAULT_LOCALE, SESSION: DEFAULT_CHARSET
|
||||
null, null,
|
||||
// return array
|
||||
[
|
||||
'locale' => 'en_US.UTF-8',
|
||||
'lang' => 'en_US',
|
||||
'domain' => 'frontend',
|
||||
'encoding' => 'UTF-8',
|
||||
'path' => "/^\/(.*\/)?includes\/locale\/$/",
|
||||
],
|
||||
'setLocale: Unset $locale or unset SESSION locale is deprecated',
|
||||
],
|
||||
'no params, session charset and lang' => [
|
||||
// lang, domain, encoding, path
|
||||
null, null, null, null,
|
||||
// SESSION DEFAULT_LOCALE, SESSION: DEFAULT_CHARSET
|
||||
'ja_JP', 'UTF-8',
|
||||
// return array
|
||||
[
|
||||
'locale' => 'ja_JP',
|
||||
'lang' => 'ja_JP',
|
||||
'domain' => 'frontend',
|
||||
'encoding' => 'UTF-8',
|
||||
'path' => "/^\/(.*\/)?includes\/locale\/$/",
|
||||
],
|
||||
'setLocale: Unset $domain is deprecated'
|
||||
],
|
||||
'no params, session charset and lang short' => [
|
||||
// lang, domain, encoding, path
|
||||
null, null, null, null,
|
||||
// SESSION DEFAULT_LOCALE, SESSION: DEFAULT_CHARSET
|
||||
'ja', 'UTF-8',
|
||||
// return array
|
||||
[
|
||||
'locale' => 'ja',
|
||||
'lang' => 'ja',
|
||||
'domain' => 'frontend',
|
||||
'encoding' => 'UTF-8',
|
||||
'path' => "/^\/(.*\/)?includes\/locale\/$/",
|
||||
],
|
||||
'setLocale: Unset $domain is deprecated',
|
||||
],
|
||||
// param lang (no sessions)
|
||||
'locale param only, no sessions' => [
|
||||
// lang, domain, encoding, path
|
||||
'ja.UTF-8', null, null, null,
|
||||
// SESSION DEFAULT_LOCALE, SESSION: DEFAULT_CHARSET
|
||||
null, null,
|
||||
// return array
|
||||
[
|
||||
'locale' => 'ja.UTF-8',
|
||||
'lang' => 'ja',
|
||||
'domain' => 'frontend',
|
||||
'encoding' => 'UTF-8',
|
||||
'path' => "/^\/(.*\/)?includes\/locale\/$/",
|
||||
],
|
||||
'setLocale: Unset $domain is deprecated',
|
||||
],
|
||||
// different locale setting
|
||||
'locale complex param only, no sessions' => [
|
||||
// lang, domain, encoding, path
|
||||
'ja_JP.SJIS', null, null, null,
|
||||
// SESSION DEFAULT_LOCALE, SESSION: DEFAULT_CHARSET
|
||||
null, null,
|
||||
// return array
|
||||
[
|
||||
'locale' => 'ja_JP.SJIS',
|
||||
'lang' => 'ja_JP',
|
||||
'domain' => 'frontend',
|
||||
'encoding' => 'SJIS',
|
||||
'path' => "/^\/(.*\/)?includes\/locale\/$/",
|
||||
],
|
||||
'setLocale: Unset $domain is deprecated',
|
||||
],
|
||||
// param lang and domain (no override)
|
||||
'locale, domain params, no sessions' => [
|
||||
// lang, domain, encoding, path
|
||||
'ja.UTF-8', 'admin', null, null,
|
||||
// SESSION DEFAULT_LOCALE, SESSION: DEFAULT_CHARSET
|
||||
null, null,
|
||||
// return array
|
||||
[
|
||||
'locale' => 'ja.UTF-8',
|
||||
'lang' => 'ja',
|
||||
'domain' => 'admin',
|
||||
'encoding' => 'UTF-8',
|
||||
'path' => "/^\/(.*\/)?includes\/locale\/$/",
|
||||
],
|
||||
'setLocale: Unset $path is deprecated',
|
||||
],
|
||||
// param lang and domain (no override)
|
||||
'locale, domain, encoding params, no sessions' => [
|
||||
// lang, domain, encoding, path
|
||||
'ja.UTF-8', 'admin', 'UTF-8', null,
|
||||
// SESSION DEFAULT_LOCALE, SESSION: DEFAULT_CHARSET
|
||||
null, null,
|
||||
// return array
|
||||
[
|
||||
'locale' => 'ja.UTF-8',
|
||||
'lang' => 'ja',
|
||||
'domain' => 'admin',
|
||||
'encoding' => 'UTF-8',
|
||||
'path' => "/^\/(.*\/)?includes\/locale\/$/",
|
||||
],
|
||||
'setLocale: Unset $path is deprecated'
|
||||
],
|
||||
// lang, domain, path (no override)
|
||||
'locale, domain and path, no sessions' => [
|
||||
// lang, domain, encoding, path
|
||||
'ja.UTF-8', 'admin', '', __DIR__ . '/locale_other/',
|
||||
// SESSION DEFAULT_LOCALE, SESSION: DEFAULT_CHARSET
|
||||
null, null,
|
||||
// return array
|
||||
[
|
||||
'locale' => 'ja.UTF-8',
|
||||
'lang' => 'ja',
|
||||
'domain' => 'admin',
|
||||
'encoding' => 'UTF-8',
|
||||
'path' => "/^\/(.*\/)?locale_other\/$/",
|
||||
],
|
||||
null
|
||||
],
|
||||
// all params set (no override)
|
||||
'all parameter, no sessions' => [
|
||||
// lang, domain, encoding, path
|
||||
'ja', 'admin', 'UTF-8', __DIR__ . '/locale_other/',
|
||||
// SESSION DEFAULT_LOCALE, SESSION: DEFAULT_CHARSET
|
||||
null, null,
|
||||
// return array
|
||||
[
|
||||
'locale' => 'ja',
|
||||
'lang' => 'ja',
|
||||
'domain' => 'admin',
|
||||
'encoding' => 'UTF-8',
|
||||
'path' => "/^\/(.*\/)?locale_other\/$/",
|
||||
],
|
||||
null
|
||||
],
|
||||
// param lang and domain (no override)
|
||||
'long locale, domain, encoding params, no sessions' => [
|
||||
// lang, domain, encoding, path
|
||||
'de_CH.UTF-8@euro', 'admin', 'UTF-8', null,
|
||||
// SESSION DEFAULT_LOCALE, SESSION: DEFAULT_CHARSET
|
||||
null, null,
|
||||
// return array
|
||||
[
|
||||
'locale' => 'de_CH.UTF-8@euro',
|
||||
'lang' => 'de_CH',
|
||||
'domain' => 'admin',
|
||||
'encoding' => 'UTF-8',
|
||||
'path' => "/^\/(.*\/)?includes\/locale\/$/",
|
||||
],
|
||||
'setLocale: Unset $path is deprecated',
|
||||
],
|
||||
// TODO invalid params (bad path) (no override)
|
||||
// TODO param calls, but with override set
|
||||
];
|
||||
} */
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::setLocale
|
||||
* @dataProvider setLocaleProvider
|
||||
* @testdox lang settings lang $language, domain $domain, encoding $encoding, path $path; session lang: $SESSION_DEFAULT_LOCALE, session char: $SESSION_DEFAULT_CHARSET [$_dataName]
|
||||
*
|
||||
* @param string|null $language
|
||||
* @param string|null $domain
|
||||
* @param string|null $encoding
|
||||
* @param string|null $path
|
||||
* @param string|null $SESSION_DEFAULT_LOCALE
|
||||
* @param string|null $SESSION_DEFAULT_CHARSET
|
||||
* @param array<mixed> $expected
|
||||
* @param string|null $deprecation_message
|
||||
* @return void
|
||||
*/
|
||||
/* public function testsetLocale(
|
||||
?string $language,
|
||||
?string $domain,
|
||||
?string $encoding,
|
||||
?string $path,
|
||||
?string $SESSION_DEFAULT_LOCALE,
|
||||
?string $SESSION_DEFAULT_CHARSET,
|
||||
array $expected,
|
||||
?string $deprecation_message
|
||||
): void {
|
||||
$return_lang_settings = [];
|
||||
global $_SESSION;
|
||||
// set override
|
||||
if ($SESSION_DEFAULT_LOCALE !== null) {
|
||||
$_SESSION['DEFAULT_LOCALE'] = $SESSION_DEFAULT_LOCALE;
|
||||
}
|
||||
if ($SESSION_DEFAULT_CHARSET !== null) {
|
||||
$_SESSION['DEFAULT_CHARSET'] = $SESSION_DEFAULT_CHARSET;
|
||||
}
|
||||
if ($deprecation_message !== null) {
|
||||
set_error_handler(
|
||||
static function (int $errno, string $errstr): never {
|
||||
throw new \Exception($errstr, $errno);
|
||||
},
|
||||
E_USER_DEPRECATED
|
||||
);
|
||||
// catch this with the message
|
||||
$this->expectExceptionMessage($deprecation_message);
|
||||
}
|
||||
// function call
|
||||
if (
|
||||
$language === null && $domain === null &&
|
||||
$encoding === null && $path === null
|
||||
) {
|
||||
$return_lang_settings = \CoreLibs\Language\GetLocale::setLocale();
|
||||
} elseif (
|
||||
$language !== null && $domain === null &&
|
||||
$encoding === null && $path === null
|
||||
) {
|
||||
$return_lang_settings = \CoreLibs\Language\GetLocale::setLocale(
|
||||
$language
|
||||
);
|
||||
} elseif (
|
||||
$language !== null && $domain !== null &&
|
||||
$encoding === null && $path === null
|
||||
) {
|
||||
$return_lang_settings = \CoreLibs\Language\GetLocale::setLocale(
|
||||
$language,
|
||||
$domain
|
||||
);
|
||||
} elseif (
|
||||
$language !== null && $domain !== null &&
|
||||
$encoding !== null && $path === null
|
||||
) {
|
||||
$return_lang_settings = \CoreLibs\Language\GetLocale::setLocale(
|
||||
$language,
|
||||
$domain,
|
||||
$encoding
|
||||
);
|
||||
} else {
|
||||
$return_lang_settings = \CoreLibs\Language\GetLocale::setLocale(
|
||||
$language,
|
||||
$domain,
|
||||
$encoding,
|
||||
$path
|
||||
);
|
||||
}
|
||||
restore_error_handler();
|
||||
// print "RETURN: " . print_r($return_lang_settings, true) . "\n";
|
||||
|
||||
foreach (
|
||||
[
|
||||
'locale', 'lang', 'domain', 'encoding', 'path'
|
||||
] as $key
|
||||
) {
|
||||
$value = $expected[$key];
|
||||
if (strpos($value, "/") === 0) {
|
||||
// this is regex
|
||||
$this->assertMatchesRegularExpression(
|
||||
$value,
|
||||
$return_lang_settings[$key],
|
||||
'assert regex failed for ' . $key
|
||||
);
|
||||
} else {
|
||||
// assert equal
|
||||
$this->assertEquals(
|
||||
$value,
|
||||
$return_lang_settings[$key],
|
||||
'assert equal failed for ' . $key
|
||||
);
|
||||
}
|
||||
}
|
||||
// unset all vars
|
||||
$_SESSION = [];
|
||||
unset($GLOBALS['OVERRIDE_LANG']);
|
||||
} */
|
||||
|
||||
/**
|
||||
* all the test data
|
||||
*
|
||||
|
||||
563
4dev/tests/Logging/CoreLibsLoggingErrorMessagesTest.php
Normal file
563
4dev/tests/Logging/CoreLibsLoggingErrorMessagesTest.php
Normal file
@@ -0,0 +1,563 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use CoreLibs\Logging\Logger\Level;
|
||||
|
||||
/**
|
||||
* Test class for Logging
|
||||
* @coversDefaultClass \CoreLibs\Logging\ErrorMessages
|
||||
* @testdox \CoreLibs\Logging\ErrorMessages method tests
|
||||
*/
|
||||
final class CoreLibsLoggingErrorMessagesTest extends TestCase
|
||||
{
|
||||
private const LOG_FOLDER = __DIR__ . DIRECTORY_SEPARATOR . 'log' . DIRECTORY_SEPARATOR;
|
||||
|
||||
/**
|
||||
* tear down and remove log data
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function tearDownAfterClass(): void
|
||||
{
|
||||
array_map('unlink', glob(self::LOG_FOLDER . '*.log'));
|
||||
}
|
||||
|
||||
/**
|
||||
* for checking level only
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function providerErrorMessageLevel(): array
|
||||
{
|
||||
return [
|
||||
'ok' => [
|
||||
'level' => 'ok',
|
||||
'str' => 'OK',
|
||||
'expected' => 'ok',
|
||||
],
|
||||
'success' => [
|
||||
'level' => 'success',
|
||||
'str' => 'SUCCESS',
|
||||
'expected' => 'success',
|
||||
],
|
||||
'info' => [
|
||||
'level' => 'info',
|
||||
'str' => 'INFO',
|
||||
'expected' => 'info',
|
||||
],
|
||||
'notice' => [
|
||||
'level' => 'notice',
|
||||
'str' => 'NOTICE',
|
||||
'expected' => 'notice',
|
||||
],
|
||||
'warn' => [
|
||||
'level' => 'warn',
|
||||
'str' => 'WARN',
|
||||
'expected' => 'warn'
|
||||
],
|
||||
'warning' => [
|
||||
'level' => 'warning',
|
||||
'str' => 'WARN',
|
||||
'expected' => 'warn'
|
||||
],
|
||||
'error' => [
|
||||
'level' => 'error',
|
||||
'str' => 'ERROR',
|
||||
'expected' => 'error'
|
||||
],
|
||||
'abort' => [
|
||||
'level' => 'abort',
|
||||
'str' => 'ABORT',
|
||||
'expected' => 'abort'
|
||||
],
|
||||
'crash' => [
|
||||
'level' => 'crash',
|
||||
'str' => 'CRASH',
|
||||
'expected' => 'crash'
|
||||
],
|
||||
'wrong level' => [
|
||||
'level' => 'wrong',
|
||||
'str' => 'WRONG',
|
||||
'expected' => 'unknown'
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @dataProvider providerErrorMessageLevel
|
||||
* @testdox error message level: $level will be $expected [$_dataName]
|
||||
*
|
||||
* @param string $level
|
||||
* @param string $str
|
||||
* @param string $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testErrorMessageLevelOk(string $level, string $str, string $expected): void
|
||||
{
|
||||
$log = new \CoreLibs\Logging\Logging([
|
||||
'log_file_id' => 'testErrorMessagesLevelOk',
|
||||
'log_folder' => self::LOG_FOLDER,
|
||||
'log_level' => Level::Error,
|
||||
]);
|
||||
$em = new \CoreLibs\Logging\ErrorMessage($log);
|
||||
$em->setMessage(
|
||||
$level,
|
||||
$str
|
||||
);
|
||||
$this->assertEquals(
|
||||
[
|
||||
'level' => $expected,
|
||||
'str' => $str,
|
||||
'id' => '',
|
||||
'target' => '',
|
||||
'target_style' => '',
|
||||
'highlight' => [],
|
||||
],
|
||||
$em->getLastErrorMsg()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @testdox Test of all methods for n messages [$_dataName]
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testErrorMessageOk(): void
|
||||
{
|
||||
$log = new \CoreLibs\Logging\Logging([
|
||||
'log_file_id' => 'testErrorMessagesOk',
|
||||
'log_folder' => self::LOG_FOLDER,
|
||||
'log_level' => Level::Error
|
||||
]);
|
||||
$em = new \CoreLibs\Logging\ErrorMessage($log);
|
||||
$em->setErrorMsg(
|
||||
'100',
|
||||
'info',
|
||||
'INFO MESSAGE'
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
[
|
||||
'id' => '100',
|
||||
'level' => 'info',
|
||||
'str' => 'INFO MESSAGE',
|
||||
'target' => '',
|
||||
'target_style' => '',
|
||||
'highlight' => [],
|
||||
],
|
||||
$em->getLastErrorMsg()
|
||||
);
|
||||
$this->assertEquals(
|
||||
['100'],
|
||||
$em->getErrorIds()
|
||||
);
|
||||
$this->assertEquals(
|
||||
[
|
||||
[
|
||||
'id' => '100',
|
||||
'level' => 'info',
|
||||
'str' => 'INFO MESSAGE',
|
||||
'target' => '',
|
||||
'target_style' => '',
|
||||
'highlight' => [],
|
||||
]
|
||||
],
|
||||
$em->getErrorMsg()
|
||||
);
|
||||
|
||||
$em->setErrorMsg(
|
||||
'200',
|
||||
'error',
|
||||
'ERROR MESSAGE'
|
||||
);
|
||||
$this->assertEquals(
|
||||
[
|
||||
'id' => '200',
|
||||
'level' => 'error',
|
||||
'str' => 'ERROR MESSAGE',
|
||||
'target' => '',
|
||||
'target_style' => '',
|
||||
'highlight' => [],
|
||||
],
|
||||
$em->getLastErrorMsg()
|
||||
);
|
||||
$this->assertEquals(
|
||||
['100', '200'],
|
||||
$em->getErrorIds()
|
||||
);
|
||||
$this->assertEquals(
|
||||
[
|
||||
[
|
||||
'id' => '100',
|
||||
'level' => 'info',
|
||||
'str' => 'INFO MESSAGE',
|
||||
'target' => '',
|
||||
'target_style' => '',
|
||||
'highlight' => [],
|
||||
],
|
||||
[
|
||||
'id' => '200',
|
||||
'level' => 'error',
|
||||
'str' => 'ERROR MESSAGE',
|
||||
'target' => '',
|
||||
'target_style' => '',
|
||||
'highlight' => [],
|
||||
]
|
||||
],
|
||||
$em->getErrorMsg()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function providerErrorMessageLog(): array
|
||||
{
|
||||
return [
|
||||
'error, not logged' => [
|
||||
'id' => '200',
|
||||
'level' => 'error',
|
||||
'str' => 'ERROR MESSAGE',
|
||||
'message' => null,
|
||||
'log_error' => null,
|
||||
'log_warning' => null,
|
||||
'expected' => '<ERROR> ERROR MESSAGE',
|
||||
],
|
||||
'error, logged' => [
|
||||
'id' => '200',
|
||||
'level' => 'error',
|
||||
'str' => 'ERROR MESSAGE',
|
||||
'message' => null,
|
||||
'log_error' => true,
|
||||
'log_warning' => null,
|
||||
'expected' => '<ERROR> ERROR MESSAGE',
|
||||
],
|
||||
'error, logged, message' => [
|
||||
'id' => '200',
|
||||
'level' => 'error',
|
||||
'str' => 'ERROR MESSAGE',
|
||||
'message' => 'OTHER ERROR MESSAGE',
|
||||
'log_error' => true,
|
||||
'log_warning' => null,
|
||||
'expected' => '<ERROR> OTHER ERROR MESSAGE',
|
||||
],
|
||||
'warn, not logged' => [
|
||||
'id' => '300',
|
||||
'level' => 'warn',
|
||||
'str' => 'WARNING MESSAGE',
|
||||
'message' => null,
|
||||
'log_error' => null,
|
||||
'log_warning' => null,
|
||||
'expected' => '<WARNING> WARNING MESSAGE',
|
||||
],
|
||||
'warn, logged' => [
|
||||
'id' => '300',
|
||||
'level' => 'warn',
|
||||
'str' => 'WARNING MESSAGE',
|
||||
'message' => null,
|
||||
'log_error' => null,
|
||||
'log_warning' => true,
|
||||
'expected' => '<WARNING> WARNING MESSAGE',
|
||||
],
|
||||
'warn, logged, message' => [
|
||||
'id' => '300',
|
||||
'level' => 'warn',
|
||||
'str' => 'WARNING MESSAGE',
|
||||
'message' => 'OTHER WARNING MESSAGE',
|
||||
'log_error' => null,
|
||||
'log_warning' => true,
|
||||
'expected' => '<WARNING> OTHER WARNING MESSAGE',
|
||||
],
|
||||
'notice' => [
|
||||
'id' => '100',
|
||||
'level' => 'notice',
|
||||
'str' => 'NOTICE MESSAGE',
|
||||
'message' => null,
|
||||
'log_error' => null,
|
||||
'log_warning' => null,
|
||||
'expected' => '<NOTICE> NOTICE MESSAGE',
|
||||
],
|
||||
'notice, message' => [
|
||||
'id' => '100',
|
||||
'level' => 'notice',
|
||||
'str' => 'NOTICE MESSAGE',
|
||||
'message' => 'OTHER NOTICE MESSAGE',
|
||||
'log_error' => null,
|
||||
'log_warning' => null,
|
||||
'expected' => '<NOTICE> OTHER NOTICE MESSAGE',
|
||||
],
|
||||
'crash' => [
|
||||
'id' => '300',
|
||||
'level' => 'crash',
|
||||
'str' => 'CRASH MESSAGE',
|
||||
'message' => null,
|
||||
'log_error' => null,
|
||||
'log_warning' => null,
|
||||
'expected' => '<ALERT> CRASH MESSAGE',
|
||||
],
|
||||
'crash, message' => [
|
||||
'id' => '300',
|
||||
'level' => 'crash',
|
||||
'str' => 'CRASH MESSAGE',
|
||||
'message' => 'OTHER CRASH MESSAGE',
|
||||
'log_error' => null,
|
||||
'log_warning' => null,
|
||||
'expected' => '<ALERT> OTHER CRASH MESSAGE',
|
||||
],
|
||||
'abort' => [
|
||||
'id' => '200',
|
||||
'level' => 'abort',
|
||||
'str' => 'ABORT MESSAGE',
|
||||
'message' => null,
|
||||
'log_error' => null,
|
||||
'log_warning' => null,
|
||||
'expected' => '<CRITICAL> ABORT MESSAGE',
|
||||
],
|
||||
'abort, message' => [
|
||||
'id' => '200',
|
||||
'level' => 'abort',
|
||||
'str' => 'ABORT MESSAGE',
|
||||
'message' => 'OTHER ABORT MESSAGE',
|
||||
'log_error' => null,
|
||||
'log_warning' => null,
|
||||
'expected' => '<CRITICAL> OTHER ABORT MESSAGE',
|
||||
],
|
||||
'unknown' => [
|
||||
'id' => '400',
|
||||
'level' => 'wrong level',
|
||||
'str' => 'WRONG LEVEL MESSAGE',
|
||||
'message' => null,
|
||||
'log_error' => null,
|
||||
'log_warning' => null,
|
||||
'expected' => '<EMERGENCY> WRONG LEVEL MESSAGE',
|
||||
],
|
||||
'unknown, message' => [
|
||||
'id' => '400',
|
||||
'level' => 'wrong level',
|
||||
'str' => 'WRONG LEVEL MESSAGE',
|
||||
'message' => 'OTHER WRONG LEVEL MESSAGE',
|
||||
'log_error' => null,
|
||||
'log_warning' => null,
|
||||
'expected' => '<EMERGENCY> OTHER WRONG LEVEL MESSAGE',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @dataProvider providerErrorMessageLog
|
||||
* @testdox Test Log writing with log level Error [$_dataName]
|
||||
*
|
||||
* @param string $id
|
||||
* @param string $level
|
||||
* @param string $str
|
||||
* @param string|null $message
|
||||
* @param bool|null $log_error
|
||||
* @param bool|null $log_warning
|
||||
* @param string $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testErrorMessageLogErrorLevel(
|
||||
string $id,
|
||||
string $level,
|
||||
string $str,
|
||||
?string $message,
|
||||
?bool $log_error,
|
||||
?bool $log_warning,
|
||||
string $expected
|
||||
): void {
|
||||
$log = new \CoreLibs\Logging\Logging([
|
||||
'log_file_id' => 'testErrorMessagesLogError',
|
||||
'log_folder' => self::LOG_FOLDER,
|
||||
'log_level' => Level::Notice,
|
||||
'log_per_run' => true
|
||||
]);
|
||||
$em = new \CoreLibs\Logging\ErrorMessage($log);
|
||||
$em->setErrorMsg(
|
||||
$id,
|
||||
$level,
|
||||
$str,
|
||||
message: $message,
|
||||
log_error: $log_error,
|
||||
log_warning: $log_warning
|
||||
);
|
||||
$file_content = '';
|
||||
if (is_file($log->getLogFolder() . $log->getLogFile())) {
|
||||
$file_content = file_get_contents(
|
||||
$log->getLogFolder() . $log->getLogFile()
|
||||
) ?: '';
|
||||
}
|
||||
// if error, if null or false, it will not be logged
|
||||
if ($level == 'error' && ($log_error === null || $log_error === false)) {
|
||||
$this->assertStringNotContainsString(
|
||||
$expected,
|
||||
$file_content
|
||||
);
|
||||
} elseif ($level == 'warn' && ($log_warning === null || $log_warning === false)) {
|
||||
$this->assertStringNotContainsString(
|
||||
$expected,
|
||||
$file_content
|
||||
);
|
||||
} else {
|
||||
$this->assertStringContainsString(
|
||||
$expected,
|
||||
$file_content
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @dataProvider providerErrorMessageLog
|
||||
* @testdox Test Log writing with log Level Debug [$_dataName]
|
||||
*
|
||||
* @param string $id
|
||||
* @param string $level
|
||||
* @param string $str
|
||||
* @param string|null $message
|
||||
* @param bool|null $log_error
|
||||
* @param bool|null $log_warning
|
||||
* @param string $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testErrorMessageLogErrorDebug(
|
||||
string $id,
|
||||
string $level,
|
||||
string $str,
|
||||
?string $message,
|
||||
?bool $log_error,
|
||||
?bool $log_warning,
|
||||
string $expected
|
||||
): void {
|
||||
$log = new \CoreLibs\Logging\Logging([
|
||||
'log_file_id' => 'testErrorMessagesLogDebug',
|
||||
'log_folder' => self::LOG_FOLDER,
|
||||
'log_level' => Level::Debug,
|
||||
'log_per_run' => true
|
||||
]);
|
||||
$em = new \CoreLibs\Logging\ErrorMessage($log);
|
||||
$em->setErrorMsg(
|
||||
$id,
|
||||
$level,
|
||||
$str,
|
||||
message: $message,
|
||||
log_error: $log_error,
|
||||
log_warning: $log_warning
|
||||
);
|
||||
$file_content = '';
|
||||
if (is_file($log->getLogFolder() . $log->getLogFile())) {
|
||||
$file_content = file_get_contents(
|
||||
$log->getLogFolder() . $log->getLogFile()
|
||||
) ?: '';
|
||||
}
|
||||
// if error, and log is debug level, only explicit false are not logged
|
||||
if ($level == 'error' && $log_error === false) {
|
||||
$this->assertStringNotContainsString(
|
||||
$expected,
|
||||
$file_content
|
||||
);
|
||||
} elseif ($level == 'warn' && $log_warning === false) {
|
||||
$this->assertStringNotContainsString(
|
||||
$expected,
|
||||
$file_content
|
||||
);
|
||||
} else {
|
||||
$this->assertStringContainsString(
|
||||
$expected,
|
||||
$file_content
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @testdox Test jump target set and reporting
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testJumpTarget(): void
|
||||
{
|
||||
$log = new \CoreLibs\Logging\Logging([
|
||||
'log_file_id' => 'testErrorMessagesLogDebug',
|
||||
'log_folder' => self::LOG_FOLDER,
|
||||
'log_level' => Level::Debug,
|
||||
'log_per_run' => true
|
||||
]);
|
||||
$em = new \CoreLibs\Logging\ErrorMessage($log);
|
||||
$em->setJumpTarget(
|
||||
'target-f',
|
||||
'Target text'
|
||||
);
|
||||
$this->assertEquals(
|
||||
[
|
||||
['target' => 'target-f', 'info' => 'Target text', 'level' => 'error']
|
||||
],
|
||||
$em->getJumpTarget()
|
||||
);
|
||||
// set same target, keep as before
|
||||
$em->setJumpTarget(
|
||||
'target-f',
|
||||
'Other text'
|
||||
);
|
||||
$this->assertEquals(
|
||||
[
|
||||
['target' => 'target-f', 'info' => 'Target text', 'level' => 'error']
|
||||
],
|
||||
$em->getJumpTarget()
|
||||
);
|
||||
// add new now two messages
|
||||
$em->setJumpTarget(
|
||||
'target-s',
|
||||
'More text'
|
||||
);
|
||||
$this->assertEquals(
|
||||
[
|
||||
['target' => 'target-f', 'info' => 'Target text', 'level' => 'error'],
|
||||
['target' => 'target-s', 'info' => 'More text', 'level' => 'error'],
|
||||
],
|
||||
$em->getJumpTarget()
|
||||
);
|
||||
// add empty info
|
||||
$em->setJumpTarget(
|
||||
'target-e',
|
||||
''
|
||||
);
|
||||
$this->assertEquals(
|
||||
[
|
||||
['target' => 'target-f', 'info' => 'Target text', 'level' => 'error'],
|
||||
['target' => 'target-s', 'info' => 'More text', 'level' => 'error'],
|
||||
['target' => 'target-e', 'info' => 'Jump to: target-e', 'level' => 'error'],
|
||||
],
|
||||
$em->getJumpTarget()
|
||||
);
|
||||
// add through message
|
||||
$em->setErrorMsg('E-101', 'abort', 'Abort message', jump_target:[
|
||||
'target' => 'abort-target',
|
||||
'info' => 'Abort error'
|
||||
]);
|
||||
$this->assertEquals(
|
||||
[
|
||||
['target' => 'target-f', 'info' => 'Target text', 'level' => 'error'],
|
||||
['target' => 'target-s', 'info' => 'More text', 'level' => 'error'],
|
||||
['target' => 'target-e', 'info' => 'Jump to: target-e', 'level' => 'error'],
|
||||
['target' => 'abort-target', 'info' => 'Abort error', 'level' => 'abort'],
|
||||
],
|
||||
$em->getJumpTarget()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
847
4dev/tests/Logging/CoreLibsLoggingLoggingTest.php
Normal file
847
4dev/tests/Logging/CoreLibsLoggingLoggingTest.php
Normal file
@@ -0,0 +1,847 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use CoreLibs\Logging\Logger\Level;
|
||||
use CoreLibs\Logging\Logger\Flag;
|
||||
|
||||
// TODO: setLogPer test log file written matches pattern
|
||||
|
||||
/**
|
||||
* Test class for Logging
|
||||
* @coversDefaultClass \CoreLibs\Logging\Logging
|
||||
* @testdox \CoreLibs\Logging\Logging method tests
|
||||
*/
|
||||
final class CoreLibsLoggingLoggingTest extends TestCase
|
||||
{
|
||||
private const LOG_FOLDER = __DIR__ . DIRECTORY_SEPARATOR . 'log' . DIRECTORY_SEPARATOR;
|
||||
private const REGEX_BASE = "\[[\d\-\s\.:]+\]\s{1}" // date
|
||||
. "\[[\w\.]+(:\d+)?\]\s{1}" // host:port
|
||||
. "\[(phar:\/\/)?[\w\-\.\/]+:\d+\]\s{1}" // folder/file [note phar:// is for phpunit]
|
||||
. "\[\w+\]\s{1}" // run id
|
||||
. "{[\w\\\\]+((::|->)\w+)?}\s{1}"; // class
|
||||
|
||||
public static function tearDownAfterClass(): void
|
||||
{
|
||||
array_map('unlink', glob(self::LOG_FOLDER . '*.log'));
|
||||
}
|
||||
|
||||
/**
|
||||
* test set for options BASIC
|
||||
*
|
||||
* 0: options
|
||||
* - null for NOT set
|
||||
* 1: expected
|
||||
* 2: override
|
||||
* override:
|
||||
* - constant for COSNTANTS
|
||||
* - global for _GLOBALS
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function optionsProvider(): array
|
||||
{
|
||||
return [
|
||||
'log folder set' => [
|
||||
'options' => [
|
||||
'log_folder' => DIRECTORY_SEPARATOR . 'tmp',
|
||||
'log_file_id' => 'testClassInit',
|
||||
],
|
||||
'expected' => [
|
||||
'log_folder' => DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR,
|
||||
'log_level' => Level::Debug,
|
||||
'log_file_id' => 'testClassInit',
|
||||
],
|
||||
'override' => [],
|
||||
],
|
||||
// -> deprecation warning, log_folder must be set
|
||||
'no log folder set' => [
|
||||
'options' => [
|
||||
'log_file_id' => 'testClassInit'
|
||||
],
|
||||
'expected' => [
|
||||
'log_folder' => getcwd() . DIRECTORY_SEPARATOR,
|
||||
'log_level' => Level::Debug,
|
||||
'log_file_id' => 'testClassInit',
|
||||
],
|
||||
'override' => []
|
||||
],
|
||||
// -> upcoming deprecated
|
||||
'file_id set but not log_file_id' => [
|
||||
'options' => [
|
||||
'log_folder' => DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR,
|
||||
'file_id' => 'testClassInit',
|
||||
],
|
||||
'expected' => [
|
||||
'log_folder' => DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR,
|
||||
'log_level' => Level::Debug,
|
||||
'log_file_id' => 'testClassInit',
|
||||
],
|
||||
'override' => [],
|
||||
],
|
||||
// both file_id and log_file_id set -> WARNING
|
||||
'file_id and log_file_id set' => [
|
||||
'options' => [
|
||||
'log_folder' => DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR,
|
||||
'file_id' => 'testClassInit',
|
||||
'log_file_id' => 'testClassInit',
|
||||
],
|
||||
'expected' => [
|
||||
'log_folder' => DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR,
|
||||
'log_level' => Level::Debug,
|
||||
'log_file_id' => 'testClassInit',
|
||||
],
|
||||
'override' => [],
|
||||
],
|
||||
// no log file id set -> error,
|
||||
'nothing set' => [
|
||||
'options' => [],
|
||||
'expected' => [
|
||||
'log_folder' => getcwd() . DIRECTORY_SEPARATOR,
|
||||
'log_level' => Level::Debug,
|
||||
'log_file_id' => 'NOHOST-0_PHPUnit-TextUI-Command',
|
||||
],
|
||||
'override' => []
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* init logging class
|
||||
*
|
||||
* @dataProvider optionsProvider
|
||||
* @testdox init test [$_dataName]
|
||||
*
|
||||
* @param array $options
|
||||
* @param array $expected
|
||||
* @param array $override
|
||||
* @return void
|
||||
*/
|
||||
public function testClassInit(array $options, array $expected, array $override): void
|
||||
{
|
||||
if (!empty($override['constant'])) {
|
||||
foreach ($override['constant'] as $var => $value) {
|
||||
if (!defined($var)) {
|
||||
define($var, $value);
|
||||
}
|
||||
}
|
||||
// for deprecated no log_folder set
|
||||
// if base is defined and it does have AAASetupData set
|
||||
// change the log_folder "Debug" to "AAASetupData"
|
||||
if (
|
||||
defined('BASE') &&
|
||||
strpos(BASE, DIRECTORY_SEPARATOR . 'AAASetupData') !== false
|
||||
) {
|
||||
$expected['log_folder'] = str_replace(
|
||||
DIRECTORY_SEPARATOR . 'Debug',
|
||||
DIRECTORY_SEPARATOR . 'AAASetupData',
|
||||
$expected['log_folder']
|
||||
);
|
||||
}
|
||||
}
|
||||
// if not log folder and constant set -> expect E_USER_DEPRECATION
|
||||
if (!empty($override['constant']) && empty($options['log_folder'])) {
|
||||
// the deprecation message
|
||||
$deprecation_message = 'options: log_folder must be set. '
|
||||
. 'Setting via BASE and LOG constants is deprecated';
|
||||
// convert E_USER_DEPRECATED to a exception
|
||||
set_error_handler(
|
||||
static function (int $errno, string $errstr): never {
|
||||
throw new \Exception($errstr, $errno);
|
||||
},
|
||||
E_USER_DEPRECATED
|
||||
);
|
||||
// catch this with the message
|
||||
$this->expectExceptionMessage($deprecation_message);
|
||||
}
|
||||
// alert for log file id with globals
|
||||
if (!empty($override['constant']) && empty($options['log_file_id'])) {
|
||||
//
|
||||
}
|
||||
// alert for log file id and file id set
|
||||
if (
|
||||
!empty($options['log_file_id']) &&
|
||||
!empty($options['file_id'])
|
||||
) {
|
||||
set_error_handler(
|
||||
static function (int $errno, string $errstr): never {
|
||||
throw new \InvalidArgumentException($errstr, $errno);
|
||||
},
|
||||
E_USER_WARNING
|
||||
);
|
||||
$error_message = 'options: "file_id" is deprecated use: "log_file_id".';
|
||||
$this->expectExceptionMessage($error_message);
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
set_error_handler(
|
||||
static function (int $errno, string $errstr): never {
|
||||
throw new \Exception($errstr, $errno);
|
||||
},
|
||||
E_USER_DEPRECATED
|
||||
);
|
||||
$this->expectException(\Exception::class);
|
||||
// $error_message = 'options: both log_file_id and log_id are set at the same time, will use log_file_id';
|
||||
// $this->expectExceptionMessage($error_message);
|
||||
}
|
||||
// empty log folder
|
||||
if (empty($override['constant']) && empty($options['log_folder'])) {
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
$this->expectExceptionMessageMatches("/^Missing mandatory option: \"/");
|
||||
} elseif (empty($options['log_file_id']) && !empty($options['file_id'])) {
|
||||
// the deprecation message
|
||||
$deprecation_message = 'options: "file_id" is deprecated use: "log_file_id".';
|
||||
// convert E_USER_DEPRECATED to a exception
|
||||
set_error_handler(
|
||||
static function (int $errno, string $errstr): never {
|
||||
throw new \Exception($errstr, $errno);
|
||||
},
|
||||
E_USER_DEPRECATED
|
||||
);
|
||||
// catch this with the message
|
||||
$this->expectExceptionMessage($deprecation_message);
|
||||
}
|
||||
$log = new \CoreLibs\Logging\Logging($options);
|
||||
// reset error handler
|
||||
restore_error_handler();
|
||||
// check that settings match
|
||||
$this->assertEquals(
|
||||
$expected['log_folder'],
|
||||
$log->getLogFolder(),
|
||||
'log folder not matching'
|
||||
);
|
||||
$this->assertEquals(
|
||||
$expected['log_file_id'],
|
||||
$log->getLogFileId(),
|
||||
'log file id not matching'
|
||||
);
|
||||
}
|
||||
|
||||
// test all setters/getters
|
||||
|
||||
// setLoggingLevel
|
||||
// getLoggingLevel
|
||||
// loggingLevelIsDebug
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::setLoggingLevel
|
||||
* @covers ::getLoggingLevel
|
||||
* @covers ::loggingLevelIsDebug
|
||||
* @testdox setLoggingLevel set/get checks
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testSetLoggingLevel(): void
|
||||
{
|
||||
// valid that is not Debug
|
||||
$log = new \CoreLibs\Logging\Logging([
|
||||
'log_file_id' => 'testSetLoggingLevel',
|
||||
'log_folder' => self::LOG_FOLDER,
|
||||
'log_level' => Level::Info
|
||||
]);
|
||||
$this->assertEquals(
|
||||
Level::Info,
|
||||
$log->getLoggingLevel()
|
||||
);
|
||||
$this->assertFalse(
|
||||
$log->loggingLevelIsDebug()
|
||||
);
|
||||
// not set, should be debug]
|
||||
$log = new \CoreLibs\Logging\Logging([
|
||||
'log_file_id' => 'testSetLoggingLevel',
|
||||
'log_folder' => self::LOG_FOLDER,
|
||||
]);
|
||||
$this->assertEquals(
|
||||
Level::Debug,
|
||||
$log->getLoggingLevel()
|
||||
);
|
||||
$this->assertTrue(
|
||||
$log->loggingLevelIsDebug()
|
||||
);
|
||||
// invalid, should be debug, will throw excpetion too
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
$this->expectExceptionMessage('Option: "log_level" is not of instance \CoreLibs\Logging\Logger\Level');
|
||||
$log = new \CoreLibs\Logging\Logging([
|
||||
'log_file_id' => 'testSetLoggingLevel',
|
||||
'log_folder' => self::LOG_FOLDER,
|
||||
'log_level' => 'I'
|
||||
]);
|
||||
$this->assertEquals(
|
||||
Level::Debug,
|
||||
$log->getLoggingLevel()
|
||||
);
|
||||
$this->assertTrue(
|
||||
$log->loggingLevelIsDebug()
|
||||
);
|
||||
// set valid, then change
|
||||
$log = new \CoreLibs\Logging\Logging([
|
||||
'log_file_id' => 'testSetLoggingLevel',
|
||||
'log_folder' => self::LOG_FOLDER,
|
||||
'log_level' => Level::Info
|
||||
]);
|
||||
$this->assertEquals(
|
||||
Level::Info,
|
||||
$log->getLoggingLevel()
|
||||
);
|
||||
$log->setLoggingLevel(Level::Notice);
|
||||
$this->assertEquals(
|
||||
Level::Notice,
|
||||
$log->getLoggingLevel()
|
||||
);
|
||||
// illegal logging level
|
||||
$this->expectException(\Psr\Log\InvalidArgumentException::class);
|
||||
$this->expectExceptionMessageMatches("/^Level \"NotGood\" is not defined, use one of: /");
|
||||
$log->setLoggingLevel('NotGood');
|
||||
}
|
||||
|
||||
// setLogFileId
|
||||
// getLogFileId
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::setLogFileId
|
||||
* @covers ::getLogFileId
|
||||
* @testdox setLogFileId set/get checks
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testLogFileId(): void
|
||||
{
|
||||
$log = new \CoreLibs\Logging\Logging([
|
||||
'log_file_id' => 'testLogFileId',
|
||||
'log_folder' => self::LOG_FOLDER
|
||||
]);
|
||||
// bad, keep same
|
||||
$log->setLogFileId('$$##$%#$%&');
|
||||
$this->assertEquals(
|
||||
'testLogFileId',
|
||||
$log->getLogFileId()
|
||||
);
|
||||
// good, change
|
||||
$log->setLogFileId('validID');
|
||||
$this->assertEquals(
|
||||
'validID',
|
||||
$log->getLogFileId()
|
||||
);
|
||||
// invalid on init
|
||||
$this->expectException(\Psr\Log\InvalidArgumentException::class);
|
||||
$this->expectExceptionMessage('LogFileId: no log file id set');
|
||||
$log = new \CoreLibs\Logging\Logging([
|
||||
'log_file_id' => '$$$"#"#$"#$',
|
||||
'log_folder' => self::LOG_FOLDER
|
||||
]);
|
||||
}
|
||||
|
||||
// setLogUniqueId
|
||||
// getLogUniqueId
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function logUniqueIdProvider(): array
|
||||
{
|
||||
return [
|
||||
'option set' => [
|
||||
'option' => true,
|
||||
'override' => false,
|
||||
],
|
||||
'direct set' => [
|
||||
'option' => false,
|
||||
'override' => false,
|
||||
],
|
||||
'override set' => [
|
||||
'option' => false,
|
||||
'override' => true,
|
||||
],
|
||||
'option and override set' => [
|
||||
'option' => false,
|
||||
'override' => true,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::setLogUniqueId
|
||||
* @covers ::getLogUniqueId
|
||||
* @dataProvider logUniqueIdProvider
|
||||
* @testdox per run log id set test: option: $option, override: $override [$_dataName]
|
||||
*
|
||||
* @param bool $option
|
||||
* @param bool $override
|
||||
* @return void
|
||||
*/
|
||||
public function testLogUniqueId(bool $option, bool $override): void
|
||||
{
|
||||
if ($option === true) {
|
||||
$log = new \CoreLibs\Logging\Logging([
|
||||
'log_file_id' => 'testLogUniqueId',
|
||||
'log_folder' => self::LOG_FOLDER,
|
||||
'log_per_run' => $option
|
||||
]);
|
||||
} else {
|
||||
$log = new \CoreLibs\Logging\Logging([
|
||||
'log_file_id' => 'testLogUniqueId',
|
||||
'log_folder' => self::LOG_FOLDER
|
||||
]);
|
||||
$log->setLogUniqueId();
|
||||
}
|
||||
$per_run_id = $log->getLogUniqueId();
|
||||
$this->assertMatchesRegularExpression(
|
||||
"/^\d{4}-\d{2}-\d{2}_\d{6}\.U_[a-z0-9]{8}$/",
|
||||
$per_run_id,
|
||||
'assert per log run id 1st'
|
||||
);
|
||||
if ($override === true) {
|
||||
$log->setLogUniqueId(true);
|
||||
$per_run_id_2nd = $log->getLogUniqueId();
|
||||
$this->assertMatchesRegularExpression(
|
||||
"/^\d{4}-\d{2}-\d{2}_\d{6}\.U_[a-z0-9]{8}$/",
|
||||
$per_run_id_2nd,
|
||||
'assert per log run id 2nd'
|
||||
);
|
||||
$this->assertNotEquals(
|
||||
$per_run_id,
|
||||
$per_run_id_2nd,
|
||||
'1st and 2nd don\'t match'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// setLogDate
|
||||
// getLogDate
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::setLogDate
|
||||
* @covers ::getLogDate
|
||||
* @testdox setLogDate set/get checks
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testSetLogDate(): void
|
||||
{
|
||||
$log = new \CoreLibs\Logging\Logging([
|
||||
'log_file_id' => 'testLogFileId',
|
||||
'log_folder' => self::LOG_FOLDER,
|
||||
'log_per_date' => true,
|
||||
]);
|
||||
$this->assertEquals(
|
||||
date('Y-m-d'),
|
||||
$log->getLogDate()
|
||||
);
|
||||
}
|
||||
|
||||
// setLogFlag
|
||||
// getLogFlag
|
||||
// unsetLogFlag
|
||||
// getLogFlags
|
||||
// Logger\Flag
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers Logger\Flag
|
||||
* @testdox Logger\Flag enum test
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testLoggerFlag(): void
|
||||
{
|
||||
// logger flags to check that they exist
|
||||
$flags = [
|
||||
'all_off' => 0,
|
||||
'per_run' => 1,
|
||||
'per_date' => 2,
|
||||
'per_group' => 4,
|
||||
'per_page' => 8,
|
||||
'per_class' => 16,
|
||||
'per_level' => 32,
|
||||
];
|
||||
// from int -> return value
|
||||
foreach ($flags as $name => $value) {
|
||||
$this->assertEquals(
|
||||
Flag::fromName($name),
|
||||
Flag::fromValue($value)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::setLogFlag
|
||||
* @covers ::getLogFlag
|
||||
* @covers ::unsetLogFlag
|
||||
* @covers ::getLogFlags
|
||||
* @testdox setLogDate set/get checks
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testSetLogFlag(): void
|
||||
{
|
||||
$log = new \CoreLibs\Logging\Logging([
|
||||
'log_file_id' => 'testSetLogFlag',
|
||||
'log_folder' => self::LOG_FOLDER,
|
||||
]);
|
||||
// set valid log flag
|
||||
$log->setLogFlag(Flag::per_run);
|
||||
$this->assertTrue(
|
||||
$log->getLogFlag(Flag::per_run)
|
||||
);
|
||||
// flags seum
|
||||
$this->assertEquals(
|
||||
Flag::per_run->value,
|
||||
$log->getLogFlags(),
|
||||
);
|
||||
// unset valid log flag
|
||||
$log->unsetLogFlag(Flag::per_run);
|
||||
$this->assertFalse(
|
||||
$log->getLogFlag(Flag::per_run)
|
||||
);
|
||||
// illegal Flags cannot be set, they will throw eerros onrun
|
||||
|
||||
// test multi set and sum is equals set
|
||||
$log->setLogFlag(Flag::per_date);
|
||||
$log->setLogFlag(Flag::per_group);
|
||||
$this->assertEquals(
|
||||
Flag::per_date->value + Flag::per_group->value,
|
||||
$log->getLogFlags()
|
||||
);
|
||||
}
|
||||
|
||||
// setLogFolder
|
||||
// getLogFolder
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::setLogFolder
|
||||
* @covers ::getLogFolder
|
||||
* @testdox setLogFolder set/get checks, init check
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testSetLogFolder(): void
|
||||
{
|
||||
// set to good folder
|
||||
$log = new \CoreLibs\Logging\Logging([
|
||||
'log_file_id' => 'testSetLogFolder',
|
||||
'log_folder' => self::LOG_FOLDER,
|
||||
]);
|
||||
$this->assertEquals(
|
||||
self::LOG_FOLDER,
|
||||
$log->getLogFolder()
|
||||
);
|
||||
// set to a good other folder
|
||||
$log->setLogFolder(DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR);
|
||||
$this->assertEquals(
|
||||
DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR,
|
||||
$log->getLogFolder()
|
||||
);
|
||||
// good other folder with missing trailing slash
|
||||
$log->setLogFolder(DIRECTORY_SEPARATOR . 'tmp');
|
||||
$this->assertEquals(
|
||||
DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR,
|
||||
$log->getLogFolder()
|
||||
);
|
||||
// a bad folder -> last good folder
|
||||
$log->setLogFolder('I-am-not existing');
|
||||
$this->assertEquals(
|
||||
DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR,
|
||||
$log->getLogFolder()
|
||||
);
|
||||
// init with a bad folder
|
||||
$this->expectException(\Psr\Log\InvalidArgumentException::class);
|
||||
$this->expectExceptionMessage('Folder: "I-am-bad" is not writeable for logging');
|
||||
$log = new \CoreLibs\Logging\Logging([
|
||||
'log_file_id' => 'testSetLogFolderInvalid',
|
||||
'log_folder' => 'I-am-bad',
|
||||
]);
|
||||
}
|
||||
|
||||
// getLogFile (no set, only correct after log run)
|
||||
|
||||
// setLogMaxFileSize
|
||||
// getLogMaxFileSize
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::setLogMaxFileSize
|
||||
* @covers ::getLogMaxFileSize
|
||||
* @testdox setLogMaxFileSize set/get checks, init check
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testSetLogMaxFileSize(): void
|
||||
{
|
||||
// init set to 0
|
||||
$log = new \CoreLibs\Logging\Logging([
|
||||
'log_file_id' => 'testSetLogMaxFileSize',
|
||||
'log_folder' => self::LOG_FOLDER,
|
||||
]);
|
||||
$this->assertEquals(
|
||||
0,
|
||||
$log->getLogMaxFileSize()
|
||||
);
|
||||
// set to new, valid size
|
||||
$file_size = 200 * 1024;
|
||||
$valid = $log->setLogMaxFileSize($file_size);
|
||||
$this->assertTrue($valid);
|
||||
$this->assertEquals(
|
||||
$file_size,
|
||||
$log->getLogMaxFileSize()
|
||||
);
|
||||
// invalid size, < 0, will be last and return false
|
||||
$valid = $log->setLogMaxFileSize(-1);
|
||||
$this->assertFalse($valid);
|
||||
$this->assertEquals(
|
||||
$file_size,
|
||||
$log->getLogMaxFileSize()
|
||||
);
|
||||
// too small (< MIN_LOG_MAX_FILESIZE)
|
||||
$valid = $log->setLogMaxFileSize($log::MIN_LOG_MAX_FILESIZE - 1);
|
||||
$this->assertFalse($valid);
|
||||
$this->assertEquals(
|
||||
$file_size,
|
||||
$log->getLogMaxFileSize()
|
||||
);
|
||||
}
|
||||
|
||||
// getOption (option params)
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::getOption
|
||||
* @testdox getOption checks
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetOption(): void
|
||||
{
|
||||
$log = new \CoreLibs\Logging\Logging([
|
||||
'log_file_id' => 'testGetOption',
|
||||
'log_folder' => self::LOG_FOLDER,
|
||||
]);
|
||||
$this->assertEquals(
|
||||
self::LOG_FOLDER,
|
||||
$log->getOption('log_folder')
|
||||
);
|
||||
// not found
|
||||
$this->assertNull(
|
||||
$log->getOption('I_do not exist')
|
||||
);
|
||||
}
|
||||
|
||||
// test all logger functions
|
||||
// debug (special)
|
||||
// info
|
||||
// notice
|
||||
// warning
|
||||
// error
|
||||
// critical
|
||||
// alert
|
||||
// emergency
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::debug
|
||||
* @testdox debug checks
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testDebug(): void
|
||||
{
|
||||
// init logger
|
||||
$log = new \CoreLibs\Logging\Logging([
|
||||
'log_file_id' => 'testDebug',
|
||||
'log_folder' => self::LOG_FOLDER,
|
||||
]);
|
||||
// clean all data in folder first
|
||||
array_map('unlink', glob($log->getLogFolder() . $log->getLogFileId() . '*.log'));
|
||||
|
||||
$group_id = 'G';
|
||||
$message = 'D';
|
||||
$log_status = $log->debug($group_id, $message);
|
||||
$this->assertTrue($log_status, 'debug write successful');
|
||||
$file_content = file_get_contents(
|
||||
$log->getLogFolder() . $log->getLogFile()
|
||||
) ?: '';
|
||||
$log_level = $log->getLoggingLevel()->getName();
|
||||
// [2023-05-30 15:51:39.36128800] [NOHOST:0]
|
||||
// [www/vendor/bin/phpunit] [7b9d0747] {PHPUnit\TextUI\Command}
|
||||
// <DEBUG:G> D
|
||||
$this->assertMatchesRegularExpression(
|
||||
"/" . self::REGEX_BASE
|
||||
. "<$log_level:$group_id>\s{1}" // log level / group id
|
||||
. "$message" // message
|
||||
. "/",
|
||||
$file_content
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function providerLoggingLevelWrite(): array
|
||||
{
|
||||
return [
|
||||
'info' => [
|
||||
'message' => 'I',
|
||||
'file_id' => Level::Info->name,
|
||||
'level' => Level::Info
|
||||
],
|
||||
'notice' => [
|
||||
'message' => 'N',
|
||||
'file_id' => Level::Notice->name,
|
||||
'level' => Level::Notice
|
||||
],
|
||||
'warning' => [
|
||||
'message' => 'W',
|
||||
'file_id' => Level::Warning->name,
|
||||
'level' => Level::Warning
|
||||
],
|
||||
'error' => [
|
||||
'message' => 'E',
|
||||
'file_id' => Level::Error->name,
|
||||
'level' => Level::Error
|
||||
],
|
||||
'crticial' => [
|
||||
'message' => 'C',
|
||||
'file_id' => Level::Critical->name,
|
||||
'level' => Level::Critical
|
||||
],
|
||||
'alert' => [
|
||||
'message' => 'A',
|
||||
'file_id' => Level::Alert->name,
|
||||
'level' => Level::Alert
|
||||
],
|
||||
'emergency' => [
|
||||
'message' => 'Em',
|
||||
'file_id' => Level::Emergency->name,
|
||||
'level' => Level::Emergency
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::info
|
||||
* @covers ::notice
|
||||
* @covers ::warning
|
||||
* @covers ::error
|
||||
* @covers ::critical
|
||||
* @covers ::alert
|
||||
* @covers ::emergency
|
||||
* @dataProvider providerLoggingLevelWrite
|
||||
* @testdox logging level write checks for $level [$_dataName]
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testLoggingLevelWrite(string $message, string $file_id, Level $level): void
|
||||
{
|
||||
// init logger
|
||||
$log = new \CoreLibs\Logging\Logging([
|
||||
'log_file_id' => 'test' . $file_id,
|
||||
'log_folder' => self::LOG_FOLDER,
|
||||
'log_level' => $level,
|
||||
]);
|
||||
// clean all data in folder first
|
||||
array_map('unlink', glob($log->getLogFolder() . $log->getLogFileId() . '*.log'));
|
||||
|
||||
switch ($level->value) {
|
||||
case 200:
|
||||
$log_status = $log->info($message);
|
||||
break;
|
||||
case 250:
|
||||
$log_status = $log->notice($message);
|
||||
break;
|
||||
case 300:
|
||||
$log_status = $log->warning($message);
|
||||
break;
|
||||
case 400:
|
||||
$log_status = $log->error($message);
|
||||
break;
|
||||
case 500:
|
||||
$log_status = $log->critical($message);
|
||||
break;
|
||||
case 550:
|
||||
$log_status = $log->alert($message);
|
||||
break;
|
||||
case 600:
|
||||
$log_status = $log->emergency($message);
|
||||
break;
|
||||
}
|
||||
$this->assertTrue($log_status, 'log write successful');
|
||||
$file_content = file_get_contents(
|
||||
$log->getLogFolder() . $log->getLogFile()
|
||||
) ?: '';
|
||||
$log_level = $log->getLoggingLevel()->getName();
|
||||
$this->assertMatchesRegularExpression(
|
||||
"/" . self::REGEX_BASE
|
||||
. "<$log_level>\s{1}" // log level / group id
|
||||
. "$message" // message
|
||||
. "/",
|
||||
$file_content,
|
||||
'log message regex'
|
||||
);
|
||||
}
|
||||
|
||||
// check log level that writer writes in correct level
|
||||
// also that non debug ignores prefix/group
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::log
|
||||
* @testdox log() general call test
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testLoggingLog(): void
|
||||
{
|
||||
// init logger
|
||||
$log = new \CoreLibs\Logging\Logging([
|
||||
'log_file_id' => 'testLoggingLog',
|
||||
'log_folder' => self::LOG_FOLDER,
|
||||
'log_per_level' => true,
|
||||
]);
|
||||
$log_ok = $log->log(Level::Debug, 'DEBUG', group_id: 'GROUP_ID', prefix: 'PREFIX:');
|
||||
$this->assertTrue($log_ok, 'assert ::log (debug) OK');
|
||||
$this->assertEquals(
|
||||
$log->getLogFile(),
|
||||
$log->getLogFileId() . '.DEBUG.log'
|
||||
);
|
||||
$log_ok = $log->log(Level::Info, 'INFO', group_id: 'GROUP_ID', prefix: 'PREFIX:');
|
||||
$this->assertTrue($log_ok, 'assert ::log (info) OK');
|
||||
$this->assertEquals(
|
||||
$log->getLogFile(),
|
||||
$log->getLogFileId() . '.INFO.log'
|
||||
);
|
||||
}
|
||||
|
||||
// must test flow:
|
||||
// init normal
|
||||
// log -> check file name
|
||||
// set per date
|
||||
// log -> check file name
|
||||
// and same for per_run
|
||||
|
||||
// deprecated calls check?
|
||||
}
|
||||
|
||||
// __END__
|
||||
3
4dev/tests/Logging/log/.gitignore
vendored
Normal file
3
4dev/tests/Logging/log/.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
*log
|
||||
*LOG
|
||||
!.gitignore
|
||||
@@ -16,17 +16,89 @@ final class CoreLibsOutputImageTest extends TestCase
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @testdox Output\Image Class tests
|
||||
* @covers ::createThumbnail
|
||||
* @testdox createThumbnail checks
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testOutputImage()
|
||||
public function testCreateThumbnail(): void
|
||||
{
|
||||
// $this->assertTrue(true, 'Output Image Tests not implemented');
|
||||
$this->markTestIncomplete(
|
||||
'Output\Image Tests have not yet been implemented'
|
||||
// CONVERT does not exist
|
||||
$this->expectException(\RuntimeException::class);
|
||||
\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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,838 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use CoreLibs\Security\CreateKey;
|
||||
use CoreLibs\Security\AsymmetricAnonymousEncryption;
|
||||
|
||||
/**
|
||||
* Test class for Security\AsymmetricAnonymousEncryption and Security\CreateKey
|
||||
* @coversDefaultClass \CoreLibs\Security\AsymmetricAnonymousEncryption
|
||||
* @testdox \CoreLibs\Security\AsymmetricAnonymousEncryption method tests
|
||||
*/
|
||||
final class CoreLibsSecurityAsymmetricAnonymousEncryptionTest extends TestCase
|
||||
{
|
||||
// MARK: key set and compare
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::getKeyPair
|
||||
* @covers ::compareKeyPair
|
||||
* @covers ::getPublicKey
|
||||
* @covers ::comparePublicKey
|
||||
* @testdox Check if init class set key pair matches to created key pair and public key
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testKeyPairInitGetCompare(): void
|
||||
{
|
||||
$key_pair = CreateKey::createKeyPair();
|
||||
$public_key = CreateKey::getPublicKey($key_pair);
|
||||
$crypt = new AsymmetricAnonymousEncryption($key_pair);
|
||||
$this->assertTrue(
|
||||
$crypt->compareKeyPair($key_pair),
|
||||
'set key pair not equal to original key pair'
|
||||
);
|
||||
$this->assertTrue(
|
||||
$crypt->comparePublicKey($public_key),
|
||||
'automatic set public key not equal to original public key'
|
||||
);
|
||||
$this->assertEquals(
|
||||
$key_pair,
|
||||
$crypt->getKeyPair(),
|
||||
'set key pair returned not equal to original key pair'
|
||||
);
|
||||
$this->assertEquals(
|
||||
$public_key,
|
||||
$crypt->getPublicKey(),
|
||||
'automatic set public key returned not equal to original public key'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::getKeyPair
|
||||
* @covers ::compareKeyPair
|
||||
* @covers ::getPublicKey
|
||||
* @covers ::comparePublicKey
|
||||
* @testdox Check if init class set key pair and public key matches to created key pair and public key
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testKeyPairPublicKeyInitGetCompare(): void
|
||||
{
|
||||
$key_pair = CreateKey::createKeyPair();
|
||||
$public_key = CreateKey::getPublicKey($key_pair);
|
||||
$crypt = new AsymmetricAnonymousEncryption($key_pair, $public_key);
|
||||
$this->assertTrue(
|
||||
$crypt->compareKeyPair($key_pair),
|
||||
'set key pair not equal to original key pair'
|
||||
);
|
||||
$this->assertTrue(
|
||||
$crypt->comparePublicKey($public_key),
|
||||
'set public key not equal to original public key'
|
||||
);
|
||||
$this->assertEquals(
|
||||
$key_pair,
|
||||
$crypt->getKeyPair(),
|
||||
'set key pair returned not equal to original key pair'
|
||||
);
|
||||
$this->assertEquals(
|
||||
$public_key,
|
||||
$crypt->getPublicKey(),
|
||||
'set public key returned not equal to original public key'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::getKeyPair
|
||||
* @covers ::getPublicKey
|
||||
* @covers ::comparePublicKey
|
||||
* @testdox Check if init class set public key matches to created public key
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testPublicKeyInitGetCompare(): void
|
||||
{
|
||||
$key_pair = CreateKey::createKeyPair();
|
||||
$public_key = CreateKey::getPublicKey($key_pair);
|
||||
$crypt = new AsymmetricAnonymousEncryption(public_key:$public_key);
|
||||
$this->assertTrue(
|
||||
$crypt->comparePublicKey($public_key),
|
||||
'set public key not equal to original public key'
|
||||
);
|
||||
$this->assertEquals(
|
||||
null,
|
||||
$crypt->getKeyPair(),
|
||||
'unset set key pair returned not equal to original key pair'
|
||||
);
|
||||
$this->assertEquals(
|
||||
$public_key,
|
||||
$crypt->getPublicKey(),
|
||||
'set public key returned not equal to original public key'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::setKeyPair
|
||||
* @covers ::getKeyPair
|
||||
* @covers ::compareKeyPair
|
||||
* @covers ::getPublicKey
|
||||
* @covers ::comparePublicKey
|
||||
* @testdox Check if set key pair after class init matches to created key pair and public key
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testKeyPairSetGetCompare(): void
|
||||
{
|
||||
$key_pair = CreateKey::createKeyPair();
|
||||
$public_key = CreateKey::getPublicKey($key_pair);
|
||||
$crypt = new AsymmetricAnonymousEncryption();
|
||||
$crypt->setKeyPair($key_pair);
|
||||
$this->assertTrue(
|
||||
$crypt->compareKeyPair($key_pair),
|
||||
'post class init set key pair not equal to original key pair'
|
||||
);
|
||||
$this->assertTrue(
|
||||
$crypt->comparePublicKey($public_key),
|
||||
'post class init automatic set public key not equal to original public key'
|
||||
);
|
||||
$this->assertEquals(
|
||||
$key_pair,
|
||||
$crypt->getKeyPair(),
|
||||
'post class init set key pair returned not equal to original key pair'
|
||||
);
|
||||
$this->assertEquals(
|
||||
$public_key,
|
||||
$crypt->getPublicKey(),
|
||||
'post class init automatic set public key returned not equal to original public key'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::setKeyPair
|
||||
* @covers ::setPublicKey
|
||||
* @covers ::getKeyPair
|
||||
* @covers ::compareKeyPair
|
||||
* @covers ::getPublicKey
|
||||
* @covers ::comparePublicKey
|
||||
* @testdox Check if set key pair after class init matches to created key pair and public key
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testKeyPairPublicKeySetGetCompare(): void
|
||||
{
|
||||
$key_pair = CreateKey::createKeyPair();
|
||||
$public_key = CreateKey::getPublicKey($key_pair);
|
||||
$crypt = new AsymmetricAnonymousEncryption();
|
||||
$crypt->setKeyPair($key_pair);
|
||||
$crypt->setPublicKey($public_key);
|
||||
$this->assertTrue(
|
||||
$crypt->compareKeyPair($key_pair),
|
||||
'post class init set key pair not equal to original key pair'
|
||||
);
|
||||
$this->assertTrue(
|
||||
$crypt->comparePublicKey($public_key),
|
||||
'post class init set public key not equal to original public key'
|
||||
);
|
||||
$this->assertEquals(
|
||||
$key_pair,
|
||||
$crypt->getKeyPair(),
|
||||
'post class init set key pair returned not equal to original key pair'
|
||||
);
|
||||
$this->assertEquals(
|
||||
$public_key,
|
||||
$crypt->getPublicKey(),
|
||||
'post class init set public key returned not equal to original public key'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::setPublicKey
|
||||
* @covers ::getKeyPair
|
||||
* @covers ::compareKeyPair
|
||||
* @covers ::getPublicKey
|
||||
* @covers ::comparePublicKey
|
||||
* @testdox Check if set key pair after class init matches to created key pair and public key
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testPublicKeySetGetCompare(): void
|
||||
{
|
||||
$key_pair = CreateKey::createKeyPair();
|
||||
$public_key = CreateKey::getPublicKey($key_pair);
|
||||
$crypt = new AsymmetricAnonymousEncryption();
|
||||
$crypt->setPublicKey($public_key);
|
||||
$this->assertTrue(
|
||||
$crypt->comparePublicKey($public_key),
|
||||
'post class init set public key not equal to original public key'
|
||||
);
|
||||
$this->assertEquals(
|
||||
null,
|
||||
$crypt->getKeyPair(),
|
||||
'post class init unset key pair returned not equal to original key pair'
|
||||
);
|
||||
$this->assertEquals(
|
||||
$public_key,
|
||||
$crypt->getPublicKey(),
|
||||
'post class init set public key returned not equal to original public key'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @testdox Check different key pair and public key set
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testDifferentSetKeyPairPublicKey()
|
||||
{
|
||||
$key_pair = CreateKey::createKeyPair();
|
||||
$public_key = CreateKey::getPublicKey($key_pair);
|
||||
$key_pair_2 = CreateKey::createKeyPair();
|
||||
$public_key_2 = CreateKey::getPublicKey($key_pair_2);
|
||||
$crypt = new AsymmetricAnonymousEncryption($key_pair, $public_key_2);
|
||||
$this->assertTrue(
|
||||
$crypt->compareKeyPair($key_pair),
|
||||
'key pair set matches key pair created'
|
||||
);
|
||||
$this->assertTrue(
|
||||
$crypt->comparePublicKey($public_key_2),
|
||||
'alternate public key set matches alternate public key created'
|
||||
);
|
||||
$this->assertFalse(
|
||||
$crypt->comparePublicKey($public_key),
|
||||
'alternate public key set does not match key pair public key'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @testdox Check if new set privat key does not overwrite set public key
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testUpdateKeyPairNotUpdatePublicKey(): void
|
||||
{
|
||||
$key_pair = CreateKey::createKeyPair();
|
||||
$public_key = CreateKey::getPublicKey($key_pair);
|
||||
$crypt = new AsymmetricAnonymousEncryption($key_pair);
|
||||
$this->assertTrue(
|
||||
$crypt->compareKeyPair($key_pair),
|
||||
'set key pair not equal to original key pair'
|
||||
);
|
||||
$this->assertTrue(
|
||||
$crypt->comparePublicKey($public_key),
|
||||
'set public key not equal to original public key'
|
||||
);
|
||||
$key_pair_2 = CreateKey::createKeyPair();
|
||||
$public_key_2 = CreateKey::getPublicKey($key_pair_2);
|
||||
$crypt->setKeyPair($key_pair_2);
|
||||
$this->assertTrue(
|
||||
$crypt->compareKeyPair($key_pair_2),
|
||||
'new set key pair not equal to original new key pair'
|
||||
);
|
||||
$this->assertTrue(
|
||||
$crypt->comparePublicKey($public_key),
|
||||
'original set public key not equal to original public key'
|
||||
);
|
||||
$this->assertFalse(
|
||||
$crypt->comparePublicKey($public_key_2),
|
||||
'new public key equal to original public key'
|
||||
);
|
||||
}
|
||||
|
||||
// MARK: empty encrytped string
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::decryptKey
|
||||
* @covers ::decrypt
|
||||
* @testdox Test empty encrypted string to decrypt
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testEmptyDecryptionString(): void
|
||||
{
|
||||
$this->expectExceptionMessage('Encrypted string cannot be empty');
|
||||
AsymmetricAnonymousEncryption::decryptKey('', CreateKey::generateRandomKey());
|
||||
}
|
||||
|
||||
// MARK: encrypt/decrypt
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function providerEncryptDecryptSuccess(): array
|
||||
{
|
||||
return [
|
||||
'valid string' => [
|
||||
'input' => 'I am a secret',
|
||||
'expected' => 'I am a secret',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* test encrypt/decrypt produce correct output
|
||||
*
|
||||
* @covers ::generateRandomKey
|
||||
* @covers ::encrypt
|
||||
* @covers ::decrypt
|
||||
* @dataProvider providerEncryptDecryptSuccess
|
||||
* @testdox encrypt/decrypt $input must be $expected [$_dataName]
|
||||
*
|
||||
* @param string $input
|
||||
* @param string $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testEncryptDecryptSuccess(string $input, string $expected): void
|
||||
{
|
||||
$key_pair = CreateKey::createKeyPair();
|
||||
$public_key = CreateKey::getPublicKey($key_pair);
|
||||
// test class
|
||||
$crypt = new AsymmetricAnonymousEncryption($key_pair);
|
||||
$encrypted = $crypt->encrypt($input);
|
||||
$decrypted = $crypt->decrypt($encrypted);
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$decrypted,
|
||||
'Class call',
|
||||
);
|
||||
$crypt = new AsymmetricAnonymousEncryption($key_pair, $public_key);
|
||||
$encrypted = $crypt->encrypt($input);
|
||||
$decrypted = $crypt->decrypt($encrypted);
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$decrypted,
|
||||
'Class call botjh set',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* test encrypt/decrypt produce correct output
|
||||
*
|
||||
* @covers ::generateRandomKey
|
||||
* @covers ::encrypt
|
||||
* @covers ::decrypt
|
||||
* @dataProvider providerEncryptDecryptSuccess
|
||||
* @testdox encrypt/decrypt indirect $input must be $expected [$_dataName]
|
||||
*
|
||||
* @param string $input
|
||||
* @param string $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testEncryptDecryptSuccessIndirect(string $input, string $expected): void
|
||||
{
|
||||
$key_pair = CreateKey::createKeyPair();
|
||||
$public_key = CreateKey::getPublicKey($key_pair);
|
||||
// test indirect
|
||||
$encrypted = AsymmetricAnonymousEncryption::getInstance(public_key:$public_key)->encrypt($input);
|
||||
$decrypted = AsymmetricAnonymousEncryption::getInstance($key_pair)->decrypt($encrypted);
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$decrypted,
|
||||
'Class Instance call',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* test encrypt/decrypt produce correct output
|
||||
*
|
||||
* @covers ::generateRandomKey
|
||||
* @covers ::encrypt
|
||||
* @covers ::decrypt
|
||||
* @dataProvider providerEncryptDecryptSuccess
|
||||
* @testdox encrypt/decrypt indirect with public key $input must be $expected [$_dataName]
|
||||
*
|
||||
* @param string $input
|
||||
* @param string $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testEncryptDecryptSuccessIndirectPublicKey(string $input, string $expected): void
|
||||
{
|
||||
$key_pair = CreateKey::createKeyPair();
|
||||
$public_key = CreateKey::getPublicKey($key_pair);
|
||||
// test indirect
|
||||
$encrypted = AsymmetricAnonymousEncryption::getInstance(public_key:$public_key)->encrypt($input);
|
||||
$decrypted = AsymmetricAnonymousEncryption::getInstance($key_pair)->decrypt($encrypted);
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$decrypted,
|
||||
'Class Instance call public key',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* test encrypt/decrypt produce correct output
|
||||
*
|
||||
* @covers ::generateRandomKey
|
||||
* @covers ::encrypt
|
||||
* @covers ::decrypt
|
||||
* @dataProvider providerEncryptDecryptSuccess
|
||||
* @testdox encrypt/decrypt static $input must be $expected [$_dataName]
|
||||
*
|
||||
* @param string $input
|
||||
* @param string $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testEncryptDecryptSuccessStatic(string $input, string $expected): void
|
||||
{
|
||||
$key_pair = CreateKey::createKeyPair();
|
||||
$public_key = CreateKey::getPublicKey($key_pair);
|
||||
// test static
|
||||
$encrypted = AsymmetricAnonymousEncryption::encryptKey($input, $public_key);
|
||||
$decrypted = AsymmetricAnonymousEncryption::decryptKey($encrypted, $key_pair);
|
||||
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$decrypted,
|
||||
'Static call',
|
||||
);
|
||||
}
|
||||
|
||||
// MARK: invalid decrypt key
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function providerEncryptFailed(): array
|
||||
{
|
||||
return [
|
||||
'wrong decryption key' => [
|
||||
'input' => 'I am a secret',
|
||||
'excpetion_message' => 'Invalid key pair'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Test decryption with wrong key
|
||||
*
|
||||
* @covers ::generateRandomKey
|
||||
* @covers ::encrypt
|
||||
* @covers ::decrypt
|
||||
* @dataProvider providerEncryptFailed
|
||||
* @testdox decrypt with wrong key $input throws $exception_message [$_dataName]
|
||||
*
|
||||
* @param string $input
|
||||
* @param string $exception_message
|
||||
* @return void
|
||||
*/
|
||||
public function testEncryptFailed(string $input, string $exception_message): void
|
||||
{
|
||||
$key_pair = CreateKey::createKeyPair();
|
||||
$public_key = CreateKey::getPublicKey($key_pair);
|
||||
$wrong_key_pair = CreateKey::createKeyPair();
|
||||
|
||||
// wrong key in class call
|
||||
$crypt = new AsymmetricAnonymousEncryption(public_key:$public_key);
|
||||
$encrypted = $crypt->encrypt($input);
|
||||
$this->expectExceptionMessage($exception_message);
|
||||
$crypt->setKeyPair($wrong_key_pair);
|
||||
$crypt->decrypt($encrypted);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test decryption with wrong key
|
||||
*
|
||||
* @covers ::generateRandomKey
|
||||
* @covers ::encrypt
|
||||
* @covers ::decrypt
|
||||
* @dataProvider providerEncryptFailed
|
||||
* @testdox decrypt indirect with wrong key $input throws $exception_message [$_dataName]
|
||||
*
|
||||
* @param string $input
|
||||
* @param string $exception_message
|
||||
* @return void
|
||||
*/
|
||||
public function testEncryptFailedIndirect(string $input, string $exception_message): void
|
||||
{
|
||||
$key_pair = CreateKey::createKeyPair();
|
||||
$public_key = CreateKey::getPublicKey($key_pair);
|
||||
$wrong_key_pair = CreateKey::createKeyPair();
|
||||
|
||||
// class instance
|
||||
$encrypted = AsymmetricAnonymousEncryption::getInstance(public_key:$public_key)->encrypt($input);
|
||||
$this->expectExceptionMessage($exception_message);
|
||||
AsymmetricAnonymousEncryption::getInstance($wrong_key_pair)->decrypt($encrypted);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test decryption with wrong key
|
||||
*
|
||||
* @covers ::generateRandomKey
|
||||
* @covers ::encrypt
|
||||
* @covers ::decrypt
|
||||
* @dataProvider providerEncryptFailed
|
||||
* @testdox decrypt static with wrong key $input throws $exception_message [$_dataName]
|
||||
*
|
||||
* @param string $input
|
||||
* @param string $exception_message
|
||||
* @return void
|
||||
*/
|
||||
public function testEncryptFailedStatic(string $input, string $exception_message): void
|
||||
{
|
||||
$key_pair = CreateKey::createKeyPair();
|
||||
$public_key = CreateKey::getPublicKey($key_pair);
|
||||
$wrong_key_pair = CreateKey::createKeyPair();
|
||||
|
||||
// class static
|
||||
$encrypted = AsymmetricAnonymousEncryption::encryptKey($input, $public_key);
|
||||
$this->expectExceptionMessage($exception_message);
|
||||
AsymmetricAnonymousEncryption::decryptKey($encrypted, $wrong_key_pair);
|
||||
}
|
||||
|
||||
// MARK: invalid key pair
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function providerWrongKeyPair(): array
|
||||
{
|
||||
return [
|
||||
'not hex key pair' => [
|
||||
'key_pair' => 'not_a_hex_key_pair',
|
||||
'exception_message' => 'Invalid hex key pair'
|
||||
],
|
||||
'too short hex key pair' => [
|
||||
'key_pair' => '1cabd5cba9e042f12522f4ff2de5c31d233b',
|
||||
'excpetion_message' => 'Key pair is not the correct size (must be '
|
||||
],
|
||||
'empty key pair' => [
|
||||
'key_pair' => '',
|
||||
'excpetion_message' => 'Key pair cannot be empty'
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* test invalid key provided to decrypt or encrypt
|
||||
*
|
||||
* @covers ::encrypt
|
||||
* @covers ::decrypt
|
||||
* @dataProvider providerWrongKeyPair
|
||||
* @testdox wrong key pair $key_pair throws $exception_message [$_dataName]
|
||||
*
|
||||
* @param string $key_pair
|
||||
* @param string $exception_message
|
||||
* @return void
|
||||
*/
|
||||
public function testWrongKeyPair(string $key_pair, string $exception_message): void
|
||||
{
|
||||
$enc_key_pair = CreateKey::createKeyPair();
|
||||
|
||||
// class
|
||||
$this->expectExceptionMessage($exception_message);
|
||||
$crypt = new AsymmetricAnonymousEncryption($key_pair);
|
||||
$this->expectExceptionMessage($exception_message);
|
||||
$crypt->encrypt('test');
|
||||
$crypt->setKeyPair($enc_key_pair);
|
||||
$encrypted = $crypt->encrypt('test');
|
||||
$this->expectExceptionMessage($exception_message);
|
||||
$crypt->setKeyPair($key_pair);
|
||||
$crypt->decrypt($encrypted);
|
||||
}
|
||||
|
||||
/**
|
||||
* test invalid key provided to decrypt or encrypt
|
||||
*
|
||||
* @covers ::encrypt
|
||||
* @covers ::decrypt
|
||||
* @dataProvider providerWrongKeyPair
|
||||
* @testdox wrong key pair indirect $key_pair throws $exception_message [$_dataName]
|
||||
*
|
||||
* @param string $key_pair
|
||||
* @param string $exception_message
|
||||
* @return void
|
||||
*/
|
||||
public function testWrongKeyPairIndirect(string $key_pair, string $exception_message): void
|
||||
{
|
||||
$enc_key_pair = CreateKey::createKeyPair();
|
||||
|
||||
// set valid encryption
|
||||
$encrypted = AsymmetricAnonymousEncryption::getInstance($enc_key_pair)->encrypt('test');
|
||||
$this->expectExceptionMessage($exception_message);
|
||||
AsymmetricAnonymousEncryption::getInstance($key_pair)->decrypt($encrypted);
|
||||
}
|
||||
|
||||
/**
|
||||
* test invalid key provided to decrypt or encrypt
|
||||
*
|
||||
* @covers ::encrypt
|
||||
* @covers ::decrypt
|
||||
* @dataProvider providerWrongKeyPair
|
||||
* @testdox wrong key pair static $key_pair throws $exception_message [$_dataName]
|
||||
*
|
||||
* @param string $key_pair
|
||||
* @param string $exception_message
|
||||
* @return void
|
||||
*/
|
||||
public function testWrongKeyPairStatic(string $key_pair, string $exception_message): void
|
||||
{
|
||||
$enc_key_pair = CreateKey::createKeyPair();
|
||||
|
||||
// set valid encryption
|
||||
$encrypted = AsymmetricAnonymousEncryption::encryptKey('test', CreateKey::getPublicKey($enc_key_pair));
|
||||
$this->expectExceptionMessage($exception_message);
|
||||
AsymmetricAnonymousEncryption::decryptKey($encrypted, $key_pair);
|
||||
}
|
||||
|
||||
// MARK: invalid public key
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function providerWrongPublicKey(): array
|
||||
{
|
||||
return [
|
||||
'not hex public key' => [
|
||||
'public_key' => 'not_a_hex_public_key',
|
||||
'exception_message' => 'Invalid hex public key'
|
||||
],
|
||||
'too short hex public key' => [
|
||||
'public_key' => '1cabd5cba9e042f12522f4ff2de5c31d233b',
|
||||
'excpetion_message' => 'Public key is not the correct size (must be '
|
||||
],
|
||||
'empty public key' => [
|
||||
'public_key' => '',
|
||||
'excpetion_message' => 'Public key cannot be empty'
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* test invalid key provided to decrypt or encrypt
|
||||
*
|
||||
* @covers ::encrypt
|
||||
* @covers ::decrypt
|
||||
* @dataProvider providerWrongPublicKey
|
||||
* @testdox wrong public key $public_key throws $exception_message [$_dataName]
|
||||
*
|
||||
* @param string $public_key
|
||||
* @param string $exception_message
|
||||
* @return void
|
||||
*/
|
||||
public function testWrongPublicKey(string $public_key, string $exception_message): void
|
||||
{
|
||||
$enc_key_pair = CreateKey::createKeyPair();
|
||||
// $enc_public_key = CreateKey::getPublicKey($enc_key_pair);
|
||||
|
||||
// class
|
||||
$this->expectExceptionMessage($exception_message);
|
||||
$crypt = new AsymmetricAnonymousEncryption(public_key:$public_key);
|
||||
$this->expectExceptionMessage($exception_message);
|
||||
$crypt->decrypt('test');
|
||||
$crypt->setKeyPair($enc_key_pair);
|
||||
$encrypted = $crypt->encrypt('test');
|
||||
$this->expectExceptionMessage($exception_message);
|
||||
$crypt->setPublicKey($public_key);
|
||||
$crypt->decrypt($encrypted);
|
||||
}
|
||||
|
||||
/**
|
||||
* test invalid key provided to decrypt or encrypt
|
||||
*
|
||||
* @covers ::encrypt
|
||||
* @covers ::decrypt
|
||||
* @dataProvider providerWrongPublicKey
|
||||
* @testdox wrong public key indirect $key throws $exception_message [$_dataName]
|
||||
*
|
||||
* @param string $key
|
||||
* @param string $exception_message
|
||||
* @return void
|
||||
*/
|
||||
public function testWrongPublicKeyIndirect(string $key, string $exception_message): void
|
||||
{
|
||||
$enc_key = CreateKey::createKeyPair();
|
||||
|
||||
// class instance
|
||||
$this->expectExceptionMessage($exception_message);
|
||||
AsymmetricAnonymousEncryption::getInstance(public_key:$key)->encrypt('test');
|
||||
// we must encrypt valid thing first so we can fail with the wrong key
|
||||
$encrypted = AsymmetricAnonymousEncryption::getInstance($enc_key)->encrypt('test');
|
||||
// $this->expectExceptionMessage($exception_message);
|
||||
AsymmetricAnonymousEncryption::getInstance($key)->decrypt($encrypted);
|
||||
}
|
||||
|
||||
/**
|
||||
* test invalid key provided to decrypt or encrypt
|
||||
*
|
||||
* @covers ::encrypt
|
||||
* @covers ::decrypt
|
||||
* @dataProvider providerWrongPublicKey
|
||||
* @testdox wrong public key static $key throws $exception_message [$_dataName]
|
||||
*
|
||||
* @param string $key
|
||||
* @param string $exception_message
|
||||
* @return void
|
||||
*/
|
||||
public function testWrongPublicKeyStatic(string $key, string $exception_message): void
|
||||
{
|
||||
$enc_key = CreateKey::createKeyPair();
|
||||
|
||||
// class static
|
||||
$this->expectExceptionMessage($exception_message);
|
||||
AsymmetricAnonymousEncryption::encryptKey('test', $key);
|
||||
// we must encrypt valid thing first so we can fail with the wrong key
|
||||
$encrypted = AsymmetricAnonymousEncryption::encryptKey('test', $enc_key);
|
||||
$this->expectExceptionMessage($exception_message);
|
||||
AsymmetricAnonymousEncryption::decryptKey($encrypted, $key);
|
||||
}
|
||||
|
||||
// MARK: wrong cipher text
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function providerWrongCiphertext(): array
|
||||
{
|
||||
return [
|
||||
'invalid cipher text' => [
|
||||
'input' => 'short',
|
||||
'exception_message' => 'base642bin failed: '
|
||||
],
|
||||
'cannot decrypt' => [
|
||||
// phpcs:disable Generic.Files.LineLength
|
||||
'input' => 'Um8tBGiVfFAOg2YoUgA5fTqK1wXPB1S7uxhPNE1lqDxgntkEhYJDOmjXa0DMpBlYHjab6sC4mgzwZSzGCUnXDAgsHckwYwfAzs/r',
|
||||
// phpcs:enable Generic.Files.LineLength
|
||||
'exception_message' => 'Invalid key pair'
|
||||
],
|
||||
'invalid text' => [
|
||||
'input' => 'U29tZSB0ZXh0IGhlcmU=',
|
||||
'exception_message' => 'Invalid key pair'
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::decrypt
|
||||
* @dataProvider providerWrongCiphertext
|
||||
* @testdox too short ciphertext $input throws $exception_message [$_dataName]
|
||||
*
|
||||
* @param string $input
|
||||
* @param string $exception_message
|
||||
* @return void
|
||||
*/
|
||||
public function testWrongCiphertext(string $input, string $exception_message): void
|
||||
{
|
||||
$key = CreateKey::createKeyPair();
|
||||
// class
|
||||
$crypt = new AsymmetricAnonymousEncryption($key);
|
||||
$this->expectExceptionMessage($exception_message);
|
||||
$crypt->decrypt($input);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::decryptKey
|
||||
* @dataProvider providerWrongCiphertext
|
||||
* @testdox too short ciphertext indirect $input throws $exception_message [$_dataName]
|
||||
*
|
||||
* @param string $input
|
||||
* @param string $exception_message
|
||||
* @return void
|
||||
*/
|
||||
public function testWrongCiphertextIndirect(string $input, string $exception_message): void
|
||||
{
|
||||
$key = CreateKey::createKeyPair();
|
||||
|
||||
// class instance
|
||||
$this->expectExceptionMessage($exception_message);
|
||||
AsymmetricAnonymousEncryption::getInstance($key)->decrypt($input);
|
||||
|
||||
// class static
|
||||
$this->expectExceptionMessage($exception_message);
|
||||
AsymmetricAnonymousEncryption::decryptKey($input, $key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::decryptKey
|
||||
* @dataProvider providerWrongCiphertext
|
||||
* @testdox too short ciphertext static $input throws $exception_message [$_dataName]
|
||||
*
|
||||
* @param string $input
|
||||
* @param string $exception_message
|
||||
* @return void
|
||||
*/
|
||||
public function testWrongCiphertextStatic(string $input, string $exception_message): void
|
||||
{
|
||||
$key = CreateKey::createKeyPair();
|
||||
// class static
|
||||
$this->expectExceptionMessage($exception_message);
|
||||
AsymmetricAnonymousEncryption::decryptKey($input, $key);
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
@@ -7,12 +7,17 @@ namespace tests;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Test class for Check\Password
|
||||
* @coversDefaultClass \CoreLibs\Check\Password
|
||||
* @testdox \CoreLibs\Check\Password method tests
|
||||
* Test class for Security\Password
|
||||
* @coversDefaultClass \CoreLibs\Security\Password
|
||||
* @testdox \CoreLibs\Security\Password method tests
|
||||
*/
|
||||
final class CoreLibsCheckPasswordTest extends TestCase
|
||||
final class CoreLibsSecurityPasswordTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function passwordProvider(): array
|
||||
{
|
||||
return [
|
||||
@@ -21,6 +26,11 @@ final class CoreLibsCheckPasswordTest extends TestCase
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Note: we need different hash types for PHP versions
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function passwordRehashProvider(): array
|
||||
{
|
||||
return [
|
||||
@@ -46,7 +56,7 @@ final class CoreLibsCheckPasswordTest extends TestCase
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Check\Password::passwordVerify($input, \CoreLibs\Check\Password::passwordSet($input_hash))
|
||||
\CoreLibs\Security\Password::passwordVerify($input, \CoreLibs\Security\Password::passwordSet($input_hash))
|
||||
);
|
||||
}
|
||||
|
||||
@@ -63,9 +73,13 @@ final class CoreLibsCheckPasswordTest extends TestCase
|
||||
*/
|
||||
public function testPasswordRehashCheck(string $input, bool $expected): void
|
||||
{
|
||||
// in PHP 8.4 the length is $12
|
||||
if (PHP_VERSION_ID > 80400) {
|
||||
$input = str_replace('$2y$10$', '$2y$12$', $input);
|
||||
}
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Check\Password::passwordRehashCheck($input)
|
||||
\CoreLibs\Security\Password::passwordRehashCheck($input)
|
||||
);
|
||||
}
|
||||
}
|
||||
468
4dev/tests/Security/CoreLibsSecuritySymmetricEncryptionTest.php
Normal file
468
4dev/tests/Security/CoreLibsSecuritySymmetricEncryptionTest.php
Normal file
@@ -0,0 +1,468 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use CoreLibs\Security\CreateKey;
|
||||
use CoreLibs\Security\SymmetricEncryption;
|
||||
|
||||
/**
|
||||
* Test class for Security\SymmetricEncryption and Security\CreateKey
|
||||
* @coversDefaultClass \CoreLibs\Security\SymmetricEncryption
|
||||
* @testdox \CoreLibs\Security\SymmetricEncryption method tests
|
||||
*/
|
||||
final class CoreLibsSecuritySymmetricEncryptionTest extends TestCase
|
||||
{
|
||||
// MARK: key set compare
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::compareKey
|
||||
* @covers ::getKey
|
||||
* @testdox Check if init class set key matches to created key
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testKeyInitGetCompare(): void
|
||||
{
|
||||
$key = CreateKey::generateRandomKey();
|
||||
$crypt = new SymmetricEncryption($key);
|
||||
$this->assertTrue(
|
||||
$crypt->compareKey($key),
|
||||
'set key not equal to original key'
|
||||
);
|
||||
$this->assertEquals(
|
||||
$key,
|
||||
$crypt->getKey(),
|
||||
'set key returned not equal to original key'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::setKey
|
||||
* @covers ::compareKey
|
||||
* @covers ::getKey
|
||||
* @testdox Check if set key after class init matches to created key
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testKeySetGetCompare(): void
|
||||
{
|
||||
$key = CreateKey::generateRandomKey();
|
||||
$crypt = new SymmetricEncryption();
|
||||
$crypt->setKey($key);
|
||||
$this->assertTrue(
|
||||
$crypt->compareKey($key),
|
||||
'set key not equal to original key'
|
||||
);
|
||||
$this->assertEquals(
|
||||
$key,
|
||||
$crypt->getKey(),
|
||||
'set key returned not equal to original key'
|
||||
);
|
||||
}
|
||||
|
||||
// MARK: empty encrypted string
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::decryptKey
|
||||
* @covers ::decrypt
|
||||
* @testdox Test empty encrypted string to decrypt
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testEmptyDecryptionString(): void
|
||||
{
|
||||
$this->expectExceptionMessage('Encrypted string cannot be empty');
|
||||
SymmetricEncryption::decryptKey('', CreateKey::generateRandomKey());
|
||||
}
|
||||
|
||||
// MARK: encrypt/decrypt compare
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function providerEncryptDecryptSuccess(): array
|
||||
{
|
||||
return [
|
||||
'valid string' => [
|
||||
'input' => 'I am a secret',
|
||||
'expected' => 'I am a secret',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* test encrypt/decrypt produce correct output
|
||||
*
|
||||
* @covers ::generateRandomKey
|
||||
* @covers ::encrypt
|
||||
* @covers ::decrypt
|
||||
* @dataProvider providerEncryptDecryptSuccess
|
||||
* @testdox encrypt/decrypt $input must be $expected [$_dataName]
|
||||
*
|
||||
* @param string $input
|
||||
* @param string $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testEncryptDecryptSuccess(string $input, string $expected): void
|
||||
{
|
||||
$key = CreateKey::generateRandomKey();
|
||||
|
||||
// test class
|
||||
$crypt = new SymmetricEncryption($key);
|
||||
$encrypted = $crypt->encrypt($input);
|
||||
$decrypted = $crypt->decrypt($encrypted);
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$decrypted,
|
||||
'Class call',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* test encrypt/decrypt produce correct output
|
||||
*
|
||||
* @covers ::generateRandomKey
|
||||
* @covers ::encrypt
|
||||
* @covers ::decrypt
|
||||
* @dataProvider providerEncryptDecryptSuccess
|
||||
* @testdox encrypt/decrypt indirect $input must be $expected [$_dataName]
|
||||
*
|
||||
* @param string $input
|
||||
* @param string $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testEncryptDecryptSuccessIndirect(string $input, string $expected): void
|
||||
{
|
||||
$key = CreateKey::generateRandomKey();
|
||||
// test indirect
|
||||
$encrypted = SymmetricEncryption::getInstance($key)->encrypt($input);
|
||||
$decrypted = SymmetricEncryption::getInstance($key)->decrypt($encrypted);
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$decrypted,
|
||||
'Class Instance call',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* test encrypt/decrypt produce correct output
|
||||
*
|
||||
* @covers ::generateRandomKey
|
||||
* @covers ::encryptKey
|
||||
* @covers ::decryptKey
|
||||
* @dataProvider providerEncryptDecryptSuccess
|
||||
* @testdox encrypt/decrypt static $input must be $expected [$_dataName]
|
||||
*
|
||||
* @param string $input
|
||||
* @param string $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testEncryptDecryptSuccessStatic(string $input, string $expected): void
|
||||
{
|
||||
$key = CreateKey::generateRandomKey();
|
||||
// test static
|
||||
$encrypted = SymmetricEncryption::encryptKey($input, $key);
|
||||
$decrypted = SymmetricEncryption::decryptKey($encrypted, $key);
|
||||
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$decrypted,
|
||||
'Static call',
|
||||
);
|
||||
}
|
||||
|
||||
// MARK: invalid key
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function providerEncryptFailed(): array
|
||||
{
|
||||
return [
|
||||
'wrong decryption key' => [
|
||||
'input' => 'I am a secret',
|
||||
'excpetion_message' => 'Invalid Key'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Test decryption with wrong key
|
||||
*
|
||||
* @covers ::generateRandomKey
|
||||
* @covers ::encrypt
|
||||
* @covers ::decrypt
|
||||
* @dataProvider providerEncryptFailed
|
||||
* @testdox decrypt with wrong key $input throws $exception_message [$_dataName]
|
||||
*
|
||||
* @param string $input
|
||||
* @param string $exception_message
|
||||
* @return void
|
||||
*/
|
||||
public function testEncryptFailed(string $input, string $exception_message): void
|
||||
{
|
||||
$key = CreateKey::generateRandomKey();
|
||||
$wrong_key = CreateKey::generateRandomKey();
|
||||
|
||||
// wrong key in class call
|
||||
$crypt = new SymmetricEncryption($key);
|
||||
$encrypted = $crypt->encrypt($input);
|
||||
$this->expectExceptionMessage($exception_message);
|
||||
$crypt->setKey($wrong_key);
|
||||
$crypt->decrypt($encrypted);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test decryption with wrong key
|
||||
*
|
||||
* @covers ::generateRandomKey
|
||||
* @covers ::encrypt
|
||||
* @covers ::decrypt
|
||||
* @dataProvider providerEncryptFailed
|
||||
* @testdox decrypt indirect with wrong key $input throws $exception_message [$_dataName]
|
||||
*
|
||||
* @param string $input
|
||||
* @param string $exception_message
|
||||
* @return void
|
||||
*/
|
||||
public function testEncryptFailedIndirect(string $input, string $exception_message): void
|
||||
{
|
||||
$key = CreateKey::generateRandomKey();
|
||||
$wrong_key = CreateKey::generateRandomKey();
|
||||
|
||||
// class instance
|
||||
$encrypted = SymmetricEncryption::getInstance($key)->encrypt($input);
|
||||
$this->expectExceptionMessage($exception_message);
|
||||
SymmetricEncryption::getInstance($wrong_key)->decrypt($encrypted);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test decryption with wrong key
|
||||
*
|
||||
* @covers ::generateRandomKey
|
||||
* @covers ::encryptKey
|
||||
* @covers ::decryptKey
|
||||
* @dataProvider providerEncryptFailed
|
||||
* @testdox decrypt static with wrong key $input throws $exception_message [$_dataName]
|
||||
*
|
||||
* @param string $input
|
||||
* @param string $exception_message
|
||||
* @return void
|
||||
*/
|
||||
public function testEncryptFailedStatic(string $input, string $exception_message): void
|
||||
{
|
||||
$key = CreateKey::generateRandomKey();
|
||||
$wrong_key = CreateKey::generateRandomKey();
|
||||
|
||||
// class static
|
||||
$encrypted = SymmetricEncryption::encryptKey($input, $key);
|
||||
$this->expectExceptionMessage($exception_message);
|
||||
SymmetricEncryption::decryptKey($encrypted, $wrong_key);
|
||||
}
|
||||
|
||||
// MARK: wrong key
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function providerWrongKey(): array
|
||||
{
|
||||
return [
|
||||
'not hex key' => [
|
||||
'key' => 'not_a_hex_key',
|
||||
'exception_message' => 'Invalid hex key'
|
||||
],
|
||||
'too short hex key' => [
|
||||
'key' => '1cabd5cba9e042f12522f4ff2de5c31d233b',
|
||||
'excpetion_message' => 'Key is not the correct size (must be '
|
||||
],
|
||||
'empty key' => [
|
||||
'key' => '',
|
||||
'excpetion_message' => 'Key cannot be empty'
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* test invalid key provided to decrypt or encrypt
|
||||
*
|
||||
* @covers ::encrypt
|
||||
* @covers ::decrypt
|
||||
* @dataProvider providerWrongKey
|
||||
* @testdox wrong key $key throws $exception_message [$_dataName]
|
||||
*
|
||||
* @param string $key
|
||||
* @param string $exception_message
|
||||
* @return void
|
||||
*/
|
||||
public function testWrongKey(string $key, string $exception_message): void
|
||||
{
|
||||
$enc_key = CreateKey::generateRandomKey();
|
||||
|
||||
// class
|
||||
$this->expectExceptionMessage($exception_message);
|
||||
$crypt = new SymmetricEncryption($key);
|
||||
$this->expectExceptionMessage($exception_message);
|
||||
$crypt->encrypt('test');
|
||||
$crypt->setKey($enc_key);
|
||||
$encrypted = $crypt->encrypt('test');
|
||||
$this->expectExceptionMessage($exception_message);
|
||||
$crypt->setKey($key);
|
||||
$crypt->decrypt($encrypted);
|
||||
}
|
||||
|
||||
/**
|
||||
* test invalid key provided to decrypt or encrypt
|
||||
*
|
||||
* @covers ::encrypt
|
||||
* @covers ::decrypt
|
||||
* @dataProvider providerWrongKey
|
||||
* @testdox wrong key indirect $key throws $exception_message [$_dataName]
|
||||
*
|
||||
* @param string $key
|
||||
* @param string $exception_message
|
||||
* @return void
|
||||
*/
|
||||
public function testWrongKeyIndirect(string $key, string $exception_message): void
|
||||
{
|
||||
$enc_key = CreateKey::generateRandomKey();
|
||||
|
||||
// class instance
|
||||
$this->expectExceptionMessage($exception_message);
|
||||
SymmetricEncryption::getInstance($key)->encrypt('test');
|
||||
// we must encrypt valid thing first so we can fail with the wrong key
|
||||
$encrypted = SymmetricEncryption::getInstance($enc_key)->encrypt('test');
|
||||
$this->expectExceptionMessage($exception_message);
|
||||
SymmetricEncryption::getInstance($key)->decrypt($encrypted);
|
||||
}
|
||||
|
||||
/**
|
||||
* test invalid key provided to decrypt or encrypt
|
||||
*
|
||||
* @covers ::encryptKey
|
||||
* @covers ::decryptKey
|
||||
* @dataProvider providerWrongKey
|
||||
* @testdox wrong key static $key throws $exception_message [$_dataName]
|
||||
*
|
||||
* @param string $key
|
||||
* @param string $exception_message
|
||||
* @return void
|
||||
*/
|
||||
public function testWrongKeyStatic(string $key, string $exception_message): void
|
||||
{
|
||||
$enc_key = CreateKey::generateRandomKey();
|
||||
|
||||
// class static
|
||||
$this->expectExceptionMessage($exception_message);
|
||||
SymmetricEncryption::encryptKey('test', $key);
|
||||
// we must encrypt valid thing first so we can fail with the wrong key
|
||||
$encrypted = SymmetricEncryption::encryptKey('test', $enc_key);
|
||||
$this->expectExceptionMessage($exception_message);
|
||||
SymmetricEncryption::decryptKey($encrypted, $key);
|
||||
}
|
||||
|
||||
// MARK: wrong input
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function providerWrongCiphertext(): array
|
||||
{
|
||||
return [
|
||||
'too short ciphertext' => [
|
||||
'input' => 'short',
|
||||
'exception_message' => 'Decipher message failed: '
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::decrypt
|
||||
* @dataProvider providerWrongCiphertext
|
||||
* @testdox too short ciphertext $input throws $exception_message [$_dataName]
|
||||
*
|
||||
* @param string $input
|
||||
* @param string $exception_message
|
||||
* @return void
|
||||
*/
|
||||
public function testWrongCiphertext(string $input, string $exception_message): void
|
||||
{
|
||||
$key = CreateKey::generateRandomKey();
|
||||
// class
|
||||
$crypt = new SymmetricEncryption($key);
|
||||
$this->expectExceptionMessage($exception_message);
|
||||
$crypt->decrypt($input);
|
||||
|
||||
// class instance
|
||||
$this->expectExceptionMessage($exception_message);
|
||||
SymmetricEncryption::getInstance($key)->decrypt($input);
|
||||
|
||||
// class static
|
||||
$this->expectExceptionMessage($exception_message);
|
||||
SymmetricEncryption::decryptKey($input, $key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::decryptKey
|
||||
* @dataProvider providerWrongCiphertext
|
||||
* @testdox too short ciphertext indirect $input throws $exception_message [$_dataName]
|
||||
*
|
||||
* @param string $input
|
||||
* @param string $exception_message
|
||||
* @return void
|
||||
*/
|
||||
public function testWrongCiphertextIndirect(string $input, string $exception_message): void
|
||||
{
|
||||
$key = CreateKey::generateRandomKey();
|
||||
|
||||
// class instance
|
||||
$this->expectExceptionMessage($exception_message);
|
||||
SymmetricEncryption::getInstance($key)->decrypt($input);
|
||||
|
||||
// class static
|
||||
$this->expectExceptionMessage($exception_message);
|
||||
SymmetricEncryption::decryptKey($input, $key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::decryptKey
|
||||
* @dataProvider providerWrongCiphertext
|
||||
* @testdox too short ciphertext static $input throws $exception_message [$_dataName]
|
||||
*
|
||||
* @param string $input
|
||||
* @param string $exception_message
|
||||
* @return void
|
||||
*/
|
||||
public function testWrongCiphertextStatic(string $input, string $exception_message): void
|
||||
{
|
||||
$key = CreateKey::generateRandomKey();
|
||||
// class static
|
||||
$this->expectExceptionMessage($exception_message);
|
||||
SymmetricEncryption::decryptKey($input, $key);
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
34
4dev/tests/Template/CoreLibsTemplateHtmlBuilderBlockTest.php
Normal file
34
4dev/tests/Template/CoreLibsTemplateHtmlBuilderBlockTest.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use CoreLibs\Template\HtmlBuilder\Block;
|
||||
|
||||
/**
|
||||
* Test class for Template\HtmlBuilder\Block
|
||||
* @coversDefaultClass \CoreLibs\Template\HtmlBuilder\Block
|
||||
* @testdox \CoreLibs\Template\HtmlBuilder\Block method tests
|
||||
*/
|
||||
final class CoreLibsTemplateHtmlBuilderBlockTest extends TestCase
|
||||
{
|
||||
public function testCreateBlock(): void
|
||||
{
|
||||
$el = Block::cel('div', 'id', 'content', ['css'], ['onclick' => 'foo();']);
|
||||
$this->assertEquals(
|
||||
'<div id="id" class="css" onclick="foo();">content</div>',
|
||||
Block::buildHtml($el)
|
||||
);
|
||||
}
|
||||
|
||||
// ael
|
||||
// aelx|addSub
|
||||
// resetSub
|
||||
// acssel/rcssel/scssel
|
||||
// buildHtml
|
||||
// buildHtmlFromList|printHtmlFromArray
|
||||
}
|
||||
|
||||
// __END__
|
||||
546
4dev/tests/Template/CoreLibsTemplateHtmlBuilderElementTest.php
Normal file
546
4dev/tests/Template/CoreLibsTemplateHtmlBuilderElementTest.php
Normal file
@@ -0,0 +1,546 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use CoreLibs\Template\HtmlBuilder\Element;
|
||||
use CoreLibs\Template\HtmlBuilder\General\Error;
|
||||
use CoreLibs\Template\HtmlBuilder\General\HtmlBuilderExcpetion;
|
||||
|
||||
/**
|
||||
* Test class for Template\HtmlBuilder\Element
|
||||
* @coversDefaultClass \CoreLibs\Template\HtmlBuilder\Element
|
||||
* @testdox \CoreLibs\Template\HtmlBuilder\Element method tests
|
||||
*/
|
||||
final class CoreLibsTemplateHtmlBuilderElementTest extends TestCase
|
||||
{
|
||||
public function providerCreateElements(): array
|
||||
{
|
||||
return [
|
||||
'simple div' => [
|
||||
'tag' => 'div',
|
||||
'id' => 'id',
|
||||
'content' => 'content',
|
||||
'css' => ['css'],
|
||||
'options' => ['onclick' => 'foo();'],
|
||||
'expected' => '<div id="id" class="css" onclick="foo();">content</div>'
|
||||
],
|
||||
'simple input' => [
|
||||
'tag' => 'input',
|
||||
'id' => 'id',
|
||||
'content' => null,
|
||||
'css' => ['css'],
|
||||
'options' => ['name' => 'name', 'onclick' => 'foo();'],
|
||||
'expected' => '<input id="id" name="name" class="css" onclick="foo();">'
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::Element
|
||||
* @covers ::buildHtml
|
||||
* @covers ::getTag
|
||||
* @covers ::getId
|
||||
* @covers ::getContent
|
||||
* @covers ::getOptions
|
||||
* @covers ::getCss
|
||||
* @dataProvider providerCreateElements
|
||||
* @testdox create single new Element test [$_dataName]
|
||||
*
|
||||
* @param string $tag
|
||||
* @param string|null $id
|
||||
* @param string|null $content
|
||||
* @param array|null $css
|
||||
* @param array|null $options
|
||||
* @param string $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testCreateElement(
|
||||
string $tag,
|
||||
?string $id,
|
||||
?string $content,
|
||||
?array $css,
|
||||
?array $options,
|
||||
string $expected
|
||||
): void {
|
||||
$el = new Element($tag, $id ?? '', $content ?? '', $css ?? [], $options ?? []);
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$el->buildHtml(),
|
||||
'element creation failed'
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
$tag,
|
||||
$el->getTag(),
|
||||
'get tag failed'
|
||||
);
|
||||
|
||||
if ($id !== null) {
|
||||
$this->assertEquals(
|
||||
$id,
|
||||
$el->getId(),
|
||||
'get id failed'
|
||||
);
|
||||
}
|
||||
if ($content !== null) {
|
||||
$this->assertEquals(
|
||||
$content,
|
||||
$el->getContent(),
|
||||
'get content failed'
|
||||
);
|
||||
}
|
||||
if ($css !== null) {
|
||||
$this->assertEquals(
|
||||
$css,
|
||||
$el->getCss(),
|
||||
'get css failed'
|
||||
);
|
||||
}
|
||||
if ($options !== null) {
|
||||
$this->assertEquals(
|
||||
$options,
|
||||
$el->getOptions(),
|
||||
'get options failed'
|
||||
);
|
||||
}
|
||||
if (!empty($options['name'])) {
|
||||
$this->assertEquals(
|
||||
$options['name'],
|
||||
$el->getName(),
|
||||
'get name failed'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* css add/remove
|
||||
*
|
||||
* @cover ::getCss
|
||||
* @cover ::addCss
|
||||
* @cover ::removeCss
|
||||
* @testdox test handling of adding and removing css classes
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testCssHandling(): void
|
||||
{
|
||||
$el = new Element('div', 'css-test', 'CSS content');
|
||||
$this->assertEqualsCanonicalizing(
|
||||
[],
|
||||
$el->getCss(),
|
||||
'check empty css'
|
||||
);
|
||||
$el->addCss('foo');
|
||||
$this->assertEqualsCanonicalizing(
|
||||
['foo'],
|
||||
$el->getCss(),
|
||||
'check added one css'
|
||||
);
|
||||
$el->removeCss('foo');
|
||||
$this->assertEqualsCanonicalizing(
|
||||
[],
|
||||
$el->getCss(),
|
||||
'check remove added css'
|
||||
);
|
||||
// add serveral
|
||||
// remove some of them
|
||||
$el->addCss('a', 'b', 'c');
|
||||
$this->assertEqualsCanonicalizing(
|
||||
['a', 'b', 'c'],
|
||||
$el->getCss(),
|
||||
'check added some css'
|
||||
);
|
||||
$el->removeCss('a', 'c');
|
||||
// $this->assertArray
|
||||
$this->assertEqualsCanonicalizing(
|
||||
['b'],
|
||||
$el->getCss(),
|
||||
'check remove some css'
|
||||
);
|
||||
// chained add and remove
|
||||
$el->addCss('a', 'b', 'c', 'd')->removeCss('b', 'd');
|
||||
$this->assertEqualsCanonicalizing(
|
||||
['a', 'c'],
|
||||
$el->getCss(),
|
||||
'check chain add remove some css'
|
||||
);
|
||||
$el->resetCss();
|
||||
$this->assertEqualsCanonicalizing(
|
||||
[],
|
||||
$el->getCss(),
|
||||
'check reset css'
|
||||
);
|
||||
// remove something that does not eixst
|
||||
$el->addCss('exists');
|
||||
$el->removeCss('not');
|
||||
$this->assertEqualsCanonicalizing(
|
||||
['exists'],
|
||||
$el->getCss(),
|
||||
'check remove not exitsing'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* nested test
|
||||
*
|
||||
* @testdox nested test and loop assign detection
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testBuildNested(): void
|
||||
{
|
||||
Error::resetMessages();
|
||||
$el = new Element('div', 'build-test');
|
||||
$el_sub = new Element('div', 'sub-1');
|
||||
$el->addSub($el_sub);
|
||||
$this->assertEquals(
|
||||
'<div id="build-test"><div id="sub-1"></div></div>',
|
||||
$el->buildHtml(),
|
||||
'nested build failed'
|
||||
);
|
||||
// this would create a loop, throws error
|
||||
$this->expectException(HtmlBuilderExcpetion::class);
|
||||
$this->expectExceptionMessage("Cannot assign Element to itself, this would create an infinite loop");
|
||||
$el_sub->addSub($el_sub);
|
||||
$this->assertEquals(
|
||||
'<div id="sub-1"></div>',
|
||||
$el_sub->buildHtml(),
|
||||
'loop detection failed'
|
||||
);
|
||||
$this->assertTrue(
|
||||
Error::hasError(),
|
||||
'failed to throw error post loop detection'
|
||||
);
|
||||
$this->assertEquals(
|
||||
[[
|
||||
'level' => 'Error',
|
||||
'id' => '100',
|
||||
'message' => 'Cannot assign Element to itself, this would create an infinite loop',
|
||||
'context' => ['tag' => 'div', 'id' => 'sub-1']
|
||||
]],
|
||||
Error::getMessages(),
|
||||
'check error is 100 failed'
|
||||
);
|
||||
// get sub
|
||||
$this->assertEquals(
|
||||
[$el_sub],
|
||||
$el->getSub(),
|
||||
'get sub failed'
|
||||
);
|
||||
// reset sub
|
||||
$el->resetSub();
|
||||
$this->assertEquals(
|
||||
[],
|
||||
$el->getSub(),
|
||||
'reset sub failed'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @testdox updated nested connection
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testNestedChangeContent(): void
|
||||
{
|
||||
$el = new Element('div', 'build-test');
|
||||
$el_s_1 = new Element('div', 'sub-1');
|
||||
$el_s_2 = new Element('div', 'sub-2');
|
||||
$el_s_3 = new Element('div', 'sub-3');
|
||||
$el_s_4 = new Element('div', 'sub-4');
|
||||
|
||||
$el->addSub($el_s_1, $el_s_2);
|
||||
// only sub -1, -2
|
||||
$this->assertEquals(
|
||||
'<div id="build-test"><div id="sub-1"></div><div id="sub-2"></div></div>',
|
||||
$el->buildHtml(),
|
||||
'check basic nested'
|
||||
);
|
||||
|
||||
// now add -3, -4 to both -1 and -2
|
||||
$el_s_1->addSub($el_s_3, $el_s_4);
|
||||
$el_s_2->addSub($el_s_3, $el_s_4);
|
||||
$this->assertEquals(
|
||||
'<div id="build-test"><div id="sub-1"><div id="sub-3"></div><div id="sub-4">'
|
||||
. '</div></div><div id="sub-2"><div id="sub-3"></div><div id="sub-4"></div>'
|
||||
. '</div></div>',
|
||||
$el->buildHtml(),
|
||||
'check nested added'
|
||||
);
|
||||
|
||||
// now add some css to el_s_3, will update in both sets
|
||||
$el_s_3->addCss('red');
|
||||
$this->assertEquals(
|
||||
'<div id="build-test"><div id="sub-1"><div id="sub-3" class="red"></div><div id="sub-4">'
|
||||
. '</div></div><div id="sub-2"><div id="sub-3" class="red"></div><div id="sub-4"></div>'
|
||||
. '</div></div>',
|
||||
$el->buildHtml(),
|
||||
'check nested u@dated'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @testdox test change tag/id/content
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testChangeElementData(): void
|
||||
{
|
||||
$el = new Element('div', 'id', 'Content');
|
||||
// content change
|
||||
$this->assertEquals(
|
||||
'Content',
|
||||
$el->getContent(),
|
||||
'set content'
|
||||
);
|
||||
$el->setContent('New Content');
|
||||
$this->assertEquals(
|
||||
'New Content',
|
||||
$el->getContent(),
|
||||
'changed content'
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'div',
|
||||
$el->getTag(),
|
||||
'set tag'
|
||||
);
|
||||
$el->setTag('span');
|
||||
$this->assertEquals(
|
||||
'span',
|
||||
$el->getTag(),
|
||||
'changed tag'
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'id',
|
||||
$el->getId(),
|
||||
'set id'
|
||||
);
|
||||
$el->setId('id-2');
|
||||
$this->assertEquals(
|
||||
'id-2',
|
||||
$el->getId(),
|
||||
'changed id'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @testdox test change options
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testChangeOptions(): void
|
||||
{
|
||||
$el = new Element('button', 'id', 'Action', ['css'], ['value' => '3']);
|
||||
$this->assertEquals(
|
||||
['value' => '3'],
|
||||
$el->getOptions(),
|
||||
'set option'
|
||||
);
|
||||
$el->setOptions([
|
||||
'value' => '2'
|
||||
]);
|
||||
$this->assertEquals(
|
||||
['value' => '2'],
|
||||
$el->getOptions(),
|
||||
'changed option'
|
||||
);
|
||||
// add a new one
|
||||
$el->setOptions([
|
||||
'Foo' => 'bar',
|
||||
'Moo' => 'cow'
|
||||
]);
|
||||
$this->assertEquals(
|
||||
[
|
||||
'value' => '2',
|
||||
'Foo' => 'bar',
|
||||
'Moo' => 'cow'
|
||||
],
|
||||
$el->getOptions(),
|
||||
'changed option'
|
||||
);
|
||||
}
|
||||
|
||||
// build output
|
||||
// build from array list
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @testdox build element tree from object
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testBuildHtmlObject(): void
|
||||
{
|
||||
// build a simple block
|
||||
// div -> div -> button
|
||||
// -> div -> span
|
||||
// -> div -> input
|
||||
$el = new Element('div', 'master', '', ['master']);
|
||||
$el->addSub(
|
||||
Element::addElement(
|
||||
new Element('div', 'div-button', '', ['dv-bt']),
|
||||
new Element('button', 'button-id', 'Click me', ['bt-red'], [
|
||||
'OnClick' => 'action();',
|
||||
'value' => 'click',
|
||||
'type' => 'button'
|
||||
]),
|
||||
),
|
||||
Element::addElement(
|
||||
new Element('div', 'div-span', '', ['dv-sp']),
|
||||
new Element('span', 'span-id', 'Big important message<br>other', ['red']),
|
||||
),
|
||||
Element::addElement(
|
||||
new Element('div', 'div-input', '', ['dv-in']),
|
||||
new Element('input', 'input-id', '', ['in-blue'], [
|
||||
'OnClick' => 'otherAction();',
|
||||
'value' => 'Touch',
|
||||
'type' => 'button'
|
||||
]),
|
||||
),
|
||||
);
|
||||
$this->assertEquals(
|
||||
'<div id="master" class="master">'
|
||||
. '<div id="div-button" class="dv-bt">'
|
||||
. '<button id="button-id" name="button-id" class="bt-red" OnClick="action();" '
|
||||
. 'value="click" type="button">Click me</button>'
|
||||
. '</div>'
|
||||
. '<div id="div-span" class="dv-sp">'
|
||||
. '<span id="span-id" class="red">Big important message<br>other</span>'
|
||||
. '</div>'
|
||||
. '<div id="div-input" class="dv-in">'
|
||||
. '<input id="input-id" name="input-id" '
|
||||
. 'class="in-blue" OnClick="otherAction();" value="Touch" type="button">'
|
||||
. '</div>'
|
||||
. '</div>',
|
||||
$el->buildHtml()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @testdox build elements from array list
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testbuildHtmlArray(): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
'<div id="id-1">A</div>'
|
||||
. '<div id="id-2">B</div>'
|
||||
. '<div id="id-3">C</div>',
|
||||
Element::buildHtmlFromList([
|
||||
new Element('div', 'id-1', 'A'),
|
||||
new Element('div', 'id-2', 'B'),
|
||||
new Element('div', 'id-3', 'C'),
|
||||
])
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @testdox check for invalid tag detection, possible invalid id, possible invalid css
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testInvalidElement(): void
|
||||
{
|
||||
Error::resetMessages();
|
||||
$this->expectException(HtmlBuilderExcpetion::class);
|
||||
$this->expectExceptionMessage("Could not create Element");
|
||||
$el = new Element('');
|
||||
$this->assertTrue(
|
||||
Error::hasError(),
|
||||
'failed to set error invalid tag detection'
|
||||
);
|
||||
$this->assertEquals(
|
||||
[[
|
||||
'level' => 'Error',
|
||||
'id' => '201',
|
||||
'message' => 'invalid or empty tag',
|
||||
'context' => ['tag' => '']
|
||||
]],
|
||||
Error::getMessages(),
|
||||
'check error message failed'
|
||||
);
|
||||
|
||||
// if we set invalid tag
|
||||
$el = new Element('div');
|
||||
$this->expectException(HtmlBuilderExcpetion::class);
|
||||
$this->expectExceptionMessageMatches("/^Invalid or empty tag: /");
|
||||
$this->expectExceptionMessage("Invalid or empty tag: 123123");
|
||||
$el->setTag('123123');
|
||||
$this->assertTrue(
|
||||
Error::hasError(),
|
||||
'failed to set error invalid tag detection'
|
||||
);
|
||||
$this->assertEquals(
|
||||
[[
|
||||
'level' => 'Error',
|
||||
'id' => '201',
|
||||
'message' => 'invalid or empty tag',
|
||||
'context' => ['tag' => '']
|
||||
]],
|
||||
Error::getMessages(),
|
||||
'check error message failed'
|
||||
);
|
||||
|
||||
|
||||
// invalid id (warning)
|
||||
Error::resetMessages();
|
||||
$el = new Element('div', '-$a15');
|
||||
$this->assertTrue(
|
||||
Error::hasWarning(),
|
||||
'failed to set warning invalid id detection'
|
||||
);
|
||||
$this->assertEquals(
|
||||
[[
|
||||
'level' => 'Warning',
|
||||
'id' => '202',
|
||||
'message' => 'possible invalid id',
|
||||
'context' => ['id' => '-$a15', 'tag' => 'div']
|
||||
]],
|
||||
Error::getMessages(),
|
||||
'check error message failed'
|
||||
);
|
||||
|
||||
// invalid name
|
||||
Error::resetMessages();
|
||||
$el = new Element('div', 'valid', '', [], ['name' => '-$asdf&']);
|
||||
$this->assertTrue(
|
||||
Error::hasWarning(),
|
||||
'failed to set warning invalid name detection'
|
||||
);
|
||||
$this->assertEquals(
|
||||
[[
|
||||
'level' => 'Warning',
|
||||
'id' => '203',
|
||||
'message' => 'possible invalid name',
|
||||
'context' => ['name' => '-$asdf&', 'id' => 'valid', 'tag' => 'div']
|
||||
]],
|
||||
Error::getMessages(),
|
||||
'check error message failed'
|
||||
);
|
||||
}
|
||||
|
||||
// static add element
|
||||
// print object/array
|
||||
}
|
||||
|
||||
// __END__
|
||||
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use CoreLibs\Template\HtmlBuilder\StringReplace;
|
||||
|
||||
/**
|
||||
* Test class for Template\HtmlBuilder\StringReplace
|
||||
* @coversDefaultClass \CoreLibs\Template\HtmlBuilder\StringReplace
|
||||
* @testdox \CoreLibs\Template\HtmlBuilder\StringReplace method tests
|
||||
*/
|
||||
final class CoreLibsTemplateHtmlBuilderStringReplaceTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::replaceData
|
||||
* @testdox test basic replaceData
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testReplaceData(): void
|
||||
{
|
||||
$html_block = <<<HTML
|
||||
<div id="{ID}" class="{CSS}">
|
||||
{CONTENT}
|
||||
</div>
|
||||
HTML;
|
||||
|
||||
$this->assertEquals(
|
||||
<<<HTML
|
||||
<div id="block-id" class="blue,red">
|
||||
Some content here<br>with bla bla inside
|
||||
</div>
|
||||
HTML,
|
||||
StringReplace::replaceData(
|
||||
$html_block,
|
||||
[
|
||||
'ID' => 'block-id',
|
||||
'CSS' => join(',', ['blue', 'red']),
|
||||
'{CONTENT}' => 'Some content here<br>with bla bla inside',
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @testdox replaceData error
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
/* public function testReplaceDataErrors(): void
|
||||
{
|
||||
$this->expectException(HtmlBuilderExcpetion::class);
|
||||
$this->expectExceptionMessage("Replace and content array count differ");
|
||||
StringReplace::replaceData('<span>{FOO}</span>', ['{FOO}', '{BAR}'], ['foo']);
|
||||
} */
|
||||
}
|
||||
|
||||
// __END__
|
||||
1232
4dev/tests/UrlRequests/CoreLibsUrlRequestsCurlTest.php
Normal file
1232
4dev/tests/UrlRequests/CoreLibsUrlRequestsCurlTest.php
Normal file
File diff suppressed because it is too large
Load Diff
15
4dev/tests/bootstrap.php
Normal file
15
4dev/tests/bootstrap.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
$set = 0;
|
||||
foreach (['/../../www', '/../www', '/../..', '/..', '/../../src', '/../src'] as $src) {
|
||||
if (is_file(dirname(__DIR__) . $src . '/vendor/autoload.php')) {
|
||||
require dirname(__DIR__) . $src . '/vendor/autoload.php';
|
||||
$set = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!$set) {
|
||||
die("Cannot find /vendor/autoload.php in reference to: " . dirname(__DIR__));
|
||||
}
|
||||
|
||||
// __END__
|
||||
@@ -0,0 +1,36 @@
|
||||
-- 20241203: update edit tables
|
||||
ALTER TABLE edit_generic ADD cuuid UUID DEFAULT gen_random_uuid();
|
||||
ALTER TABLE edit_log ADD eucuid VARCHAR;
|
||||
ALTER TABLE edit_log ADD eucuuid VARCHAR;
|
||||
ALTER TABLE edit_log ADD action_sub_id VARCHAR;
|
||||
ALTER TABLE edit_log ADD http_data JSONB;
|
||||
ALTER TABLE edit_log ADD ip_address JSONB;
|
||||
ALTER TABLE edit_log ADD action_data JSONB;
|
||||
ALTER TABLE edit_log ADD request_scheme VARCHAR;
|
||||
ALTER TABLE edit_user ADD force_logout INT DEFAULT 0;
|
||||
COMMENT ON COLUMN edit_user.force_logout IS 'Counter for forced log out, if this one is higher than the session set one the session gets terminated';
|
||||
ALTER TABLE edit_user ADD last_login TIMESTAMP WITHOUT TIME ZONE;
|
||||
COMMENT ON COLUMN edit_user.last_login IS 'Last succesfull login tiemstamp';
|
||||
|
||||
-- update set_edit_gneric
|
||||
-- adds the created or updated date tags
|
||||
|
||||
CREATE OR REPLACE FUNCTION set_edit_generic()
|
||||
RETURNS TRIGGER AS
|
||||
$$
|
||||
DECLARE
|
||||
random_length INT = 25; -- that should be long enough
|
||||
BEGIN
|
||||
IF TG_OP = 'INSERT' THEN
|
||||
NEW.date_created := clock_timestamp();
|
||||
NEW.cuid := random_string(random_length);
|
||||
NEW.cuuid := gen_random_uuid();
|
||||
ELSIF TG_OP = 'UPDATE' THEN
|
||||
NEW.date_updated := clock_timestamp();
|
||||
END IF;
|
||||
RETURN NEW;
|
||||
END;
|
||||
$$
|
||||
LANGUAGE 'plpgsql';
|
||||
|
||||
-- END --
|
||||
43
README.Exceptions.md
Normal file
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
|
||||
22
README.md
22
README.md
@@ -92,3 +92,25 @@ Loads classes internal (not passed in, not extend)
|
||||
* \CoreLibs\Admin\EditBase loads \CoreLibs\Template\SmartyExtend, \CoreLibs\Output\Form\Generate
|
||||
* \CoreLibs\Output\From\Generate loads \CoreLibs\Debug\Logging, \CoreLibs\Language\L10n if not passed on
|
||||
* \CoreLibs\Output\From\Generate loads \CoreLibs\Output\From\TableArrays
|
||||
|
||||
## PHP unit testing and Intelephense
|
||||
|
||||
Intelephense can not directly read phar files so we do the following
|
||||
|
||||
In the workspace root we have `.libs/`, be in the workspace folder not the `.libs/` folder
|
||||
|
||||
`php -r "(new Phar('/path/to/.phive/phars/phpunit-9.6.13.phar'))->extractTo('.libs/phpunit/');"`
|
||||
|
||||
andd add in vscode Intelephense > Enviroment: Include Paths (intelephense.environment.includePaths)
|
||||
|
||||
```json
|
||||
"intelephense.environment.includePaths": [
|
||||
"/.libs/phpunit/"
|
||||
]
|
||||
```
|
||||
|
||||
Add `.libs` to the master .gitingore
|
||||
|
||||
### Update phpunit
|
||||
|
||||
On a version update the old phpunit folder in .libs has to be removed and the new version extracted again
|
||||
|
||||
@@ -2,20 +2,22 @@
|
||||
"name": "egrajp/development-corelibs-dev",
|
||||
"version": "dev-master",
|
||||
"description": "CoreLibs: Development package",
|
||||
"keywords": ["corelib", "logging", "database", "templating", "tools"],
|
||||
"type": "library",
|
||||
"require": {
|
||||
"php": ">=8.3"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpstan/phpstan": "^1.10",
|
||||
"phpstan/phpstan": "^2.0",
|
||||
"phpstan/phpstan-deprecation-rules": "^2.0",
|
||||
"phpstan/extension-installer": "^1.4",
|
||||
"phan/phan": "^5.4",
|
||||
"phpstan/extension-installer": "^1.2",
|
||||
"vimeo/psalm": "^5.7",
|
||||
"phpstan/phpstan-deprecation-rules": "^1.1"
|
||||
"phpunit/phpunit": "^9",
|
||||
"yamadashy/phpstan-friendly-formatter": "^1.1"
|
||||
},
|
||||
"config": {
|
||||
"allow-plugins": {
|
||||
"phpstan/extension-installer": true
|
||||
}
|
||||
},
|
||||
"require": {
|
||||
"php": ">=8.1"
|
||||
}
|
||||
}
|
||||
|
||||
2579
composer.lock
generated
2579
composer.lock
generated
File diff suppressed because it is too large
Load Diff
15
jsconfig.json
Normal file
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
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,47 +0,0 @@
|
||||
parameters:
|
||||
ignoreErrors:
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$connection of function pg_escape_bytea expects PgSql\\\\Connection\\|string, object\\|resource given\\.$#"
|
||||
count: 1
|
||||
path: www/lib/CoreLibs/DB/SQL/PgSQL.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$connection of function pg_escape_identifier expects PgSql\\\\Connection\\|string, object\\|resource given\\.$#"
|
||||
count: 1
|
||||
path: www/lib/CoreLibs/DB/SQL/PgSQL.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$connection of function pg_escape_literal expects PgSql\\\\Connection\\|string, object\\|resource given\\.$#"
|
||||
count: 1
|
||||
path: www/lib/CoreLibs/DB/SQL/PgSQL.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$connection of function pg_escape_string expects PgSql\\\\Connection\\|string, object\\|resource given\\.$#"
|
||||
count: 1
|
||||
path: www/lib/CoreLibs/DB/SQL/PgSQL.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$connection of function pg_execute expects PgSql\\\\Connection\\|string, object\\|resource given\\.$#"
|
||||
count: 1
|
||||
path: www/lib/CoreLibs/DB/SQL/PgSQL.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$connection of function pg_parameter_status expects PgSql\\\\Connection\\|string, object\\|resource given\\.$#"
|
||||
count: 1
|
||||
path: www/lib/CoreLibs/DB/SQL/PgSQL.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$connection of function pg_prepare expects PgSql\\\\Connection\\|string, object\\|resource given\\.$#"
|
||||
count: 1
|
||||
path: www/lib/CoreLibs/DB/SQL/PgSQL.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$connection of function pg_query expects PgSql\\\\Connection\\|string, object\\|resource given\\.$#"
|
||||
count: 1
|
||||
path: www/lib/CoreLibs/DB/SQL/PgSQL.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$connection of function pg_query_params expects PgSql\\\\Connection\\|string, object\\|resource given\\.$#"
|
||||
count: 1
|
||||
path: www/lib/CoreLibs/DB/SQL/PgSQL.php
|
||||
|
||||
24
phpstan.neon
24
phpstan.neon
@@ -1,11 +1,22 @@
|
||||
# PHP Stan Config
|
||||
includes:
|
||||
- phpstan-conditional.php
|
||||
#- ./vendor/yamadashy/phpstan-friendly-formatter/extension.neon
|
||||
# - phar://phpstan.phar/conf/bleedingEdge.neon
|
||||
parameters:
|
||||
tmpDir: /tmp/phpstan-corelibs
|
||||
level: 8 # max is now 9
|
||||
tmpDir: %currentWorkingDirectory%/tmp/phpstan-corelibs
|
||||
#errorFormat: friendly
|
||||
#friendly:
|
||||
# lineBefore: 3
|
||||
# lineAfter: 3
|
||||
level: 8 # max is now 10
|
||||
# strictRules:
|
||||
# allRules: false
|
||||
checkMissingCallableSignature: true
|
||||
treatPhpDocTypesAsCertain: false
|
||||
# phpVersion:
|
||||
# min: 80200 # PHP 8.2.0
|
||||
# max: 80300 # PHP latest
|
||||
paths:
|
||||
- %currentWorkingDirectory%/www
|
||||
bootstrapFiles:
|
||||
@@ -39,9 +50,9 @@ parameters:
|
||||
- www/vendor
|
||||
# ignore errores with
|
||||
ignoreErrors:
|
||||
- # in the class_test tree we allow deprecated calls
|
||||
message: "#^Call to deprecated method #"
|
||||
path: %currentWorkingDirectory%/www/admin/class_test.*.php
|
||||
# - # in the class_test tree we allow deprecated calls
|
||||
# message: "#^Call to deprecated method #"
|
||||
# path: %currentWorkingDirectory%/www/admin/class_test.*.php
|
||||
# - '#Expression in empty\(\) is always falsy.#'
|
||||
# -
|
||||
# message: '#Reflection error: [a-zA-Z0-9\\_]+ not found.#'
|
||||
@@ -53,3 +64,6 @@ parameters:
|
||||
# paths:
|
||||
# - ...
|
||||
# - ...
|
||||
# -
|
||||
# message: "#^Call to deprecated method #"
|
||||
# path: www/admin/class_test*.php
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
<phpunit
|
||||
cacheResultFile="/tmp/phpunit-corelibs.result.cache"
|
||||
colors="true"
|
||||
verbose="true"
|
||||
verbose="false"
|
||||
convertDeprecationsToExceptions="true"
|
||||
bootstrap="4dev/tests/bootstrap.php"
|
||||
>
|
||||
<testsuites>
|
||||
<testsuite name="deploy">
|
||||
<directory>4dev/tests</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
</phpunit>
|
||||
|
||||
23
vendor/amphp/amp/LICENSE
vendored
23
vendor/amphp/amp/LICENSE
vendored
@@ -1,23 +0,0 @@
|
||||
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015-2019 amphp
|
||||
Copyright (c) 2016 PHP Asynchronous Interoperability Group
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
74
vendor/amphp/amp/composer.json
vendored
74
vendor/amphp/amp/composer.json
vendored
@@ -1,74 +0,0 @@
|
||||
{
|
||||
"name": "amphp/amp",
|
||||
"homepage": "https://amphp.org/amp",
|
||||
"description": "A non-blocking concurrency framework for PHP applications.",
|
||||
"keywords": [
|
||||
"async",
|
||||
"asynchronous",
|
||||
"concurrency",
|
||||
"promise",
|
||||
"awaitable",
|
||||
"future",
|
||||
"non-blocking",
|
||||
"event",
|
||||
"event-loop"
|
||||
],
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Daniel Lowrey",
|
||||
"email": "rdlowrey@php.net"
|
||||
},
|
||||
{
|
||||
"name": "Aaron Piotrowski",
|
||||
"email": "aaron@trowski.com"
|
||||
},
|
||||
{
|
||||
"name": "Bob Weinand",
|
||||
"email": "bobwei9@hotmail.com"
|
||||
},
|
||||
{
|
||||
"name": "Niklas Keller",
|
||||
"email": "me@kelunik.com"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=7.1"
|
||||
},
|
||||
"require-dev": {
|
||||
"ext-json": "*",
|
||||
"amphp/phpunit-util": "^1",
|
||||
"amphp/php-cs-fixer-config": "dev-master",
|
||||
"react/promise": "^2",
|
||||
"phpunit/phpunit": "^7 | ^8 | ^9",
|
||||
"psalm/phar": "^3.11@dev",
|
||||
"jetbrains/phpstorm-stubs": "^2019.3"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Amp\\": "lib"
|
||||
},
|
||||
"files": [
|
||||
"lib/functions.php",
|
||||
"lib/Internal/functions.php"
|
||||
]
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"Amp\\Test\\": "test"
|
||||
}
|
||||
},
|
||||
"support": {
|
||||
"issues": "https://github.com/amphp/amp/issues",
|
||||
"irc": "irc://irc.freenode.org/amphp"
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "2.x-dev"
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"test": "@php -dzend.assertions=1 -dassert.exception=1 ./vendor/bin/phpunit",
|
||||
"code-style": "@php ./vendor/bin/php-cs-fixer fix"
|
||||
}
|
||||
}
|
||||
80
vendor/amphp/amp/lib/CallableMaker.php
vendored
80
vendor/amphp/amp/lib/CallableMaker.php
vendored
@@ -1,80 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Amp;
|
||||
|
||||
// @codeCoverageIgnoreStart
|
||||
if (\PHP_VERSION_ID < 70100) {
|
||||
/** @psalm-suppress DuplicateClass */
|
||||
trait CallableMaker
|
||||
{
|
||||
/** @var \ReflectionClass */
|
||||
private static $__reflectionClass;
|
||||
|
||||
/** @var \ReflectionMethod[] */
|
||||
private static $__reflectionMethods = [];
|
||||
|
||||
/**
|
||||
* Creates a callable from a protected or private instance method that may be invoked by callers requiring a
|
||||
* publicly invokable callback.
|
||||
*
|
||||
* @param string $method Instance method name.
|
||||
*
|
||||
* @return callable
|
||||
*
|
||||
* @psalm-suppress MixedInferredReturnType
|
||||
*/
|
||||
private function callableFromInstanceMethod(string $method): callable
|
||||
{
|
||||
if (!isset(self::$__reflectionMethods[$method])) {
|
||||
if (self::$__reflectionClass === null) {
|
||||
self::$__reflectionClass = new \ReflectionClass(self::class);
|
||||
}
|
||||
self::$__reflectionMethods[$method] = self::$__reflectionClass->getMethod($method);
|
||||
}
|
||||
|
||||
return self::$__reflectionMethods[$method]->getClosure($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a callable from a protected or private static method that may be invoked by methods requiring a
|
||||
* publicly invokable callback.
|
||||
*
|
||||
* @param string $method Static method name.
|
||||
*
|
||||
* @return callable
|
||||
*
|
||||
* @psalm-suppress MixedInferredReturnType
|
||||
*/
|
||||
private static function callableFromStaticMethod(string $method): callable
|
||||
{
|
||||
if (!isset(self::$__reflectionMethods[$method])) {
|
||||
if (self::$__reflectionClass === null) {
|
||||
self::$__reflectionClass = new \ReflectionClass(self::class);
|
||||
}
|
||||
self::$__reflectionMethods[$method] = self::$__reflectionClass->getMethod($method);
|
||||
}
|
||||
|
||||
return self::$__reflectionMethods[$method]->getClosure();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
/** @psalm-suppress DuplicateClass */
|
||||
trait CallableMaker
|
||||
{
|
||||
/**
|
||||
* @deprecated Use \Closure::fromCallable() instead of this method in PHP 7.1.
|
||||
*/
|
||||
private function callableFromInstanceMethod(string $method): callable
|
||||
{
|
||||
return \Closure::fromCallable([$this, $method]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use \Closure::fromCallable() instead of this method in PHP 7.1.
|
||||
*/
|
||||
private static function callableFromStaticMethod(string $method): callable
|
||||
{
|
||||
return \Closure::fromCallable([self::class, $method]);
|
||||
}
|
||||
}
|
||||
} // @codeCoverageIgnoreEnd
|
||||
49
vendor/amphp/amp/lib/CancellationToken.php
vendored
49
vendor/amphp/amp/lib/CancellationToken.php
vendored
@@ -1,49 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Amp;
|
||||
|
||||
/**
|
||||
* Cancellation tokens are simple objects that allow registering handlers to subscribe to cancellation requests.
|
||||
*/
|
||||
interface CancellationToken
|
||||
{
|
||||
/**
|
||||
* Subscribes a new handler to be invoked on a cancellation request.
|
||||
*
|
||||
* This handler might be invoked immediately in case the token has already been cancelled. Returned generators will
|
||||
* automatically be run as coroutines. Any unhandled exceptions will be throw into the event loop.
|
||||
*
|
||||
* @param callable(CancelledException) $callback Callback to be invoked on a cancellation request. Will receive a
|
||||
* `CancelledException` as first argument that may be used to fail the operation's promise.
|
||||
*
|
||||
* @return string Identifier that can be used to cancel the subscription.
|
||||
*/
|
||||
public function subscribe(callable $callback): string;
|
||||
|
||||
/**
|
||||
* Unsubscribes a previously registered handler.
|
||||
*
|
||||
* The handler will no longer be called as long as this method isn't invoked from a subscribed callback.
|
||||
*
|
||||
* @param string $id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function unsubscribe(string $id);
|
||||
|
||||
/**
|
||||
* Returns whether cancellation has been requested yet.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isRequested(): bool;
|
||||
|
||||
/**
|
||||
* Throws the `CancelledException` if cancellation has been requested, otherwise does nothing.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws CancelledException
|
||||
*/
|
||||
public function throwIfRequested();
|
||||
}
|
||||
163
vendor/amphp/amp/lib/CancellationTokenSource.php
vendored
163
vendor/amphp/amp/lib/CancellationTokenSource.php
vendored
@@ -1,163 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Amp;
|
||||
|
||||
use React\Promise\PromiseInterface as ReactPromise;
|
||||
use function Amp\Promise\rethrow;
|
||||
|
||||
/**
|
||||
* A cancellation token source provides a mechanism to cancel operations.
|
||||
*
|
||||
* Cancellation of operation works by creating a cancellation token source and passing the corresponding token when
|
||||
* starting the operation. To cancel the operation, invoke `CancellationTokenSource::cancel()`.
|
||||
*
|
||||
* Any operation can decide what to do on a cancellation request, it has "don't care" semantics. An operation SHOULD be
|
||||
* aborted, but MAY continue. Example: A DNS client might continue to receive and cache the response, as the query has
|
||||
* been sent anyway. An HTTP client would usually close a connection, but might not do so in case a response is close to
|
||||
* be fully received to reuse the connection.
|
||||
*
|
||||
* **Example**
|
||||
*
|
||||
* ```php
|
||||
* $tokenSource = new CancellationTokenSource;
|
||||
* $token = $tokenSource->getToken();
|
||||
*
|
||||
* $response = yield $httpClient->request("https://example.com/stream", $token);
|
||||
* $responseBody = $response->getBody();
|
||||
*
|
||||
* while (($chunk = yield $response->read()) !== null) {
|
||||
* // consume $chunk
|
||||
*
|
||||
* if ($noLongerInterested) {
|
||||
* $cancellationTokenSource->cancel();
|
||||
* break;
|
||||
* }
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
* @see CancellationToken
|
||||
* @see CancelledException
|
||||
*/
|
||||
final class CancellationTokenSource
|
||||
{
|
||||
/** @var CancellationToken */
|
||||
private $token;
|
||||
|
||||
/** @var callable|null */
|
||||
private $onCancel;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$onCancel = null;
|
||||
|
||||
$this->token = new class($onCancel) implements CancellationToken {
|
||||
/** @var string */
|
||||
private $nextId = "a";
|
||||
|
||||
/** @var callable[] */
|
||||
private $callbacks = [];
|
||||
|
||||
/** @var \Throwable|null */
|
||||
private $exception;
|
||||
|
||||
/**
|
||||
* @param mixed $onCancel
|
||||
* @param-out callable $onCancel
|
||||
*/
|
||||
public function __construct(&$onCancel)
|
||||
{
|
||||
/** @psalm-suppress MissingClosureReturnType We still support PHP 7.0 */
|
||||
$onCancel = function (\Throwable $exception) {
|
||||
$this->exception = $exception;
|
||||
|
||||
$callbacks = $this->callbacks;
|
||||
$this->callbacks = [];
|
||||
|
||||
foreach ($callbacks as $callback) {
|
||||
$this->invokeCallback($callback);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @param callable $callback
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function invokeCallback(callable $callback)
|
||||
{
|
||||
// No type declaration to prevent exception outside the try!
|
||||
try {
|
||||
/** @var mixed $result */
|
||||
$result = $callback($this->exception);
|
||||
|
||||
if ($result instanceof \Generator) {
|
||||
/** @psalm-var \Generator<mixed, Promise|ReactPromise|(Promise|ReactPromise)[], mixed, mixed> $result */
|
||||
$result = new Coroutine($result);
|
||||
}
|
||||
|
||||
if ($result instanceof Promise || $result instanceof ReactPromise) {
|
||||
rethrow($result);
|
||||
}
|
||||
} catch (\Throwable $exception) {
|
||||
Loop::defer(static function () use ($exception) {
|
||||
throw $exception;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public function subscribe(callable $callback): string
|
||||
{
|
||||
$id = $this->nextId++;
|
||||
|
||||
if ($this->exception) {
|
||||
$this->invokeCallback($callback);
|
||||
} else {
|
||||
$this->callbacks[$id] = $callback;
|
||||
}
|
||||
|
||||
return $id;
|
||||
}
|
||||
|
||||
public function unsubscribe(string $id)
|
||||
{
|
||||
unset($this->callbacks[$id]);
|
||||
}
|
||||
|
||||
public function isRequested(): bool
|
||||
{
|
||||
return isset($this->exception);
|
||||
}
|
||||
|
||||
public function throwIfRequested()
|
||||
{
|
||||
if (isset($this->exception)) {
|
||||
throw $this->exception;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
$this->onCancel = $onCancel;
|
||||
}
|
||||
|
||||
public function getToken(): CancellationToken
|
||||
{
|
||||
return $this->token;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Throwable|null $previous Exception to be used as the previous exception to CancelledException.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function cancel(\Throwable $previous = null)
|
||||
{
|
||||
if ($this->onCancel === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$onCancel = $this->onCancel;
|
||||
$this->onCancel = null;
|
||||
$onCancel(new CancelledException($previous));
|
||||
}
|
||||
}
|
||||
17
vendor/amphp/amp/lib/CancelledException.php
vendored
17
vendor/amphp/amp/lib/CancelledException.php
vendored
@@ -1,17 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Amp;
|
||||
|
||||
/**
|
||||
* Will be thrown in case an operation is cancelled.
|
||||
*
|
||||
* @see CancellationToken
|
||||
* @see CancellationTokenSource
|
||||
*/
|
||||
class CancelledException extends \Exception
|
||||
{
|
||||
public function __construct(\Throwable $previous = null)
|
||||
{
|
||||
parent::__construct("The operation was cancelled", 0, $previous);
|
||||
}
|
||||
}
|
||||
@@ -1,87 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Amp;
|
||||
|
||||
final class CombinedCancellationToken implements CancellationToken
|
||||
{
|
||||
/** @var array{0: CancellationToken, 1: string}[] */
|
||||
private $tokens = [];
|
||||
|
||||
/** @var string */
|
||||
private $nextId = "a";
|
||||
|
||||
/** @var callable[] */
|
||||
private $callbacks = [];
|
||||
|
||||
/** @var CancelledException|null */
|
||||
private $exception;
|
||||
|
||||
public function __construct(CancellationToken ...$tokens)
|
||||
{
|
||||
$thatException = &$this->exception;
|
||||
$thatCallbacks = &$this->callbacks;
|
||||
|
||||
foreach ($tokens as $token) {
|
||||
$id = $token->subscribe(static function (CancelledException $exception) use (&$thatException, &$thatCallbacks) {
|
||||
$thatException = $exception;
|
||||
|
||||
$callbacks = $thatCallbacks;
|
||||
$thatCallbacks = [];
|
||||
|
||||
foreach ($callbacks as $callback) {
|
||||
asyncCall($callback, $thatException);
|
||||
}
|
||||
});
|
||||
|
||||
$this->tokens[] = [$token, $id];
|
||||
}
|
||||
}
|
||||
|
||||
public function __destruct()
|
||||
{
|
||||
foreach ($this->tokens as list($token, $id)) {
|
||||
/** @var CancellationToken $token */
|
||||
$token->unsubscribe($id);
|
||||
}
|
||||
}
|
||||
|
||||
/** @inheritdoc */
|
||||
public function subscribe(callable $callback): string
|
||||
{
|
||||
$id = $this->nextId++;
|
||||
|
||||
if ($this->exception) {
|
||||
asyncCall($callback, $this->exception);
|
||||
} else {
|
||||
$this->callbacks[$id] = $callback;
|
||||
}
|
||||
|
||||
return $id;
|
||||
}
|
||||
|
||||
/** @inheritdoc */
|
||||
public function unsubscribe(string $id)
|
||||
{
|
||||
unset($this->callbacks[$id]);
|
||||
}
|
||||
|
||||
/** @inheritdoc */
|
||||
public function isRequested(): bool
|
||||
{
|
||||
foreach ($this->tokens as list($token)) {
|
||||
if ($token->isRequested()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/** @inheritdoc */
|
||||
public function throwIfRequested()
|
||||
{
|
||||
foreach ($this->tokens as list($token)) {
|
||||
$token->throwIfRequested();
|
||||
}
|
||||
}
|
||||
}
|
||||
160
vendor/amphp/amp/lib/Coroutine.php
vendored
160
vendor/amphp/amp/lib/Coroutine.php
vendored
@@ -1,160 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Amp;
|
||||
|
||||
use React\Promise\PromiseInterface as ReactPromise;
|
||||
|
||||
/**
|
||||
* Creates a promise from a generator function yielding promises.
|
||||
*
|
||||
* When a promise is yielded, execution of the generator is interrupted until the promise is resolved. A success
|
||||
* value is sent into the generator, while a failure reason is thrown into the generator. Using a coroutine,
|
||||
* asynchronous code can be written without callbacks and be structured like synchronous code.
|
||||
*
|
||||
* @template-covariant TReturn
|
||||
* @template-implements Promise<TReturn>
|
||||
*/
|
||||
final class Coroutine implements Promise
|
||||
{
|
||||
use Internal\Placeholder;
|
||||
|
||||
/**
|
||||
* Attempts to transform the non-promise yielded from the generator into a promise, otherwise returns an instance
|
||||
* `Amp\Failure` failed with an instance of `Amp\InvalidYieldError`.
|
||||
*
|
||||
* @param mixed $yielded Non-promise yielded from generator.
|
||||
* @param \Generator $generator No type for performance, we already know the type.
|
||||
*
|
||||
* @return Promise
|
||||
*/
|
||||
private static function transform($yielded, $generator): Promise
|
||||
{
|
||||
$exception = null; // initialize here, see https://github.com/vimeo/psalm/issues/2951
|
||||
|
||||
try {
|
||||
if (\is_array($yielded)) {
|
||||
return Promise\all($yielded);
|
||||
}
|
||||
|
||||
if ($yielded instanceof ReactPromise) {
|
||||
return Promise\adapt($yielded);
|
||||
}
|
||||
|
||||
// No match, continue to returning Failure below.
|
||||
} catch (\Throwable $exception) {
|
||||
// Conversion to promise failed, fall-through to returning Failure below.
|
||||
}
|
||||
|
||||
return new Failure(new InvalidYieldError(
|
||||
$generator,
|
||||
\sprintf(
|
||||
"Unexpected yield; Expected an instance of %s or %s or an array of such instances",
|
||||
Promise::class,
|
||||
ReactPromise::class
|
||||
),
|
||||
$exception
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Generator $generator
|
||||
* @psalm-param \Generator<mixed,Promise|ReactPromise|array<array-key,
|
||||
* Promise|ReactPromise>,mixed,Promise<TReturn>|ReactPromise|TReturn> $generator
|
||||
*/
|
||||
public function __construct(\Generator $generator)
|
||||
{
|
||||
try {
|
||||
$yielded = $generator->current();
|
||||
|
||||
if (!$yielded instanceof Promise) {
|
||||
if (!$generator->valid()) {
|
||||
$this->resolve($generator->getReturn());
|
||||
return;
|
||||
}
|
||||
|
||||
$yielded = self::transform($yielded, $generator);
|
||||
}
|
||||
} catch (\Throwable $exception) {
|
||||
$this->fail($exception);
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Throwable|null $e Exception to be thrown into the generator.
|
||||
* @param mixed $v Value to be sent into the generator.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @psalm-suppress MissingClosureParamType
|
||||
* @psalm-suppress MissingClosureReturnType
|
||||
*/
|
||||
$onResolve = function (\Throwable $e = null, $v) use ($generator, &$onResolve) {
|
||||
/** @var bool $immediate Used to control iterative coroutine continuation. */
|
||||
static $immediate = true;
|
||||
|
||||
/** @var \Throwable|null $exception Promise failure reason when executing next coroutine step, null at all other times. */
|
||||
static $exception;
|
||||
|
||||
/** @var mixed $value Promise success value when executing next coroutine step, null at all other times. */
|
||||
static $value;
|
||||
|
||||
$exception = $e;
|
||||
/** @psalm-suppress MixedAssignment */
|
||||
$value = $v;
|
||||
|
||||
if (!$immediate) {
|
||||
$immediate = true;
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
try {
|
||||
do {
|
||||
if ($exception) {
|
||||
// Throw exception at current execution point.
|
||||
$yielded = $generator->throw($exception);
|
||||
} else {
|
||||
// Send the new value and execute to next yield statement.
|
||||
$yielded = $generator->send($value);
|
||||
}
|
||||
|
||||
if (!$yielded instanceof Promise) {
|
||||
if (!$generator->valid()) {
|
||||
$this->resolve($generator->getReturn());
|
||||
$onResolve = null;
|
||||
return;
|
||||
}
|
||||
|
||||
$yielded = self::transform($yielded, $generator);
|
||||
}
|
||||
|
||||
$immediate = false;
|
||||
$yielded->onResolve($onResolve);
|
||||
} while ($immediate);
|
||||
|
||||
$immediate = true;
|
||||
} catch (\Throwable $exception) {
|
||||
$this->fail($exception);
|
||||
$onResolve = null;
|
||||
} finally {
|
||||
$exception = null;
|
||||
$value = null;
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
Loop::defer(static function () use ($e) {
|
||||
throw $e;
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
try {
|
||||
$yielded->onResolve($onResolve);
|
||||
|
||||
unset($generator, $yielded, $onResolve);
|
||||
} catch (\Throwable $e) {
|
||||
Loop::defer(static function () use ($e) {
|
||||
throw $e;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
76
vendor/amphp/amp/lib/Deferred.php
vendored
76
vendor/amphp/amp/lib/Deferred.php
vendored
@@ -1,76 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Amp;
|
||||
|
||||
/**
|
||||
* Deferred is a container for a promise that is resolved using the resolve() and fail() methods of this object.
|
||||
* The contained promise may be accessed using the promise() method. This object should not be part of a public
|
||||
* API, but used internally to create and resolve a promise.
|
||||
*
|
||||
* @template TValue
|
||||
*/
|
||||
final class Deferred
|
||||
{
|
||||
/** @var Promise<TValue> Has public resolve and fail methods. */
|
||||
private $resolver;
|
||||
|
||||
/** @var Promise<TValue> Hides placeholder methods */
|
||||
private $promise;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->resolver = new class implements Promise {
|
||||
use Internal\Placeholder {
|
||||
resolve as public;
|
||||
fail as public;
|
||||
isResolved as public;
|
||||
}
|
||||
};
|
||||
|
||||
$this->promise = new Internal\PrivatePromise($this->resolver);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Promise<TValue>
|
||||
*/
|
||||
public function promise(): Promise
|
||||
{
|
||||
return $this->promise;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fulfill the promise with the given value.
|
||||
*
|
||||
* @param mixed $value
|
||||
*
|
||||
* @psalm-param TValue|Promise<TValue> $value
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function resolve($value = null)
|
||||
{
|
||||
/** @psalm-suppress UndefinedInterfaceMethod */
|
||||
$this->resolver->resolve($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fails the promise the the given reason.
|
||||
*
|
||||
* @param \Throwable $reason
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function fail(\Throwable $reason)
|
||||
{
|
||||
/** @psalm-suppress UndefinedInterfaceMethod */
|
||||
$this->resolver->fail($reason);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool True if the promise has been resolved.
|
||||
*/
|
||||
public function isResolved(): bool
|
||||
{
|
||||
return $this->resolver->isResolved();
|
||||
}
|
||||
}
|
||||
58
vendor/amphp/amp/lib/Delayed.php
vendored
58
vendor/amphp/amp/lib/Delayed.php
vendored
@@ -1,58 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Amp;
|
||||
|
||||
/**
|
||||
* Creates a promise that resolves itself with a given value after a number of milliseconds.
|
||||
*
|
||||
* @template-covariant TReturn
|
||||
* @template-implements Promise<TReturn>
|
||||
*/
|
||||
final class Delayed implements Promise
|
||||
{
|
||||
use Internal\Placeholder;
|
||||
|
||||
/** @var string|null Event loop watcher identifier. */
|
||||
private $watcher;
|
||||
|
||||
/**
|
||||
* @param int $time Milliseconds before succeeding the promise.
|
||||
* @param TReturn $value Succeed the promise with this value.
|
||||
*/
|
||||
public function __construct(int $time, $value = null)
|
||||
{
|
||||
$this->watcher = Loop::delay($time, function () use ($value) {
|
||||
$this->watcher = null;
|
||||
$this->resolve($value);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* References the internal watcher in the event loop, keeping the loop running while this promise is pending.
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function reference(): self
|
||||
{
|
||||
if ($this->watcher !== null) {
|
||||
Loop::reference($this->watcher);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unreferences the internal watcher in the event loop, allowing the loop to stop while this promise is pending if
|
||||
* no other events are pending in the loop.
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function unreference(): self
|
||||
{
|
||||
if ($this->watcher !== null) {
|
||||
Loop::unreference($this->watcher);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
84
vendor/amphp/amp/lib/Emitter.php
vendored
84
vendor/amphp/amp/lib/Emitter.php
vendored
@@ -1,84 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Amp;
|
||||
|
||||
/**
|
||||
* Emitter is a container for an iterator that can emit values using the emit() method and completed using the
|
||||
* complete() and fail() methods of this object. The contained iterator may be accessed using the iterate()
|
||||
* method. This object should not be part of a public API, but used internally to create and emit values to an
|
||||
* iterator.
|
||||
*
|
||||
* @template TValue
|
||||
*/
|
||||
final class Emitter
|
||||
{
|
||||
/** @var Iterator<TValue> Has public emit, complete, and fail methods. */
|
||||
private $emitter;
|
||||
|
||||
/** @var Iterator<TValue> Hides producer methods. */
|
||||
private $iterator;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->emitter = new class implements Iterator {
|
||||
use Internal\Producer {
|
||||
emit as public;
|
||||
complete as public;
|
||||
fail as public;
|
||||
}
|
||||
};
|
||||
|
||||
$this->iterator = new Internal\PrivateIterator($this->emitter);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Iterator
|
||||
* @psalm-return Iterator<TValue>
|
||||
*/
|
||||
public function iterate(): Iterator
|
||||
{
|
||||
return $this->iterator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Emits a value to the iterator.
|
||||
*
|
||||
* @param mixed $value
|
||||
*
|
||||
* @psalm-param TValue $value
|
||||
*
|
||||
* @return Promise
|
||||
* @psalm-return Promise<null>
|
||||
* @psalm-suppress MixedInferredReturnType
|
||||
* @psalm-suppress MixedReturnStatement
|
||||
*/
|
||||
public function emit($value): Promise
|
||||
{
|
||||
/** @psalm-suppress UndefinedInterfaceMethod */
|
||||
return $this->emitter->emit($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Completes the iterator.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function complete()
|
||||
{
|
||||
/** @psalm-suppress UndefinedInterfaceMethod */
|
||||
$this->emitter->complete();
|
||||
}
|
||||
|
||||
/**
|
||||
* Fails the iterator with the given reason.
|
||||
*
|
||||
* @param \Throwable $reason
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function fail(\Throwable $reason)
|
||||
{
|
||||
/** @psalm-suppress UndefinedInterfaceMethod */
|
||||
$this->emitter->fail($reason);
|
||||
}
|
||||
}
|
||||
52
vendor/amphp/amp/lib/Failure.php
vendored
52
vendor/amphp/amp/lib/Failure.php
vendored
@@ -1,52 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Amp;
|
||||
|
||||
use React\Promise\PromiseInterface as ReactPromise;
|
||||
|
||||
/**
|
||||
* Creates a failed promise using the given exception.
|
||||
*
|
||||
* @template-covariant TValue
|
||||
* @template-implements Promise<TValue>
|
||||
*/
|
||||
final class Failure implements Promise
|
||||
{
|
||||
/** @var \Throwable $exception */
|
||||
private $exception;
|
||||
|
||||
/**
|
||||
* @param \Throwable $exception Rejection reason.
|
||||
*/
|
||||
public function __construct(\Throwable $exception)
|
||||
{
|
||||
$this->exception = $exception;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function onResolve(callable $onResolved)
|
||||
{
|
||||
try {
|
||||
/** @var mixed $result */
|
||||
$result = $onResolved($this->exception, null);
|
||||
|
||||
if ($result === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($result instanceof \Generator) {
|
||||
$result = new Coroutine($result);
|
||||
}
|
||||
|
||||
if ($result instanceof Promise || $result instanceof ReactPromise) {
|
||||
Promise\rethrow($result);
|
||||
}
|
||||
} catch (\Throwable $exception) {
|
||||
Loop::defer(static function () use ($exception) {
|
||||
throw $exception;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
187
vendor/amphp/amp/lib/Internal/Placeholder.php
vendored
187
vendor/amphp/amp/lib/Internal/Placeholder.php
vendored
@@ -1,187 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Amp\Internal;
|
||||
|
||||
use Amp\Coroutine;
|
||||
use Amp\Failure;
|
||||
use Amp\Loop;
|
||||
use Amp\Promise;
|
||||
use React\Promise\PromiseInterface as ReactPromise;
|
||||
|
||||
/**
|
||||
* Trait used by Promise implementations. Do not use this trait in your code, instead compose your class from one of
|
||||
* the available classes implementing \Amp\Promise.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
trait Placeholder
|
||||
{
|
||||
/** @var bool */
|
||||
private $resolved = false;
|
||||
|
||||
/** @var mixed */
|
||||
private $result;
|
||||
|
||||
/** @var ResolutionQueue|null|callable(\Throwable|null, mixed): (Promise|\React\Promise\PromiseInterface|\Generator<mixed,
|
||||
* Promise|\React\Promise\PromiseInterface|array<array-key, Promise|\React\Promise\PromiseInterface>, mixed,
|
||||
* mixed>|null)|callable(\Throwable|null, mixed): void */
|
||||
private $onResolved;
|
||||
|
||||
/** @var null|array */
|
||||
private $resolutionTrace;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function onResolve(callable $onResolved)
|
||||
{
|
||||
if ($this->resolved) {
|
||||
if ($this->result instanceof Promise) {
|
||||
$this->result->onResolve($onResolved);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
/** @var mixed $result */
|
||||
$result = $onResolved(null, $this->result);
|
||||
|
||||
if ($result === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($result instanceof \Generator) {
|
||||
$result = new Coroutine($result);
|
||||
}
|
||||
|
||||
if ($result instanceof Promise || $result instanceof ReactPromise) {
|
||||
Promise\rethrow($result);
|
||||
}
|
||||
} catch (\Throwable $exception) {
|
||||
Loop::defer(static function () use ($exception) {
|
||||
throw $exception;
|
||||
});
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (null === $this->onResolved) {
|
||||
$this->onResolved = $onResolved;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$this->onResolved instanceof ResolutionQueue) {
|
||||
/** @psalm-suppress InternalClass */
|
||||
$this->onResolved = new ResolutionQueue($this->onResolved);
|
||||
}
|
||||
|
||||
/** @psalm-suppress InternalMethod */
|
||||
$this->onResolved->push($onResolved);
|
||||
}
|
||||
|
||||
public function __destruct()
|
||||
{
|
||||
try {
|
||||
$this->result = null;
|
||||
} catch (\Throwable $e) {
|
||||
Loop::defer(static function () use ($e) {
|
||||
throw $e;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws \Error Thrown if the promise has already been resolved.
|
||||
*/
|
||||
private function resolve($value = null)
|
||||
{
|
||||
if ($this->resolved) {
|
||||
$message = "Promise has already been resolved";
|
||||
|
||||
if (isset($this->resolutionTrace)) {
|
||||
$trace = formatStacktrace($this->resolutionTrace);
|
||||
$message .= ". Previous resolution trace:\n\n{$trace}\n\n";
|
||||
} else {
|
||||
// @codeCoverageIgnoreStart
|
||||
$message .= ", define environment variable AMP_DEBUG or const AMP_DEBUG = true and enable assertions "
|
||||
. "for a stacktrace of the previous resolution.";
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
|
||||
throw new \Error($message);
|
||||
}
|
||||
|
||||
\assert((function () {
|
||||
$env = \getenv("AMP_DEBUG") ?: "0";
|
||||
if (($env !== "0" && $env !== "false") || (\defined("AMP_DEBUG") && \AMP_DEBUG)) {
|
||||
$trace = \debug_backtrace(\DEBUG_BACKTRACE_IGNORE_ARGS);
|
||||
\array_shift($trace); // remove current closure
|
||||
$this->resolutionTrace = $trace;
|
||||
}
|
||||
|
||||
return true;
|
||||
})());
|
||||
|
||||
if ($value instanceof ReactPromise) {
|
||||
$value = Promise\adapt($value);
|
||||
}
|
||||
|
||||
$this->resolved = true;
|
||||
$this->result = $value;
|
||||
|
||||
if ($this->onResolved === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$onResolved = $this->onResolved;
|
||||
$this->onResolved = null;
|
||||
|
||||
if ($this->result instanceof Promise) {
|
||||
$this->result->onResolve($onResolved);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
/** @var mixed $result */
|
||||
$result = $onResolved(null, $this->result);
|
||||
$onResolved = null; // allow garbage collection of $onResolved, to catch any exceptions from destructors
|
||||
|
||||
if ($result === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($result instanceof \Generator) {
|
||||
$result = new Coroutine($result);
|
||||
}
|
||||
|
||||
if ($result instanceof Promise || $result instanceof ReactPromise) {
|
||||
Promise\rethrow($result);
|
||||
}
|
||||
} catch (\Throwable $exception) {
|
||||
Loop::defer(static function () use ($exception) {
|
||||
throw $exception;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Throwable $reason Failure reason.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function fail(\Throwable $reason)
|
||||
{
|
||||
$this->resolve(new Failure($reason));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool True if the placeholder has been resolved.
|
||||
*/
|
||||
private function isResolved(): bool
|
||||
{
|
||||
return $this->resolved;
|
||||
}
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Amp\Internal;
|
||||
|
||||
use Amp\Iterator;
|
||||
use Amp\Promise;
|
||||
|
||||
/**
|
||||
* Wraps an Iterator instance that has public methods to emit, complete, and fail into an object that only allows
|
||||
* access to the public API methods.
|
||||
*
|
||||
* @template-covariant TValue
|
||||
* @template-implements Iterator<TValue>
|
||||
*/
|
||||
final class PrivateIterator implements Iterator
|
||||
{
|
||||
/** @var Iterator<TValue> */
|
||||
private $iterator;
|
||||
|
||||
/**
|
||||
* @param Iterator $iterator
|
||||
*
|
||||
* @psalm-param Iterator<TValue> $iterator
|
||||
*/
|
||||
public function __construct(Iterator $iterator)
|
||||
{
|
||||
$this->iterator = $iterator;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Promise<bool>
|
||||
*/
|
||||
public function advance(): Promise
|
||||
{
|
||||
return $this->iterator->advance();
|
||||
}
|
||||
|
||||
/**
|
||||
* @psalm-return TValue
|
||||
*/
|
||||
public function getCurrent()
|
||||
{
|
||||
return $this->iterator->getCurrent();
|
||||
}
|
||||
}
|
||||
25
vendor/amphp/amp/lib/Internal/PrivatePromise.php
vendored
25
vendor/amphp/amp/lib/Internal/PrivatePromise.php
vendored
@@ -1,25 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Amp\Internal;
|
||||
|
||||
use Amp\Promise;
|
||||
|
||||
/**
|
||||
* Wraps a Promise instance that has public methods to resolve and fail the promise into an object that only allows
|
||||
* access to the public API methods.
|
||||
*/
|
||||
final class PrivatePromise implements Promise
|
||||
{
|
||||
/** @var Promise */
|
||||
private $promise;
|
||||
|
||||
public function __construct(Promise $promise)
|
||||
{
|
||||
$this->promise = $promise;
|
||||
}
|
||||
|
||||
public function onResolve(callable $onResolved)
|
||||
{
|
||||
$this->promise->onResolve($onResolved);
|
||||
}
|
||||
}
|
||||
212
vendor/amphp/amp/lib/Internal/Producer.php
vendored
212
vendor/amphp/amp/lib/Internal/Producer.php
vendored
@@ -1,212 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Amp\Internal;
|
||||
|
||||
use Amp\Deferred;
|
||||
use Amp\Failure;
|
||||
use Amp\Promise;
|
||||
use Amp\Success;
|
||||
use React\Promise\PromiseInterface as ReactPromise;
|
||||
|
||||
/**
|
||||
* Trait used by Iterator implementations. Do not use this trait in your code, instead compose your class from one of
|
||||
* the available classes implementing \Amp\Iterator.
|
||||
* Note that it is the responsibility of the user of this trait to ensure that listeners have a chance to listen first
|
||||
* before emitting values.
|
||||
*
|
||||
* @internal
|
||||
* @template-covariant TValue
|
||||
*/
|
||||
trait Producer
|
||||
{
|
||||
/** @var Promise|null */
|
||||
private $complete;
|
||||
|
||||
/** @var mixed[] */
|
||||
private $values = [];
|
||||
|
||||
/** @var Deferred[] */
|
||||
private $backPressure = [];
|
||||
|
||||
/** @var int */
|
||||
private $consumePosition = -1;
|
||||
|
||||
/** @var int */
|
||||
private $emitPosition = -1;
|
||||
|
||||
/** @var Deferred|null */
|
||||
private $waiting;
|
||||
|
||||
/** @var null|array */
|
||||
private $resolutionTrace;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @return Promise<bool>
|
||||
*/
|
||||
public function advance(): Promise
|
||||
{
|
||||
if ($this->waiting !== null) {
|
||||
throw new \Error("The prior promise returned must resolve before invoking this method again");
|
||||
}
|
||||
|
||||
unset($this->values[$this->consumePosition]);
|
||||
|
||||
$position = ++$this->consumePosition;
|
||||
|
||||
if (\array_key_exists($position, $this->values)) {
|
||||
\assert(isset($this->backPressure[$position]));
|
||||
$deferred = $this->backPressure[$position];
|
||||
unset($this->backPressure[$position]);
|
||||
$deferred->resolve();
|
||||
|
||||
return new Success(true);
|
||||
}
|
||||
|
||||
if ($this->complete) {
|
||||
return $this->complete;
|
||||
}
|
||||
|
||||
$this->waiting = new Deferred;
|
||||
|
||||
return $this->waiting->promise();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @return TValue
|
||||
*/
|
||||
public function getCurrent()
|
||||
{
|
||||
if (empty($this->values) && $this->complete) {
|
||||
throw new \Error("The iterator has completed");
|
||||
}
|
||||
|
||||
if (!\array_key_exists($this->consumePosition, $this->values)) {
|
||||
throw new \Error("Promise returned from advance() must resolve before calling this method");
|
||||
}
|
||||
|
||||
return $this->values[$this->consumePosition];
|
||||
}
|
||||
|
||||
/**
|
||||
* Emits a value from the iterator. The returned promise is resolved once the emitted value has been consumed.
|
||||
*
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return Promise
|
||||
* @psalm-return Promise<null>
|
||||
*
|
||||
* @throws \Error If the iterator has completed.
|
||||
*/
|
||||
private function emit($value): Promise
|
||||
{
|
||||
if ($this->complete) {
|
||||
throw new \Error("Iterators cannot emit values after calling complete");
|
||||
}
|
||||
|
||||
if ($value instanceof ReactPromise) {
|
||||
$value = Promise\adapt($value);
|
||||
}
|
||||
|
||||
if ($value instanceof Promise) {
|
||||
$deferred = new Deferred;
|
||||
$value->onResolve(function ($e, $v) use ($deferred) {
|
||||
if ($this->complete) {
|
||||
$deferred->fail(
|
||||
new \Error("The iterator was completed before the promise result could be emitted")
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if ($e) {
|
||||
$this->fail($e);
|
||||
$deferred->fail($e);
|
||||
return;
|
||||
}
|
||||
|
||||
$deferred->resolve($this->emit($v));
|
||||
});
|
||||
|
||||
return $deferred->promise();
|
||||
}
|
||||
|
||||
$position = ++$this->emitPosition;
|
||||
|
||||
$this->values[$position] = $value;
|
||||
|
||||
if ($this->waiting !== null) {
|
||||
$waiting = $this->waiting;
|
||||
$this->waiting = null;
|
||||
$waiting->resolve(true);
|
||||
return new Success; // Consumer was already waiting for a new value, so back-pressure is unnecessary.
|
||||
}
|
||||
|
||||
$this->backPressure[$position] = $pressure = new Deferred;
|
||||
|
||||
return $pressure->promise();
|
||||
}
|
||||
|
||||
/**
|
||||
* Completes the iterator.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws \Error If the iterator has already been completed.
|
||||
*/
|
||||
private function complete()
|
||||
{
|
||||
if ($this->complete) {
|
||||
$message = "Iterator has already been completed";
|
||||
|
||||
if (isset($this->resolutionTrace)) {
|
||||
$trace = formatStacktrace($this->resolutionTrace);
|
||||
$message .= ". Previous completion trace:\n\n{$trace}\n\n";
|
||||
} else {
|
||||
// @codeCoverageIgnoreStart
|
||||
$message .= ", define environment variable AMP_DEBUG or const AMP_DEBUG = true and enable assertions "
|
||||
. "for a stacktrace of the previous resolution.";
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
|
||||
throw new \Error($message);
|
||||
}
|
||||
|
||||
\assert((function () {
|
||||
$env = \getenv("AMP_DEBUG") ?: "0";
|
||||
if (($env !== "0" && $env !== "false") || (\defined("AMP_DEBUG") && \AMP_DEBUG)) {
|
||||
$trace = \debug_backtrace(\DEBUG_BACKTRACE_IGNORE_ARGS);
|
||||
\array_shift($trace); // remove current closure
|
||||
$this->resolutionTrace = $trace;
|
||||
}
|
||||
|
||||
return true;
|
||||
})());
|
||||
|
||||
$this->complete = new Success(false);
|
||||
|
||||
if ($this->waiting !== null) {
|
||||
$waiting = $this->waiting;
|
||||
$this->waiting = null;
|
||||
$waiting->resolve($this->complete);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Throwable $exception
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function fail(\Throwable $exception)
|
||||
{
|
||||
$this->complete = new Failure($exception);
|
||||
|
||||
if ($this->waiting !== null) {
|
||||
$waiting = $this->waiting;
|
||||
$this->waiting = null;
|
||||
$waiting->resolve($this->complete);
|
||||
}
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user