Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ffdd45e32a |
@@ -7,6 +7,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace tests;
|
namespace tests;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -274,7 +275,6 @@ final class CoreLibsCombinedArrayHandlerTest extends TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO: create provider for n array merge
|
|
||||||
* provides array listing for the merge test
|
* provides array listing for the merge test
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
@@ -282,6 +282,61 @@ final class CoreLibsCombinedArrayHandlerTest extends TestCase
|
|||||||
public function arrayMergeRecursiveProvider(): array
|
public function arrayMergeRecursiveProvider(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
// 0: expected
|
||||||
|
// 1..n: to merge arrays
|
||||||
|
// n+1: trigger for handle keys as string
|
||||||
|
'two arrays' => [
|
||||||
|
['a' => 1, 'b' => 2, 'c' => 3],
|
||||||
|
['a' => 1, 'b' => 2],
|
||||||
|
['b' => 2, 'c' => 3],
|
||||||
|
],
|
||||||
|
'two arrays, string flag' => [
|
||||||
|
['a' => 1, 'b' => 2, 'c' => 3],
|
||||||
|
['a' => 1, 'b' => 2],
|
||||||
|
['b' => 2, 'c' => 3],
|
||||||
|
true,
|
||||||
|
],
|
||||||
|
// non hash arrays
|
||||||
|
'non hash array merge, no string flag' => [
|
||||||
|
[3, 4, 5],
|
||||||
|
[1, 2, 3],
|
||||||
|
[3, 4, 5],
|
||||||
|
],
|
||||||
|
'non hash array merge, string flag' => [
|
||||||
|
[1, 2, 3, 3, 4, 5],
|
||||||
|
[1, 2, 3],
|
||||||
|
[3, 4, 5],
|
||||||
|
true
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* for warning checks
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function arrayMergeRecursiveProviderWarning(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
// error <2 arguments
|
||||||
|
'too view arguments' => [
|
||||||
|
'arrayMergeRecursive needs two or more array arguments',
|
||||||
|
[1]
|
||||||
|
],
|
||||||
|
// error <2 arrays
|
||||||
|
'only one array' => [
|
||||||
|
'arrayMergeRecursive needs two or more array arguments',
|
||||||
|
[1],
|
||||||
|
true,
|
||||||
|
],
|
||||||
|
// error element is not array
|
||||||
|
'non array between array' => [
|
||||||
|
'arrayMergeRecursive encountered a non array argument',
|
||||||
|
[1],
|
||||||
|
'string',
|
||||||
|
[2]
|
||||||
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -626,21 +681,43 @@ final class CoreLibsCombinedArrayHandlerTest extends TestCase
|
|||||||
* Undocumented function
|
* Undocumented function
|
||||||
*
|
*
|
||||||
* @covers ::arrayMergeRecursive
|
* @covers ::arrayMergeRecursive
|
||||||
* @#dataProvider arrayMergeRecursiveProvider
|
* @dataProvider arrayMergeRecursiveProvider
|
||||||
* @testdox arrayMergeRecursive ... will be $expected [$_dataName]
|
* @testdox arrayMergeRecursive ... [$_dataName]
|
||||||
*
|
*
|
||||||
* @param array $input nested array set as each parameter
|
|
||||||
* @param bool $flag
|
|
||||||
* @param bool|array $expected
|
|
||||||
* @return void
|
* @return void
|
||||||
* array $input, bool $flag, $expected
|
*
|
||||||
*/
|
*/
|
||||||
public function testArrayMergeRecursive(): void
|
public function testArrayMergeRecursive(): void
|
||||||
{
|
{
|
||||||
$this->assertTrue(true, 'Implement proper test run');
|
$arrays = func_get_args();
|
||||||
$this->markTestIncomplete(
|
// first is expected array, always
|
||||||
'testArrayMergeRecursive has not been implemented yet.'
|
$expected = array_shift($arrays);
|
||||||
|
$output = \CoreLibs\Combined\ArrayHandler::arrayMergeRecursive(
|
||||||
|
...$arrays
|
||||||
);
|
);
|
||||||
|
$this->assertEquals(
|
||||||
|
$expected,
|
||||||
|
$output
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @covers ::arrayMergeRecursive
|
||||||
|
* @dataProvider arrayMergeRecursiveProviderWarning
|
||||||
|
* @testdox arrayMergeRecursive with E_USER_WARNING [$_dataName]
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testArrayMergeRecursiveWarningA(): void
|
||||||
|
{
|
||||||
|
$arrays = func_get_args();
|
||||||
|
// first is expected warning
|
||||||
|
$warning = array_shift($arrays);
|
||||||
|
$this->expectWarning();
|
||||||
|
$this->expectWarningMessage($warning);
|
||||||
|
\CoreLibs\Combined\ArrayHandler::arrayMergeRecursive(...$arrays);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -68,6 +68,7 @@ final class CoreLibsCreateSessionTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testStartSession(string $input, string $type, $expected_n, $expected_i): void
|
public function testStartSession(string $input, string $type, $expected_n, $expected_i): void
|
||||||
{
|
{
|
||||||
|
// NEEDS MOCKING
|
||||||
/* $session_id = '';
|
/* $session_id = '';
|
||||||
switch ($type) {
|
switch ($type) {
|
||||||
case 'p':
|
case 'p':
|
||||||
@@ -97,7 +98,8 @@ final class CoreLibsCreateSessionTest extends TestCase
|
|||||||
if ($type == 'g') {
|
if ($type == 'g') {
|
||||||
unset($GLOBALS['SET_SESSION_NAME']);
|
unset($GLOBALS['SET_SESSION_NAME']);
|
||||||
} */
|
} */
|
||||||
$this->markTestSkipped('No implementation for Create\Session. Cannot run session_start in CLI');
|
$this->markTestSkipped('[CoreLibsCreateSessionTest] No implementation '
|
||||||
|
. 'for Create\Session. Cannot run session_start in CLI');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -54,14 +54,16 @@ final class CoreLibsDebugLoggingTest extends TestCase
|
|||||||
'no options set, constant set' => [
|
'no options set, constant set' => [
|
||||||
null,
|
null,
|
||||||
[
|
[
|
||||||
'log_folder' => '/tmp/',
|
'log_folder' => str_replace('/configs', '', __DIR__)
|
||||||
|
. DIRECTORY_SEPARATOR . 'log/',
|
||||||
'debug_all' => false,
|
'debug_all' => false,
|
||||||
'print_all' => false,
|
'print_all' => false,
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'constant' => [
|
'constant' => [
|
||||||
'BASE' => '/tmp',
|
'BASE' => str_replace('/configs', '', __DIR__)
|
||||||
'LOG' => '/'
|
. DIRECTORY_SEPARATOR,
|
||||||
|
'LOG' => 'log/'
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -22,17 +22,36 @@ final class CoreLibsLanguageGetLocaleTest extends TestCase
|
|||||||
public static function setUpBeforeClass(): void
|
public static function setUpBeforeClass(): void
|
||||||
{
|
{
|
||||||
// default web page encoding setting
|
// default web page encoding setting
|
||||||
define('DEFAULT_ENCODING', 'UTF-8');
|
if (!defined('DEFAULT_ENCODING')) {
|
||||||
// default lang + encoding
|
define('DEFAULT_ENCODING', 'UTF-8');
|
||||||
define('DEFAULT_LOCALE', 'en_US.UTF-8');
|
}
|
||||||
|
if (!defined('DEFAULT_LOCALE')) {
|
||||||
|
// default lang + encoding
|
||||||
|
define('DEFAULT_LOCALE', 'en_US.UTF-8');
|
||||||
|
}
|
||||||
// site
|
// site
|
||||||
define('SITE_ENCODING', DEFAULT_ENCODING);
|
if (!defined('SITE_ENCODING')) {
|
||||||
define('SITE_LOCALE', DEFAULT_LOCALE);
|
define('SITE_ENCODING', DEFAULT_ENCODING);
|
||||||
|
}
|
||||||
|
if (!defined('SITE_LOCALE')) {
|
||||||
|
define('SITE_LOCALE', DEFAULT_LOCALE);
|
||||||
|
}
|
||||||
// just set
|
// just set
|
||||||
define('BASE', str_replace('/configs', '', __DIR__) . DIRECTORY_SEPARATOR);
|
if (!defined('BASE')) {
|
||||||
define('INCLUDES', 'includes' . DIRECTORY_SEPARATOR);
|
define('BASE', str_replace('/configs', '', __DIR__) . DIRECTORY_SEPARATOR);
|
||||||
define('LOCALE', 'locale' . DIRECTORY_SEPARATOR);
|
}
|
||||||
define('CONTENT_PATH', 'frontend' . 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
|
// array session
|
||||||
$_SESSION = [];
|
$_SESSION = [];
|
||||||
global $_SESSION;
|
global $_SESSION;
|
||||||
|
|||||||
@@ -22,19 +22,37 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public static function setUpBeforeClass(): void
|
public static function setUpBeforeClass(): void
|
||||||
{
|
{
|
||||||
define('DEFAULT_LANG', 'en_US');
|
|
||||||
// default web page encoding setting
|
// default web page encoding setting
|
||||||
define('DEFAULT_ENCODING', 'UTF-8');
|
if (!defined('DEFAULT_ENCODING')) {
|
||||||
// default lang + encoding
|
define('DEFAULT_ENCODING', 'UTF-8');
|
||||||
define('DEFAULT_LOCALE', 'en_US.UTF-8');
|
}
|
||||||
|
if (!defined('DEFAULT_LOCALE')) {
|
||||||
|
// default lang + encoding
|
||||||
|
define('DEFAULT_LOCALE', 'en_US.UTF-8');
|
||||||
|
}
|
||||||
// site
|
// site
|
||||||
define('SITE_LANG', DEFAULT_LANG);
|
if (!defined('SITE_ENCODING')) {
|
||||||
|
define('SITE_ENCODING', DEFAULT_ENCODING);
|
||||||
|
}
|
||||||
|
if (!defined('SITE_LOCALE')) {
|
||||||
|
define('SITE_LOCALE', DEFAULT_LOCALE);
|
||||||
|
}
|
||||||
// just set
|
// just set
|
||||||
define('BASE', str_replace('/configs', '', __DIR__) . DIRECTORY_SEPARATOR);
|
if (!defined('BASE')) {
|
||||||
define('INCLUDES', 'includes' . DIRECTORY_SEPARATOR);
|
define('BASE', str_replace('/configs', '', __DIR__) . DIRECTORY_SEPARATOR);
|
||||||
define('LANG', 'lang' . DIRECTORY_SEPARATOR);
|
}
|
||||||
define('LOCALE', 'locale' . DIRECTORY_SEPARATOR);
|
if (!defined('INCLUDES')) {
|
||||||
define('CONTENT_PATH', 'frontend' . DIRECTORY_SEPARATOR);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -218,7 +218,8 @@ class ArrayHandler
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
foreach ($array as $key => $value) {
|
foreach ($array as $key => $value) {
|
||||||
// if string or if key is assumed to be string do key match else add new entry
|
// if string or if key is assumed to be string do key match
|
||||||
|
// else add new entry
|
||||||
if (is_string($key) || $key_is_string === false) {
|
if (is_string($key) || $key_is_string === false) {
|
||||||
if (is_array($value) && array_key_exists($key, $merged) && is_array($merged[$key])) {
|
if (is_array($value) && array_key_exists($key, $merged) && is_array($merged[$key])) {
|
||||||
// $merged[$key] = call_user_func(__METHOD__, $merged[$key], $value, $key_is_string);
|
// $merged[$key] = call_user_func(__METHOD__, $merged[$key], $value, $key_is_string);
|
||||||
|
|||||||
Reference in New Issue
Block a user