Fix remainder of unit test warnings in PHP 8.0

This commit is contained in:
Kijin Sung 2021-01-29 00:36:24 +09:00
parent e368cb2f2a
commit 334b1cc277
8 changed files with 30 additions and 19 deletions

View file

@ -114,8 +114,8 @@ class Password
{ {
if (class_exists('\MemberModel')) if (class_exists('\MemberModel'))
{ {
$config = \MemberModel::getInstance()->getMemberConfig(); $config = @\MemberModel::getInstance()->getMemberConfig();
$algorithm = $config->password_hashing_algorithm; $algorithm = $config->password_hashing_algorithm ?? '';
if (strval($algorithm) === '') if (strval($algorithm) === '')
{ {
$algorithm = 'md5'; $algorithm = 'md5';
@ -137,8 +137,8 @@ class Password
{ {
if (class_exists('\MemberModel')) if (class_exists('\MemberModel'))
{ {
$config = \MemberModel::getInstance()->getMemberConfig(); $config = @\MemberModel::getInstance()->getMemberConfig();
$work_factor = $config->password_hashing_work_factor; $work_factor = $config->password_hashing_work_factor ?? 10;
if (!$work_factor || $work_factor < 4 || $work_factor > 31) if (!$work_factor || $work_factor < 4 || $work_factor > 31)
{ {
$work_factor = 10; $work_factor = 10;

View file

@ -690,12 +690,12 @@ class SMS
} }
// If message subject is not supported, prepend it to the content instead. // If message subject is not supported, prepend it to the content instead.
if ($item->subject && !$spec[strtolower($item->type) . '_subject_supported']) if (isset($item->subject) && $item->subject && !$spec[strtolower($item->type) . '_subject_supported'])
{ {
$content = $item->subject . "\n" . $content; $content = $item->subject . "\n" . $content;
unset($item->subject); unset($item->subject);
} }
elseif ($item->subject && $this->_getLengthInCharset($item->subject, $spec[strtolower($item->type) . '_max_length_in_charset']) > $spec[strtolower($item->type) . '_subject_max_length']) elseif (isset($item->subject) && $item->subject && $this->_getLengthInCharset($item->subject, $spec[strtolower($item->type) . '_max_length_in_charset']) > $spec[strtolower($item->type) . '_subject_max_length'])
{ {
$subject_parts = $this->_splitString($item->subject, $spec[strtolower($item->type) . '_subject_max_length'], $spec[strtolower($item->type) . '_max_length_in_charset']); $subject_parts = $this->_splitString($item->subject, $spec[strtolower($item->type) . '_subject_max_length'], $spec[strtolower($item->type) . '_max_length_in_charset']);
$subject_short = array_shift($subject_parts); $subject_short = array_shift($subject_parts);
@ -750,7 +750,7 @@ class SMS
$cloneitem = clone $item; $cloneitem = clone $item;
// Determine the best message type for this part. // Determine the best message type for this part.
if ($cloneitem->type !== 'SMS' && !$cloneitem->subject) if ($cloneitem->type !== 'SMS' && (!isset($cloneitem->subject) || !$cloneitem->subject))
{ {
$cloneitem->type = $attachment ? 'MMS' : ($this->_getLengthInCharset($content_part, $spec['sms_max_length_in_charset']) > $spec['sms_max_length'] ? 'LMS' : 'SMS'); $cloneitem->type = $attachment ? 'MMS' : ($this->_getLengthInCharset($content_part, $spec['sms_max_length_in_charset']) > $spec['sms_max_length'] ? 'LMS' : 'SMS');
} }

View file

@ -38,7 +38,7 @@ class Advanced_MailerController extends Advanced_Mailer
$mail->setReplyTo($replyTo); $mail->setReplyTo($replyTo);
} }
} }
elseif (toBool($config->force_sender)) elseif (toBool($config->force_sender ?? 'N'))
{ {
if (stripos($mail->driver->getName(), 'woorimail') !== false && config('mail.woorimail.api_type') === 'free') if (stripos($mail->driver->getName(), 'woorimail') !== false && config('mail.woorimail.api_type') === 'free')
{ {
@ -66,7 +66,7 @@ class Advanced_MailerController extends Advanced_Mailer
{ {
$config = $this->getConfig(); $config = $this->getConfig();
if (toBool($config->log_sent_mail) || (toBool($config->log_errors) && count($mail->errors))) if (toBool($config->log_sent_mail ?? 'N') || (toBool($config->log_errors ?? 'N') && count($mail->errors)))
{ {
$obj = new \stdClass(); $obj = new \stdClass();
$obj->mail_from = ''; $obj->mail_from = '';
@ -182,7 +182,7 @@ class Advanced_MailerController extends Advanced_Mailer
{ {
$config = $this->getConfig(); $config = $this->getConfig();
if (toBool($config->log_sent_sms) || (toBool($config->log_sms_errors) && count($sms->errors))) if (toBool($config->log_sent_sms ?? 'N') || (toBool($config->log_sms_errors ?? 'N') && count($sms->errors)))
{ {
$obj = new \stdClass(); $obj = new \stdClass();
$obj->sms_from = $sms->getFrom(); $obj->sms_from = $sms->getFrom();
@ -219,7 +219,7 @@ class Advanced_MailerController extends Advanced_Mailer
{ {
$config = $this->getConfig(); $config = $this->getConfig();
if (toBool($config->log_sent_push) || (toBool($config->log_push_errors) && count($push->getErrors()))) if (toBool($config->log_sent_push ?? 'N') || (toBool($config->log_push_errors ?? 'N') && count($push->getErrors())))
{ {
$obj = new \stdClass(); $obj = new \stdClass();
$obj->push_from = $push->getFrom(); $obj->push_from = $push->getFrom();

View file

@ -1,2 +1,2 @@
<?php <?php
// Here you can initialize variables that will be available to your tests // Here you can initialize variables that will be available to your tests

View file

@ -46,7 +46,9 @@ class ContextTest extends \Codeception\TestCase\Test
$data->var2 = 'val2'; $data->var2 = 'val2';
$this->assertEquals(Context::gets('var1','var2'), $data); $this->assertEquals(Context::gets('var1','var2'), $data);
$data->var3 = 'val3'; $data->var3 = 'val3';
$this->assertEquals(Context::getAll(), $data); $this->assertEquals('val1', Context::getAll()->var1);
$this->assertEquals('val2', Context::getAll()->var2);
$this->assertEquals('val3', Context::getAll()->var3);
} }
public function testAddGetBodyClass() public function testAddGetBodyClass()

View file

@ -5,8 +5,6 @@ class ValidatorTest extends \Codeception\TestCase\Test
public function _before() public function _before()
{ {
$ob_level = ob_get_level(); $ob_level = ob_get_level();
Context::init();
while (ob_get_level() > $ob_level) while (ob_get_level() > $ob_level)
{ {
ob_end_clean(); ob_end_clean();

View file

@ -9,6 +9,7 @@ class DateTimeTest extends \Codeception\TestCase\Test
// Add some dummy data to system configuration. Asia/Seoul offset is 32400. // Add some dummy data to system configuration. Asia/Seoul offset is 32400.
Rhymix\Framework\Config::set('locale.default_timezone', 'Asia/Seoul'); Rhymix\Framework\Config::set('locale.default_timezone', 'Asia/Seoul');
Rhymix\Framework\Config::set('locale.internal_timezone', 10800); Rhymix\Framework\Config::set('locale.internal_timezone', 10800);
Context::set('_default_timezone', $GLOBALS['_time_zone'] = 'Asia/Seoul');
// Set PHP time zone to the internal time zone. // Set PHP time zone to the internal time zone.
$this->old_timezone = @date_default_timezone_get(); $this->old_timezone = @date_default_timezone_get();
@ -17,6 +18,11 @@ class DateTimeTest extends \Codeception\TestCase\Test
public function _after() public function _after()
{ {
// Restore the default and internal timezone.
Rhymix\Framework\Config::set('locale.default_timezone', 'Asia/Seoul');
Rhymix\Framework\Config::set('locale.internal_timezone', 10800);
Context::set('_default_timezone', $GLOBALS['_time_zone'] = 'Asia/Seoul');
// Restore the old timezone. // Restore the old timezone.
date_default_timezone_set($this->old_timezone); date_default_timezone_set($this->old_timezone);
} }

View file

@ -2,6 +2,11 @@
class SMSTest extends \Codeception\TestCase\Test class SMSTest extends \Codeception\TestCase\Test
{ {
public function _before()
{
Context::init();
}
public function testGetSetDefaultDriver() public function testGetSetDefaultDriver()
{ {
$driver = Rhymix\Framework\SMS::getDefaultDriver(); $driver = Rhymix\Framework\SMS::getDefaultDriver();
@ -188,7 +193,7 @@ class SMSTest extends \Codeception\TestCase\Test
$sms->send(); $sms->send();
$messages = $driver->getSentMessages(); $messages = $driver->getSentMessages();
$this->assertEquals('01099998888', count($messages) ? $messages[0]->from : ''); $this->assertEquals('01099998888', $messages[0]->from);
config('sms.default_force', false); config('sms.default_force', false);
@ -329,7 +334,7 @@ class SMSTest extends \Codeception\TestCase\Test
$messages = $driver->getSentMessages(); $messages = $driver->getSentMessages();
$this->assertEquals(2, count($messages)); $this->assertEquals(2, count($messages));
$this->assertEquals($message[0]->to, $message[1]->to); $this->assertEquals($messages[0]->to, $messages[1]->to);
$this->assertEquals('MMS', $messages[0]->type); $this->assertEquals('MMS', $messages[0]->type);
$this->assertEquals('MMS', $messages[1]->type); $this->assertEquals('MMS', $messages[1]->type);
$this->assertEquals('MMS 내용입니다.', $messages[0]->content); $this->assertEquals('MMS 내용입니다.', $messages[0]->content);
@ -394,8 +399,8 @@ class SMSTest extends \Codeception\TestCase\Test
$this->assertEquals(\RX_BASEDIR . 'tests/_data/images/rhymix.png', $messages[0]->image); $this->assertEquals(\RX_BASEDIR . 'tests/_data/images/rhymix.png', $messages[0]->image);
$this->assertEquals(\RX_BASEDIR . 'tests/_output/rhymix-copy-1.png', $messages[1]->image); $this->assertEquals(\RX_BASEDIR . 'tests/_output/rhymix-copy-1.png', $messages[1]->image);
$this->assertEquals(\RX_BASEDIR . 'tests/_output/rhymix-copy-2.png', $messages[2]->image); $this->assertEquals(\RX_BASEDIR . 'tests/_output/rhymix-copy-2.png', $messages[2]->image);
$this->assertNull($messages[3]->image); $this->assertNull($messages[3]->image ?? null);
$this->assertNull($messages[4]->image); $this->assertNull($messages[4]->image ?? null);
// Test MMS with no text content. // Test MMS with no text content.
$driver->resetSentMessages(); $driver->resetSentMessages();