Fixed more Exceptions to be not Errors but Exceptions
DateTime, Session, FileWrite, Image, SymmetricEncryption phpunit tests updated, run checks added
This commit is contained in:
@@ -309,41 +309,49 @@ final class CoreLibsCombinedDateTimeTest extends TestCase
|
||||
'2020-12-12',
|
||||
'2021-12-12',
|
||||
-1,
|
||||
null,
|
||||
],
|
||||
'dates equal' => [
|
||||
'2020-12-12',
|
||||
'2020-12-12',
|
||||
0,
|
||||
null,
|
||||
],
|
||||
'second date smaller' => [
|
||||
'2021-12-12',
|
||||
'2020-12-12',
|
||||
1
|
||||
1,
|
||||
null,
|
||||
],
|
||||
'dates equal with different time' => [
|
||||
'2020-12-12 12:12:12',
|
||||
'2020-12-12 13:13:13',
|
||||
0,
|
||||
null,
|
||||
],
|
||||
'invalid dates --' => [
|
||||
'--',
|
||||
'--',
|
||||
false
|
||||
false,
|
||||
'UnexpectedValueException',
|
||||
],
|
||||
'empty dates' => [
|
||||
'',
|
||||
'',
|
||||
false
|
||||
false,
|
||||
'UnexpectedValueException'
|
||||
],
|
||||
'invalid dates' => [
|
||||
'not a date',
|
||||
'not a date either',
|
||||
false,
|
||||
'UnexpectedValueException'
|
||||
],
|
||||
'out of bound dates' => [
|
||||
'1900-1-1',
|
||||
'9999-12-31',
|
||||
-1
|
||||
-1,
|
||||
null,
|
||||
]
|
||||
];
|
||||
}
|
||||
@@ -355,51 +363,61 @@ final class CoreLibsCombinedDateTimeTest extends TestCase
|
||||
'2020-12-12',
|
||||
'2021-12-12',
|
||||
-1,
|
||||
null,
|
||||
],
|
||||
'dates equal no timestamp' => [
|
||||
'2020-12-12',
|
||||
'2020-12-12',
|
||||
0,
|
||||
null,
|
||||
],
|
||||
'second date smaller no timestamp' => [
|
||||
'2021-12-12',
|
||||
'2020-12-12',
|
||||
1
|
||||
1,
|
||||
null,
|
||||
],
|
||||
'date equal first time smaller' => [
|
||||
'2020-12-12 12:12:12',
|
||||
'2020-12-12 13:13:13',
|
||||
-1,
|
||||
null,
|
||||
],
|
||||
'date equal time equal' => [
|
||||
'2020-12-12 12:12:12',
|
||||
'2020-12-12 12:12:12',
|
||||
0,
|
||||
null,
|
||||
],
|
||||
'date equal second time smaller' => [
|
||||
'2020-12-12 13:13:13',
|
||||
'2020-12-12 12:12:12',
|
||||
1,
|
||||
null,
|
||||
],
|
||||
'valid date invalid time' => [
|
||||
'2020-12-12 13:99:13',
|
||||
'2020-12-12 12:12:99',
|
||||
false,
|
||||
'UnexpectedValueException'
|
||||
],
|
||||
'invalid datetimes --' => [
|
||||
'--',
|
||||
'--',
|
||||
false,
|
||||
'UnexpectedValueException'
|
||||
],
|
||||
'empty datetimess' => [
|
||||
'',
|
||||
'',
|
||||
false,
|
||||
'UnexpectedValueException'
|
||||
],
|
||||
'invalid datetimes' => [
|
||||
'not a date',
|
||||
'not a date either',
|
||||
false,
|
||||
'UnexpectedValueException'
|
||||
],
|
||||
];
|
||||
}
|
||||
@@ -616,8 +634,11 @@ final class CoreLibsCombinedDateTimeTest extends TestCase
|
||||
* @param int|bool $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testCompareDate(string $input_a, string $input_b, $expected): void
|
||||
public function testCompareDate(string $input_a, string $input_b, int|bool $expected, ?string $exception): void
|
||||
{
|
||||
if ($expected === false) {
|
||||
$this->expectException($exception);
|
||||
}
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Combined\DateTime::compareDate($input_a, $input_b)
|
||||
@@ -636,8 +657,11 @@ final class CoreLibsCombinedDateTimeTest extends TestCase
|
||||
* @param int|bool $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testCompareDateTime(string $input_a, string $input_b, $expected): void
|
||||
public function testCompareDateTime(string $input_a, string $input_b, int|bool $expected, ?string $exception): void
|
||||
{
|
||||
if ($expected === false) {
|
||||
$this->expectException($exception);
|
||||
}
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Combined\DateTime::compareDateTime($input_a, $input_b)
|
||||
|
||||
@@ -30,8 +30,9 @@ 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: Exception thrown on error
|
||||
// 5: expected error string
|
||||
return [
|
||||
'session parameter' => [
|
||||
'sessionNameParameter',
|
||||
@@ -44,7 +45,8 @@ final class CoreLibsCreateSessionTest extends TestCase
|
||||
'getSessionId' => '1234abcd4567'
|
||||
],
|
||||
'sessionNameParameter',
|
||||
''
|
||||
null,
|
||||
'',
|
||||
],
|
||||
'session globals' => [
|
||||
'sessionNameGlobals',
|
||||
@@ -57,7 +59,8 @@ final class CoreLibsCreateSessionTest extends TestCase
|
||||
'getSessionId' => '1234abcd4567'
|
||||
],
|
||||
'sessionNameGlobals',
|
||||
''
|
||||
null,
|
||||
'',
|
||||
],
|
||||
'session name default' => [
|
||||
'',
|
||||
@@ -70,7 +73,8 @@ final class CoreLibsCreateSessionTest extends TestCase
|
||||
'getSessionId' => '1234abcd4567'
|
||||
],
|
||||
'',
|
||||
''
|
||||
null,
|
||||
'',
|
||||
],
|
||||
// error checks
|
||||
// 1: we are in cli
|
||||
@@ -85,6 +89,7 @@ final class CoreLibsCreateSessionTest extends TestCase
|
||||
'getSessionId' => '1234abcd4567'
|
||||
],
|
||||
'',
|
||||
'RuntimeException',
|
||||
'[SESSION] No sessions in php cli'
|
||||
],
|
||||
// 2: session disabled
|
||||
@@ -99,6 +104,7 @@ final class CoreLibsCreateSessionTest extends TestCase
|
||||
'getSessionId' => '1234abcd4567'
|
||||
],
|
||||
'',
|
||||
'RuntimeException',
|
||||
'[SESSION] Sessions are disabled'
|
||||
],
|
||||
// 3: invalid session name: string
|
||||
@@ -113,6 +119,7 @@ final class CoreLibsCreateSessionTest extends TestCase
|
||||
'getSessionId' => '1234abcd4567'
|
||||
],
|
||||
'',
|
||||
'UnexpectedValueException',
|
||||
'[SESSION] Invalid session name: 1invalid$session#;'
|
||||
],
|
||||
// 3: invalid session name: only numbers
|
||||
@@ -127,6 +134,7 @@ final class CoreLibsCreateSessionTest extends TestCase
|
||||
'getSessionId' => '1234abcd4567'
|
||||
],
|
||||
'',
|
||||
'UnexpectedValueException',
|
||||
'[SESSION] Invalid session name: 123'
|
||||
],
|
||||
// 3: invalid session name: invalid name short
|
||||
@@ -143,6 +151,7 @@ final class CoreLibsCreateSessionTest extends TestCase
|
||||
'getSessionId' => '1234abcd4567'
|
||||
],
|
||||
'',
|
||||
'RuntimeException',
|
||||
'[SESSION] Failed to activate session'
|
||||
],
|
||||
// 5: get session id return false
|
||||
@@ -157,6 +166,7 @@ final class CoreLibsCreateSessionTest extends TestCase
|
||||
'getSessionId' => false
|
||||
],
|
||||
'',
|
||||
'UnexpectedValueException',
|
||||
'[SESSION] getSessionId did not return a session id'
|
||||
],
|
||||
];
|
||||
@@ -173,6 +183,7 @@ final class CoreLibsCreateSessionTest extends TestCase
|
||||
* @param string $type
|
||||
* @param array<mixed> $mock_data
|
||||
* @param string $expected
|
||||
* @param string|null $exception
|
||||
* @param string $expected_error
|
||||
* @return void
|
||||
*/
|
||||
@@ -181,6 +192,7 @@ final class CoreLibsCreateSessionTest extends TestCase
|
||||
string $type,
|
||||
array $mock_data,
|
||||
string $expected,
|
||||
?string $exception,
|
||||
string $expected_error
|
||||
): void {
|
||||
// override expected
|
||||
@@ -224,6 +236,10 @@ final class CoreLibsCreateSessionTest extends TestCase
|
||||
// regex for session id
|
||||
$ression_id_regex = "/^\w+$/";
|
||||
|
||||
if ($exception !== null) {
|
||||
$this->expectException($exception);
|
||||
}
|
||||
|
||||
unset($GLOBALS['SET_SESSION_NAME']);
|
||||
$session_id = '';
|
||||
switch ($type) {
|
||||
@@ -253,13 +269,6 @@ final class CoreLibsCreateSessionTest extends TestCase
|
||||
$expected,
|
||||
$session_mock->getSessionName()
|
||||
);
|
||||
} else {
|
||||
// false checks
|
||||
$this->assertEquals(
|
||||
$expected_error,
|
||||
$session_mock->getErrorStr(),
|
||||
'error assert'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user