diff --git a/.ddev/commands/web/phpunit b/.ddev/commands/web/phpunit index 3ff16280ac0..688d9dc33a8 100755 --- a/.ddev/commands/web/phpunit +++ b/.ddev/commands/web/phpunit @@ -4,4 +4,4 @@ ## Usage: phpunit ## Example: ddev phpunit -php vendor/bin/phpunit --configuration .phpunit.dist.xml --no-coverage "$@" --testdox +php vendor/bin/phpunit --configuration .phpunit.dist.xml --no-coverage "$@" diff --git a/.ddev/commands/web/phpunit-coverage-local b/.ddev/commands/web/phpunit-coverage-local index 0e4ed542650..d039b9108f8 100755 --- a/.ddev/commands/web/phpunit-coverage-local +++ b/.ddev/commands/web/phpunit-coverage-local @@ -5,5 +5,5 @@ ## Example: ddev phpunit-coverage-local enable_xdebug -XDEBUG_MODE=coverage php vendor/bin/phpunit --configuration .phpunit.dist.xml --coverage-html build/coverage --testdox "$@" +XDEBUG_MODE=coverage php vendor/bin/phpunit --configuration .phpunit.dist.xml --coverage-html build/coverage "$@" disable_xdebug \ No newline at end of file diff --git a/.phpstan.dist.baseline.neon b/.phpstan.dist.baseline.neon index f1663f0ea35..664151c205a 100644 --- a/.phpstan.dist.baseline.neon +++ b/.phpstan.dist.baseline.neon @@ -912,12 +912,6 @@ parameters: count: 1 path: app/code/core/Mage/Adminhtml/controllers/Sales/Order/ShipmentController.php - - - message: '#^Parameter \#1 \$order of method Mage_Sales_Model_Resource_Order_Collection_Abstract\:\:setOrderFilter\(\) expects int\|Mage_Sales_Model_Order, array\ given\.$#' - identifier: argument.type - count: 1 - path: app/code/core/Mage/Adminhtml/controllers/Sales/Order/ShipmentController.php - - message: '#^Parameter \#1 \$prefix of function uniqid expects string, int\<0, max\> given\.$#' identifier: argument.type @@ -2730,24 +2724,6 @@ parameters: count: 1 path: app/code/core/Mage/CatalogRule/Model/Observer.php - - - message: '#^Parameter \#1 \$expression of class Zend_Db_Expr constructor expects string, float given\.$#' - identifier: argument.type - count: 2 - path: app/code/core/Mage/CatalogRule/Model/Resource/Rule.php - - - - message: '#^Parameter \#1 \$expression of class Zend_Db_Expr constructor expects string, int given\.$#' - identifier: argument.type - count: 3 - path: app/code/core/Mage/CatalogRule/Model/Resource/Rule.php - - - - message: '#^Parameter \#1 \$expression of class Zend_Db_Expr constructor expects string, int\<0, 86398\>\|int\<86400, max\> given\.$#' - identifier: argument.type - count: 1 - path: app/code/core/Mage/CatalogRule/Model/Resource/Rule.php - - message: '#^Variable \$indexAlias might not be defined\.$#' identifier: variable.undefined @@ -3252,24 +3228,6 @@ parameters: count: 1 path: app/code/core/Mage/Core/Model/Cookie.php - - - message: '#^Binary operation "\+" between string and string results in an error\.$#' - identifier: binaryOp.invalid - count: 1 - path: app/code/core/Mage/Core/Model/Date.php - - - - message: '#^Binary operation "\-" between string and string results in an error\.$#' - identifier: binaryOp.invalid - count: 1 - path: app/code/core/Mage/Core/Model/Date.php - - - - message: '#^Property Mage_Core_Model_Date\:\:\$_systemOffset is never read, only written\.$#' - identifier: property.onlyWritten - count: 1 - path: app/code/core/Mage/Core/Model/Date.php - - message: '#^Call to an undefined method Mage_Core_Model_Resource_Design\:\:validate\(\)\.$#' identifier: method.notFound @@ -5292,18 +5250,6 @@ parameters: count: 1 path: app/code/core/Mage/Reports/Block/Product/Abstract.php - - - message: '#^Variable \$dateStart might not be defined\.$#' - identifier: variable.undefined - count: 7 - path: app/code/core/Mage/Reports/Helper/Data.php - - - - message: '#^Variable \$t might not be defined\.$#' - identifier: variable.undefined - count: 1 - path: app/code/core/Mage/Reports/Helper/Data.php - - message: '#^Property Mage_Reports_Model_Grouped_Collection\:\:\$_resourceCollection \(Mage_Core_Model_Resource_Db_Collection_Abstract\) does not accept Varien_Data_Collection_Db\.$#' identifier: assign.propertyType @@ -5532,12 +5478,6 @@ parameters: count: 1 path: app/code/core/Mage/Rss/Helper/Data.php - - - message: '#^Property Mage_Rule_Model_Abstract\:\:\$_conditions \(Mage_Rule_Model_Condition_Combine\) in empty\(\) is not falsy\.$#' - identifier: empty.property - count: 1 - path: app/code/core/Mage/Rule/Model/Abstract.php - - message: '#^Parameter \#1 \$renderer of method Varien_Data_Form_Element_Abstract\:\:setRenderer\(\) expects Varien_Data_Form_Element_Renderer_Interface, Mage_Core_Block_Abstract\|false given\.$#' identifier: argument.type @@ -5652,12 +5592,6 @@ parameters: count: 1 path: app/code/core/Mage/Sales/Block/Recurring/Profiles.php - - - message: '#^Parameter \#1 \$order of method Mage_Sales_Model_Resource_Order_Collection_Abstract\:\:setOrderFilter\(\) expects int\|Mage_Sales_Model_Order, array given\.$#' - identifier: argument.type - count: 1 - path: app/code/core/Mage/Sales/Model/Api2/Order.php - - message: '#^Parameter \#2 \$code of method Mage_Api2_Model_Resource\:\:_critical\(\) expects int\|null, string given\.$#' identifier: argument.type @@ -10092,12 +10026,6 @@ parameters: count: 2 path: lib/Varien/Cache/Backend/Database.php - - - message: '#^Method Varien_Cache_Backend_Database\:\:touch\(\) should return bool but returns int\.$#' - identifier: return.type - count: 1 - path: lib/Varien/Cache/Backend/Database.php - - message: '#^Parameter \#2 \$chunks of method Varien_Cache_Backend_Memcached\:\:_cleanTheMess\(\) expects int, string given\.$#' identifier: argument.type diff --git a/.phpunit.dist.xml b/.phpunit.dist.xml index fad1f954416..80e4b28a695 100644 --- a/.phpunit.dist.xml +++ b/.phpunit.dist.xml @@ -17,6 +17,10 @@ + + + + tests/unit/Base diff --git a/.rector.php b/.rector.php index abcbbb4cb95..82042da4812 100644 --- a/.rector.php +++ b/.rector.php @@ -22,7 +22,8 @@ CodeQuality\BooleanNot\SimplifyDeMorganBinaryRector::class, CodeQuality\If_\SimplifyIfReturnBoolRector::class, __DIR__ . '/shell/translations.php', - __DIR__ . '/shell/update-copyright.php.php' + __DIR__ . '/shell/update-copyright.php.php', + __DIR__ . '/tests/unit/Mage/Reports/Model/Resource/Report/CollectionTest.php', ]) ->withRules([ CodeQuality\BooleanNot\ReplaceMultipleBooleanNotRector::class, @@ -51,12 +52,10 @@ false, false, false, - false, - false, true, false, + true, false, false, false, - true, - ); \ No newline at end of file + ); diff --git a/app/code/core/Mage/Admin/Model/Acl/Assert/Time.php b/app/code/core/Mage/Admin/Model/Acl/Assert/Time.php index 602a03c76fa..24dad070570 100644 --- a/app/code/core/Mage/Admin/Model/Acl/Assert/Time.php +++ b/app/code/core/Mage/Admin/Model/Acl/Assert/Time.php @@ -14,6 +14,8 @@ * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +use Carbon\Carbon; + /** * Assert time for admin acl * @@ -34,7 +36,7 @@ public function assert( ?Mage_Admin_Model_Acl_Resource $resource = null, $privilege = null ) { - return $this->_isCleanTime(time()); + return $this->_isCleanTime(Carbon::now()->getTimestamp()); } /** diff --git a/app/code/core/Mage/Admin/Model/Resource/User.php b/app/code/core/Mage/Admin/Model/Resource/User.php index 3ef0dfd67e1..89c2b2be937 100644 --- a/app/code/core/Mage/Admin/Model/Resource/User.php +++ b/app/code/core/Mage/Admin/Model/Resource/User.php @@ -14,6 +14,8 @@ * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +use Carbon\Carbon; + /** * ACL user resource * @@ -55,7 +57,7 @@ public function recordLogin(Mage_Admin_Model_User $user) $adapter = $this->_getWriteAdapter(); $data = [ - 'logdate' => Varien_Date::now(), + 'logdate' => Carbon::now()->format(Carbon::DEFAULT_TO_STRING_FORMAT), 'lognum' => $user->getLognum() + 1, ]; diff --git a/app/code/core/Mage/Admin/Model/User.php b/app/code/core/Mage/Admin/Model/User.php index 9655a4af4e9..2d5adad3825 100644 --- a/app/code/core/Mage/Admin/Model/User.php +++ b/app/code/core/Mage/Admin/Model/User.php @@ -14,6 +14,8 @@ * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +use Carbon\Carbon; + /** * Admin user model * @@ -678,7 +680,7 @@ public function changeResetPasswordLinkToken($newResetPasswordLinkToken) throw Mage::exception('Mage_Core', Mage::helper('adminhtml')->__('Invalid password reset token.')); } $this->setRpToken($newResetPasswordLinkToken); - $currentDate = Varien_Date::now(); + $currentDate = Carbon::now()->format(Carbon::DEFAULT_TO_STRING_FORMAT); $this->setRpTokenCreatedAt($currentDate); return $this; @@ -698,17 +700,14 @@ public function isResetPasswordLinkTokenExpired() return true; } - $tokenExpirationPeriod = Mage::helper('admin')->getResetPasswordLinkExpirationPeriod(); - - $currentDate = Varien_Date::now(); - $currentTimestamp = Varien_Date::toTimestamp($currentDate); - $tokenTimestamp = Varien_Date::toTimestamp($resetPasswordLinkTokenCreatedAt); + $currentTimestamp = Carbon::now(); + $tokenTimestamp = Carbon::now()->setTimeFromTimeString($resetPasswordLinkTokenCreatedAt); if ($tokenTimestamp > $currentTimestamp) { return true; } - $hoursDifference = floor(($currentTimestamp - $tokenTimestamp) / (60 * 60)); - if ($hoursDifference >= $tokenExpirationPeriod) { + $tokenExpirationPeriod = Mage::helper('admin')->getResetPasswordLinkExpirationPeriod(); + if ($currentTimestamp->diffInDays($tokenTimestamp) >= $tokenExpirationPeriod) { return true; } @@ -737,7 +736,8 @@ public function cleanPasswordsValidationData() */ protected function _getDateNow($dayOnly = false) { - return Varien_Date::now($dayOnly); + $format = $dayOnly ? Mage_Core_Helper_Date::DATE_PHP_FORMAT : Mage_Core_Helper_Date::DATETIME_PHP_FORMAT; + return Carbon::now()->format($format); } /** diff --git a/app/code/core/Mage/AdminNotification/Model/Feed.php b/app/code/core/Mage/AdminNotification/Model/Feed.php index 7b72d55b74d..cd4ea792aaf 100644 --- a/app/code/core/Mage/AdminNotification/Model/Feed.php +++ b/app/code/core/Mage/AdminNotification/Model/Feed.php @@ -14,6 +14,8 @@ * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +use Carbon\Carbon; + /** * AdminNotification Feed model * @@ -60,7 +62,7 @@ public function getFeedUrl() */ public function checkUpdate() { - if (($this->getFrequency() + $this->getLastUpdate()) > time()) { + if (($this->getFrequency() + $this->getLastUpdate()) > Carbon::now()->getTimestamp()) { return $this; } @@ -126,7 +128,7 @@ public function getLastUpdate() */ public function setLastUpdate() { - Mage::app()->saveCache(time(), 'admin_notifications_lastcheck'); + Mage::app()->saveCache(Carbon::now()->getTimestamp(), 'admin_notifications_lastcheck'); return $this; } diff --git a/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/View.php b/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/View.php index 781faa1f654..73bd56b4983 100644 --- a/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/View.php +++ b/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/View.php @@ -14,6 +14,8 @@ * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +use Carbon\Carbon; + /** * Customer account form block * @@ -144,7 +146,7 @@ public function getCurrentStatus() $log = $this->getCustomerLog(); if ($log->getLogoutAt() || !$log->getLastVisitAt() - || strtotime(Varien_Date::now()) - strtotime($log->getLastVisitAt()) > Mage_Log_Model_Visitor::getOnlineMinutesInterval() * 60 + || strtotime(Carbon::now()->format(Carbon::DEFAULT_TO_STRING_FORMAT)) - strtotime($log->getLastVisitAt()) > Mage_Log_Model_Visitor::getOnlineMinutesInterval() * 60 ) { return Mage::helper('customer')->__('Offline'); } diff --git a/app/code/core/Mage/Adminhtml/Block/Newsletter/Queue/Edit/Form.php b/app/code/core/Mage/Adminhtml/Block/Newsletter/Queue/Edit/Form.php index 1dcaa96808b..815be4698be 100644 --- a/app/code/core/Mage/Adminhtml/Block/Newsletter/Queue/Edit/Form.php +++ b/app/code/core/Mage/Adminhtml/Block/Newsletter/Queue/Edit/Form.php @@ -96,7 +96,7 @@ protected function _prepareForm() if ($queue->getQueueStartAt()) { $form->getElement('date')->setValue( - Mage::app()->getLocale()->date($queue->getQueueStartAt(), Varien_Date::DATETIME_INTERNAL_FORMAT), + Mage::app()->getLocale()->date($queue->getQueueStartAt(), Mage_Core_Helper_Date::DATETIME_INTERNAL_FORMAT), ); } diff --git a/app/code/core/Mage/Adminhtml/Block/Promo/Catalog/Edit/Tab/Main.php b/app/code/core/Mage/Adminhtml/Block/Promo/Catalog/Edit/Tab/Main.php index 2c109ffcc72..79f62f6b1d6 100644 --- a/app/code/core/Mage/Adminhtml/Block/Promo/Catalog/Edit/Tab/Main.php +++ b/app/code/core/Mage/Adminhtml/Block/Promo/Catalog/Edit/Tab/Main.php @@ -146,7 +146,7 @@ protected function _prepareForm() 'label' => Mage::helper('catalogrule')->__('From Date'), 'title' => Mage::helper('catalogrule')->__('From Date'), 'image' => $this->getSkinUrl('images/grid-cal.gif'), - 'input_format' => Varien_Date::DATE_INTERNAL_FORMAT, + 'input_format' => Mage_Core_Helper_Date::DATE_INTERNAL_FORMAT, 'format' => $dateFormatIso, ]); $fieldset->addField('to_date', 'date', [ @@ -154,7 +154,7 @@ protected function _prepareForm() 'label' => Mage::helper('catalogrule')->__('To Date'), 'title' => Mage::helper('catalogrule')->__('To Date'), 'image' => $this->getSkinUrl('images/grid-cal.gif'), - 'input_format' => Varien_Date::DATE_INTERNAL_FORMAT, + 'input_format' => Mage_Core_Helper_Date::DATE_INTERNAL_FORMAT, 'format' => $dateFormatIso, ]); diff --git a/app/code/core/Mage/Adminhtml/Block/Promo/Quote/Edit/Tab/Main.php b/app/code/core/Mage/Adminhtml/Block/Promo/Quote/Edit/Tab/Main.php index 6f37001f9a5..3fe076d6014 100644 --- a/app/code/core/Mage/Adminhtml/Block/Promo/Quote/Edit/Tab/Main.php +++ b/app/code/core/Mage/Adminhtml/Block/Promo/Quote/Edit/Tab/Main.php @@ -200,7 +200,7 @@ protected function _prepareForm() 'label' => Mage::helper('salesrule')->__('From Date'), 'title' => Mage::helper('salesrule')->__('From Date'), 'image' => $this->getSkinUrl('images/grid-cal.gif'), - 'input_format' => Varien_Date::DATE_INTERNAL_FORMAT, + 'input_format' => Mage_Core_Helper_Date::DATE_INTERNAL_FORMAT, 'format' => $dateFormatIso, ]); $fieldset->addField('to_date', 'date', [ @@ -208,7 +208,7 @@ protected function _prepareForm() 'label' => Mage::helper('salesrule')->__('To Date'), 'title' => Mage::helper('salesrule')->__('To Date'), 'image' => $this->getSkinUrl('images/grid-cal.gif'), - 'input_format' => Varien_Date::DATE_INTERNAL_FORMAT, + 'input_format' => Mage_Core_Helper_Date::DATE_INTERNAL_FORMAT, 'format' => $dateFormatIso, ]); diff --git a/app/code/core/Mage/Adminhtml/Block/Promo/Widget/Chooser/Daterange.php b/app/code/core/Mage/Adminhtml/Block/Promo/Widget/Chooser/Daterange.php index ca679414d85..d6d635a98c9 100644 --- a/app/code/core/Mage/Adminhtml/Block/Promo/Widget/Chooser/Daterange.php +++ b/app/code/core/Mage/Adminhtml/Block/Promo/Widget/Chooser/Daterange.php @@ -64,7 +64,7 @@ protected function _toHtml() ) { $id = "{$key}_{$idSuffix}"; $element = new Varien_Data_Form_Element_Date([ - 'format' => Varien_Date::DATE_INTERNAL_FORMAT, // hardcode because hardcoded values delimiter + 'format' => Mage_Core_Helper_Date::DATE_INTERNAL_FORMAT, // hardcode because hardcoded values delimiter 'label' => $label, 'image' => $this->getSkinUrl('images/grid-cal.gif'), 'onchange' => "dateTimeChoose_{$idSuffix}()", // won't work through Event.observe() diff --git a/app/code/core/Mage/Adminhtml/Block/Report/Config/Form/Field/YtdStart.php b/app/code/core/Mage/Adminhtml/Block/Report/Config/Form/Field/YtdStart.php index c4eac51cf82..c99f59a024e 100644 --- a/app/code/core/Mage/Adminhtml/Block/Report/Config/Form/Field/YtdStart.php +++ b/app/code/core/Mage/Adminhtml/Block/Report/Config/Form/Field/YtdStart.php @@ -14,6 +14,8 @@ * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +use Carbon\Carbon; + /** * Dashboard Year-To-Date Month and Day starts Field Renderer * @@ -27,7 +29,7 @@ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element) $_months = []; for ($i = 1; $i <= 12; $i++) { $_months[$i] = Mage::app()->getLocale() - ->date(mktime(0, 0, 0, $i)) + ->date(Carbon::now()->setHour(0)->setMinute(0)->setSecond(0)->setMonth($i)) ->get(Zend_Date::MONTH_NAME); } diff --git a/app/code/core/Mage/Adminhtml/Block/Report/Grid.php b/app/code/core/Mage/Adminhtml/Block/Report/Grid.php index d90c497488a..7c0adeacc8e 100644 --- a/app/code/core/Mage/Adminhtml/Block/Report/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Report/Grid.php @@ -14,6 +14,8 @@ * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +use Carbon\Carbon; + /** * Adminhtml report grid block * @@ -112,10 +114,11 @@ protected function _prepareColumns() /** * @return $this + * @throws Zend_Date_Exception */ protected function _prepareCollection() { - $filter = $this->getParam($this->getVarNameFilter(), null); + $filter = $this->getParam($this->getVarNameFilter()); if (is_null($filter)) { $filter = $this->_defaultFilter; @@ -128,7 +131,13 @@ protected function _prepareCollection() if (!isset($data['report_from'])) { // getting all reports from 2001 year - $date = new Zend_Date(mktime(0, 0, 0, 1, 1, 2001)); + $date = new Zend_Date(Carbon::now() + ->setHour(0) + ->setMinute(0) + ->setSecond(0) + ->setMonth(1) + ->setYear(2001)); + $data['report_from'] = $date->toString($this->getLocale()->getDateFormat('short')); } diff --git a/app/code/core/Mage/Adminhtml/Block/Report/Refresh/Statistics/Grid.php b/app/code/core/Mage/Adminhtml/Block/Report/Refresh/Statistics/Grid.php index 7917e063b08..2974cfe2806 100644 --- a/app/code/core/Mage/Adminhtml/Block/Report/Refresh/Statistics/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Report/Refresh/Statistics/Grid.php @@ -43,7 +43,7 @@ protected function _getUpdatedAt($reportCode) return ($flag->hasData()) ? Mage::app()->getLocale()->storeDate( 0, - new Zend_Date($flag->getLastUpdate(), Varien_Date::DATETIME_INTERNAL_FORMAT), + new Zend_Date($flag->getLastUpdate(), Mage_Core_Helper_Date::DATETIME_INTERNAL_FORMAT), true, ) : ''; diff --git a/app/code/core/Mage/Adminhtml/Block/Report/Sales/Grid/Column/Renderer/Date.php b/app/code/core/Mage/Adminhtml/Block/Report/Sales/Grid/Column/Renderer/Date.php index cf4c89b573f..50476dcde5a 100644 --- a/app/code/core/Mage/Adminhtml/Block/Report/Sales/Grid/Column/Renderer/Date.php +++ b/app/code/core/Mage/Adminhtml/Block/Report/Sales/Grid/Column/Renderer/Date.php @@ -74,7 +74,7 @@ public function render(Varien_Object $row) $dateFormat = 'yyyy'; break; default: - $dateFormat = Varien_Date::DATE_INTERNAL_FORMAT; + $dateFormat = Mage_Core_Helper_Date::DATE_INTERNAL_FORMAT; break; } diff --git a/app/code/core/Mage/Adminhtml/Block/Sitemap/Grid/Renderer/Time.php b/app/code/core/Mage/Adminhtml/Block/Sitemap/Grid/Renderer/Time.php index 62dd3f24ab7..839d493d9b4 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sitemap/Grid/Renderer/Time.php +++ b/app/code/core/Mage/Adminhtml/Block/Sitemap/Grid/Renderer/Time.php @@ -30,7 +30,7 @@ class Mage_Adminhtml_Block_Sitemap_Grid_Renderer_Time extends Mage_Adminhtml_Blo public function render(Varien_Object $row) { return date( - Varien_Date::DATETIME_PHP_FORMAT, + Mage_Core_Helper_Date::DATETIME_PHP_FORMAT, strtotime($row->getSitemapTime()) + Mage::getSingleton('core/date')->getGmtOffset(), ); } diff --git a/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Field/Import.php b/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Field/Import.php index f16aca8a882..f48329641e6 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Field/Import.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Field/Import.php @@ -14,6 +14,8 @@ * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +use Varien_Date as Date; + /** * Custom import CSV file field for shipping table rates * @@ -38,7 +40,7 @@ public function getElementHtml() { $html = ''; - $html .= ''; + $html .= ''; $html .= << diff --git a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Filter/Date.php b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Filter/Date.php index b72ae442923..4e30fb601a0 100644 --- a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Filter/Date.php +++ b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Filter/Date.php @@ -123,7 +123,7 @@ public function getValue($index = null) { if ($index) { if ($data = $this->getData('value', 'orig_' . $index)) { - return $data;//date('Y-m-d', strtotime($data)); + return $data; //date('Y-m-d', strtotime($data)); } return null; } diff --git a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Filter/Datetime.php b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Filter/Datetime.php index 4878943f9e2..fa1139e9c99 100644 --- a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Filter/Datetime.php +++ b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Filter/Datetime.php @@ -30,7 +30,7 @@ public function getValue($index = null) { if ($index) { if ($data = $this->getData('value', 'orig_' . $index)) { - return $data;//date('Y-m-d', strtotime($data)); + return $data; //date('Y-m-d', strtotime($data)); } return null; } diff --git a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Date.php b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Date.php index b4734546385..648b791b211 100644 --- a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Date.php +++ b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Date.php @@ -63,7 +63,7 @@ public function render(Varien_Object $row) try { if ($this->getColumn()->getGmtoffset()) { $data = Mage::app()->getLocale() - ->date($data, Varien_Date::DATETIME_INTERNAL_FORMAT)->toString($format); + ->date($data, Mage_Core_Helper_Date::DATETIME_INTERNAL_FORMAT)->toString($format); } else { $data = Mage::getSingleton('core/locale') ->date($data, Zend_Date::ISO_8601, null, false)->toString($format); @@ -71,7 +71,7 @@ public function render(Varien_Object $row) } catch (Exception $e) { if ($this->getColumn()->getTimezone()) { $data = Mage::app()->getLocale() - ->date($data, Varien_Date::DATETIME_INTERNAL_FORMAT)->toString($format); + ->date($data, Mage_Core_Helper_Date::DATETIME_INTERNAL_FORMAT)->toString($format); } else { $data = Mage::getSingleton('core/locale')->date($data, null, null, false)->toString($format); } diff --git a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Datetime.php b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Datetime.php index 950a18c3a27..40fe0f429ff 100644 --- a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Datetime.php +++ b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Datetime.php @@ -63,11 +63,11 @@ public function render(Varien_Object $row) $locale = $this->getColumn()->getLocale() ?? null; try { $data = Mage::app()->getLocale() - ->date($data, Varien_Date::DATETIME_INTERNAL_FORMAT, $locale, $useTimezone) + ->date($data, Mage_Core_Helper_Date::DATETIME_INTERNAL_FORMAT, $locale, $useTimezone) ->toString($format); } catch (Exception $e) { $data = Mage::app()->getLocale() - ->date($data, Varien_Date::DATETIME_INTERNAL_FORMAT)->toString($format); + ->date($data, Mage_Core_Helper_Date::DATETIME_INTERNAL_FORMAT)->toString($format); } return $data; } diff --git a/app/code/core/Mage/Adminhtml/Controller/Report/Abstract.php b/app/code/core/Mage/Adminhtml/Controller/Report/Abstract.php index 754eecb0490..984614636d2 100644 --- a/app/code/core/Mage/Adminhtml/Controller/Report/Abstract.php +++ b/app/code/core/Mage/Adminhtml/Controller/Report/Abstract.php @@ -100,7 +100,7 @@ protected function _showLastExecutionTime($flagCode, $refreshCode) $updatedAt = ($flag->hasData()) ? Mage::app()->getLocale()->storeDate( 0, - new Zend_Date($flag->getLastUpdate(), Varien_Date::DATETIME_INTERNAL_FORMAT), + new Zend_Date($flag->getLastUpdate(), Mage_Core_Helper_Date::DATETIME_INTERNAL_FORMAT), true, ) : 'undefined'; diff --git a/app/code/core/Mage/Adminhtml/Model/Sales/Order/Create.php b/app/code/core/Mage/Adminhtml/Model/Sales/Order/Create.php index 6e7451d8188..eafbfcfc02f 100644 --- a/app/code/core/Mage/Adminhtml/Model/Sales/Order/Create.php +++ b/app/code/core/Mage/Adminhtml/Model/Sales/Order/Create.php @@ -14,6 +14,8 @@ * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +use Carbon\Carbon; + /** * Order create model * @@ -1653,7 +1655,7 @@ protected function _getNewCustomerEmail($customer) $host = $this->getSession() ->getStore() ->getConfig(Mage_Customer_Model_Customer::XML_PATH_DEFAULT_EMAIL_DOMAIN); - $account = $customer->getIncrementId() ? $customer->getIncrementId() : time(); + $account = $customer->getIncrementId() ? $customer->getIncrementId() : Carbon::now()->getTimestamp(); $email = $account . '@' . $host; $account = $this->getData('account'); $account['email'] = $email; diff --git a/app/code/core/Mage/Adminhtml/Model/Sales/Order/Random.php b/app/code/core/Mage/Adminhtml/Model/Sales/Order/Random.php index 28515f15baa..99f4637fef7 100644 --- a/app/code/core/Mage/Adminhtml/Model/Sales/Order/Random.php +++ b/app/code/core/Mage/Adminhtml/Model/Sales/Order/Random.php @@ -14,6 +14,8 @@ * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +use Carbon\Carbon; + /** * Create random order * @@ -145,8 +147,14 @@ public function render() protected function _getRandomDate() { - $timestamp = mktime(rand(0, 23), rand(0, 59), 0, rand(1, 11), rand(1, 28), rand(2006, 2007)); - return date(Varien_Date::DATETIME_PHP_FORMAT, $timestamp); + return Carbon::now() + ->setHour(rand(0, 23)) + ->setMinute(rand(0, 59)) + ->setSecond(rand(0, 0)) + ->setMonth(rand(1, 11)) + ->setDay(rand(1, 28)) + ->setYear(rand(2006, 2007)) + ->format(Mage_Core_Helper_Date::DATETIME_PHP_FORMAT); } public function save() diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Date/Short.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Date/Short.php index 3b3e8211c11..938317f7c4a 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Date/Short.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Date/Short.php @@ -14,6 +14,8 @@ * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +use Carbon\Carbon; + /** * @category Mage * @package Mage_Adminhtml @@ -25,10 +27,10 @@ public function toOptionArray() { $arr = []; $arr[] = ['label' => '', 'value' => '']; - $arr[] = ['label' => sprintf('MM/DD/YY (%s)', date('m/d/y')), 'value' => '%m/%d/%y']; - $arr[] = ['label' => sprintf('MM/DD/YYYY (%s)', date('m/d/Y')), 'value' => '%m/%d/%Y']; - $arr[] = ['label' => sprintf('DD/MM/YY (%s)', date('d/m/y')), 'value' => '%d/%m/%y']; - $arr[] = ['label' => sprintf('DD/MM/YYYY (%s)', date('d/m/Y')), 'value' => '%d/%m/%Y']; + $arr[] = ['label' => sprintf('MM/DD/YY (%s)', Carbon::now()->format('m/d/y')), 'value' => '%m/%d/%y']; + $arr[] = ['label' => sprintf('MM/DD/YYYY (%s)', Carbon::now()->format('m/d/y')), 'value' => '%m/%d/%Y']; + $arr[] = ['label' => sprintf('DD/MM/YY (%s)', Carbon::now()->format('m/d/y')), 'value' => '%d/%m/%y']; + $arr[] = ['label' => sprintf('DD/MM/YYYY (%s)', Carbon::now()->format('m/d/y')), 'value' => '%d/%m/%Y']; return $arr; } } diff --git a/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/Action/AttributeController.php b/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/Action/AttributeController.php index 18280d329cd..640d608568f 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/Action/AttributeController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/Action/AttributeController.php @@ -89,7 +89,7 @@ public function saveAction() 'date_format' => $dateFormat, ]); $filterInternal = new Zend_Filter_NormalizedToLocalized([ - 'date_format' => Varien_Date::DATE_INTERNAL_FORMAT, + 'date_format' => Mage_Core_Helper_Date::DATE_INTERNAL_FORMAT, ]); $value = $filterInternal->filter($filterInput->filter($value)); } else { diff --git a/app/code/core/Mage/Adminhtml/controllers/CustomerController.php b/app/code/core/Mage/Adminhtml/controllers/CustomerController.php index 7e6e7b9d216..631149ce233 100644 --- a/app/code/core/Mage/Adminhtml/controllers/CustomerController.php +++ b/app/code/core/Mage/Adminhtml/controllers/CustomerController.php @@ -14,6 +14,8 @@ * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +use Carbon\Carbon; + /** * Customer admin controller * @@ -330,7 +332,7 @@ public function saveAction() // Force new customer confirmation if ($isNewCustomer) { $customer->setPassword($data['account']['password']); - $customer->setPasswordCreatedAt(time()); + $customer->setPasswordCreatedAt(Carbon::now()->getTimestamp()); $customer->setForceConfirmed(true); if ($customer->getPassword() === 'auto') { $sendPassToEmail = true; diff --git a/app/code/core/Mage/Adminhtml/controllers/Sales/Order/ShipmentController.php b/app/code/core/Mage/Adminhtml/controllers/Sales/Order/ShipmentController.php index 9bad471b905..f4d3692c978 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Sales/Order/ShipmentController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Sales/Order/ShipmentController.php @@ -14,6 +14,8 @@ * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +use Varien_Date as Date; + /** * Adminhtml sales order shipment controller * @@ -564,6 +566,8 @@ public function createLabelAction() /** * Print label for one specific shipment + * + * @return Mage_Core_Controller_Varien_Action|void */ public function printLabelAction() { @@ -720,7 +724,7 @@ protected function _createPdfPageFromImageString($imageString) imageinterlace($image, 0); $tmpFileName = sys_get_temp_dir() . DS . 'shipping_labels_' - . uniqid(mt_rand()) . time() . '.png'; + . uniqid(mt_rand()) . Date::toTimestamp(true) . '.png'; imagepng($image, $tmpFileName); $pdfImage = Zend_Pdf_Image::imageWithPath($tmpFileName); $page->drawImage($pdfImage, 0, 0, $xSize, $ySize); diff --git a/app/code/core/Mage/Adminhtml/controllers/System/Config/System/StorageController.php b/app/code/core/Mage/Adminhtml/controllers/System/Config/System/StorageController.php index ff9c1c15c40..c2de1a5212c 100644 --- a/app/code/core/Mage/Adminhtml/controllers/System/Config/System/StorageController.php +++ b/app/code/core/Mage/Adminhtml/controllers/System/Config/System/StorageController.php @@ -14,6 +14,8 @@ * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +use Carbon\Carbon; + /** * Adminhtml account controller * @@ -64,7 +66,7 @@ public function synchronizeAction() $flag = $this->_getSyncFlag(); if ($flag && $flag->getState() == Mage_Core_Model_File_Storage_Flag::STATE_RUNNING && $flag->getLastUpdate() - && time() <= (strtotime($flag->getLastUpdate()) + Mage_Core_Model_File_Storage_Flag::FLAG_TTL) + && Carbon::now()->lessThanOrEqualTo(strtotime($flag->getLastUpdate()) + Mage_Core_Model_File_Storage_Flag::FLAG_TTL) ) { return; } @@ -73,7 +75,7 @@ public function synchronizeAction() Mage::getSingleton('admin/session')->setSyncProcessStopWatch(false); $storage = ['type' => (int) $_REQUEST['storage']]; - if (isset($_REQUEST['connection']) && !empty($_REQUEST['connection'])) { + if (!empty($_REQUEST['connection'])) { $storage['connection'] = $_REQUEST['connection']; } @@ -102,7 +104,7 @@ public function statusAction() case Mage_Core_Model_File_Storage_Flag::STATE_INACTIVE: $flagData = $flag->getFlagData(); if (is_array($flagData)) { - if (isset($flagData['destination']) && !empty($flagData['destination'])) { + if (!empty($flagData['destination'])) { $result['destination'] = $flagData['destination']; } } @@ -111,13 +113,10 @@ public function statusAction() break; case Mage_Core_Model_File_Storage_Flag::STATE_RUNNING: if (!$flag->getLastUpdate() - || time() <= (strtotime($flag->getLastUpdate()) + Mage_Core_Model_File_Storage_Flag::FLAG_TTL) + || Carbon::now()->lessThanOrEqualTo(strtotime($flag->getLastUpdate()) + Mage_Core_Model_File_Storage_Flag::FLAG_TTL) ) { $flagData = $flag->getFlagData(); - if (is_array($flagData) - && isset($flagData['source']) && !empty($flagData['source']) - && isset($flagData['destination']) && !empty($flagData['destination']) - ) { + if (is_array($flagData) && !empty($flagData['source']) && !empty($flagData['destination'])) { $result['message'] = Mage::helper('adminhtml')->__('Synchronizing %s to %s', $flagData['source'], $flagData['destination']); } else { $result['message'] = Mage::helper('adminhtml')->__('Synchronizing...'); diff --git a/app/code/core/Mage/Adminhtml/controllers/System/StoreController.php b/app/code/core/Mage/Adminhtml/controllers/System/StoreController.php index 29ad5f08df9..ca7b92d1334 100644 --- a/app/code/core/Mage/Adminhtml/controllers/System/StoreController.php +++ b/app/code/core/Mage/Adminhtml/controllers/System/StoreController.php @@ -14,6 +14,8 @@ * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +use Carbon\Carbon; + /** * Store controller * @@ -467,7 +469,7 @@ protected function _backupDatabase($failPath, $arguments = []) try { $backupDb = Mage::getModel('backup/db'); $backup = Mage::getModel('backup/backup') - ->setTime(time()) + ->setTime(Carbon::now()->getTimestamp()) ->setType('db') ->setPath(Mage::getBaseDir('var') . DS . 'backups'); diff --git a/app/code/core/Mage/Api/Model/Acl/Assert/Time.php b/app/code/core/Mage/Api/Model/Acl/Assert/Time.php index 5c21198dfda..11b5fcf0871 100644 --- a/app/code/core/Mage/Api/Model/Acl/Assert/Time.php +++ b/app/code/core/Mage/Api/Model/Acl/Assert/Time.php @@ -14,6 +14,8 @@ * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +use Carbon\Carbon; + /** * Assert time for admin acl * @@ -26,7 +28,6 @@ class Mage_Api_Model_Acl_Assert_Time implements Zend_Acl_Assert_Interface * Assert time * * @param string|null $privilege - * @return bool|null */ public function assert( Mage_Api_Model_Acl $acl, @@ -34,7 +35,7 @@ public function assert( ?Mage_Api_Model_Acl_Resource $resource = null, $privilege = null ) { - return $this->_isCleanTime(time()); + $this->_isCleanTime(Carbon::now()->getTimestamp()); } /** diff --git a/app/code/core/Mage/Api/Model/Resource/Role.php b/app/code/core/Mage/Api/Model/Resource/Role.php index 2001879e5fc..cc583354b63 100644 --- a/app/code/core/Mage/Api/Model/Resource/Role.php +++ b/app/code/core/Mage/Api/Model/Resource/Role.php @@ -14,6 +14,8 @@ * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +use Carbon\Carbon; + /** * ACL role resource * @@ -34,7 +36,7 @@ protected function _construct() */ protected function _beforeSave(Mage_Core_Model_Abstract $object) { - $now = Varien_Date::now(); + $now = Carbon::now()->format(Carbon::DEFAULT_TO_STRING_FORMAT); if (!$object->getId()) { $object->setCreated($now); } diff --git a/app/code/core/Mage/Api/Model/Resource/User.php b/app/code/core/Mage/Api/Model/Resource/User.php index 12c0082534f..4af9e6305d5 100644 --- a/app/code/core/Mage/Api/Model/Resource/User.php +++ b/app/code/core/Mage/Api/Model/Resource/User.php @@ -14,6 +14,8 @@ * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +use Carbon\Carbon; + /** * ACL user resource * @@ -75,7 +77,7 @@ public function recordSession(Mage_Api_Model_User $user) ->from($this->getTable('api/session'), 'user_id') ->where('user_id = ?', $user->getId()) ->where('sessid = ?', $user->getSessid()); - $loginDate = Varien_Date::now(); + $loginDate = Carbon::now()->format(Carbon::DEFAULT_TO_STRING_FORMAT); if ($readAdapter->fetchRow($select)) { $writeAdapter->update( $this->getTable('api/session'), @@ -113,7 +115,7 @@ public function cleanOldSessions(?Mage_Api_Model_User $user) Varien_Db_Adapter_Interface::INTERVAL_SECOND, ); $where = [ - $readAdapter->quote(Varien_Date::now()) . ' > ' . $timeSubtract, + $readAdapter->quote(Carbon::now()->format(Carbon::DEFAULT_TO_STRING_FORMAT)) . ' > ' . $timeSubtract, ]; if ($user) { $where['user_id = ?'] = $user->getId(); @@ -211,7 +213,7 @@ public function hasAssigned2Role($user) */ protected function _beforeSave(Mage_Core_Model_Abstract $user) { - $now = Varien_Date::now(); + $now = Carbon::now()->format(Carbon::DEFAULT_TO_STRING_FORMAT); if (!$user->getId()) { $user->setCreated($now); } diff --git a/app/code/core/Mage/Api/Model/Session.php b/app/code/core/Mage/Api/Model/Session.php index f9e272ee069..c688302c23f 100644 --- a/app/code/core/Mage/Api/Model/Session.php +++ b/app/code/core/Mage/Api/Model/Session.php @@ -14,6 +14,8 @@ * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +use Carbon\Carbon; + /** * Webservice api session * @@ -36,7 +38,7 @@ class Mage_Api_Model_Session extends Mage_Core_Model_Session_Abstract */ public function start($sessionName = null) { - $this->_currentSessId = md5(time() . uniqid('', true) . $sessionName); + $this->_currentSessId = md5(Carbon::now()->getTimestamp() . uniqid('', true) . $sessionName); $this->sessionIds[] = $this->getSessionId(); return $this; } @@ -218,7 +220,7 @@ public function isSessionExpired($user) if (!$user->getId()) { return true; } - $timeout = strtotime(Varien_Date::now()) - strtotime($user->getLogdate()); + $timeout = strtotime(Carbon::now()->format(Carbon::DEFAULT_TO_STRING_FORMAT)) - strtotime($user->getLogdate()); return $timeout > Mage::getStoreConfig('api/config/session_timeout'); } diff --git a/app/code/core/Mage/Api2/Model/Acl/Global/Role.php b/app/code/core/Mage/Api2/Model/Acl/Global/Role.php index a9dcbcf4f2c..12b8eaf62dd 100644 --- a/app/code/core/Mage/Api2/Model/Acl/Global/Role.php +++ b/app/code/core/Mage/Api2/Model/Acl/Global/Role.php @@ -14,6 +14,8 @@ * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +use Carbon\Carbon; + /** * API2 Global ACL Role model * @@ -66,9 +68,9 @@ protected function _construct() protected function _beforeSave() { if ($this->isObjectNew() && $this->getCreatedAt() === null) { - $this->setCreatedAt(Varien_Date::now()); + $this->setCreatedAt(Carbon::now()->format(Carbon::DEFAULT_TO_STRING_FORMAT)); } else { - $this->setUpdatedAt(Varien_Date::now()); + $this->setUpdatedAt(Carbon::now()->format(Carbon::DEFAULT_TO_STRING_FORMAT)); } //check and protect guest role diff --git a/app/code/core/Mage/Authorizenet/Model/Directpost/Request.php b/app/code/core/Mage/Authorizenet/Model/Directpost/Request.php index 246aec6a3cc..c68082277ce 100644 --- a/app/code/core/Mage/Authorizenet/Model/Directpost/Request.php +++ b/app/code/core/Mage/Authorizenet/Model/Directpost/Request.php @@ -14,6 +14,8 @@ * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +use Carbon\Carbon; + /** * Authorize.net request model for DirectPost model. * @@ -163,7 +165,7 @@ public function setDataFromOrder(Mage_Sales_Model_Order $order, Mage_Authorizene */ public function signRequestData() { - $fpTimestamp = (string) time(); + $fpTimestamp = (string) Carbon::now()->getTimestamp(); $signatureKey = $this->_getSignatureKey(); if (!empty($signatureKey)) { $hash = $this->_generateSha2RequestSign( diff --git a/app/code/core/Mage/Captcha/Model/Observer.php b/app/code/core/Mage/Captcha/Model/Observer.php index 57b302cc680..763ecf6426d 100644 --- a/app/code/core/Mage/Captcha/Model/Observer.php +++ b/app/code/core/Mage/Captcha/Model/Observer.php @@ -14,6 +14,8 @@ * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +use Carbon\Carbon; + /** * Captcha Observer * @@ -239,7 +241,8 @@ public function deleteOldAttempts() public function deleteExpiredImages() { foreach (Mage::app()->getWebsites(true) as $website) { - $expire = time() - Mage::helper('captcha')->getConfigNode('timeout', $website->getDefaultStore()) * 60; + $timeout = (int) Mage::helper('captcha')->getConfigNode('timeout', $website->getDefaultStore()); + $expire = Carbon::now()->subMinutes($timeout)->getTimestamp(); $imageDirectory = Mage::helper('captcha')->getImgDir($website); foreach (new DirectoryIterator($imageDirectory) as $file) { if ($file->isFile() && pathinfo($file->getFilename(), PATHINFO_EXTENSION) == 'png') { diff --git a/app/code/core/Mage/Captcha/Model/Resource/Log.php b/app/code/core/Mage/Captcha/Model/Resource/Log.php index f87ff3fab2c..4bc975d3300 100644 --- a/app/code/core/Mage/Captcha/Model/Resource/Log.php +++ b/app/code/core/Mage/Captcha/Model/Resource/Log.php @@ -14,6 +14,8 @@ * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +use Carbon\Carbon; + /** * Log Attempts resource * @@ -135,7 +137,7 @@ public function deleteOldAttempts() { $this->_getWriteAdapter()->delete( $this->getMainTable(), - ['updated_at < ?' => Mage::getSingleton('core/date')->gmtDate(null, time() - 60 * 30)], + ['updated_at < ?' => Mage::getSingleton('core/date')->gmtDate(null, Carbon::now()->subSeconds(60 * 30)->getTimestamp())], ); } } diff --git a/app/code/core/Mage/Captcha/Model/Zend.php b/app/code/core/Mage/Captcha/Model/Zend.php index feaa2c2038f..5b5dc5ff7d2 100644 --- a/app/code/core/Mage/Captcha/Model/Zend.php +++ b/app/code/core/Mage/Captcha/Model/Zend.php @@ -14,6 +14,8 @@ * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +use Carbon\Carbon; + /** * Implementation of Zend_Captcha * @@ -457,7 +459,7 @@ public function getWord() if (!is_array($sessionData)) { return null; } - return time() < $sessionData['expires'] ? $sessionData['data'] : null; + return Carbon::now()->lessThan($sessionData['expires']) ? $sessionData['data'] : null; } /** @@ -470,7 +472,7 @@ protected function _setWord($word) { $this->getSession()->setData( $this->_getFormIdKey(self::SESSION_WORD), - ['data' => $word, 'expires' => time() + $this->getTimeout()], + ['data' => $word, 'expires' => Carbon::now()->addSeconds($this->getTimeout())->getTimestamp()], ); $this->_word = $word; return $this; diff --git a/app/code/core/Mage/Catalog/Block/Product/New.php b/app/code/core/Mage/Catalog/Block/Product/New.php index 7bfd58d6ca4..a65c8f88963 100644 --- a/app/code/core/Mage/Catalog/Block/Product/New.php +++ b/app/code/core/Mage/Catalog/Block/Product/New.php @@ -78,11 +78,11 @@ protected function _getProductCollection() { $todayStartOfDayDate = Mage::app()->getLocale()->date() ->setTime('00:00:00') - ->toString(Varien_Date::DATETIME_INTERNAL_FORMAT); + ->toString(Mage_Core_Helper_Date::DATETIME_INTERNAL_FORMAT); $todayEndOfDayDate = Mage::app()->getLocale()->date() ->setTime('23:59:59') - ->toString(Varien_Date::DATETIME_INTERNAL_FORMAT); + ->toString(Mage_Core_Helper_Date::DATETIME_INTERNAL_FORMAT); /** @var Mage_Catalog_Model_Resource_Product_Collection $collection */ $collection = Mage::getResourceModel('catalog/product_collection'); diff --git a/app/code/core/Mage/Catalog/Model/Product/Option/Type/Date.php b/app/code/core/Mage/Catalog/Model/Product/Option/Type/Date.php index 76bedbc44da..a774c68534c 100644 --- a/app/code/core/Mage/Catalog/Model/Product/Option/Type/Date.php +++ b/app/code/core/Mage/Catalog/Model/Product/Option/Type/Date.php @@ -14,6 +14,8 @@ * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +use Carbon\Carbon; + /** * Catalog product option date type * @@ -96,7 +98,6 @@ public function validateUserValue($values) public function prepareForCart() { if ($this->getIsValid() && $this->getUserValue() !== null) { - $option = $this->getOption(); $value = $this->getUserValue(); if (isset($value['date_internal']) && $value['date_internal'] != '') { @@ -111,10 +112,22 @@ public function prepareForCart() $format = Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT); $timestamp += Mage::app()->getLocale()->date($value['date'], $format, null, false)->getTimestamp(); } else { - $timestamp += mktime(0, 0, 0, $value['month'], $value['day'], $value['year']); + $timestamp += Carbon::now() + ->setHour(0) + ->setMinute(0) + ->setSecond(0) + ->setMonth($value['month']) + ->setDay($value['day']) + ->setYear($value['year']); } } else { - $timestamp += mktime(0, 0, 0, date('m'), date('d'), date('Y')); + $timestamp += Carbon::now() + ->setHour(0) + ->setMinute(0) + ->setSecond(0) + ->setMonth(Carbon::now()->format('m')) + ->setDay(Carbon::now()->format('d')) + ->setYear(Carbon::now()->format('Y')); } if ($this->_timeExists()) { @@ -128,11 +141,12 @@ public function prepareForCart() } } - $timestamp += 60 * 60 * $value['hour'] + 60 * $value['minute']; + $timestamp->addMinutes($value['minute']); + $timestamp->addHours($value['hour']); } $date = new Zend_Date($timestamp); - $result = $date->toString(Varien_Date::DATETIME_INTERNAL_FORMAT); + $result = $date->toString(Mage_Core_Helper_Date::DATETIME_INTERNAL_FORMAT); // Save date in internal format to avoid locale date bugs $this->_setInternalInRequest($result); @@ -152,7 +166,6 @@ public function prepareForCart() public function getFormattedOptionValue($optionValue) { if ($this->_formattedOptionValue === null) { - $option = $this->getOption(); if ($this->getOption()->getType() == Mage_Catalog_Model_Product_Option::OPTION_TYPE_DATE) { $format = Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM); $result = Mage::app()->getLocale()->date($optionValue, Zend_Date::ISO_8601, null, false) @@ -160,7 +173,7 @@ public function getFormattedOptionValue($optionValue) } elseif ($this->getOption()->getType() == Mage_Catalog_Model_Product_Option::OPTION_TYPE_DATE_TIME) { $format = Mage::app()->getLocale()->getDateTimeFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT); $result = Mage::app()->getLocale() - ->date($optionValue, Varien_Date::DATETIME_INTERNAL_FORMAT, null, false)->toString($format); + ->date($optionValue, Mage_Core_Helper_Date::DATETIME_INTERNAL_FORMAT, null, false)->toString($format); } elseif ($this->getOption()->getType() == Mage_Catalog_Model_Product_Option::OPTION_TYPE_TIME) { $date = new Zend_Date($optionValue); $result = date($this->is24hTimeFormat() ? 'H:i' : 'h:i a', $date->getTimestamp()); @@ -209,7 +222,7 @@ public function parseOptionValue($optionValue, $productOptionValues) } $date = new Zend_Date($timestamp); - return $date->toString(Varien_Date::DATETIME_INTERNAL_FORMAT); + return $date->toString(Mage_Core_Helper_Date::DATETIME_INTERNAL_FORMAT); } /** @@ -265,7 +278,7 @@ public function getYearStart() if (isset($_range[0]) && !empty($_range[0])) { return $_range[0]; } else { - return date('Y'); + return Carbon::now()->format('Y'); } } @@ -280,7 +293,7 @@ public function getYearEnd() if (isset($_range[1]) && !empty($_range[1])) { return $_range[1]; } else { - return date('Y'); + return Carbon::now()->format('Y'); } } diff --git a/app/code/core/Mage/Catalog/Model/Resource/Product/Action.php b/app/code/core/Mage/Catalog/Model/Resource/Product/Action.php index 1a6851866a3..74f063632cb 100644 --- a/app/code/core/Mage/Catalog/Model/Resource/Product/Action.php +++ b/app/code/core/Mage/Catalog/Model/Resource/Product/Action.php @@ -14,6 +14,8 @@ * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +use Carbon\Carbon; + /** * Catalog Product Mass processing resource model * @@ -92,7 +94,7 @@ public function updateAttributes($entityIds, $attrData, $storeId) */ protected function _updateUpdatedAt(array $entityIds): void { - $updatedAt = Varien_Date::now(); + $updatedAt = Carbon::now()->format(Carbon::DEFAULT_TO_STRING_FORMAT); $catalogProductTable = $this->getTable('catalog/product'); $adapter = $this->_getWriteAdapter(); diff --git a/app/code/core/Mage/CatalogIndex/Model/Resource/Aggregation.php b/app/code/core/Mage/CatalogIndex/Model/Resource/Aggregation.php index 1c2b3015185..540c03e1f83 100644 --- a/app/code/core/Mage/CatalogIndex/Model/Resource/Aggregation.php +++ b/app/code/core/Mage/CatalogIndex/Model/Resource/Aggregation.php @@ -14,6 +14,8 @@ * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +use Carbon\Carbon; + /** * Resource Model CatalogIndex Aggregation * @@ -99,7 +101,7 @@ public function saveCacheData($data, $key, $tags, $storeId) } else { $this->_getWriteAdapter()->insert($this->getMainTable(), array( 'store_id' => $storeId, - 'created_at'=> $this->formatDate(time()), + 'created_at'=> $this->formatDate(Carbon::now()->getTimestamp()), 'key' => $key, 'data' => $data )); @@ -108,10 +110,10 @@ public function saveCacheData($data, $key, $tags, $storeId) */ $this->_getWriteAdapter()->insertOnDuplicate($this->getMainTable(), [ - 'store_id' => $storeId, - 'created_at' => $this->formatDate(time()), - 'key' => $key, - 'data' => $data, + 'store_id' => $storeId, + 'created_at' => $this->formatDate(Carbon::now()->getTimestamp()), + 'key' => $key, + 'data' => $data, ], ['created_at', 'data']); $id = $this->_getWriteAdapter()->lastInsertId($this->getMainTable()); diff --git a/app/code/core/Mage/CatalogInventory/Model/Stock/Item.php b/app/code/core/Mage/CatalogInventory/Model/Stock/Item.php index faa35607cfd..6f7a09138c9 100644 --- a/app/code/core/Mage/CatalogInventory/Model/Stock/Item.php +++ b/app/code/core/Mage/CatalogInventory/Model/Stock/Item.php @@ -764,7 +764,7 @@ protected function _beforeSave() $this->setLowStockDate(null); if ($this->verifyNotification()) { $this->setLowStockDate(Mage::app()->getLocale()->date(null, null, null, false) - ->toString(Varien_Date::DATETIME_INTERNAL_FORMAT)); + ->toString(Mage_Core_Helper_Date::DATETIME_INTERNAL_FORMAT)); } $this->setStockStatusChangedAutomatically(0); diff --git a/app/code/core/Mage/CatalogRule/Model/Resource/Rule.php b/app/code/core/Mage/CatalogRule/Model/Resource/Rule.php index 517a411dfa6..9c8b3dc84a5 100644 --- a/app/code/core/Mage/CatalogRule/Model/Resource/Rule.php +++ b/app/code/core/Mage/CatalogRule/Model/Resource/Rule.php @@ -14,6 +14,8 @@ * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +use Carbon\Carbon; + /** * Catalog rules resource model * @@ -185,22 +187,24 @@ public function insertRuleData(Mage_CatalogRule_Model_Rule $rule, array $website $customerGroupIds = $rule->getCustomerGroupIds(); - $fromTime = (int) Mage::getModel('core/date')->gmtTimestamp(strtotime((string) $rule->getFromDate())); - $toTime = (int) Mage::getModel('core/date')->gmtTimestamp(strtotime((string) $rule->getToDate())); - $toTime = $toTime ? ($toTime + self::SECONDS_IN_DAY - 1) : 0; + $fromTime = (int) Mage::getModel('core/date')->gmtTimestamp(strtotime((string) $rule->getFromDate())); + $toTime = (int) Mage::getModel('core/date')->gmtTimestamp(strtotime((string) $rule->getToDate())); + $toTime = $toTime ? ($toTime + self::SECONDS_IN_DAY - 1) : 0; - $timestamp = time(); + $timestamp = Carbon::now()->getTimestamp(); if ($fromTime > $timestamp || ($toTime && $toTime < $timestamp) ) { return; } - $sortOrder = (int) $rule->getSortOrder(); - $actionOperator = $rule->getSimpleAction(); - $actionAmount = (float) $rule->getDiscountAmount(); - $subActionOperator = $rule->getSubIsEnable() ? $rule->getSubSimpleAction() : ''; - $subActionAmount = (float) $rule->getSubDiscountAmount(); - $actionStop = (int) $rule->getStopRulesProcessing(); + + $sortOrder = (string) $rule->getSortOrder(); + $actionOperator = $rule->getSimpleAction(); + $actionAmount = (string) $rule->getDiscountAmount(); + $subActionOperator = $rule->getSubIsEnable() ? $rule->getSubSimpleAction() : ''; + $subActionAmount = (string) $rule->getSubDiscountAmount(); + $actionStop = (string) $rule->getStopRulesProcessing(); + /** @var Mage_Catalog_Helper_Product_Flat $helper */ $helper = $this->_factory->getHelper('catalog/product_flat'); @@ -219,8 +223,8 @@ public function insertRuleData(Mage_CatalogRule_Model_Rule $rule, array $website 'cg.customer_group_id', 'p.entity_id', new Zend_Db_Expr($rule->getId()), - new Zend_Db_Expr($fromTime), - new Zend_Db_Expr($toTime), + new Zend_Db_Expr((string) $fromTime), + new Zend_Db_Expr((string) $toTime), new Zend_Db_Expr("'" . $actionOperator . "'"), new Zend_Db_Expr($actionAmount), new Zend_Db_Expr($actionStop), diff --git a/app/code/core/Mage/CatalogRule/Model/Rule.php b/app/code/core/Mage/CatalogRule/Model/Rule.php index 7cae8e9606e..cecc1a6548e 100644 --- a/app/code/core/Mage/CatalogRule/Model/Rule.php +++ b/app/code/core/Mage/CatalogRule/Model/Rule.php @@ -14,6 +14,8 @@ * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +use Carbon\Carbon; + /** * Catalog Rule data model * @@ -188,7 +190,7 @@ public function getCustomerGroupIds() public function getNow() { if (!$this->_now) { - return Varien_Date::now(); + return Carbon::now()->format(Carbon::DEFAULT_TO_STRING_FORMAT); } return $this->_now; } diff --git a/app/code/core/Mage/CatalogSearch/Model/Resource/Fulltext.php b/app/code/core/Mage/CatalogSearch/Model/Resource/Fulltext.php index ab9d003e9d1..5c0693f54be 100644 --- a/app/code/core/Mage/CatalogSearch/Model/Resource/Fulltext.php +++ b/app/code/core/Mage/CatalogSearch/Model/Resource/Fulltext.php @@ -816,7 +816,7 @@ protected function _getStoreDate($storeId, $date = null) if (!is_empty_date($date)) { list($dateObj, $format) = $this->_dates[$storeId]; - $dateObj->setDate($date, Varien_Date::DATETIME_INTERNAL_FORMAT); + $dateObj->setDate($date, Mage_Core_Helper_Date::DATETIME_INTERNAL_FORMAT); return $dateObj->toString($format); } diff --git a/app/code/core/Mage/Checkout/Model/Api/Resource/Customer.php b/app/code/core/Mage/Checkout/Model/Api/Resource/Customer.php index fcba96a74ef..c01738ab8b5 100644 --- a/app/code/core/Mage/Checkout/Model/Api/Resource/Customer.php +++ b/app/code/core/Mage/Checkout/Model/Api/Resource/Customer.php @@ -14,6 +14,8 @@ * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +use Carbon\Carbon; + /** * Checkout api resource for Customer * @@ -136,7 +138,7 @@ protected function _prepareNewCustomerQuote(Mage_Sales_Model_Quote $quote) Mage::helper('core')->copyFieldset('checkout_onepage_quote', 'to_customer', $quote, $customer); $customer->setPassword($customer->decryptPassword($quote->getPasswordHash())); - $customer->setPasswordCreatedAt(time()); + $customer->setPasswordCreatedAt(Carbon::now()->getTimestamp()); $quote->setCustomer($customer) ->setCustomerId(true); $quote->setPasswordHash(''); diff --git a/app/code/core/Mage/Checkout/Model/Type/Onepage.php b/app/code/core/Mage/Checkout/Model/Type/Onepage.php index 3ff917162cb..4399d33d2d4 100644 --- a/app/code/core/Mage/Checkout/Model/Type/Onepage.php +++ b/app/code/core/Mage/Checkout/Model/Type/Onepage.php @@ -14,6 +14,8 @@ * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +use Carbon\Carbon; + /** * One page checkout processing model * @@ -716,7 +718,7 @@ protected function _prepareNewCustomerQuote() Mage::helper('core')->copyFieldset('checkout_onepage_quote', 'to_customer', $quote, $customer); $customer->setPassword($customer->decryptPassword($quote->getPasswordHash())); - $customer->setPasswordCreatedAt(time()); + $customer->setPasswordCreatedAt(Carbon::now()->getTimestamp()); $quote->setCustomer($customer) ->setCustomerId(true); $quote->setPasswordHash(''); diff --git a/app/code/core/Mage/Cms/Model/Wysiwyg/Images/Storage.php b/app/code/core/Mage/Cms/Model/Wysiwyg/Images/Storage.php index 10039d135d4..7c924cc9444 100644 --- a/app/code/core/Mage/Cms/Model/Wysiwyg/Images/Storage.php +++ b/app/code/core/Mage/Cms/Model/Wysiwyg/Images/Storage.php @@ -14,6 +14,8 @@ * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +use Carbon\Carbon; + /** * Wysiwyg Images model * @@ -344,7 +346,7 @@ public function getThumbnailUrl($filePath, $checkFile = false) if (str_starts_with($filePath, $mediaRootDir)) { $thumbSuffix = self::THUMBS_DIRECTORY_NAME . DS . substr($filePath, strlen($mediaRootDir)); if (!$checkFile || is_readable($this->getHelper()->getStorageRoot() . $thumbSuffix)) { - $randomIndex = '?rand=' . time(); + $randomIndex = '?rand=' . Carbon::now()->getTimestamp(); $thumbUrl = $this->getHelper()->getBaseUrl() . Mage_Cms_Model_Wysiwyg_Config::IMAGE_DIRECTORY . DS . $thumbSuffix; return str_replace('\\', '/', $thumbUrl) . $randomIndex; diff --git a/app/code/core/Mage/Cms/sql/cms_setup/mysql4-upgrade-0.7.7-0.7.8.php b/app/code/core/Mage/Cms/sql/cms_setup/mysql4-upgrade-0.7.7-0.7.8.php index 5ec38990a57..5175169653a 100644 --- a/app/code/core/Mage/Cms/sql/cms_setup/mysql4-upgrade-0.7.7-0.7.8.php +++ b/app/code/core/Mage/Cms/sql/cms_setup/mysql4-upgrade-0.7.7-0.7.8.php @@ -15,13 +15,16 @@ */ /** @var Mage_Core_Model_Resource_Setup $installer */ + +use Carbon\Carbon; + $installer = $this; $installer->startSetup(); /** @var Varien_Db_Adapter_Pdo_Mysql $connection */ $connection = $installer->getConnection(); -$now = Varien_Date::now(); +$now = Carbon::now()->format(Carbon::DEFAULT_TO_STRING_FORMAT); $connection->insert($installer->getTable('cms/page'), [ 'title' => 'Enable Cookies', 'root_template' => 'one_column', diff --git a/app/code/core/Mage/Core/Controller/Front/Action.php b/app/code/core/Mage/Core/Controller/Front/Action.php index 8ba40b38a25..8d7e96403c2 100644 --- a/app/code/core/Mage/Core/Controller/Front/Action.php +++ b/app/code/core/Mage/Core/Controller/Front/Action.php @@ -14,6 +14,8 @@ * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +use Carbon\Carbon; + /** * Base front controller * @@ -131,7 +133,7 @@ protected function _prepareDownloadResponse( ->setHeader('Content-type', $contentType, true) ->setHeader('Content-Length', is_null($contentLength) ? strlen($content) : $contentLength) ->setHeader('Content-Disposition', 'attachment; filename="' . $fileName . '"') - ->setHeader('Last-Modified', date('r')); + ->setHeader('Last-Modified', Carbon::now()->format('r')); if (!is_null($content)) { if ($isFile) { diff --git a/app/code/core/Mage/Core/Controller/Varien/Action.php b/app/code/core/Mage/Core/Controller/Varien/Action.php index 03a71127598..d84887eaa65 100644 --- a/app/code/core/Mage/Core/Controller/Varien/Action.php +++ b/app/code/core/Mage/Core/Controller/Varien/Action.php @@ -14,6 +14,8 @@ * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +use Carbon\Carbon; + /** * Custom Zend_Controller_Action class (formally) * @@ -985,7 +987,7 @@ protected function _filterDates($array, $dateFields) 'date_format' => Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT), ]); $filterInternal = new Zend_Filter_NormalizedToLocalized([ - 'date_format' => Varien_Date::DATE_INTERNAL_FORMAT, + 'date_format' => Mage_Core_Helper_Date::DATE_INTERNAL_FORMAT, ]); foreach ($dateFields as $dateField) { @@ -1013,7 +1015,7 @@ protected function _filterDateTime($array, $dateFields) 'date_format' => Mage::app()->getLocale()->getDateTimeFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT), ]); $filterInternal = new Zend_Filter_NormalizedToLocalized([ - 'date_format' => Varien_Date::DATETIME_INTERNAL_FORMAT, + 'date_format' => Mage_Core_Helper_Date::DATETIME_INTERNAL_FORMAT, ]); foreach ($dateFields as $dateField) { @@ -1069,7 +1071,7 @@ protected function _prepareDownloadResponse( ->setHeader('Content-type', $contentType, true) ->setHeader('Content-Length', is_null($contentLength) ? strlen($content) : $contentLength, true) ->setHeader('Content-Disposition', 'attachment; filename="' . $fileName . '"', true) - ->setHeader('Last-Modified', date('r'), true); + ->setHeader('Last-Modified', Carbon::now()->format('r'), true); if (!is_null($content)) { if ($isFile) { diff --git a/app/code/core/Mage/Core/Helper/Data.php b/app/code/core/Mage/Core/Helper/Data.php index 695521a2dfb..0ad582f241d 100644 --- a/app/code/core/Mage/Core/Helper/Data.php +++ b/app/code/core/Mage/Core/Helper/Data.php @@ -14,6 +14,8 @@ * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +use Carbon\Carbon; + /** * Core data helper * @@ -208,7 +210,7 @@ public function formatTime($time = null, $format = Mage_Core_Model_Locale::FORMA $locale = Mage::app()->getLocale(); if (is_null($time)) { - $date = $locale->date(time()); + $date = $locale->date(Carbon::now()->getTimestamp()); } elseif ($time instanceof Zend_Date) { $date = $time; } else { diff --git a/app/code/core/Mage/Core/Helper/Date.php b/app/code/core/Mage/Core/Helper/Date.php new file mode 100644 index 00000000000..50504b3bc69 --- /dev/null +++ b/app/code/core/Mage/Core/Helper/Date.php @@ -0,0 +1,32 @@ +addSeconds($period)->getTimestamp(); } if (is_null($path)) { $path = $this->getPath(); diff --git a/app/code/core/Mage/Core/Model/Date.php b/app/code/core/Mage/Core/Model/Date.php index 9260e371875..f385c50ecc8 100644 --- a/app/code/core/Mage/Core/Model/Date.php +++ b/app/code/core/Mage/Core/Model/Date.php @@ -14,6 +14,8 @@ * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +use Carbon\Carbon; + /** * Date conversion model * @@ -29,13 +31,6 @@ class Mage_Core_Model_Date */ private $_offset = 0; - /** - * Current system offset in seconds - * - * @var int - */ - private $_systemOffset = 0; - /** * Init offset * @@ -43,7 +38,6 @@ class Mage_Core_Model_Date public function __construct() { $this->_offset = $this->calculateOffset($this->_getConfigTimezone()); - $this->_systemOffset = $this->calculateOffset(); } /** @@ -75,7 +69,7 @@ public function calculateOffset($timezone = null) } if ($result === true) { - $offset = (int) date('Z'); + $offset = (int) Carbon::now()->format('Z'); } if (!is_null($timezone)) { @@ -95,7 +89,7 @@ public function calculateOffset($timezone = null) public function gmtDate($format = null, $input = null) { if (is_null($format)) { - $format = Varien_Date::DATETIME_PHP_FORMAT; + $format = Mage_Core_Helper_Date::DATETIME_PHP_FORMAT; } $date = $this->gmtTimestamp($input); @@ -118,7 +112,7 @@ public function gmtDate($format = null, $input = null) public function date($format = null, $input = null) { if (is_null($format)) { - $format = Varien_Date::DATETIME_PHP_FORMAT; + $format = Mage_Core_Helper_Date::DATETIME_PHP_FORMAT; } return date($format, $this->timestamp($input)); @@ -146,7 +140,7 @@ public function gmtTimestamp($input = null) } $date = Mage::app()->getLocale()->date($result); - $timestamp = $date->get(Zend_Date::TIMESTAMP) - $date->get(Zend_Date::TIMEZONE_SECS); + $timestamp = (int) $date->get(Zend_Date::TIMESTAMP) - (int) $date->get(Zend_Date::TIMEZONE_SECS); unset($date); return $timestamp; @@ -170,7 +164,7 @@ public function timestamp($input = null) } $date = Mage::app()->getLocale()->date($result); - $timestamp = $date->get(Zend_Date::TIMESTAMP) + $date->get(Zend_Date::TIMEZONE_SECS); + $timestamp = (int) $date->get(Zend_Date::TIMESTAMP) + (int) $date->get(Zend_Date::TIMEZONE_SECS); unset($date); return $timestamp; diff --git a/app/code/core/Mage/Core/Model/Locale.php b/app/code/core/Mage/Core/Model/Locale.php index c7457f72589..830fddbe6e8 100644 --- a/app/code/core/Mage/Core/Model/Locale.php +++ b/app/code/core/Mage/Core/Model/Locale.php @@ -589,7 +589,7 @@ public function storeTimeStamp($store = null) $timezone = Mage::app()->getStore($store)->getConfig(self::XML_PATH_DEFAULT_TIMEZONE); $currentTimezone = @date_default_timezone_get(); @date_default_timezone_set($timezone); - $date = date(Varien_Date::DATETIME_PHP_FORMAT); + $date = date(Mage_Core_Helper_Date::DATETIME_PHP_FORMAT); @date_default_timezone_set($currentTimezone); return strtotime($date); } diff --git a/app/code/core/Mage/Core/Model/Resource/Abstract.php b/app/code/core/Mage/Core/Model/Resource/Abstract.php index 55497b83026..16041b57be8 100644 --- a/app/code/core/Mage/Core/Model/Resource/Abstract.php +++ b/app/code/core/Mage/Core/Model/Resource/Abstract.php @@ -14,6 +14,8 @@ * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +use Carbon\Carbon; + /** * Abstract resource model * @@ -142,7 +144,7 @@ public function formatDate($date, $includeTime = true) */ public function mktime($str) { - return Varien_Date::toTimestamp($str); + return Carbon::now()->setTimeFromTimeString($str)->getTimestamp(); } /** diff --git a/app/code/core/Mage/Core/Model/Resource/Design.php b/app/code/core/Mage/Core/Model/Resource/Design.php index 0a295233ecc..80f421608cc 100644 --- a/app/code/core/Mage/Core/Model/Resource/Design.php +++ b/app/code/core/Mage/Core/Model/Resource/Design.php @@ -14,6 +14,8 @@ * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +use Carbon\Carbon; + /** * Core Design Resource Model * @@ -30,6 +32,7 @@ protected function _construct() /** * @param Mage_Core_Model_Design $object * @inheritDoc + * @throws Mage_Core_Exception */ public function _beforeSave(Mage_Core_Model_Abstract $object) { @@ -40,7 +43,7 @@ public function _beforeSave(Mage_Core_Model_Abstract $object) if (!$validator->isValid($dateFrom) || !$validator->isValid($dateTo)) { Mage::throwException(Mage::helper('core')->__('Invalid date')); } - if (Varien_Date::toTimestamp($dateFrom) > Varien_Date::toTimestamp($dateTo)) { + if (Carbon::now()->setTimeFromTimeString($dateFrom) > Carbon::now()->setTimeFromTimeString($dateTo)) { Mage::throwException(Mage::helper('core')->__('Start date cannot be greater than end date.')); } } @@ -142,7 +145,7 @@ protected function _checkIntersection($storeId, $dateFrom, $dateTo, $currentId) public function loadChange($storeId, $date = null) { if (is_null($date)) { - $date = Varien_Date::now(); + $date = Carbon::now()->format(Carbon::DEFAULT_TO_STRING_FORMAT); } $select = $this->_getReadAdapter()->select() diff --git a/app/code/core/Mage/Core/Model/Resource/Session.php b/app/code/core/Mage/Core/Model/Resource/Session.php index a125cedf358..6970672b3eb 100644 --- a/app/code/core/Mage/Core/Model/Resource/Session.php +++ b/app/code/core/Mage/Core/Model/Resource/Session.php @@ -14,6 +14,8 @@ * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +use Carbon\Carbon; + /** * Mysql4 session save handler * @@ -197,7 +199,7 @@ public function read($sessId) ->where('session_expires > :session_expires'); $bind = [ 'session_id' => $sessId, - 'session_expires' => Varien_Date::toTimestamp(true), + 'session_expires' => Carbon::now()->getTimestamp(), ]; $data = $this->_read->fetchOne($select, $bind); @@ -224,7 +226,7 @@ public function write($sessId, $sessData) $exists = $this->_read->fetchOne($select, $bindValues); $bind = [ - 'session_expires' => Varien_Date::toTimestamp(true) + $this->getLifeTime(), + 'session_expires' => Carbon::now()->addSeconds($this->getLifeTime())->getTimestamp(), 'session_data' => $sessData, ]; if ($exists) { @@ -268,7 +270,7 @@ public function gc($sessMaxLifeTime) if ($this->_automaticCleaningFactor == 1 || rand(1, $this->_automaticCleaningFactor) == 1 ) { - $where = ['session_expires < ?' => Varien_Date::toTimestamp(true)]; + $where = ['session_expires < ?' => Carbon::now()->getTimestamp()]; $this->_write->delete($this->_sessionTable, $where); } } diff --git a/app/code/core/Mage/Core/Model/Session/Abstract/Varien.php b/app/code/core/Mage/Core/Model/Session/Abstract/Varien.php index efaabb063b9..4ddaf74bd75 100644 --- a/app/code/core/Mage/Core/Model/Session/Abstract/Varien.php +++ b/app/code/core/Mage/Core/Model/Session/Abstract/Varien.php @@ -14,6 +14,8 @@ * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +use Carbon\Carbon; + /** * @category Mage * @package Mage_Core @@ -488,7 +490,7 @@ public function validate() // Refresh expire timestamp if ($this->useValidateSessionExpire() || $this->useValidateSessionPasswordTimestamp()) { - $this->setValidatorSessionRenewTimestamp(time()); + $this->setValidatorSessionRenewTimestamp(Carbon::now()->getTimestamp()); $_SESSION[self::VALIDATOR_KEY][self::VALIDATOR_SESSION_LIFETIME] = $this->getCookie()->getLifetime(); } } @@ -552,16 +554,14 @@ protected function _validate() if ($this->useValidateSessionExpire() && isset($sessionData[self::VALIDATOR_SESSION_RENEW_TIMESTAMP]) && isset($sessionData[self::VALIDATOR_SESSION_LIFETIME]) - && ((int) $sessionData[self::VALIDATOR_SESSION_RENEW_TIMESTAMP] + (int) $sessionData[self::VALIDATOR_SESSION_LIFETIME]) - < time() + && Carbon::now()->greaterThan((int) $sessionData[self::VALIDATOR_SESSION_RENEW_TIMESTAMP] + (int) $sessionData[self::VALIDATOR_SESSION_LIFETIME]) ) { return false; } if ($this->useValidateSessionPasswordTimestamp() && isset($validatorData[self::VALIDATOR_PASSWORD_CREATE_TIMESTAMP]) && isset($sessionData[self::VALIDATOR_SESSION_RENEW_TIMESTAMP]) - && $validatorData[self::VALIDATOR_PASSWORD_CREATE_TIMESTAMP] - > $sessionData[self::VALIDATOR_SESSION_RENEW_TIMESTAMP] + && $validatorData[self::VALIDATOR_PASSWORD_CREATE_TIMESTAMP] > $sessionData[self::VALIDATOR_SESSION_RENEW_TIMESTAMP] ) { return false; } diff --git a/app/code/core/Mage/Core/functions.php b/app/code/core/Mage/Core/functions.php index 47698522792..99cfcd6eec0 100644 --- a/app/code/core/Mage/Core/functions.php +++ b/app/code/core/Mage/Core/functions.php @@ -10,10 +10,12 @@ * @category Mage * @package Mage_Core * @copyright Copyright (c) 2006-2020 Magento, Inc. (https://www.magento.com) - * @copyright Copyright (c) 2018-2024 The OpenMage Contributors (https://www.openmage.org) + * @copyright Copyright (c) 2018-2025 The OpenMage Contributors (https://www.openmage.org) * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +use Carbon\Carbon; + /** * Object destructor * @@ -62,11 +64,12 @@ function uc_words($str, $destSep = '_', $srcSep = '_') * @param bool $dayOnly * @return string * @deprecated use equivalent Varien method directly - * @see Varien_Date::now() + * @see Carbon::now() */ function now($dayOnly = false) { - return Varien_Date::now($dayOnly); + $format = $dayOnly ? 'Y-m-d' : Carbon::DEFAULT_TO_STRING_FORMAT; + return Carbon::now()->format($format); } /** diff --git a/app/code/core/Mage/Cron/Model/Observer.php b/app/code/core/Mage/Cron/Model/Observer.php index 66b374e1bd6..51d143c65e3 100644 --- a/app/code/core/Mage/Cron/Model/Observer.php +++ b/app/code/core/Mage/Cron/Model/Observer.php @@ -14,6 +14,8 @@ * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +use Carbon\Carbon; + /** * Crontab observer * @@ -112,7 +114,7 @@ public function generate() * check if schedule generation is needed */ $lastRun = Mage::app()->loadCache(self::CACHE_KEY_LAST_SCHEDULE_GENERATE_AT); - if ($lastRun > time() - Mage::getStoreConfig(self::XML_PATH_SCHEDULE_GENERATE_EVERY) * 60) { + if ($lastRun > Carbon::now()->subMinutes(Mage::getStoreConfig(self::XML_PATH_SCHEDULE_GENERATE_EVERY))->getTimestamp()) { return $this; } @@ -141,7 +143,7 @@ public function generate() /** * save time schedules generation was ran with no expiration */ - Mage::app()->saveCache(time(), self::CACHE_KEY_LAST_SCHEDULE_GENERATE_AT, ['crontab'], null); + Mage::app()->saveCache(Carbon::now()->getTimestamp(), self::CACHE_KEY_LAST_SCHEDULE_GENERATE_AT, ['crontab'], null); return $this; } @@ -170,7 +172,7 @@ protected function _generateJobs($jobs, $exists) continue; } - $now = time(); + $now = Carbon::now()->getTimestamp(); $timeAhead = $now + $scheduleAheadFor; $schedule->setJobCode($jobCode) ->setCronExpr($cronExpr) @@ -201,7 +203,7 @@ public function cleanup() { // check if history cleanup is needed $lastCleanup = Mage::app()->loadCache(self::CACHE_KEY_LAST_HISTORY_CLEANUP_AT); - if ($lastCleanup > time() - Mage::getStoreConfig(self::XML_PATH_HISTORY_CLEANUP_EVERY) * 60) { + if ($lastCleanup > Carbon::now()->subMinutes(Mage::getStoreConfig(self::XML_PATH_HISTORY_CLEANUP_EVERY))->getTimestamp()) { return $this; } @@ -219,7 +221,7 @@ public function cleanup() Mage_Cron_Model_Schedule::STATUS_ERROR => Mage::getStoreConfig(self::XML_PATH_HISTORY_FAILURE) * 60, ]; - $now = time(); + $now = Carbon::now()->getTimestamp(); foreach ($history->getIterator() as $record) { if (empty($record->getExecutedAt()) || (strtotime($record->getExecutedAt()) < $now - $historyLifetimes[$record->getStatus()]) @@ -229,7 +231,7 @@ public function cleanup() } // save time history cleanup was ran with no expiration - Mage::app()->saveCache(time(), self::CACHE_KEY_LAST_HISTORY_CLEANUP_AT, ['crontab'], null); + Mage::app()->saveCache(Carbon::now()->getTimestamp(), self::CACHE_KEY_LAST_HISTORY_CLEANUP_AT, ['crontab'], null); return $this; } @@ -273,7 +275,7 @@ protected function _processJob($schedule, $jobConfig, $isAlways = false) $runConfig = $jobConfig->run; if (!$isAlways) { $scheduleLifetime = Mage::getStoreConfig(self::XML_PATH_SCHEDULE_LIFETIME) * 60; - $now = time(); + $now = Carbon::now()->getTimestamp(); $time = strtotime($schedule->getScheduledAt()); if ($time > $now) { return; @@ -348,7 +350,7 @@ protected function _getAlwaysJobSchedule($jobCode) /** @var Mage_Cron_Model_Schedule $schedule */ $schedule = Mage::getModel('cron/schedule')->load($jobCode, 'job_code'); if ($schedule->getId() === null) { - $ts = date('Y-m-d H:i:00'); + $ts = Carbon::now()->format('Y-m-d H:i:00'); $schedule->setJobCode($jobCode) ->setCreatedAt($ts) ->setScheduledAt($ts); diff --git a/app/code/core/Mage/Customer/Model/Customer.php b/app/code/core/Mage/Customer/Model/Customer.php index 4dcf9b2c926..34ea8e43156 100644 --- a/app/code/core/Mage/Customer/Model/Customer.php +++ b/app/code/core/Mage/Customer/Model/Customer.php @@ -14,6 +14,8 @@ * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +use Carbon\Carbon; + /** * Customer model * @@ -1443,7 +1445,7 @@ public function getCreatedAtTimestamp() { $date = $this->getCreatedAt(); if ($date) { - return Varien_Date::toTimestamp($date); + return Carbon::now()->setTimeFromTimeString($date)->getTimestamp(); } return null; } @@ -1633,18 +1635,15 @@ public function isResetPasswordLinkTokenExpired() return true; } - $tokenExpirationPeriod = Mage::helper('customer')->getResetPasswordLinkExpirationPeriod(); + $currentTimestamp = Carbon::now(); + $tokenTimestamp = Carbon::now()->setTimeFromTimeString($resetPasswordLinkTokenCreatedAt); - $currentDate = Varien_Date::now(); - $currentTimestamp = Varien_Date::toTimestamp($currentDate); - $tokenTimestamp = Varien_Date::toTimestamp($resetPasswordLinkTokenCreatedAt); - if ($tokenTimestamp > $currentTimestamp) { + if ($currentTimestamp->lessThan($tokenTimestamp)) { return true; } - $hoursDifference = floor(($currentTimestamp - $tokenTimestamp) / (60 * 60)); - - return $hoursDifference >= $tokenExpirationPeriod; + $tokenExpirationPeriod = Mage::helper('customer')->getResetPasswordLinkExpirationPeriod(); + return Carbon::now()->diffInDays($tokenTimestamp) >= $tokenExpirationPeriod; } /** diff --git a/app/code/core/Mage/Customer/Model/Resource/Customer.php b/app/code/core/Mage/Customer/Model/Resource/Customer.php index 05afecc9299..0e6fea7f33d 100644 --- a/app/code/core/Mage/Customer/Model/Resource/Customer.php +++ b/app/code/core/Mage/Customer/Model/Resource/Customer.php @@ -14,6 +14,8 @@ * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +use Carbon\Carbon; + /** * Customer entity resource model * @@ -226,7 +228,7 @@ public function loadByEmail(Mage_Customer_Model_Customer $customer, $email, $tes */ public function changePassword(Mage_Customer_Model_Customer $customer, $newPassword) { - $customer->setPassword($newPassword)->setPasswordCreatedAt(time()); + $customer->setPassword($newPassword)->setPasswordCreatedAt(Carbon::now()->getTimestamp()); $this->saveAttribute($customer, 'password_hash'); $this->saveAttribute($customer, 'password_created_at'); return $this; @@ -316,7 +318,7 @@ public function changeResetPasswordLinkToken(Mage_Customer_Model_Customer $custo { if (is_string($newResetPasswordLinkToken) && !empty($newResetPasswordLinkToken)) { $customer->setRpToken($newResetPasswordLinkToken); - $currentDate = Varien_Date::now(); + $currentDate = Carbon::now()->format(Carbon::DEFAULT_TO_STRING_FORMAT); $customer->setRpTokenCreatedAt($currentDate); $this->saveAttribute($customer, 'rp_token'); $this->saveAttribute($customer, 'rp_token_created_at'); @@ -371,7 +373,7 @@ public function getPasswordTimestamp($customerId) $value = $this->_getReadAdapter()->fetchOne($select); if ($value && !is_numeric($value)) { // Convert created_at string to unix timestamp - $value = Varien_Date::toTimestamp($value); + $value = Carbon::now()->setTimeFromTimeString($value)->getTimestamp(); } return $value; } diff --git a/app/code/core/Mage/Customer/controllers/AccountController.php b/app/code/core/Mage/Customer/controllers/AccountController.php index 09737e0a1cf..efab445a8e5 100644 --- a/app/code/core/Mage/Customer/controllers/AccountController.php +++ b/app/code/core/Mage/Customer/controllers/AccountController.php @@ -14,6 +14,7 @@ * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +use Carbon\Carbon; use Mage_Customer_Helper_Data as Helper; /** @@ -295,7 +296,7 @@ public function createPostAction() if (empty($errors)) { $customer->cleanPasswordsValidationData(); - $customer->setPasswordCreatedAt(time()); + $customer->setPasswordCreatedAt(Carbon::now()->getTimestamp()); $customer->save(); $this->_dispatchRegisterSuccess($customer); $this->_successProcessRegistration($customer); @@ -873,7 +874,7 @@ public function resetPasswordPostAction() $customer->setRpToken(null); $customer->setRpTokenCreatedAt(null); $customer->cleanPasswordsValidationData(); - $customer->setPasswordCreatedAt(time()); + $customer->setPasswordCreatedAt(Carbon::now()->getTimestamp()); $customer->setRpCustomerId(null); $customer->setConfirmation(null); // Set email is confirmed. $customer->save(); @@ -1041,7 +1042,7 @@ public function editPostAction() try { $customer->cleanPasswordsValidationData(); - $customer->setPasswordCreatedAt(time()); + $customer->setPasswordCreatedAt(Carbon::now()->getTimestamp()); // Reset all password reset tokens if all data was sufficient and correct on email change if ($customer->getIsChangeEmail()) { diff --git a/app/code/core/Mage/Dataflow/Model/Convert/Adapter/Http.php b/app/code/core/Mage/Dataflow/Model/Convert/Adapter/Http.php index 67b59315400..a36081a2fd8 100644 --- a/app/code/core/Mage/Dataflow/Model/Convert/Adapter/Http.php +++ b/app/code/core/Mage/Dataflow/Model/Convert/Adapter/Http.php @@ -72,7 +72,7 @@ public function loadFile() $uploader->save($path); if ($uploadFile = $uploader->getUploadedFileName()) { $session = Mage::getModel('dataflow/session'); - $session->setCreatedDate(date(Varien_Date::DATETIME_PHP_FORMAT)); + $session->setCreatedDate(date(Mage_Core_Helper_Date::DATETIME_PHP_FORMAT)); $session->setDirection('import'); $session->setUserId(Mage::getSingleton('admin/session')->getUser()->getId()); $session->save(); diff --git a/app/code/core/Mage/Dataflow/Model/Convert/Iterator.php b/app/code/core/Mage/Dataflow/Model/Convert/Iterator.php index 1e7135e00b8..e310479b395 100644 --- a/app/code/core/Mage/Dataflow/Model/Convert/Iterator.php +++ b/app/code/core/Mage/Dataflow/Model/Convert/Iterator.php @@ -14,6 +14,8 @@ * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +use Carbon\Carbon; + /** * @category Mage * @package Mage_Dataflow @@ -62,7 +64,7 @@ protected function _getProgressBarHtml($sessionId, $totalRows) '; + . $args['row']['session_id'] . '", "' . $args['idx'] . '", "' . Carbon::now()->getTimestamp() . '", "' . $memory . '");'; echo '
  • ' . $memory . '
  • '; return []; diff --git a/app/code/core/Mage/Dataflow/Model/Profile.php b/app/code/core/Mage/Dataflow/Model/Profile.php index 1163196d315..e92f16f4f76 100644 --- a/app/code/core/Mage/Dataflow/Model/Profile.php +++ b/app/code/core/Mage/Dataflow/Model/Profile.php @@ -14,6 +14,8 @@ * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +use Carbon\Carbon; + /** * Convert profile * @@ -234,7 +236,7 @@ protected function _afterSave() ); } if ($uploadFile) { - $newFilename = 'import-' . date('YmdHis') . '-' . ($index + 1) . '_' . $uploadFile; + $newFilename = 'import-' . Carbon::now()->format('YmdHis') . '-' . ($index + 1) . '_' . $uploadFile; rename($path . $uploadFile, $path . $newFilename); $newUploadedFilenames[] = $newFilename; } diff --git a/app/code/core/Mage/Dataflow/Model/Resource/Profile.php b/app/code/core/Mage/Dataflow/Model/Resource/Profile.php index 1229df2a6bb..efe34fcf060 100644 --- a/app/code/core/Mage/Dataflow/Model/Resource/Profile.php +++ b/app/code/core/Mage/Dataflow/Model/Resource/Profile.php @@ -14,6 +14,8 @@ * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +use Carbon\Carbon; + /** * Convert profile resource model * @@ -35,9 +37,9 @@ protected function _construct() protected function _beforeSave(Mage_Core_Model_Abstract $object) { if (!$object->getCreatedAt()) { - $object->setCreatedAt($this->formatDate(time())); + $object->setCreatedAt($this->formatDate(Carbon::now()->getTimestamp())); } - $object->setUpdatedAt($this->formatDate(time())); + $object->setUpdatedAt($this->formatDate(Carbon::now()->getTimestamp())); return parent::_beforeSave($object); } diff --git a/app/code/core/Mage/Dataflow/Model/Resource/Profile/History.php b/app/code/core/Mage/Dataflow/Model/Resource/Profile/History.php index 283619178bd..d8b31938f96 100644 --- a/app/code/core/Mage/Dataflow/Model/Resource/Profile/History.php +++ b/app/code/core/Mage/Dataflow/Model/Resource/Profile/History.php @@ -14,6 +14,8 @@ * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +use Carbon\Carbon; + /** * Convert history resource model * @@ -35,7 +37,7 @@ protected function _construct() protected function _beforeSave(Mage_Core_Model_Abstract $object) { if (!$object->getPerformedAt()) { - $object->setPerformedAt($this->formatDate(time())); + $object->setPerformedAt($this->formatDate(Carbon::now()->getTimestamp())); } parent::_beforeSave($object); return $this; diff --git a/app/code/core/Mage/Dataflow/Model/Session/Adapter/Http.php b/app/code/core/Mage/Dataflow/Model/Session/Adapter/Http.php index d612e8c597f..baa06ce02c0 100644 --- a/app/code/core/Mage/Dataflow/Model/Session/Adapter/Http.php +++ b/app/code/core/Mage/Dataflow/Model/Session/Adapter/Http.php @@ -42,7 +42,7 @@ public function load() $uploader->save($path); if ($uploadFile = $uploader->getUploadedFileName()) { $session = Mage::getModel('dataflow/session'); - $session->setCreatedDate(date(Varien_Date::DATETIME_PHP_FORMAT)); + $session->setCreatedDate(date(Mage_Core_Helper_Date::DATETIME_PHP_FORMAT)); $session->setDirection('import'); $session->setUserId(Mage::getSingleton('admin/session')->getUser()->getId()); $session->save(); diff --git a/app/code/core/Mage/Eav/Model/Attribute/Data/Abstract.php b/app/code/core/Mage/Eav/Model/Attribute/Data/Abstract.php index b403a8b80e9..6b2e6bcd900 100644 --- a/app/code/core/Mage/Eav/Model/Attribute/Data/Abstract.php +++ b/app/code/core/Mage/Eav/Model/Attribute/Data/Abstract.php @@ -421,7 +421,7 @@ protected function _validateInputRule($value) } break; case 'date': - $validator = new Zend_Validate_Date(Varien_Date::DATE_INTERNAL_FORMAT); + $validator = new Zend_Validate_Date(Mage_Core_Helper_Date::DATE_INTERNAL_FORMAT); $validator->setMessage( Mage::helper('eav')->__('"%s" invalid type entered.', $label), Zend_Validate_Date::INVALID, diff --git a/app/code/core/Mage/Eav/Model/Entity/Abstract.php b/app/code/core/Mage/Eav/Model/Entity/Abstract.php index 2afd0c8245f..b5d4dcb7ad3 100644 --- a/app/code/core/Mage/Eav/Model/Entity/Abstract.php +++ b/app/code/core/Mage/Eav/Model/Entity/Abstract.php @@ -863,8 +863,8 @@ public function checkAttributeUniqueValue(Mage_Eav_Model_Entity_Attribute_Abstra } else { $value = $object->getData($attribute->getAttributeCode()); if ($attribute->getBackend()->getType() === 'datetime') { - $date = new Zend_Date($value, Varien_Date::DATE_INTERNAL_FORMAT); - $value = $date->toString(Varien_Date::DATETIME_INTERNAL_FORMAT); + $date = new Zend_Date($value, Mage_Core_Helper_Date::DATE_INTERNAL_FORMAT); + $value = $date->toString(Mage_Core_Helper_Date::DATETIME_INTERNAL_FORMAT); } $bind = [ 'entity_type_id' => $this->getTypeId(), diff --git a/app/code/core/Mage/Eav/Model/Entity/Attribute/Backend/Datetime.php b/app/code/core/Mage/Eav/Model/Entity/Attribute/Backend/Datetime.php index 252577293ff..396d4aeb3ef 100644 --- a/app/code/core/Mage/Eav/Model/Entity/Attribute/Backend/Datetime.php +++ b/app/code/core/Mage/Eav/Model/Entity/Attribute/Backend/Datetime.php @@ -82,6 +82,6 @@ public function formatDate($date) false, ); } - return $date->toString(Varien_Date::DATETIME_INTERNAL_FORMAT); + return $date->toString(Mage_Core_Helper_Date::DATETIME_INTERNAL_FORMAT); } } diff --git a/app/code/core/Mage/Eav/Model/Entity/Attribute/Backend/Time/Created.php b/app/code/core/Mage/Eav/Model/Entity/Attribute/Backend/Time/Created.php index def2dac6b72..3a9f05f17b6 100644 --- a/app/code/core/Mage/Eav/Model/Entity/Attribute/Backend/Time/Created.php +++ b/app/code/core/Mage/Eav/Model/Entity/Attribute/Backend/Time/Created.php @@ -14,6 +14,8 @@ * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +use Carbon\Carbon; + /** * Entity/Attribute/Model - attribute backend default * @@ -49,7 +51,7 @@ public function beforeSave($object) $date = $object->getData($attributeCode); if (is_null($date)) { if ($object->isObjectNew()) { - $object->setData($attributeCode, Varien_Date::now()); + $object->setData($attributeCode, Carbon::now()->format(Carbon::DEFAULT_TO_STRING_FORMAT)); } } else { // convert to UTC diff --git a/app/code/core/Mage/Eav/Model/Entity/Attribute/Backend/Time/Updated.php b/app/code/core/Mage/Eav/Model/Entity/Attribute/Backend/Time/Updated.php index f30b9adfa20..af333bfaf96 100644 --- a/app/code/core/Mage/Eav/Model/Entity/Attribute/Backend/Time/Updated.php +++ b/app/code/core/Mage/Eav/Model/Entity/Attribute/Backend/Time/Updated.php @@ -14,6 +14,8 @@ * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +use Carbon\Carbon; + /** * Entity/Attribute/Model - attribute backend default * @@ -30,7 +32,7 @@ class Mage_Eav_Model_Entity_Attribute_Backend_Time_Updated extends Mage_Eav_Mode */ public function beforeSave($object) { - $object->setData($this->getAttribute()->getAttributeCode(), Varien_Date::now()); + $object->setData($this->getAttribute()->getAttributeCode(), Carbon::now()->format(Carbon::DEFAULT_TO_STRING_FORMAT)); return $this; } } diff --git a/app/code/core/Mage/ImportExport/Model/Export.php b/app/code/core/Mage/ImportExport/Model/Export.php index c361b8312b0..467ef6f8924 100644 --- a/app/code/core/Mage/ImportExport/Model/Export.php +++ b/app/code/core/Mage/ImportExport/Model/Export.php @@ -14,6 +14,8 @@ * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +use Carbon\Carbon; + /** * Export model * @@ -298,6 +300,6 @@ public function getFileFormat() */ public function getFileName() { - return $this->getEntity() . '_' . date('Ymd_His') . '.' . $this->_getWriter()->getFileExtension(); + return $this->getEntity() . '_' . Carbon::now()->format('Ymd_His') . '.' . $this->_getWriter()->getFileExtension(); } } diff --git a/app/code/core/Mage/ImportExport/Model/Import/Entity/Customer.php b/app/code/core/Mage/ImportExport/Model/Import/Entity/Customer.php index a5c96958c06..253dde75df6 100644 --- a/app/code/core/Mage/ImportExport/Model/Import/Entity/Customer.php +++ b/app/code/core/Mage/ImportExport/Model/Import/Entity/Customer.php @@ -14,6 +14,8 @@ * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +use Carbon\Carbon; + /** * Import entity customer model * @@ -380,13 +382,13 @@ protected function _saveCustomers() } if (self::SCOPE_DEFAULT == $this->getRowScope($rowData)) { // entity table data - $now = Varien_Date::now(); + $now = Carbon::now()->format(Carbon::DEFAULT_TO_STRING_FORMAT); $entityRow = [ 'group_id' => empty($rowData['group_id']) ? self::DEFAULT_GROUP_ID : $rowData['group_id'], 'store_id' => empty($rowData[self::COL_STORE]) ? 0 : $this->_storeCodeToId[$rowData[self::COL_STORE]], 'created_at' => empty($rowData['created_at']) - ? $now : gmdate(Varien_Date::DATETIME_PHP_FORMAT, strtotime($rowData['created_at'])), + ? $now : gmdate(Mage_Core_Helper_Date::DATETIME_PHP_FORMAT, strtotime($rowData['created_at'])), 'updated_at' => $now, ]; @@ -418,7 +420,7 @@ protected function _saveCustomers() if ($attrParams['type'] === 'select') { $value = $attrParams['options'][strtolower($value)]; } elseif ($attrParams['type'] === 'datetime') { - $value = gmdate(Varien_Date::DATETIME_PHP_FORMAT, strtotime($value)); + $value = gmdate(Mage_Core_Helper_Date::DATETIME_PHP_FORMAT, strtotime($value)); } elseif ($attrParams['type'] === 'multiselect') { $value = (array) $attrParams['options'][strtolower($value)]; $attribute->getBackend()->beforeSave($resource->setData($attrCode, $value)); diff --git a/app/code/core/Mage/ImportExport/Model/Import/Entity/Customer/Address.php b/app/code/core/Mage/ImportExport/Model/Import/Entity/Customer/Address.php index 162583b3a5b..e4f8696ed99 100644 --- a/app/code/core/Mage/ImportExport/Model/Import/Entity/Customer/Address.php +++ b/app/code/core/Mage/ImportExport/Model/Import/Entity/Customer/Address.php @@ -14,6 +14,8 @@ * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +use Carbon\Carbon; + /** * Import entity customer address * @@ -191,7 +193,7 @@ protected function _importData() if ($attrParams['type'] === 'select') { $value = $attrParams['options'][strtolower($rowData[$attrAlias])]; } elseif ($attrParams['type'] === 'datetime') { - $value = gmdate(Varien_Date::DATETIME_PHP_FORMAT, strtotime($rowData[$attrAlias])); + $value = gmdate(Mage_Core_Helper_Date::DATETIME_PHP_FORMAT, strtotime($rowData[$attrAlias])); } elseif ($attrParams['type'] === 'multiselect') { $value = $attrParams['options'][strtolower($rowData[$attrAlias])]; $multiSelect[$attrParams['id']][] = $value; @@ -214,7 +216,7 @@ protected function _importData() || $rowScope == Mage_ImportExport_Model_Import_Entity_Customer::SCOPE_ADDRESS ) { // entity table data - $now = Varien_Date::now(); + $now = Carbon::now()->format(Carbon::DEFAULT_TO_STRING_FORMAT); $entityRows[] = [ 'entity_id' => $entityId, 'entity_type_id' => $this->_entityTypeId, diff --git a/app/code/core/Mage/ImportExport/Model/Import/Entity/Product.php b/app/code/core/Mage/ImportExport/Model/Import/Entity/Product.php index 302a3a3d961..93e03abd5d9 100644 --- a/app/code/core/Mage/ImportExport/Model/Import/Entity/Product.php +++ b/app/code/core/Mage/ImportExport/Model/Import/Entity/Product.php @@ -14,6 +14,8 @@ * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +use Carbon\Carbon; + /** * Import entity product model * @@ -904,7 +906,7 @@ protected function _saveCustomOptions() 'entity_id' => $productId, 'has_options' => 0, 'required_options' => 0, - 'updated_at' => Varien_Date::now(), + 'updated_at' => Carbon::now()->format(Carbon::DEFAULT_TO_STRING_FORMAT), ]; } @@ -1383,7 +1385,7 @@ protected function _saveProducts() if (self::SCOPE_DEFAULT == $rowScope) { $rowSku = $rowData[self::COL_SKU]; - $now = Varien_Date::now(); + $now = Carbon::now()->format(Carbon::DEFAULT_TO_STRING_FORMAT); // 1. Entity phase if (isset($this->_oldSku[$rowSku])) { // existing row @@ -1519,7 +1521,7 @@ protected function _saveProducts() */ protected function _getStrftimeFormat() { - return Varien_Date::convertZendToStrftime(Varien_Date::DATETIME_INTERNAL_FORMAT, true, true); + return Varien_Date::convertZendToStrftime(Mage_Core_Helper_Date::DATETIME_INTERNAL_FORMAT, true, true); } /** @@ -1568,7 +1570,7 @@ protected function _prepareAttributes($rowData, $rowScope, $attributes, $rowSku, $storeIds = [0]; if ($attribute->getBackendType() === 'datetime' && strtotime($attrValue)) { - $attrValue = gmdate(Varien_Date::DATETIME_PHP_FORMAT, strtotime($attrValue)); + $attrValue = gmdate(Mage_Core_Helper_Date::DATETIME_PHP_FORMAT, strtotime($attrValue)); } elseif ($attribute->getAttributeCode() === 'url_key') { if (empty($attrValue)) { $locale = Mage::getStoreConfig(Mage_Core_Model_Locale::XML_PATH_DEFAULT_LOCALE, $product->getStoreId()); @@ -1955,7 +1957,7 @@ protected function _saveStockItem() if ($stockItem->verifyNotification()) { $stockItem->setLowStockDate(Mage::app()->getLocale() ->date(null, null, null, false) - ->toString(Varien_Date::DATETIME_INTERNAL_FORMAT)); + ->toString(Mage_Core_Helper_Date::DATETIME_INTERNAL_FORMAT)); } $stockItem->setStockStatusChangedAutomatically((int) !$stockItem->verifyStock()); } else { diff --git a/app/code/core/Mage/Index/Model/Event.php b/app/code/core/Mage/Index/Model/Event.php index 7e6c3a597ee..80c2151821a 100644 --- a/app/code/core/Mage/Index/Model/Event.php +++ b/app/code/core/Mage/Index/Model/Event.php @@ -14,6 +14,8 @@ * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +use Carbon\Carbon; + /** * @category Mage * @package Mage_Index @@ -327,7 +329,7 @@ protected function _beforeSave() $newData = $this->getNewData(false); $this->setNewData(serialize($newData)); if (!$this->hasCreatedAt()) { - $this->setCreatedAt($this->_getResource()->formatDate(time(), true)); + $this->setCreatedAt($this->_getResource()->formatDate(Carbon::now()->getTimestamp())); } return parent::_beforeSave(); } diff --git a/app/code/core/Mage/Index/Model/Lock.php b/app/code/core/Mage/Index/Model/Lock.php index 64b00178600..78fed02943d 100644 --- a/app/code/core/Mage/Index/Model/Lock.php +++ b/app/code/core/Mage/Index/Model/Lock.php @@ -14,6 +14,8 @@ * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +use Carbon\Carbon; + /** * Lock model * @@ -293,7 +295,7 @@ protected function _getLockFile($lockName) self::$_lockFileResource[$lockName] = null; throw new Exception(sprintf('Unable to open lock file \'%s\': %s', $file, error_get_last())); } - fwrite(self::$_lockFileResource[$lockName], date('r')); + fwrite(self::$_lockFileResource[$lockName], Carbon::now()->format('r')); } return self::$_lockFileResource[$lockName]; } diff --git a/app/code/core/Mage/Index/Model/Observer.php b/app/code/core/Mage/Index/Model/Observer.php index 5def2ba217f..385110d5bc8 100644 --- a/app/code/core/Mage/Index/Model/Observer.php +++ b/app/code/core/Mage/Index/Model/Observer.php @@ -14,6 +14,8 @@ * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +use Carbon\Carbon; + /** * @category Mage * @package Mage_Index @@ -152,7 +154,7 @@ public function cleanOutdatedEvents() ->getProcessesCollection() ->addFieldToFilter('mode', Mage_Index_Model_Process::MODE_MANUAL); - $now = new DateTime(); + $now = Carbon::now(); /** @noinspection PhpUnhandledExceptionInspection */ $dateInterval = new DateInterval('PT' . self::OLD_INDEX_EVENT_THRESHOLD_SECONDS . 'S'); $oldEventsThreshold = $now diff --git a/app/code/core/Mage/Index/Model/Resource/Process.php b/app/code/core/Mage/Index/Model/Resource/Process.php index a58c96f4295..0054bcc8b79 100644 --- a/app/code/core/Mage/Index/Model/Resource/Process.php +++ b/app/code/core/Mage/Index/Model/Resource/Process.php @@ -14,6 +14,8 @@ * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +use Carbon\Carbon; + /** * Index Process Resource Model * @@ -55,7 +57,7 @@ public function endProcess(Mage_Index_Model_Process $process) { $data = [ 'status' => Mage_Index_Model_Process::STATUS_PENDING, - 'ended_at' => $this->formatDate(time()), + 'ended_at' => $this->formatDate(Carbon::now()->getTimestamp()), ]; $this->_updateProcessData($process->getId(), $data); return $this; @@ -70,7 +72,7 @@ public function startProcess(Mage_Index_Model_Process $process) { $data = [ 'status' => Mage_Index_Model_Process::STATUS_RUNNING, - 'started_at' => $this->formatDate(time()), + 'started_at' => $this->formatDate(Carbon::now()->getTimestamp()), ]; $this->_updateProcessData($process->getId(), $data); return $this; @@ -85,7 +87,7 @@ public function failProcess(Mage_Index_Model_Process $process) { $data = [ 'status' => Mage_Index_Model_Process::STATUS_REQUIRE_REINDEX, - 'ended_at' => $this->formatDate(time()), + 'ended_at' => $this->formatDate(Carbon::now()->getTimestamp()), ]; $this->_updateProcessData($process->getId(), $data); return $this; @@ -127,7 +129,7 @@ protected function _updateProcessData($processId, $data) */ public function updateProcessStartDate(Mage_Index_Model_Process $process) { - $this->_updateProcessData($process->getId(), ['started_at' => $this->formatDate(time())]); + $this->_updateProcessData($process->getId(), ['started_at' => $this->formatDate(Carbon::now()->getTimestamp())]); return $this; } @@ -138,7 +140,7 @@ public function updateProcessStartDate(Mage_Index_Model_Process $process) */ public function updateProcessEndDate(Mage_Index_Model_Process $process) { - $this->_updateProcessData($process->getId(), ['ended_at' => $this->formatDate(time())]); + $this->_updateProcessData($process->getId(), ['ended_at' => $this->formatDate(Carbon::now()->getTimestamp())]); return $this; } diff --git a/app/code/core/Mage/Install/Model/Installer/Config.php b/app/code/core/Mage/Install/Model/Installer/Config.php index 1a3a5bb9dcc..e7df326d9ea 100644 --- a/app/code/core/Mage/Install/Model/Installer/Config.php +++ b/app/code/core/Mage/Install/Model/Installer/Config.php @@ -14,6 +14,8 @@ * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +use Carbon\Carbon; + /** * Config installer * @@ -171,7 +173,7 @@ public function replaceTmpInstallDate($date = null) { $stamp = strtotime((string) $date); $localXml = file_get_contents($this->_localConfigFile); - $localXml = str_replace(self::TMP_INSTALL_DATE_VALUE, date('r', $stamp ? $stamp : time()), $localXml); + $localXml = str_replace(self::TMP_INSTALL_DATE_VALUE, date('r', $stamp ? $stamp : Carbon::now()->getTimestamp()), $localXml); file_put_contents($this->_localConfigFile, $localXml); return $this; diff --git a/app/code/core/Mage/Log/Model/Aggregation.php b/app/code/core/Mage/Log/Model/Aggregation.php index 5a70b23d44c..f11974de6d1 100644 --- a/app/code/core/Mage/Log/Model/Aggregation.php +++ b/app/code/core/Mage/Log/Model/Aggregation.php @@ -14,6 +14,8 @@ * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +use Carbon\Carbon; + /** * Log Aggregation Model * @@ -61,7 +63,7 @@ private function _process($store) { $lastDateRecord = null; $start = $this->_lastRecord; - $end = time(); + $end = Carbon::now()->getTimestamp(); $date = $start; while ($date < $end) { @@ -150,7 +152,7 @@ private function _date($in, $offset = null) { $out = $in; if (is_numeric($in)) { - $out = date(Varien_Date::DATETIME_PHP_FORMAT, $in); + $out = date(Mage_Core_Helper_Date::DATETIME_PHP_FORMAT, $in); } return $out; } diff --git a/app/code/core/Mage/Log/Model/Customer.php b/app/code/core/Mage/Log/Model/Customer.php index 7597c58da3d..1ff1c64d607 100644 --- a/app/code/core/Mage/Log/Model/Customer.php +++ b/app/code/core/Mage/Log/Model/Customer.php @@ -14,6 +14,8 @@ * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +use Carbon\Carbon; + /** * Customer log model * @@ -69,7 +71,7 @@ public function getLoginAtTimestamp() { $loginAt = $this->getLoginAt(); if ($loginAt) { - return Varien_Date::toTimestamp($loginAt); + return Carbon::now()->setTimeFromTimeString($loginAt)->getTimestamp(); } return null; diff --git a/app/code/core/Mage/Log/Model/Resource/Visitor/Online.php b/app/code/core/Mage/Log/Model/Resource/Visitor/Online.php index 1b3bb9e345b..db9c7dbf7b3 100644 --- a/app/code/core/Mage/Log/Model/Resource/Visitor/Online.php +++ b/app/code/core/Mage/Log/Model/Resource/Visitor/Online.php @@ -14,6 +14,8 @@ * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +use Carbon\Carbon; + /** * Log Prepare Online visitors resource * @@ -34,7 +36,7 @@ protected function _construct() */ public function prepare(Mage_Log_Model_Visitor_Online $object) { - if (($object->getUpdateFrequency() + $object->getPrepareAt()) > time()) { + if (($object->getUpdateFrequency() + $object->getPrepareAt()) > Carbon::now()->getTimestamp()) { return $this; } diff --git a/app/code/core/Mage/Log/Model/Visitor.php b/app/code/core/Mage/Log/Model/Visitor.php index 016bbacb99b..64a4d98d4ec 100644 --- a/app/code/core/Mage/Log/Model/Visitor.php +++ b/app/code/core/Mage/Log/Model/Visitor.php @@ -14,6 +14,8 @@ * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +use Carbon\Carbon; + /** * @category Mage * @package Mage_Log @@ -182,7 +184,7 @@ public function getUrl() public function getFirstVisitAt() { if (!$this->hasData('first_visit_at')) { - $this->setData('first_visit_at', Varien_Date::now()); + $this->setData('first_visit_at', Carbon::now()->format(Carbon::DEFAULT_TO_STRING_FORMAT)); } return $this->getData('first_visit_at'); } @@ -193,7 +195,7 @@ public function getFirstVisitAt() public function getLastVisitAt() { if (!$this->hasData('last_visit_at')) { - $this->setData('last_visit_at', Varien_Date::now()); + $this->setData('last_visit_at', Carbon::now()->format(Carbon::DEFAULT_TO_STRING_FORMAT)); } return $this->getData('last_visit_at'); } @@ -217,7 +219,7 @@ public function initByRequest($observer) $visitorId = $this->getId(); if (!$visitorId) { $this->initServerData(); - $this->setFirstVisitAt(Varien_Date::now()); + $this->setFirstVisitAt(Carbon::now()->format(Carbon::DEFAULT_TO_STRING_FORMAT)); $this->setIsNewVisitor(true); $this->save(); } @@ -258,7 +260,7 @@ public function saveByRequest($observer) try { $this->initServerData(); - $this->setLastVisitAt(Varien_Date::now()); + $this->setLastVisitAt(Carbon::now()->format(Carbon::DEFAULT_TO_STRING_FORMAT)); $this->save(); $this->_session->setVisitorData($this->getData()); } catch (Exception $e) { diff --git a/app/code/core/Mage/Log/Model/Visitor/Online.php b/app/code/core/Mage/Log/Model/Visitor/Online.php index 187fbe43129..b97b4ee0b3f 100644 --- a/app/code/core/Mage/Log/Model/Visitor/Online.php +++ b/app/code/core/Mage/Log/Model/Visitor/Online.php @@ -14,6 +14,8 @@ * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +use Carbon\Carbon; + /** * Prepare Log Online Visitors Model * @@ -76,7 +78,7 @@ public function getPrepareAt() public function setPrepareAt($time = null) { if (is_null($time)) { - $time = time(); + $time = Carbon::now()->getTimestamp(); } Mage::app()->saveCache($time, 'log_visitor_online_prepare_at'); return $this; diff --git a/app/code/core/Mage/Oauth/Model/Consumer.php b/app/code/core/Mage/Oauth/Model/Consumer.php index e85db94bb2f..460e5f1ac76 100644 --- a/app/code/core/Mage/Oauth/Model/Consumer.php +++ b/app/code/core/Mage/Oauth/Model/Consumer.php @@ -14,6 +14,8 @@ * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +use Carbon\Carbon; + /** * Application model * @@ -64,7 +66,7 @@ protected function _construct() protected function _beforeSave() { if (!$this->getId()) { - $this->setUpdatedAt(time()); + $this->setUpdatedAt(Carbon::now()->getTimestamp()); } $this->setCallbackUrl(trim($this->getCallbackUrl())); $this->setRejectedCallbackUrl(trim($this->getRejectedCallbackUrl())); diff --git a/app/code/core/Mage/Oauth/Model/Resource/Nonce.php b/app/code/core/Mage/Oauth/Model/Resource/Nonce.php index 2972d45cfc9..35959f6b363 100644 --- a/app/code/core/Mage/Oauth/Model/Resource/Nonce.php +++ b/app/code/core/Mage/Oauth/Model/Resource/Nonce.php @@ -14,6 +14,8 @@ * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +use Carbon\Carbon; + /** * oAuth nonce resource model * @@ -40,7 +42,7 @@ public function deleteOldEntries($minutes) return $adapter->delete( $this->getMainTable(), - $adapter->quoteInto('timestamp <= ?', time() - $minutes * 60, Zend_Db::INT_TYPE), + $adapter->quoteInto('timestamp <= ?', Carbon::now()->subMinutes($minutes)->getTimestamp(), Zend_Db::INT_TYPE), ); } else { return 0; diff --git a/app/code/core/Mage/Oauth/Model/Resource/Token.php b/app/code/core/Mage/Oauth/Model/Resource/Token.php index 9ae8e421fd0..277c4a77ffd 100644 --- a/app/code/core/Mage/Oauth/Model/Resource/Token.php +++ b/app/code/core/Mage/Oauth/Model/Resource/Token.php @@ -14,6 +14,8 @@ * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +use Carbon\Carbon; + /** * OAuth token resource model * @@ -74,7 +76,7 @@ public function deleteOldEntries($minutes) $this->getMainTable(), $adapter->quoteInto( 'type = "' . Mage_Oauth_Model_Token::TYPE_REQUEST . '" AND created_at <= ?', - Varien_Date::formatDate(time() - $minutes * 60), + Varien_Date::formatDate(Carbon::now()->subMinutes($minutes)->getTimestamp()), ), ); } else { diff --git a/app/code/core/Mage/Oauth/Model/Server.php b/app/code/core/Mage/Oauth/Model/Server.php index 5f5c907f597..ab3e5aee8a1 100644 --- a/app/code/core/Mage/Oauth/Model/Server.php +++ b/app/code/core/Mage/Oauth/Model/Server.php @@ -14,6 +14,8 @@ * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +use Carbon\Carbon; + /** * oAuth Server * @@ -450,12 +452,14 @@ protected function _validateCallbackUrlParam() * * @param string $nonce Nonce string * @param string|int $timestamp UNIX Timestamp + * @throws Mage_Core_Exception + * @throws Throwable */ protected function _validateNonce($nonce, $timestamp) { $timestamp = (int) $timestamp; - if ($timestamp <= 0 || $timestamp > (time() + self::TIME_DEVIATION)) { + if ($timestamp <= 0 || $timestamp > Carbon::now()->addSeconds(self::TIME_DEVIATION)->getTimestamp()) { $this->_throwException('', self::ERR_TIMESTAMP_REFUSED); } /** @var Mage_Oauth_Model_Nonce $nonceObj */ diff --git a/app/code/core/Mage/Oauth/Model/Token.php b/app/code/core/Mage/Oauth/Model/Token.php index 129c4c67e4c..c99f0a78e15 100644 --- a/app/code/core/Mage/Oauth/Model/Token.php +++ b/app/code/core/Mage/Oauth/Model/Token.php @@ -14,6 +14,8 @@ * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +use Carbon\Carbon; + /** * oAuth token model * @@ -212,7 +214,7 @@ protected function _beforeSave() $this->validate(); if ($this->isObjectNew() && $this->getCreatedAt() === null) { - $this->setCreatedAt(Varien_Date::now()); + $this->setCreatedAt(Carbon::now()->format(Carbon::DEFAULT_TO_STRING_FORMAT)); } parent::_beforeSave(); return $this; diff --git a/app/code/core/Mage/Payment/Block/Form/Cc.php b/app/code/core/Mage/Payment/Block/Form/Cc.php index c7cddd4cb98..b68bf5fcfd0 100644 --- a/app/code/core/Mage/Payment/Block/Form/Cc.php +++ b/app/code/core/Mage/Payment/Block/Form/Cc.php @@ -14,6 +14,8 @@ * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +use Carbon\Carbon; + /** * @category Mage * @package Mage_Payment @@ -133,7 +135,7 @@ public function hasSsCardType() public function getSsStartYears() { $years = []; - $first = date('Y'); + $first = Carbon::now()->format('Y'); for ($index = 5; $index >= 0; $index--) { $year = $first - $index; diff --git a/app/code/core/Mage/Payment/Model/Config.php b/app/code/core/Mage/Payment/Model/Config.php index 779f81c2553..91faa90a1e1 100644 --- a/app/code/core/Mage/Payment/Model/Config.php +++ b/app/code/core/Mage/Payment/Model/Config.php @@ -14,6 +14,8 @@ * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +use Carbon\Carbon; + /** * Payment configuration model * @@ -135,7 +137,7 @@ public function getMonths() public function getYears() { $years = []; - $first = date('Y'); + $first = (int) Carbon::now()->format('Y'); for ($index = 0; $index <= 10; $index++) { $year = $first + $index; diff --git a/app/code/core/Mage/Payment/Model/Recurring/Profile.php b/app/code/core/Mage/Payment/Model/Recurring/Profile.php index e6a8a669f66..9d8b6d6b237 100644 --- a/app/code/core/Mage/Payment/Model/Recurring/Profile.php +++ b/app/code/core/Mage/Payment/Model/Recurring/Profile.php @@ -14,6 +14,8 @@ * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +use Carbon\Carbon; + /** * Recurring payment profile * Extends from Mage_Core_Abstract for a reason: to make descendants have its own resource @@ -110,7 +112,7 @@ public function isValid() // start date, order ref ID, schedule description if (!$this->getStartDatetime()) { $this->_errors['start_datetime'][] = Mage::helper('payment')->__('Start date is undefined.'); - } elseif (!Zend_Date::isDate($this->getStartDatetime(), Varien_Date::DATETIME_INTERNAL_FORMAT)) { + } elseif (!Zend_Date::isDate($this->getStartDatetime(), Mage_Core_Helper_Date::DATETIME_INTERNAL_FORMAT)) { $this->_errors['start_datetime'][] = Mage::helper('payment')->__('Start date has invalid format.'); } if (!$this->getScheduleDescription()) { @@ -230,7 +232,7 @@ public function importBuyRequest(Varien_Object $buyRequest) Mage::throwException(Mage::helper('payment')->__('Recurring profile start date has invalid format.')); } $utcTime = $this->_locale->utcDate($this->_store, $startDate, true, $dateFormat) - ->toString(Varien_Date::DATETIME_INTERNAL_FORMAT); + ->toString(Mage_Core_Helper_Date::DATETIME_INTERNAL_FORMAT); $this->setStartDatetime($utcTime)->setImportedStartDatetime($startDate); } return $this->_filterValues(); @@ -259,7 +261,7 @@ public function importProduct(Mage_Catalog_Model_Product $product) $options = unserialize($options->getValue(), ['allowed_classes' => false]); if (is_array($options)) { if (isset($options['start_datetime'])) { - $startDatetime = new Zend_Date($options['start_datetime'], Varien_Date::DATETIME_INTERNAL_FORMAT); + $startDatetime = new Zend_Date($options['start_datetime'], Mage_Core_Helper_Date::DATETIME_INTERNAL_FORMAT); $this->setNearestStartDatetime($startDatetime); } } @@ -303,10 +305,10 @@ public function setNearestStartDatetime(?Zend_Date $minAllowed = null) { // TODO: implement proper logic with invoking payment method instance $date = $minAllowed; - if (!$date || $date->getTimestamp() < time()) { - $date = new Zend_Date(time()); + if (!$date || $date->getTimestamp() < Carbon::now()->getTimestamp()) { + $date = new Zend_Date(Carbon::now()->getTimestamp()); } - $this->setStartDatetime($date->toString(Varien_Date::DATETIME_INTERNAL_FORMAT)); + $this->setStartDatetime($date->toString(Mage_Core_Helper_Date::DATETIME_INTERNAL_FORMAT)); return $this; } @@ -553,7 +555,7 @@ protected function _filterValues() // automatically determine start date, if not set if ($this->getStartDatetime()) { - $date = new Zend_Date($this->getStartDatetime(), Varien_Date::DATETIME_INTERNAL_FORMAT); + $date = new Zend_Date($this->getStartDatetime(), Mage_Core_Helper_Date::DATETIME_INTERNAL_FORMAT); $this->setNearestStartDatetime($date); } else { $this->setNearestStartDatetime(); diff --git a/app/code/core/Mage/Paypal/Model/Express.php b/app/code/core/Mage/Paypal/Model/Express.php index d2e27b1a905..f4772ef7189 100644 --- a/app/code/core/Mage/Paypal/Model/Express.php +++ b/app/code/core/Mage/Paypal/Model/Express.php @@ -14,6 +14,8 @@ * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +use Carbon\Carbon; + /** * @category Mage * @package Mage_Paypal @@ -641,7 +643,7 @@ public function canCapture() $dateCompass = new DateTime($orderTransaction->getCreatedAt()); $dateCompass->modify('+' . $orderValidPeriod . ' days'); - $currentDate = new DateTime(); + $currentDate = Carbon::now(); if ($currentDate > $dateCompass || $orderValidPeriod == 0) { return false; diff --git a/app/code/core/Mage/Paypal/Model/Express/Checkout.php b/app/code/core/Mage/Paypal/Model/Express/Checkout.php index 0ec6258ad76..4a0fdd174ff 100644 --- a/app/code/core/Mage/Paypal/Model/Express/Checkout.php +++ b/app/code/core/Mage/Paypal/Model/Express/Checkout.php @@ -14,6 +14,8 @@ * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +use Carbon\Carbon; + /** * Wrapper that performs Paypal Express and Checkout communication * Use current Paypal Express method instance @@ -982,7 +984,7 @@ protected function _prepareNewCustomerQuote() $customer->setSuffix($quote->getCustomerSuffix()); $customer->setPassword($customer->decryptPassword($quote->getPasswordHash())); $customer->setPasswordHash($customer->hashPassword($customer->getPassword())); - $customer->setPasswordCreatedAt(time()); + $customer->setPasswordCreatedAt(Carbon::now()->getTimestamp()); $customer->save(); $quote->setCustomer($customer); $quote->setPasswordHash(''); diff --git a/app/code/core/Mage/Paypal/Model/Report/Settlement.php b/app/code/core/Mage/Paypal/Model/Report/Settlement.php index 699006fdfb0..bdaa6d2e76b 100644 --- a/app/code/core/Mage/Paypal/Model/Report/Settlement.php +++ b/app/code/core/Mage/Paypal/Model/Report/Settlement.php @@ -216,7 +216,7 @@ public function fetchAndSave($config) // Set last modified date, this value will be overwritten during parsing if (isset($attributes['mtime'])) { $lastModified = new Zend_Date($attributes['mtime']); - $this->setReportLastModified($lastModified->toString(Varien_Date::DATETIME_INTERNAL_FORMAT)); + $this->setReportLastModified($lastModified->toString(Mage_Core_Helper_Date::DATETIME_INTERNAL_FORMAT)); } $this->setReportDate($this->_fileNameToDate($filename)) @@ -262,7 +262,7 @@ public function parseCsv($localCsv, $format = 'new') switch ($lineType) { case 'RH': // Report header. $lastModified = new Zend_Date($line[1]); - $this->setReportLastModified($lastModified->toString(Varien_Date::DATETIME_INTERNAL_FORMAT)); + $this->setReportLastModified($lastModified->toString(Mage_Core_Helper_Date::DATETIME_INTERNAL_FORMAT)); //$this->setAccountId($columns[2]); -- probably we'll just take that from the section header... break; case 'FH': // File header. diff --git a/app/code/core/Mage/Persistent/Model/Session.php b/app/code/core/Mage/Persistent/Model/Session.php index 3138355bd7e..220e939abac 100644 --- a/app/code/core/Mage/Persistent/Model/Session.php +++ b/app/code/core/Mage/Persistent/Model/Session.php @@ -14,6 +14,8 @@ * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +use Carbon\Carbon; + /** * Persistent Session Model * @@ -88,7 +90,7 @@ public function getExpiredBefore($store = null) { return gmdate( Varien_Db_Adapter_Pdo_Mysql::TIMESTAMP_FORMAT, - time() - Mage::helper('persistent')->getLifeTime($store), + Carbon::now()->subSeconds(Mage::helper('persistent')->getLifeTime($store))->getTimestamp(), ); } @@ -216,7 +218,7 @@ public function deleteExpired($websiteId = null) if ($lifetime) { $this->getResource()->deleteExpired( $websiteId, - gmdate(Varien_Date::DATETIME_PHP_FORMAT, time() - $lifetime), + gmdate(Mage_Core_Helper_Date::DATETIME_PHP_FORMAT, Carbon::now()->subSeconds((int) $lifetime->__toString())->getTimestamp()), ); } @@ -241,7 +243,7 @@ protected function _afterDeleteCommit() */ public function save() { - $this->setUpdatedAt(gmdate(Varien_Date::DATETIME_PHP_FORMAT)); + $this->setUpdatedAt(gmdate(Mage_Core_Helper_Date::DATETIME_PHP_FORMAT)); return parent::save(); } } diff --git a/app/code/core/Mage/Reports/Helper/Data.php b/app/code/core/Mage/Reports/Helper/Data.php index b99a77a546a..579c8535bef 100644 --- a/app/code/core/Mage/Reports/Helper/Data.php +++ b/app/code/core/Mage/Reports/Helper/Data.php @@ -14,6 +14,8 @@ * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +use Carbon\Carbon; + /** * @category Mage * @package Mage_Reports @@ -42,63 +44,54 @@ public function isReportsEnabled() /** * Retrieve array of intervals * - * @param string $from - * @param string $to - * @param string $period + * @param string $dateFrom + * @param string $dateTo + * @param self::REPORT_PERIOD_TYPE_* $period * @return array */ - public function getIntervals($from, $to, $period = self::REPORT_PERIOD_TYPE_DAY) + public function getIntervals($dateFrom, $dateTo, $period = self::REPORT_PERIOD_TYPE_DAY) { $intervals = []; - if (!$from && !$to) { + if (!$dateFrom && !$dateTo) { return $intervals; } - $start = new Zend_Date($from, Varien_Date::DATE_INTERNAL_FORMAT); - - if ($period == self::REPORT_PERIOD_TYPE_DAY) { - $dateStart = $start; - } + $dateStart = Carbon::now()->setTimeFromTimeString($dateFrom); + $endDate = Carbon::now()->setTimeFromTimeString($dateTo); - if ($period == self::REPORT_PERIOD_TYPE_MONTH) { - $dateStart = new Zend_Date(date('Y-m', $start->getTimestamp()), Varien_Date::DATE_INTERNAL_FORMAT); + switch ($period) { + case self::REPORT_PERIOD_TYPE_DAY: + $format = 'YYYY-MM-DD'; + $modifier = 'addDay'; + break; + case self::REPORT_PERIOD_TYPE_MONTH: + $format = 'YYYY-MM'; + $modifier = 'addMonth'; + break; + default: + case self::REPORT_PERIOD_TYPE_YEAR: + $format = 'YYYY'; + $modifier = 'addYear'; + $dateStart->addYear(); + break; } - if ($period == self::REPORT_PERIOD_TYPE_YEAR) { - $dateStart = new Zend_Date(date('Y', $start->getTimestamp()), Varien_Date::DATE_INTERNAL_FORMAT); + for ($date = $dateStart->copy(); $date->lte($endDate); $date->$modifier()) { + $intervals[] = $date->isoFormat($format); } - $dateEnd = new Zend_Date($to, Varien_Date::DATE_INTERNAL_FORMAT); - - while ($dateStart->compare($dateEnd) <= 0) { - switch ($period) { - case self::REPORT_PERIOD_TYPE_DAY: - $t = $dateStart->toString('yyyy-MM-dd'); - $dateStart->addDay(1); - break; - case self::REPORT_PERIOD_TYPE_MONTH: - $t = $dateStart->toString('yyyy-MM'); - $dateStart->addMonth(1); - break; - case self::REPORT_PERIOD_TYPE_YEAR: - $t = $dateStart->toString('yyyy'); - $dateStart->addYear(1); - break; - } - $intervals[] = $t; - } return $intervals; } /** * @param Varien_Data_Collection $collection - * @param string $from - * @param string $to - * @param string $periodType + * @param string $dateFrom + * @param string $dateTo + * @param self::REPORT_PERIOD_TYPE_* $periodType */ - public function prepareIntervalsCollection($collection, $from, $to, $periodType = self::REPORT_PERIOD_TYPE_DAY) + public function prepareIntervalsCollection($collection, $dateFrom, $dateTo, $periodType = self::REPORT_PERIOD_TYPE_DAY) { - $intervals = $this->getIntervals($from, $to, $periodType); + $intervals = $this->getIntervals($dateFrom, $dateTo, $periodType); foreach ($intervals as $interval) { $item = Mage::getModel('adminhtml/report_item'); diff --git a/app/code/core/Mage/Reports/Model/Product/Index/Abstract.php b/app/code/core/Mage/Reports/Model/Product/Index/Abstract.php index 8ff5ff2606c..bb5298b2293 100644 --- a/app/code/core/Mage/Reports/Model/Product/Index/Abstract.php +++ b/app/code/core/Mage/Reports/Model/Product/Index/Abstract.php @@ -14,6 +14,8 @@ * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +use Carbon\Carbon; + /** * Reports Product Index Abstract Model * @@ -58,7 +60,7 @@ public function save() $this->setStoreId($this->getStoreId()); } if (!$this->hasAddedAt()) { - $this->setAddedAt(Varien_Date::now()); + $this->setAddedAt(Carbon::now()->format(Carbon::DEFAULT_TO_STRING_FORMAT)); } // Thanks to new performance tweaks it is possible to switch off visitor logging diff --git a/app/code/core/Mage/Reports/Model/Resource/Entity/Summary/Collection/Abstract.php b/app/code/core/Mage/Reports/Model/Resource/Entity/Summary/Collection/Abstract.php index 2a6c8fb818f..b55ede42c9e 100644 --- a/app/code/core/Mage/Reports/Model/Resource/Entity/Summary/Collection/Abstract.php +++ b/app/code/core/Mage/Reports/Model/Resource/Entity/Summary/Collection/Abstract.php @@ -14,6 +14,8 @@ * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +use Carbon\Carbon; + /** * Reports summary collection * @@ -41,23 +43,23 @@ public function setSelectPeriod($periodType, $customStart = null, $customEnd = n { switch ($periodType) { case '24h': - $customStart = Varien_Date::toTimestamp(true) - 86400; - $customEnd = Varien_Date::toTimestamp(true); + $customStart = Carbon::now()->subDay()->getTimestamp(); + $customEnd = Carbon::now()->getTimestamp(); break; case '7d': - $customStart = Varien_Date::toTimestamp(true) - 604800; - $customEnd = Varien_Date::toTimestamp(true); + $customStart = Carbon::now()->subWeek()->getTimestamp(); + $customEnd = Carbon::now()->getTimestamp(); break; case '30d': - $customStart = Varien_Date::toTimestamp(true) - 2592000; - $customEnd = Varien_Date::toTimestamp(true); + $customStart = Carbon::now()->subMonth()->getTimestamp(); + $customEnd = Carbon::now()->getTimestamp(); break; case '1y': - $customStart = Varien_Date::toTimestamp(true) - 31536000; - $customEnd = Varien_Date::toTimestamp(true); + $customStart = Carbon::now()->subYear()->getTimestamp(); + $customEnd = Carbon::now()->getTimestamp(); break; default: diff --git a/app/code/core/Mage/Reports/Model/Resource/Order/Collection.php b/app/code/core/Mage/Reports/Model/Resource/Order/Collection.php index 867ffd517af..2323010d1f8 100644 --- a/app/code/core/Mage/Reports/Model/Resource/Order/Collection.php +++ b/app/code/core/Mage/Reports/Model/Resource/Order/Collection.php @@ -808,8 +808,8 @@ public function addCreateAtPeriodFilter($period) } $this->addFieldToFilter($fieldToFilter, [ - 'from' => $from->toString(Varien_Date::DATETIME_INTERNAL_FORMAT), - 'to' => $to->toString(Varien_Date::DATETIME_INTERNAL_FORMAT), + 'from' => $from->toString(Mage_Core_Helper_Date::DATETIME_INTERNAL_FORMAT), + 'to' => $to->toString(Mage_Core_Helper_Date::DATETIME_INTERNAL_FORMAT), ]); return $this; diff --git a/app/code/core/Mage/Reports/Model/Resource/Product/Index/Abstract.php b/app/code/core/Mage/Reports/Model/Resource/Product/Index/Abstract.php index 2cfecc8e589..4f54f56d268 100644 --- a/app/code/core/Mage/Reports/Model/Resource/Product/Index/Abstract.php +++ b/app/code/core/Mage/Reports/Model/Resource/Product/Index/Abstract.php @@ -14,6 +14,8 @@ * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +use Carbon\Carbon; + /** * Reports Product Index Abstract Resource Model * @@ -69,14 +71,14 @@ public function updateCustomerFromVisitor(Mage_Reports_Model_Product_Index_Abstr $data = [ 'visitor_id' => $object->getVisitorId(), 'store_id' => $object->getStoreId(), - 'added_at' => Varien_Date::now(), + 'added_at' => Carbon::now()->format(Carbon::DEFAULT_TO_STRING_FORMAT), ]; } else { $where = ['index_id = ?' => $row['index_id']]; $data = [ 'customer_id' => $object->getCustomerId(), 'store_id' => $object->getStoreId(), - 'added_at' => Varien_Date::now(), + 'added_at' => Carbon::now()->format(Carbon::DEFAULT_TO_STRING_FORMAT), ]; } @@ -187,7 +189,7 @@ public function registerIds(Varien_Object $object, $productIds) 'customer_id' => $object->getCustomerId(), 'store_id' => $object->getStoreId(), ]; - $addedAt = Varien_Date::toTimestamp(true); + $addedAt = Carbon::now()->getTimestamp(); $data = []; foreach ($productIds as $productId) { $productId = (int) $productId; diff --git a/app/code/core/Mage/Reports/Model/Resource/Report/Abstract.php b/app/code/core/Mage/Reports/Model/Resource/Report/Abstract.php index 71b1a6713cf..1bf94a69288 100644 --- a/app/code/core/Mage/Reports/Model/Resource/Report/Abstract.php +++ b/app/code/core/Mage/Reports/Model/Resource/Report/Abstract.php @@ -14,6 +14,8 @@ * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +use Carbon\Carbon; + /** * Abstract report aggregate resource model * @@ -60,7 +62,7 @@ protected function _setFlagData($code, $value = null) $this->_getFlag()->setFlagData($value); } - $time = Varien_Date::toTimestamp(true); + $time = Carbon::now()->getTimestamp(); // touch last_update $this->_getFlag()->setLastUpdate($this->formatDate($time)); @@ -407,12 +409,12 @@ protected function _getTZOffsetTransitions($timezone, $from = null, $to = null) $tzTransitions = []; try { if (!empty($from)) { - $from = new Zend_Date($from, Varien_Date::DATETIME_INTERNAL_FORMAT); + $from = new Zend_Date($from, Mage_Core_Helper_Date::DATETIME_INTERNAL_FORMAT); $from = $from->getTimestamp(); } - $to = new Zend_Date($to, Varien_Date::DATETIME_INTERNAL_FORMAT); - $nextPeriod = $this->_getWriteAdapter()->formatDate($to->toString(Varien_Date::DATETIME_INTERNAL_FORMAT)); + $to = new Zend_Date($to, Mage_Core_Helper_Date::DATETIME_INTERNAL_FORMAT); + $nextPeriod = $this->_getWriteAdapter()->formatDate($to->toString(Mage_Core_Helper_Date::DATETIME_INTERNAL_FORMAT)); $to = $to->getTimestamp(); $dtz = new DateTimeZone($timezone); @@ -426,7 +428,7 @@ protected function _getTZOffsetTransitions($timezone, $from = null, $to = null) $dateTimeObject->set($tr['time']); $tr['time'] = $this->_getWriteAdapter() - ->formatDate($dateTimeObject->toString(Varien_Date::DATETIME_INTERNAL_FORMAT)); + ->formatDate($dateTimeObject->toString(Mage_Core_Helper_Date::DATETIME_INTERNAL_FORMAT)); $tzTransitions[$tr['offset']][] = ['from' => $tr['time'], 'to' => $nextPeriod]; if (!empty($from) && $tr['ts'] < $from) { diff --git a/app/code/core/Mage/Reports/Model/Resource/Report/Collection.php b/app/code/core/Mage/Reports/Model/Resource/Report/Collection.php index b53f3063b28..cfc5c442d7e 100644 --- a/app/code/core/Mage/Reports/Model/Resource/Report/Collection.php +++ b/app/code/core/Mage/Reports/Model/Resource/Report/Collection.php @@ -67,7 +67,7 @@ class Mage_Reports_Model_Resource_Report_Collection /** * Array of store ids * - * @var array + * @var array|null */ protected $_storeIds; @@ -116,24 +116,24 @@ public function getIntervals() $dateStart = new Zend_Date($this->_from); $dateEnd = new Zend_Date($this->_to); - $t = []; + $time = []; $firstInterval = true; while ($dateStart->compare($dateEnd) <= 0) { switch ($this->_period) { - case 'day': - $t['title'] = $dateStart->toString(Mage::app()->getLocale()->getDateFormat()); - $t['start'] = $dateStart->toString('yyyy-MM-dd HH:mm:ss'); - $t['end'] = $dateStart->toString('yyyy-MM-dd 23:59:59'); + case Mage_Reports_Helper_Data::REPORT_PERIOD_TYPE_DAY: + $time['title'] = $dateStart->toString(Mage::app()->getLocale()->getDateFormat()); + $time['start'] = $dateStart->toString('yyyy-MM-dd HH:mm:ss'); + $time['end'] = $dateStart->toString('yyyy-MM-dd 23:59:59'); $dateStart->addDay(1); break; - case 'month': - $t['title'] = $dateStart->toString('MM/yyyy'); - $t['start'] = ($firstInterval) ? $dateStart->toString('yyyy-MM-dd 00:00:00') + case Mage_Reports_Helper_Data::REPORT_PERIOD_TYPE_MONTH: + $time['title'] = $dateStart->toString('MM/yyyy'); + $time['start'] = ($firstInterval) ? $dateStart->toString('yyyy-MM-dd 00:00:00') : $dateStart->toString('yyyy-MM-01 00:00:00'); $lastInterval = ($dateStart->compareMonth($dateEnd->getMonth()) == 0); - $t['end'] = ($lastInterval) ? $dateStart->setDay($dateEnd->getDay()) + $time['end'] = ($lastInterval) ? $dateStart->setDay($dateEnd->getDay()) ->toString('yyyy-MM-dd 23:59:59') : $dateStart->toString('yyyy-MM-' . date('t', $dateStart->getTimestamp()) . ' 23:59:59'); @@ -145,14 +145,15 @@ public function getIntervals() $firstInterval = false; break; - case 'year': - $t['title'] = $dateStart->toString('yyyy'); - $t['start'] = ($firstInterval) ? $dateStart->toString('yyyy-MM-dd 00:00:00') + default: + case Mage_Reports_Helper_Data::REPORT_PERIOD_TYPE_YEAR: + $time['title'] = $dateStart->toString('yyyy'); + $time['start'] = ($firstInterval) ? $dateStart->toString('yyyy-MM-dd 00:00:00') : $dateStart->toString('yyyy-01-01 00:00:00'); $lastInterval = ($dateStart->compareYear($dateEnd->getYear()) == 0); - $t['end'] = ($lastInterval) ? $dateStart->setMonth($dateEnd->getMonth()) + $time['end'] = ($lastInterval) ? $dateStart->setMonth($dateEnd->getMonth()) ->setDay($dateEnd->getDay())->toString('yyyy-MM-dd 23:59:59') : $dateStart->toString('yyyy-12-31 23:59:59'); $dateStart->addYear(1); @@ -164,7 +165,7 @@ public function getIntervals() $firstInterval = false; break; } - $this->_intervals[$t['title']] = $t; + $this->_intervals[$time['title']] = $time; } } return $this->_intervals; @@ -178,9 +179,9 @@ public function getIntervals() public function getPeriods() { return [ - 'day' => Mage::helper('reports')->__('Day'), - 'month' => Mage::helper('reports')->__('Month'), - 'year' => Mage::helper('reports')->__('Year'), + Mage_Reports_Helper_Data::REPORT_PERIOD_TYPE_DAY => Mage::helper('reports')->__('Day'), + Mage_Reports_Helper_Data::REPORT_PERIOD_TYPE_MONTH => Mage::helper('reports')->__('Month'), + Mage_Reports_Helper_Data::REPORT_PERIOD_TYPE_YEAR => Mage::helper('reports')->__('Year'), ]; } @@ -199,7 +200,7 @@ public function setStoreIds($storeIds) /** * Get store ids * - * @return array + * @return array|null */ public function getStoreIds() { @@ -231,7 +232,7 @@ public function setPageSize($size) /** * Get page size * - * @return int + * @return int|null */ public function getPageSize() { @@ -287,7 +288,7 @@ public function getReport($from, $to) public function timeShift($datetime) { return Mage::app()->getLocale() - ->utcDate(null, $datetime, true, Varien_Date::DATETIME_INTERNAL_FORMAT) - ->toString(Varien_Date::DATETIME_INTERNAL_FORMAT); + ->utcDate(null, $datetime, true, Mage_Core_Helper_Date::DATETIME_INTERNAL_FORMAT) + ->toString(Mage_Core_Helper_Date::DATETIME_INTERNAL_FORMAT); } } diff --git a/app/code/core/Mage/Reports/Model/Resource/Report/Product/Viewed/Collection.php b/app/code/core/Mage/Reports/Model/Resource/Report/Product/Viewed/Collection.php index dbe8d77391d..771749d6a70 100644 --- a/app/code/core/Mage/Reports/Model/Resource/Report/Product/Viewed/Collection.php +++ b/app/code/core/Mage/Reports/Model/Resource/Report/Product/Viewed/Collection.php @@ -212,7 +212,7 @@ protected function _beforeLoad() $selectUnions = []; // apply date boundaries (before calling $this->_applyDateRangeFilter()) - $dtFormat = Varien_Date::DATE_INTERNAL_FORMAT; + $dtFormat = Mage_Core_Helper_Date::DATE_INTERNAL_FORMAT; $periodFrom = (!is_null($this->_from) ? new Zend_Date($this->_from, $dtFormat) : null); $periodTo = (!is_null($this->_to) ? new Zend_Date($this->_to, $dtFormat) : null); if ($this->_period == 'year') { diff --git a/app/code/core/Mage/Reports/Model/Test.php b/app/code/core/Mage/Reports/Model/Test.php index a6813189d56..8fe469dd3c4 100644 --- a/app/code/core/Mage/Reports/Model/Test.php +++ b/app/code/core/Mage/Reports/Model/Test.php @@ -14,6 +14,8 @@ * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +use Carbon\Carbon; + /** * Model for flex reports * @@ -79,7 +81,7 @@ public function getAllLinearExample() { $session = Mage::getModel('review/session'); - $startPoint = time() - 24 * 60 * 60; + $startPoint = Carbon::now()->subDay()->getTimestamp(); $allData = []; $countOfStartData = 12; diff --git a/app/code/core/Mage/Rss/Block/Catalog/New.php b/app/code/core/Mage/Rss/Block/Catalog/New.php index e970ff22bf3..34faaf6ebb5 100644 --- a/app/code/core/Mage/Rss/Block/Catalog/New.php +++ b/app/code/core/Mage/Rss/Block/Catalog/New.php @@ -52,11 +52,11 @@ protected function _toHtml() $todayStartOfDayDate = Mage::app()->getLocale()->date() ->setTime('00:00:00') - ->toString(Varien_Date::DATETIME_INTERNAL_FORMAT); + ->toString(Mage_Core_Helper_Date::DATETIME_INTERNAL_FORMAT); $todayEndOfDayDate = Mage::app()->getLocale()->date() ->setTime('23:59:59') - ->toString(Varien_Date::DATETIME_INTERNAL_FORMAT); + ->toString(Mage_Core_Helper_Date::DATETIME_INTERNAL_FORMAT); $products = $product->getCollection() ->setStoreId($storeId) diff --git a/app/code/core/Mage/Rss/Block/Catalog/Salesrule.php b/app/code/core/Mage/Rss/Block/Catalog/Salesrule.php index 1efb0083b62..593b9c28de6 100644 --- a/app/code/core/Mage/Rss/Block/Catalog/Salesrule.php +++ b/app/code/core/Mage/Rss/Block/Catalog/Salesrule.php @@ -14,6 +14,8 @@ * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +use Carbon\Carbon; + /** * Review form block * @@ -41,7 +43,7 @@ protected function _toHtml() $storeId = $this->_getStoreId(); $websiteId = Mage::app()->getStore($storeId)->getWebsiteId(); $customerGroup = $this->_getCustomerGroupId(); - $now = date('Y-m-d'); + $now = Carbon::now()->format('Y-m-d'); $url = Mage::getUrl(''); $newUrl = Mage::getUrl('rss/catalog/salesrule'); $lang = Mage::getStoreConfig('general/locale/code'); diff --git a/app/code/core/Mage/Rss/Block/Catalog/Special.php b/app/code/core/Mage/Rss/Block/Catalog/Special.php index 977de87dc80..99920dc6c93 100644 --- a/app/code/core/Mage/Rss/Block/Catalog/Special.php +++ b/app/code/core/Mage/Rss/Block/Catalog/Special.php @@ -182,7 +182,7 @@ public function addSpecialXmlCallback($args) if (isset($row['special_to_date']) && $row['final_price'] <= $row['special_price'] && $row['allowed_price_in_rss'] ) { - $compareDate = self::$_currentDate->compareDate($row['special_to_date'], Varien_Date::DATE_INTERNAL_FORMAT); + $compareDate = self::$_currentDate->compareDate($row['special_to_date'], Mage_Core_Helper_Date::DATE_INTERNAL_FORMAT); if ($compareDate === -1 || $compareDate === 0) { $row['use_special'] = true; } diff --git a/app/code/core/Mage/Rss/Block/Order/New.php b/app/code/core/Mage/Rss/Block/Order/New.php index e070359aae6..459e38a650f 100644 --- a/app/code/core/Mage/Rss/Block/Order/New.php +++ b/app/code/core/Mage/Rss/Block/Order/New.php @@ -14,6 +14,8 @@ * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +use Carbon\Carbon; + /** * Review form block * @@ -49,7 +51,7 @@ protected function _toHtml() $order = Mage::getModel('sales/order'); $period = Mage::helper('rss')->getRssAdminOrderNewPeriod($storeId); $passDate = $order->getResource()->formatDate( - mktime(0, 0, 0, (int) date('m'), (int) date('d') - $period), + Carbon::now()->setHour(0)->setMinute(0)->setSecond(0)->subDays($period)->getTimestamp(), ); $newurl = Mage::helper('adminhtml')->getUrl('adminhtml/sales_order', ['_secure' => true, '_nosecret' => true]); diff --git a/app/code/core/Mage/Rule/Model/Abstract.php b/app/code/core/Mage/Rule/Model/Abstract.php index 4a8a6d6eea8..e52fe4d4246 100644 --- a/app/code/core/Mage/Rule/Model/Abstract.php +++ b/app/code/core/Mage/Rule/Model/Abstract.php @@ -43,7 +43,7 @@ abstract class Mage_Rule_Model_Abstract extends Mage_Core_Model_Abstract /** * Store rule combine conditions model * - * @var Mage_Rule_Model_Condition_Combine + * @var Mage_Rule_Model_Condition_Combine|null */ protected $_conditions; @@ -94,6 +94,7 @@ abstract public function getActionsInstance(); * * @param int $storeId * @return Varien_Db_Select + * @throws Mage_Core_Exception */ public function getProductFlatSelect($storeId) { @@ -318,7 +319,9 @@ protected function _convertFlatToRecursive(array $data) $path = explode('--', $id); $node = & $arr; for ($i = 0, $l = count($path); $i < $l; $i++) { - $node = & $node[$key][$path[$i]] ?? []; + // @phpstan-ignore-next-line + $var = $node[$key][$path[$i]] ?? []; + $node = &$var; } foreach ($data as $k => $v) { $node[$k] = $v; @@ -331,7 +334,7 @@ protected function _convertFlatToRecursive(array $data) if (in_array($key, ['from_date', 'to_date']) && $value) { $value = Mage::app()->getLocale()->date( $value, - Varien_Date::DATE_INTERNAL_FORMAT, + Mage_Core_Helper_Date::DATE_INTERNAL_FORMAT, null, false, ); @@ -371,8 +374,8 @@ public function validateData(Varien_Object $object) } if ($fromDate && $toDate) { - $fromDate = new Zend_Date($fromDate, Varien_Date::DATE_INTERNAL_FORMAT); - $toDate = new Zend_Date($toDate, Varien_Date::DATE_INTERNAL_FORMAT); + $fromDate = new Zend_Date($fromDate, Mage_Core_Helper_Date::DATE_INTERNAL_FORMAT); + $toDate = new Zend_Date($toDate, Mage_Core_Helper_Date::DATE_INTERNAL_FORMAT); if ($fromDate->compare($toDate) === 1) { $result[] = Mage::helper('rule')->__('End Date must be greater than Start Date.'); @@ -445,6 +448,7 @@ public function setIsReadonly($value) * Get rule associated website Ids * * @return array + * @throws Mage_Core_Exception */ public function getWebsiteIds() { diff --git a/app/code/core/Mage/Rule/Model/Condition/Abstract.php b/app/code/core/Mage/Rule/Model/Condition/Abstract.php index d99ad1f87f8..ea86018804c 100644 --- a/app/code/core/Mage/Rule/Model/Condition/Abstract.php +++ b/app/code/core/Mage/Rule/Model/Condition/Abstract.php @@ -374,11 +374,11 @@ public function getValue() $format = null; switch ($this->getInputType()) { case 'date': - $format = Varien_Date::DATE_INTERNAL_FORMAT; + $format = Mage_Core_Helper_Date::DATE_INTERNAL_FORMAT; break; case 'datetime': - $format = Varien_Date::DATETIME_INTERNAL_FORMAT; + $format = Mage_Core_Helper_Date::DATETIME_INTERNAL_FORMAT; break; } @@ -599,13 +599,13 @@ public function getValueElement() switch ($this->getInputType()) { case 'date': - $elementParams['input_format'] = Varien_Date::DATE_INTERNAL_FORMAT; - $elementParams['format'] = Varien_Date::DATE_INTERNAL_FORMAT; + $elementParams['input_format'] = Mage_Core_Helper_Date::DATE_INTERNAL_FORMAT; + $elementParams['format'] = Mage_Core_Helper_Date::DATE_INTERNAL_FORMAT; break; case 'datetime': - $elementParams['input_format'] = Varien_Date::DATETIME_INTERNAL_FORMAT; - $elementParams['format'] = Varien_Date::DATETIME_INTERNAL_FORMAT; + $elementParams['input_format'] = Mage_Core_Helper_Date::DATETIME_INTERNAL_FORMAT; + $elementParams['format'] = Mage_Core_Helper_Date::DATETIME_INTERNAL_FORMAT; $elementParams['time'] = true; break; } diff --git a/app/code/core/Mage/Rule/Model/Environment.php b/app/code/core/Mage/Rule/Model/Environment.php index a3e769745a1..a46e3091d2f 100644 --- a/app/code/core/Mage/Rule/Model/Environment.php +++ b/app/code/core/Mage/Rule/Model/Environment.php @@ -14,6 +14,8 @@ * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +use Carbon\Carbon; + /** * Class Mage_Rule_Model_Environment * @@ -32,7 +34,7 @@ class Mage_Rule_Model_Environment extends Varien_Object */ public function collect() { - $this->setNow(time()); + $this->setNow(Carbon::now()->getTimestamp()); Mage::dispatchEvent('rule_environment_collect', ['env' => $this]); diff --git a/app/code/core/Mage/Rule/Model/Resource/Abstract.php b/app/code/core/Mage/Rule/Model/Resource/Abstract.php index 31e256d0436..1fd51cf0d07 100644 --- a/app/code/core/Mage/Rule/Model/Resource/Abstract.php +++ b/app/code/core/Mage/Rule/Model/Resource/Abstract.php @@ -54,14 +54,14 @@ public function _beforeSave(Mage_Core_Model_Abstract $object) { $fromDate = $object->getFromDate(); if ($fromDate instanceof Zend_Date) { - $object->setFromDate($fromDate->toString(Varien_Date::DATETIME_INTERNAL_FORMAT)); + $object->setFromDate($fromDate->toString(Mage_Core_Helper_Date::DATETIME_INTERNAL_FORMAT)); } elseif (!is_string($fromDate) || empty($fromDate)) { $object->setFromDate(null); } $toDate = $object->getToDate(); if ($toDate instanceof Zend_Date) { - $object->setToDate($toDate->toString(Varien_Date::DATETIME_INTERNAL_FORMAT)); + $object->setToDate($toDate->toString(Mage_Core_Helper_Date::DATETIME_INTERNAL_FORMAT)); } elseif (!is_string($toDate) || empty($toDate)) { $object->setToDate(null); } diff --git a/app/code/core/Mage/Sales/Model/Abstract.php b/app/code/core/Mage/Sales/Model/Abstract.php index a67e5ec1181..52ac1a58fca 100644 --- a/app/code/core/Mage/Sales/Model/Abstract.php +++ b/app/code/core/Mage/Sales/Model/Abstract.php @@ -14,6 +14,8 @@ * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +use Carbon\Carbon; + /** * Sales abstract model * Provide date processing functionality @@ -54,10 +56,7 @@ public function afterCommitCallback() public function getCreatedAtDate() { return Mage::app()->getLocale()->date( - Varien_Date::toTimestamp($this->getCreatedAt()), - null, - null, - true, + Carbon::now()->setTimeFromTimeString(($this->getCreatedAt()))->getTimestamp(), ); } @@ -70,7 +69,7 @@ public function getCreatedAtStoreDate() { return Mage::app()->getLocale()->storeDate( $this->getStore(), - Varien_Date::toTimestamp($this->getCreatedAt()), + Carbon::now()->setTimeFromTimeString($this->getCreatedAt())->getTimestamp(), true, ); } diff --git a/app/code/core/Mage/Sales/Model/Observer.php b/app/code/core/Mage/Sales/Model/Observer.php index 6863e0111bc..1edfb04bf40 100644 --- a/app/code/core/Mage/Sales/Model/Observer.php +++ b/app/code/core/Mage/Sales/Model/Observer.php @@ -14,6 +14,8 @@ * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +use Carbon\Carbon; + /** * Sales observer * @@ -34,7 +36,6 @@ class Mage_Sales_Model_Observer * * @param Mage_Cron_Model_Schedule $schedule * @return $this - * @throws Mage_Core_Exception */ public function cleanExpiredQuotes($schedule) { @@ -43,12 +44,12 @@ public function cleanExpiredQuotes($schedule) foreach ($lifetimes as $storeId => $day) { $day = (int) $day; - $lifetime = 86400 * $day; /** @var Mage_Sales_Model_Resource_Quote_Collection $quotes */ $quotes = Mage::getResourceModel('sales/quote_collection'); $quotes->addFieldToFilter('store_id', $storeId); - $quotes->addFieldToFilter('updated_at', ['to' => date('Y-m-d', time() - $lifetime)]); + $quotes->addFieldToFilter('updated_at', ['to' => Carbon::now()->subDays($day)->format('Y-m-d')]); + if ($day == 0) { $quotes->addFieldToFilter('is_active', 0); } diff --git a/app/code/core/Mage/Sales/Model/Resource/Abstract.php b/app/code/core/Mage/Sales/Model/Resource/Abstract.php index ba18dc53ff4..cf0b5187902 100644 --- a/app/code/core/Mage/Sales/Model/Resource/Abstract.php +++ b/app/code/core/Mage/Sales/Model/Resource/Abstract.php @@ -14,6 +14,8 @@ * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +use Carbon\Carbon; + /** * Sales abstract resource model * @@ -29,7 +31,7 @@ abstract class Mage_Sales_Model_Resource_Abstract extends Mage_Core_Model_Resour */ protected function _prepareDataForSave(Mage_Core_Model_Abstract $object) { - $currentTime = Varien_Date::now(); + $currentTime = Carbon::now()->format(Carbon::DEFAULT_TO_STRING_FORMAT); if ((!$object->getId() || $object->isObjectNew()) && !$object->getCreatedAt()) { $object->setCreatedAt($currentTime); } diff --git a/app/code/core/Mage/Sales/Model/Resource/Order/Collection/Abstract.php b/app/code/core/Mage/Sales/Model/Resource/Order/Collection/Abstract.php index 803f0c80bf4..c7821a78a9a 100644 --- a/app/code/core/Mage/Sales/Model/Resource/Order/Collection/Abstract.php +++ b/app/code/core/Mage/Sales/Model/Resource/Order/Collection/Abstract.php @@ -69,7 +69,7 @@ public function getSalesOrder() /** * Add order filter * - * @param int|Mage_Sales_Model_Order $order + * @param array|int|Mage_Sales_Model_Order $order * @return $this */ public function setOrderFilter($order) diff --git a/app/code/core/Mage/Sales/Model/Resource/Report/Bestsellers/Collection.php b/app/code/core/Mage/Sales/Model/Resource/Report/Bestsellers/Collection.php index f2bd3a13db3..8bb520bef57 100644 --- a/app/code/core/Mage/Sales/Model/Resource/Report/Bestsellers/Collection.php +++ b/app/code/core/Mage/Sales/Model/Resource/Report/Bestsellers/Collection.php @@ -213,7 +213,7 @@ protected function _beforeLoad() $selectUnions = []; // apply date boundaries (before calling $this->_applyDateRangeFilter()) - $dtFormat = Varien_Date::DATE_INTERNAL_FORMAT; + $dtFormat = Mage_Core_Helper_Date::DATE_INTERNAL_FORMAT; $periodFrom = (!is_null($this->_from) ? new Zend_Date($this->_from, $dtFormat) : null); $periodTo = (!is_null($this->_to) ? new Zend_Date($this->_to, $dtFormat) : null); if ($this->_period == 'year') { diff --git a/app/code/core/Mage/SalesRule/Model/Coupon/Massgenerator.php b/app/code/core/Mage/SalesRule/Model/Coupon/Massgenerator.php index 432381186cc..9ae2bcc5419 100644 --- a/app/code/core/Mage/SalesRule/Model/Coupon/Massgenerator.php +++ b/app/code/core/Mage/SalesRule/Model/Coupon/Massgenerator.php @@ -149,7 +149,7 @@ public function generatePool() $expirationDate = $this->getToDate(); if ($expirationDate instanceof Zend_Date) { - $expirationDate = $expirationDate->toString(Varien_Date::DATETIME_INTERNAL_FORMAT); + $expirationDate = $expirationDate->toString(Mage_Core_Helper_Date::DATETIME_INTERNAL_FORMAT); } $coupon->setId(null) diff --git a/app/code/core/Mage/SalesRule/Model/Resource/Coupon.php b/app/code/core/Mage/SalesRule/Model/Resource/Coupon.php index 1c8f8b1636e..e3744dd869c 100644 --- a/app/code/core/Mage/SalesRule/Model/Resource/Coupon.php +++ b/app/code/core/Mage/SalesRule/Model/Resource/Coupon.php @@ -41,7 +41,7 @@ public function _beforeSave(Mage_Core_Model_Abstract $object) if (!$object->getExpirationDate()) { $object->setExpirationDate(null); } elseif ($object->getExpirationDate() instanceof Zend_Date) { - $object->setExpirationDate($object->getExpirationDate()->toString(Varien_Date::DATETIME_INTERNAL_FORMAT)); + $object->setExpirationDate($object->getExpirationDate()->toString(Mage_Core_Helper_Date::DATETIME_INTERNAL_FORMAT)); } // maintain single primary coupon per rule diff --git a/app/code/core/Mage/SalesRule/Model/Rule.php b/app/code/core/Mage/SalesRule/Model/Rule.php index 2acb66e1d08..42f67365cba 100644 --- a/app/code/core/Mage/SalesRule/Model/Rule.php +++ b/app/code/core/Mage/SalesRule/Model/Rule.php @@ -173,7 +173,7 @@ protected function _construct() /** * Returns code mass generator instance for auto generated specific coupons * - * @return Mage_Core_Model_Abstract|Mage_SalesRule_Model_Coupon_Massgenerator + * @return Mage_SalesRule_Model_Coupon_Massgenerator */ public static function getCouponMassGenerator() { @@ -448,7 +448,7 @@ public function acquireCoupon($saveNewlyCreated = true, $saveAttemptCount = 10) public function hasIsValidForAddress($address) { $addressId = $this->_getAddressId($address); - return isset($this->_validatedAddresses[$addressId]) ? true : false; + return isset($this->_validatedAddresses[$addressId]); } /** diff --git a/app/code/core/Mage/Tag/Model/Resource/Tag/Relation.php b/app/code/core/Mage/Tag/Model/Resource/Tag/Relation.php index 841ce9d944d..a7585550a7e 100644 --- a/app/code/core/Mage/Tag/Model/Resource/Tag/Relation.php +++ b/app/code/core/Mage/Tag/Model/Resource/Tag/Relation.php @@ -14,6 +14,8 @@ * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +use Carbon\Carbon; + /** * Tag Relation resource model * @@ -176,7 +178,7 @@ public function addRelations($model) 'store_id' => $model->getStoreId(), 'product_id' => $value, 'customer_id' => $model->getCustomerId(), - 'created_at' => $this->formatDate(time()), + 'created_at' => $this->formatDate(Carbon::now()->getTimestamp()), ]; } $write->insertMultiple($this->getMainTable(), $insertData); diff --git a/app/code/core/Mage/Tag/Model/Tag.php b/app/code/core/Mage/Tag/Model/Tag.php index c7e4f7acc27..18a08b49f76 100644 --- a/app/code/core/Mage/Tag/Model/Tag.php +++ b/app/code/core/Mage/Tag/Model/Tag.php @@ -14,6 +14,8 @@ * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +use Carbon\Carbon; + /** * Tag model * @@ -364,7 +366,7 @@ public function saveRelation($productId, $customerId, $storeId) ->setProductId($productId) ->setCustomerId($customerId) ->setActive(Mage_Tag_Model_Tag_Relation::STATUS_ACTIVE) - ->setCreatedAt($relationModel->getResource()->formatDate(time())); + ->setCreatedAt($relationModel->getResource()->formatDate(Carbon::now()->getTimestamp())); $result = ''; $relationModelSaveNeed = false; diff --git a/app/code/core/Mage/Usa/Model/Shipping/Carrier/Fedex.php b/app/code/core/Mage/Usa/Model/Shipping/Carrier/Fedex.php index 1912f9f3307..8228871f6b1 100644 --- a/app/code/core/Mage/Usa/Model/Shipping/Carrier/Fedex.php +++ b/app/code/core/Mage/Usa/Model/Shipping/Carrier/Fedex.php @@ -14,6 +14,8 @@ * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +use Carbon\Carbon; + /** * Fedex shipping implementation * @@ -312,7 +314,7 @@ protected function _formRateRequest($purpose) 'Version' => $this->getVersionInfo(), 'RequestedShipment' => [ 'DropoffType' => $r->getDropoffType(), - 'ShipTimestamp' => date('c'), + 'ShipTimestamp' => Carbon::now()->format('c'), 'PackagingType' => $r->getPackaging(), 'TotalInsuredValue' => [ 'Amount' => $r->getValue(), @@ -602,7 +604,7 @@ protected function _getXmlQuotes() $requestHeader->addChild('AccountNumber', $r->getAccount()); $requestHeader->addChild('MeterNumber', '0'); - $xml->addChild('ShipDate', date('Y-m-d')); + $xml->addChild('ShipDate', Carbon::now()->format('Y-m-d')); $xml->addChild('DropoffType', $r->getDropoffType()); if ($r->hasService()) { $xml->addChild('Service', $r->getService()); @@ -1343,10 +1345,10 @@ protected function _formShipmentRequest(Varien_Object $request) $paymentType = $request->getIsReturn() ? 'RECIPIENT' : 'SENDER'; $requestClient = [ 'RequestedShipment' => [ - 'ShipTimestamp' => time(), + 'ShipTimestamp' => Carbon::now()->getTimestamp(), 'DropoffType' => $this->getConfigData('dropoff'), 'PackagingType' => $request->getPackagingType(), - 'ServiceType' => $request->getShippingMethod(), + 'ServiceType' => $request->getShippingMethod(), 'Shipper' => [ 'Contact' => [ 'PersonName' => $request->getShipperContactPersonName(), diff --git a/app/code/core/Mage/Weee/Model/Resource/Tax.php b/app/code/core/Mage/Weee/Model/Resource/Tax.php index d11ef452cde..db1d893edfa 100644 --- a/app/code/core/Mage/Weee/Model/Resource/Tax.php +++ b/app/code/core/Mage/Weee/Model/Resource/Tax.php @@ -14,6 +14,8 @@ * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +use Carbon\Carbon; + /** * Wee tax resource model * @@ -78,7 +80,7 @@ public function updateProductsDiscountPercent($condition) */ protected function _updateDiscountPercents($productCondition = null) { - $now = Varien_Date::toTimestamp(Varien_Date::now()); + $now = Carbon::now()->getTimestamp(); $adapter = $this->_getWriteAdapter(); $select = $this->_getReadAdapter()->select(); diff --git a/app/code/core/Mage/Wishlist/Model/Resource/Item/Collection.php b/app/code/core/Mage/Wishlist/Model/Resource/Item/Collection.php index 5de7dafe43c..8a144e1bc78 100644 --- a/app/code/core/Mage/Wishlist/Model/Resource/Item/Collection.php +++ b/app/code/core/Mage/Wishlist/Model/Resource/Item/Collection.php @@ -394,14 +394,14 @@ public function addDaysFilter($constraints) $now = Mage::getSingleton('core/date')->date(); $gmtOffset = (int) Mage::getSingleton('core/date')->getGmtOffset(); if (isset($constraints['from'])) { - $lastDay = new Zend_Date($now, Varien_Date::DATETIME_INTERNAL_FORMAT); + $lastDay = new Zend_Date($now, Mage_Core_Helper_Date::DATETIME_INTERNAL_FORMAT); $lastDay->subSecond($gmtOffset) ->subDay($constraints['from'] - 1); $filter['to'] = $lastDay; } if (isset($constraints['to'])) { - $firstDay = new Zend_Date($now, Varien_Date::DATETIME_INTERNAL_FORMAT); + $firstDay = new Zend_Date($now, Mage_Core_Helper_Date::DATETIME_INTERNAL_FORMAT); $firstDay->subSecond($gmtOffset) ->subDay($constraints['to']); $filter['from'] = $firstDay; diff --git a/app/code/core/Mage/Wishlist/Model/Wishlist.php b/app/code/core/Mage/Wishlist/Model/Wishlist.php index 8dd3d2eada8..c5272e7246b 100644 --- a/app/code/core/Mage/Wishlist/Model/Wishlist.php +++ b/app/code/core/Mage/Wishlist/Model/Wishlist.php @@ -201,7 +201,7 @@ protected function _addCatalogProduct(Mage_Catalog_Model_Product $product, $qty $item = Mage::getModel('wishlist/item'); $item->setProductId($product->getId()) ->setWishlistId($this->getId()) - ->setAddedAt(Varien_Date::now()) + ->setAddedAt(now()) ->setStoreId($storeId) ->setOptions($product->getCustomOptions()) ->setProduct($product) diff --git a/app/etc/modules/Mage_Admin.xml b/app/etc/modules/Mage_Admin.xml index c111007799a..df2d98cda8e 100644 --- a/app/etc/modules/Mage_Admin.xml +++ b/app/etc/modules/Mage_Admin.xml @@ -14,7 +14,9 @@ * @license https://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> - + true diff --git a/composer.json b/composer.json index cb784a9d0c8..e17d9429a7d 100644 --- a/composer.json +++ b/composer.json @@ -30,6 +30,7 @@ "ezyang/htmlpurifier": "^4.17", "magento-hackathon/magento-composer-installer": "^3.1 || ^2.1 || ^4.0", "mklkj/tinymce-i18n": "^24.11", + "nesbot/carbon": "^2.72", "openmage/composer-plugin": "^1.1.1", "pelago/emogrifier": "^7.0", "phpseclib/mcrypt_compat": "^2.0.3", @@ -58,7 +59,7 @@ "phpmd/phpmd": "^2.13", "phpstan/phpstan": "^2.1", "phpunit/phpunit": "^9.6", - "rector/rector": "^2.0.5", + "rector/rector": "^2.0", "squizlabs/php_codesniffer": "^3.7", "symplify/vendor-patches": "^11.1" }, @@ -147,9 +148,9 @@ "phpmd": "vendor/bin/phpmd app/code/core/Mage text .phpmd.dist.xml --color --cache --baseline-file .phpmd.dist.baseline.xml", "phpstan": "XDEBUG_MODE=off php vendor/bin/phpstan analyze", "phpstan:baseline": "XDEBUG_MODE=off php vendor/bin/phpstan analyze -b .phpstan.dist.baseline.neon", - "phpunit:test": "XDEBUG_MODE=off php vendor/bin/phpunit --configuration .phpunit.dist.xml --no-coverage --testdox", + "phpunit:test": "XDEBUG_MODE=off php vendor/bin/phpunit --configuration .phpunit.dist.xml --no-coverage", "phpunit:coverage": "XDEBUG_MODE=coverage php vendor/bin/phpunit --configuration .phpunit.dist.xml --testdox", - "phpunit:coverage-local": "XDEBUG_MODE=coverage php vendor/bin/phpunit --configuration .phpunit.dist.xml --coverage-html build/coverage --testdox", + "phpunit:coverage-local": "XDEBUG_MODE=coverage php vendor/bin/phpunit --configuration .phpunit.dist.xml --coverage-html build/coverage", "rector:test": "vendor/bin/rector process --config .rector.php --dry-run", "rector:fix": "vendor/bin/rector --config .rector.php process" }, diff --git a/composer.lock b/composer.lock index bf965b7158c..701dbd669d3 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,77 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "8ab5b0a7d21ed992d661f401b45576d2", + "content-hash": "7187fb521f528678bb442a2ee62242d1", "packages": [ + { + "name": "carbonphp/carbon-doctrine-types", + "version": "2.1.0", + "source": { + "type": "git", + "url": "https://github.com/CarbonPHP/carbon-doctrine-types.git", + "reference": "99f76ffa36cce3b70a4a6abce41dba15ca2e84cb" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/CarbonPHP/carbon-doctrine-types/zipball/99f76ffa36cce3b70a4a6abce41dba15ca2e84cb", + "reference": "99f76ffa36cce3b70a4a6abce41dba15ca2e84cb", + "shasum": "" + }, + "require": { + "php": "^7.4 || ^8.0" + }, + "conflict": { + "doctrine/dbal": "<3.7.0 || >=4.0.0" + }, + "require-dev": { + "doctrine/dbal": "^3.7.0", + "nesbot/carbon": "^2.71.0 || ^3.0.0", + "phpunit/phpunit": "^10.3" + }, + "type": "library", + "autoload": { + "psr-4": { + "Carbon\\Doctrine\\": "src/Carbon/Doctrine/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "KyleKatarn", + "email": "kylekatarnls@gmail.com" + } + ], + "description": "Types to use Carbon in Doctrine", + "keywords": [ + "carbon", + "date", + "datetime", + "doctrine", + "time" + ], + "support": { + "issues": "https://github.com/CarbonPHP/carbon-doctrine-types/issues", + "source": "https://github.com/CarbonPHP/carbon-doctrine-types/tree/2.1.0" + }, + "funding": [ + { + "url": "https://github.com/kylekatarnls", + "type": "github" + }, + { + "url": "https://opencollective.com/Carbon", + "type": "open_collective" + }, + { + "url": "https://tidelift.com/funding/github/packagist/nesbot/carbon", + "type": "tidelift" + } + ], + "time": "2023-12-11T17:09:12+00:00" + }, { "name": "colinmollenhour/cache-backend-redis", "version": "1.17.1", @@ -601,6 +670,113 @@ }, "time": "2024-12-30T10:42:10+00:00" }, + { + "name": "nesbot/carbon", + "version": "2.72.6", + "source": { + "type": "git", + "url": "https://github.com/CarbonPHP/carbon.git", + "reference": "1e9d50601e7035a4c61441a208cb5bed73e108c5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/CarbonPHP/carbon/zipball/1e9d50601e7035a4c61441a208cb5bed73e108c5", + "reference": "1e9d50601e7035a4c61441a208cb5bed73e108c5", + "shasum": "" + }, + "require": { + "carbonphp/carbon-doctrine-types": "*", + "ext-json": "*", + "php": "^7.1.8 || ^8.0", + "psr/clock": "^1.0", + "symfony/polyfill-mbstring": "^1.0", + "symfony/polyfill-php80": "^1.16", + "symfony/translation": "^3.4 || ^4.0 || ^5.0 || ^6.0" + }, + "provide": { + "psr/clock-implementation": "1.0" + }, + "require-dev": { + "doctrine/dbal": "^2.0 || ^3.1.4 || ^4.0", + "doctrine/orm": "^2.7 || ^3.0", + "friendsofphp/php-cs-fixer": "^3.0", + "kylekatarnls/multi-tester": "^2.0", + "ondrejmirtes/better-reflection": "<6", + "phpmd/phpmd": "^2.9", + "phpstan/extension-installer": "^1.0", + "phpstan/phpstan": "^0.12.99 || ^1.7.14", + "phpunit/php-file-iterator": "^2.0.5 || ^3.0.6", + "phpunit/phpunit": "^7.5.20 || ^8.5.26 || ^9.5.20", + "squizlabs/php_codesniffer": "^3.4" + }, + "bin": [ + "bin/carbon" + ], + "type": "library", + "extra": { + "laravel": { + "providers": [ + "Carbon\\Laravel\\ServiceProvider" + ] + }, + "phpstan": { + "includes": [ + "extension.neon" + ] + }, + "branch-alias": { + "dev-2.x": "2.x-dev", + "dev-master": "3.x-dev" + } + }, + "autoload": { + "psr-4": { + "Carbon\\": "src/Carbon/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Brian Nesbitt", + "email": "brian@nesbot.com", + "homepage": "https://markido.com" + }, + { + "name": "kylekatarnls", + "homepage": "https://github.com/kylekatarnls" + } + ], + "description": "An API extension for DateTime that supports 281 different languages.", + "homepage": "https://carbon.nesbot.com", + "keywords": [ + "date", + "datetime", + "time" + ], + "support": { + "docs": "https://carbon.nesbot.com/docs", + "issues": "https://github.com/briannesbitt/Carbon/issues", + "source": "https://github.com/briannesbitt/Carbon" + }, + "funding": [ + { + "url": "https://github.com/sponsors/kylekatarnls", + "type": "github" + }, + { + "url": "https://opencollective.com/Carbon#sponsor", + "type": "opencollective" + }, + { + "url": "https://tidelift.com/subscription/pkg/packagist-nesbot-carbon?utm_source=packagist-nesbot-carbon&utm_medium=referral&utm_campaign=readme", + "type": "tidelift" + } + ], + "time": "2024-12-27T09:28:11+00:00" + }, { "name": "openmage/composer-plugin", "version": "v1.1.1", @@ -1032,6 +1208,54 @@ ], "time": "2024-12-14T21:12:59+00:00" }, + { + "name": "psr/clock", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/php-fig/clock.git", + "reference": "e41a24703d4560fd0acb709162f73b8adfc3aa0d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/clock/zipball/e41a24703d4560fd0acb709162f73b8adfc3aa0d", + "reference": "e41a24703d4560fd0acb709162f73b8adfc3aa0d", + "shasum": "" + }, + "require": { + "php": "^7.0 || ^8.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Psr\\Clock\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "https://www.php-fig.org/" + } + ], + "description": "Common interface for reading the clock.", + "homepage": "https://github.com/php-fig/clock", + "keywords": [ + "clock", + "now", + "psr", + "psr-20", + "time" + ], + "support": { + "issues": "https://github.com/php-fig/clock/issues", + "source": "https://github.com/php-fig/clock/tree/1.0.0" + }, + "time": "2022-11-25T14:36:26+00:00" + }, { "name": "psr/container", "version": "1.1.2", @@ -2594,6 +2818,103 @@ ], "time": "2024-11-10T20:33:58+00:00" }, + { + "name": "symfony/translation", + "version": "v5.4.45", + "source": { + "type": "git", + "url": "https://github.com/symfony/translation.git", + "reference": "98f26acc99341ca4bab345fb14d7b1d7cb825bed" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/translation/zipball/98f26acc99341ca4bab345fb14d7b1d7cb825bed", + "reference": "98f26acc99341ca4bab345fb14d7b1d7cb825bed", + "shasum": "" + }, + "require": { + "php": ">=7.2.5", + "symfony/deprecation-contracts": "^2.1|^3", + "symfony/polyfill-mbstring": "~1.0", + "symfony/polyfill-php80": "^1.16", + "symfony/translation-contracts": "^2.3" + }, + "conflict": { + "symfony/config": "<4.4", + "symfony/console": "<5.3", + "symfony/dependency-injection": "<5.0", + "symfony/http-kernel": "<5.0", + "symfony/twig-bundle": "<5.0", + "symfony/yaml": "<4.4" + }, + "provide": { + "symfony/translation-implementation": "2.3" + }, + "require-dev": { + "psr/log": "^1|^2|^3", + "symfony/config": "^4.4|^5.0|^6.0", + "symfony/console": "^5.4|^6.0", + "symfony/dependency-injection": "^5.0|^6.0", + "symfony/finder": "^4.4|^5.0|^6.0", + "symfony/http-client-contracts": "^1.1|^2.0|^3.0", + "symfony/http-kernel": "^5.0|^6.0", + "symfony/intl": "^4.4|^5.0|^6.0", + "symfony/polyfill-intl-icu": "^1.21", + "symfony/service-contracts": "^1.1.2|^2|^3", + "symfony/yaml": "^4.4|^5.0|^6.0" + }, + "suggest": { + "psr/log-implementation": "To use logging capability in translator", + "symfony/config": "", + "symfony/yaml": "" + }, + "type": "library", + "autoload": { + "files": [ + "Resources/functions.php" + ], + "psr-4": { + "Symfony\\Component\\Translation\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Provides tools to internationalize your application", + "homepage": "https://symfony.com", + "support": { + "source": "https://github.com/symfony/translation/tree/v5.4.45" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2024-09-25T14:11:13+00:00" + }, { "name": "symfony/translation-contracts", "version": "v2.5.4", @@ -7485,7 +7806,7 @@ ], "aliases": [], "minimum-stability": "dev", - "stability-flags": [], + "stability-flags": {}, "prefer-stable": true, "prefer-lowest": false, "platform": { diff --git a/get.php b/get.php index ab6ea3606d1..601baf8503b 100644 --- a/get.php +++ b/get.php @@ -14,6 +14,8 @@ * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +use Carbon\Carbon; + $start = microtime(true); /** * Error reporting @@ -62,7 +64,7 @@ $config = json_decode(file_get_contents($configCacheFile), true); //checking update time - if (filemtime($configCacheFile) + $config['update_time'] > time()) { + if (filemtime($configCacheFile) + $config['update_time'] > Carbon::now()->getTimestamp()) { $mediaDirectory = trim(str_replace($bp . $ds, '', $config['media_directory']), $ds); $allowedResources = array_merge($allowedResources, $config['allowed_resources']); } diff --git a/lib/Mage/Cache/Backend/File.php b/lib/Mage/Cache/Backend/File.php index 379580a38a5..e1c531b9b05 100644 --- a/lib/Mage/Cache/Backend/File.php +++ b/lib/Mage/Cache/Backend/File.php @@ -42,6 +42,8 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +use Carbon\Carbon; + /** * Optimized file cache backend * @@ -70,7 +72,7 @@ class Mage_Cache_Backend_File extends Zend_Cache_Backend_File /** * Prevents unnecessary checks * - * @var boolean + * @var bool */ protected $_isTagDirChecked; @@ -135,7 +137,7 @@ public function load($id, $doNotTestCacheValidity = false) return false; } list($metadatas, $data) = $cache; - if (!$doNotTestCacheValidity && time() > $metadatas['expire']) { + if (!$doNotTestCacheValidity && Carbon::now()->greaterThan($metadatas['expire'])) { // ?? $this->remove($id); return false; } @@ -189,7 +191,7 @@ public function save($data, $id, $tags = [], $specificLifetime = false) } $metadatas = [ 'hash' => $hash, - 'mtime' => time(), + 'mtime' => Carbon::now()->getTimestamp(), 'expire' => $this->_expireTime($this->getLifetime($specificLifetime)), 'tags' => implode(',', $tags), ]; @@ -339,7 +341,7 @@ public function getMetadatas($id) * @param string $id Cache id * @param int $extraLifetime * - * @return boolean In case of success returns true + * @return bool In case of success returns true */ public function touch($id, $extraLifetime) { @@ -349,12 +351,12 @@ public function touch($id, $extraLifetime) return false; } list($metadatas, $data) = $cache; - if (time() > $metadatas['expire']) { + if (Carbon::now()->greaterThan($metadatas['expire'])) { return false; } $newMetadatas = [ 'hash' => $metadatas['hash'], - 'mtime' => time(), + 'mtime' => Carbon::now()->getTimestamp(), 'expire' => $metadatas['expire'] + $extraLifetime, 'tags' => $metadatas['tags'], ]; @@ -436,7 +438,7 @@ protected function _setMetadatas($id, $metadatas, $save = true) * Uses multiple letters for a single-level hash rather than multiple levels * * @param string $id Cache id - * @param boolean $parts If true, returns array of directory parts instead of single string + * @param bool $parts If true, returns array of directory parts instead of single string * * @return string|array Complete directory path */ @@ -473,7 +475,7 @@ protected function _path($id, $parts = false) * @param array $tags * * @throws Zend_Cache_Exception - * @return boolean In case of success returns true + * @return bool In case of success returns true * * @SuppressWarnings("PHPMD.ErrorControlOperator") */ @@ -506,7 +508,7 @@ protected function _clean($dir, $mode = Zend_Cache::CLEANING_MODE_ALL, $tags = [ continue; } if ($mode == Zend_Cache::CLEANING_MODE_OLD) { - if (time() > $metadatas['expire']) { + if (Carbon::now()->greaterThan($metadatas['expire'])) { $result = $this->_remove($file) && $result; $result = $this->_updateIdsTags([$id], explode(',', $metadatas['tags']), 'diff') && $result; } @@ -549,8 +551,7 @@ protected function _clean($dir, $mode = Zend_Cache::CLEANING_MODE_ALL, $tags = [ * @param string $mode Clean mode * @param array $tags Array of tags * - * @throws Zend_Cache_Exception - * @return boolean In case of success returns true + * @return bool In case of success returns true */ protected function _cleanNew($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = []) { @@ -694,7 +695,7 @@ protected function _getTagIds($tag) * @param array $tags * @param string $mode * - * @return boolean + * @return bool */ protected function _updateIdsTags($ids, $tags, $mode) { @@ -742,7 +743,7 @@ protected function _updateIdsTags($ids, $tags, $mode) * @param string $file File complete path * @param string $string String to put in file * - * @return boolean In case of success returns true + * @return true|int In case of success returns true * * @SuppressWarnings("PHPMD.ErrorControlOperator") */ @@ -760,7 +761,7 @@ protected function _filePutContents($file, $string) * Make the directory structure for the given id * * @param string $id cache id - * @return boolean true + * @return bool true * * @SuppressWarnings("PHPMD.ErrorControlOperator") */ diff --git a/lib/Varien/Cache/Backend/Database.php b/lib/Varien/Cache/Backend/Database.php index 5e18cdb0b05..e5c8e1d48cc 100644 --- a/lib/Varien/Cache/Backend/Database.php +++ b/lib/Varien/Cache/Backend/Database.php @@ -37,6 +37,8 @@ ) ENGINE=InnoDB DEFAULT CHARSET=utf8; */ +use Carbon\Carbon; + /** * Database cache backend */ @@ -61,6 +63,7 @@ class Varien_Cache_Backend_Database extends Zend_Cache_Backend implements Zend_C * Constructor * * @param array $options associative array of options + * @throws Zend_Cache_Exception */ public function __construct($options = []) { @@ -79,6 +82,7 @@ public function __construct($options = []) * Get DB adapter * * @return Zend_Db_Adapter_Abstract + * @throws Zend_Cache_Exception */ protected function _getAdapter() { @@ -122,8 +126,8 @@ protected function _getTagsTable() * * Note : return value is always "string" (unserialization is done by the core not by the backend) * - * @param string $id Cache id - * @param boolean $doNotTestCacheValidity If set to true, the cache validity won't be tested + * @param string $id Cache id + * @param bool $doNotTestCacheValidity If set to true, the cache validity won't be tested * @return string|false cached data */ public function load($id, $doNotTestCacheValidity = false) @@ -134,7 +138,7 @@ public function load($id, $doNotTestCacheValidity = false) ->where('id=:cache_id'); if (!$doNotTestCacheValidity) { - $select->where('expire_time=0 OR expire_time>?', time()); + $select->where('expire_time=0 OR expire_time>?', Carbon::now()->getTimestamp()); } return $this->_getAdapter()->fetchOne($select, ['cache_id' => $id]); } else { @@ -146,7 +150,7 @@ public function load($id, $doNotTestCacheValidity = false) * Test if a cache is available or not (for the given id) * * @param string $id cache id - * @return mixed|false (a cache is not available) or "last modified" timestamp (int) of the available cache record + * @return false|null|string (a cache is not available) or "last modified" timestamp (int) of the available cache record */ public function test($id) { @@ -154,7 +158,7 @@ public function test($id) $select = $this->_getAdapter()->select() ->from($this->_getDataTable(), 'update_time') ->where('id=:cache_id') - ->where('expire_time=0 OR expire_time>?', time()); + ->where('expire_time=0 OR expire_time>?', Carbon::now()->getTimestamp()); return $this->_getAdapter()->fetchOne($select, ['cache_id' => $id]); } else { return false; @@ -182,7 +186,7 @@ public function save($data, $id, $tags = [], $specificLifetime = false) $dataTable = $this->_getDataTable(); $lifetime = $this->getLifetime($specificLifetime); - $time = time(); + $time = Varien_Date::toTimestamp(true); $expire = ($lifetime === 0 || $lifetime === null) ? 0 : $time + $lifetime; $dataCol = $adapter->quoteIdentifier('data'); @@ -259,7 +263,9 @@ protected function _deleteCachesFromTagsTable($cacheIdsToRemove) * * @param string $mode Clean mode * @param array $tags Array of tags - * @return boolean true if no problem + * @return bool true if no problem + * @throws Zend_Cache_Exception + * @throws Zend_Db_Statement_Exception */ public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = []) { @@ -285,7 +291,6 @@ public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = []) break; default: Zend_Cache::throwException('Invalid mode for clean() method'); - break; } return $result; @@ -298,7 +303,7 @@ public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = []) */ protected function _cleanOldCache() { - $time = time(); + $time = Varien_Date::toTimestamp(true); $counter = 0; $result = true; $adapter = $this->_getAdapter(); @@ -458,7 +463,7 @@ public function getMetadatas($id) * * @param string $id cache id * @param int $extraLifetime - * @return boolean true if ok + * @return int|true true if ok */ public function touch($id, $extraLifetime) { @@ -466,7 +471,7 @@ public function touch($id, $extraLifetime) return $this->_getAdapter()->update( $this->_getDataTable(), ['expire_time' => new Zend_Db_Expr('expire_time+' . $extraLifetime)], - ['id=?' => $id, 'expire_time = 0 OR expire_time>?' => time()], + ['id=?' => $id, 'expire_time = 0 OR expire_time>?' => Varien_Date::toTimestamp(true)], ); } else { return true; @@ -547,6 +552,8 @@ protected function _saveTags($id, $tags) * @param string $mode * @param array $tags * @return bool + * @throws Zend_Cache_Exception + * @throws Zend_Db_Statement_Exception */ protected function _cleanByTags($mode, $tags) { @@ -568,7 +575,6 @@ protected function _cleanByTags($mode, $tags) break; default: Zend_Cache::throwException('Invalid mode for _cleanByTags() method'); - break; } $cacheIdsToRemove = []; diff --git a/lib/Varien/Data/Form/Element/Date.php b/lib/Varien/Data/Form/Element/Date.php index b1a35f88169..24b41659c11 100644 --- a/lib/Varien/Data/Form/Element/Date.php +++ b/lib/Varien/Data/Form/Element/Date.php @@ -92,7 +92,7 @@ public function setValue($value, $format = null, $locale = null) } // last check, if input format was set if (null === $format) { - $format = Varien_Date::DATETIME_INTERNAL_FORMAT; + $format = Mage_Core_Helper_Date::DATETIME_INTERNAL_FORMAT; if ($this->getInputFormat()) { $format = $this->getInputFormat(); } diff --git a/lib/Varien/Data/Form/Filter/Date.php b/lib/Varien/Data/Form/Filter/Date.php index 3d96631de84..971b641e5e9 100644 --- a/lib/Varien/Data/Form/Filter/Date.php +++ b/lib/Varien/Data/Form/Filter/Date.php @@ -45,7 +45,7 @@ class Varien_Data_Form_Filter_Date implements Varien_Data_Form_Filter_Interface public function __construct($format = null, $locale = null) { if (is_null($format)) { - $format = Varien_Date::DATE_INTERNAL_FORMAT; + $format = Mage_Core_Helper_Date::DATE_INTERNAL_FORMAT; } $this->_dateFormat = $format; $this->_locale = $locale; @@ -68,7 +68,7 @@ public function inputFilter($value) 'locale' => $this->_locale, ]); $filterInternal = new Zend_Filter_NormalizedToLocalized([ - 'date_format' => Varien_Date::DATE_INTERNAL_FORMAT, + 'date_format' => Mage_Core_Helper_Date::DATE_INTERNAL_FORMAT, 'locale' => $this->_locale, ]); @@ -89,7 +89,7 @@ public function outputFilter($value) } $filterInput = new Zend_Filter_LocalizedToNormalized([ - 'date_format' => Varien_Date::DATE_INTERNAL_FORMAT, + 'date_format' => Mage_Core_Helper_Date::DATE_INTERNAL_FORMAT, 'locale' => $this->_locale, ]); $filterInternal = new Zend_Filter_NormalizedToLocalized([ diff --git a/lib/Varien/Data/Form/Filter/Datetime.php b/lib/Varien/Data/Form/Filter/Datetime.php index 7dfb40d551d..fefc8acbf41 100644 --- a/lib/Varien/Data/Form/Filter/Datetime.php +++ b/lib/Varien/Data/Form/Filter/Datetime.php @@ -39,7 +39,7 @@ public function inputFilter($value) 'locale' => $this->_locale, ]); $filterInternal = new Zend_Filter_NormalizedToLocalized([ - 'date_format' => Varien_Date::DATETIME_INTERNAL_FORMAT, + 'date_format' => Mage_Core_Helper_Date::DATETIME_INTERNAL_FORMAT, 'locale' => $this->_locale, ]); @@ -60,7 +60,7 @@ public function outputFilter($value) } $filterInput = new Zend_Filter_LocalizedToNormalized([ - 'date_format' => Varien_Date::DATETIME_INTERNAL_FORMAT, + 'date_format' => Mage_Core_Helper_Date::DATETIME_INTERNAL_FORMAT, 'locale' => $this->_locale, ]); $filterInternal = new Zend_Filter_NormalizedToLocalized([ diff --git a/lib/Varien/Date.php b/lib/Varien/Date.php index 4bd4378304e..1409d065851 100644 --- a/lib/Varien/Date.php +++ b/lib/Varien/Date.php @@ -14,12 +14,17 @@ * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +use Carbon\Carbon; + /** * Converter of date formats * Internal dates * * @category Varien * @package Varien_Date + * @deprecated + * @see Carbon + * @see Mage_Core_Helper_Date */ class Varien_Date { @@ -117,7 +122,7 @@ public static function toTimestamp($date) } if ($date === true) { - return time(); + return Carbon::now()->getTimestamp(); } return strtotime($date); @@ -126,8 +131,9 @@ public static function toTimestamp($date) /** * Retrieve current date in internal format * - * @param boolean $withoutTime day only flag + * @param bool $withoutTime day only flag * @return string + * @deprecated replaced by carbon */ public static function now($withoutTime = false) { diff --git a/lib/Varien/Event/Observer/Cron.php b/lib/Varien/Event/Observer/Cron.php index 660dd73212f..b85e7141338 100644 --- a/lib/Varien/Event/Observer/Cron.php +++ b/lib/Varien/Event/Observer/Cron.php @@ -14,6 +14,8 @@ * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +use Carbon\Carbon; + /** * Event cron observer object * @@ -55,7 +57,7 @@ public function isValidFor(Varien_Event $event) public function getNow() { if (!$this->hasNow()) { - $this->setNow(time()); + $this->setNow(Carbon::now()->getTimestamp()); } return $this->getData('now'); } diff --git a/lib/Varien/Io/File.php b/lib/Varien/Io/File.php index b431461c29a..d1f4352df8d 100644 --- a/lib/Varien/Io/File.php +++ b/lib/Varien/Io/File.php @@ -817,7 +817,7 @@ public function ls($grep = null) } $list_item['text'] = $entry; - $list_item['mod_date'] = date(Varien_Date::DATETIME_PHP_FORMAT, filectime($fullpath)); + $list_item['mod_date'] = date(Mage_Core_Helper_Date::DATETIME_PHP_FORMAT, filectime($fullpath)); $list_item['permissions'] = $this->_parsePermissions(fileperms($fullpath)); $list_item['owner'] = $this->_getFileOwner($fullpath); diff --git a/tests/unit/LongRunningTestAlert.php b/tests/unit/LongRunningTestAlert.php new file mode 100644 index 00000000000..8dc861d7b83 --- /dev/null +++ b/tests/unit/LongRunningTestAlert.php @@ -0,0 +1,35 @@ + self::MAX_SECONDS_ALLOWED) { + file_put_contents('php://stderr', sprintf("\n\nThe %s test took %s seconds!\n\n", $test, $time)); + } + } +} diff --git a/tests/unit/Mage/Admin/Helper/BlockTest.php b/tests/unit/Mage/Admin/Helper/BlockTest.php index 51a8d722cf9..a600f34197f 100644 --- a/tests/unit/Mage/Admin/Helper/BlockTest.php +++ b/tests/unit/Mage/Admin/Helper/BlockTest.php @@ -18,12 +18,12 @@ namespace OpenMage\Tests\Unit\Mage\Admin\Helper; use Mage; -use Mage_Admin_Helper_Block; +use Mage_Admin_Helper_Block as Subject; use PHPUnit\Framework\TestCase; class BlockTest extends TestCase { - public Mage_Admin_Helper_Block $subject; + public Subject $subject; public function setUp(): void { diff --git a/tests/unit/Mage/Admin/Helper/DataTest.php b/tests/unit/Mage/Admin/Helper/DataTest.php index 64e7567dbd4..392bc72acdc 100644 --- a/tests/unit/Mage/Admin/Helper/DataTest.php +++ b/tests/unit/Mage/Admin/Helper/DataTest.php @@ -18,12 +18,12 @@ namespace OpenMage\Tests\Unit\Mage\Admin\Helper; use Mage; -use Mage_Admin_Helper_Data; +use Mage_Admin_Helper_Data as Subject; use PHPUnit\Framework\TestCase; class DataTest extends TestCase { - public Mage_Admin_Helper_Data $subject; + public Subject $subject; public function setUp(): void { diff --git a/tests/unit/Mage/Admin/Helper/VariableTest.php b/tests/unit/Mage/Admin/Helper/VariableTest.php index b826a3829a7..dc9dc1c0e6f 100644 --- a/tests/unit/Mage/Admin/Helper/VariableTest.php +++ b/tests/unit/Mage/Admin/Helper/VariableTest.php @@ -18,12 +18,12 @@ namespace OpenMage\Tests\Unit\Mage\Admin\Helper; use Mage; -use Mage_Admin_Helper_Variable; +use Mage_Admin_Helper_Variable as Subject; use PHPUnit\Framework\TestCase; class VariableTest extends TestCase { - public Mage_Admin_Helper_Variable $subject; + public Subject $subject; public function setUp(): void { diff --git a/tests/unit/Mage/Admin/Model/BlockTest.php b/tests/unit/Mage/Admin/Model/BlockTest.php index 2f67ed69164..6bcffea0a5e 100644 --- a/tests/unit/Mage/Admin/Model/BlockTest.php +++ b/tests/unit/Mage/Admin/Model/BlockTest.php @@ -19,12 +19,12 @@ use Generator; use Mage; -use Mage_Admin_Model_Block; +use Mage_Admin_Model_Block as Subject; use PHPUnit\Framework\TestCase; class BlockTest extends TestCase { - public Mage_Admin_Model_Block $subject; + public Subject $subject; public function setUp(): void { @@ -41,7 +41,7 @@ public function setUp(): void */ public function testValidate(array $expectedResult, array $methods): void { - $mock = $this->getMockBuilder(Mage_Admin_Model_Block::class) + $mock = $this->getMockBuilder(Subject::class) ->setMethods([ 'getBlockName', 'getIsAllowed', diff --git a/tests/unit/Mage/Admin/Model/ConfigTest.php b/tests/unit/Mage/Admin/Model/ConfigTest.php index 84194eaa840..ccacf778e3b 100644 --- a/tests/unit/Mage/Admin/Model/ConfigTest.php +++ b/tests/unit/Mage/Admin/Model/ConfigTest.php @@ -19,13 +19,13 @@ use Mage; use Mage_Admin_Model_Acl; -use Mage_Admin_Model_Config; +use Mage_Admin_Model_Config as Subject; use PHPUnit\Framework\TestCase; use Varien_Simplexml_Config; class ConfigTest extends TestCase { - public Mage_Admin_Model_Config $subject; + public Subject $subject; public function setUp(): void { @@ -57,8 +57,7 @@ public function testGetAclPrivilegeSet(): void */ public function testLoadAclResources(): void { - // phpcs:ignore Ecg.Classes.ObjectInstantiation.DirectInstantiation - $this->assertInstanceOf(Mage_Admin_Model_Config::class, $this->subject->loadAclResources(new Mage_Admin_Model_Acl())); + $this->assertInstanceOf(Subject::class, $this->subject->loadAclResources(new Mage_Admin_Model_Acl())); } /** diff --git a/tests/unit/Mage/Admin/Model/UserTest.php b/tests/unit/Mage/Admin/Model/UserTest.php index 76f81e3d172..98f341fc1f2 100644 --- a/tests/unit/Mage/Admin/Model/UserTest.php +++ b/tests/unit/Mage/Admin/Model/UserTest.php @@ -19,13 +19,13 @@ use Generator; use Mage; -use Mage_Admin_Model_User; +use Mage_Admin_Model_User as Subject; use Mage_Core_Exception; use PHPUnit\Framework\TestCase; class UserTest extends TestCase { - public Mage_Admin_Model_User $subject; + public Subject $subject; public function setUp(): void { @@ -44,7 +44,7 @@ public function setUp(): void */ public function testAuthenticate($expectedResult, array $methods): void { - $mock = $this->getMockBuilder(Mage_Admin_Model_User::class) + $mock = $this->getMockBuilder(Subject::class) ->setMethods([ 'loadByUsername', 'getId', @@ -66,8 +66,8 @@ public function testAuthenticate($expectedResult, array $methods): void try { $this->assertSame($expectedResult, $mock->authenticate($methods['getUsername'], $methods['getPassword'])); - } catch (Mage_Core_Exception $e) { - $this->assertSame($expectedResult, $e->getMessage()); + } catch (Mage_Core_Exception $exception) { + $this->assertSame($expectedResult, $exception->getMessage()); } } @@ -127,7 +127,7 @@ public function provideAuthenticateData(): Generator */ public function testValidate($expectedResult, array $methods): void { - $mock = $this->getMockBuilder(Mage_Admin_Model_User::class) + $mock = $this->getMockBuilder(Subject::class) ->setMethods([ 'hasNewPassword', 'getNewPassword', @@ -195,7 +195,7 @@ public function testValidateCurrentPassword(): void */ public function testLoadByUsername(): void { - $this->assertInstanceOf(Mage_Admin_Model_User::class, $this->subject->loadByUsername('invalid-user')); + $this->assertInstanceOf(Subject::class, $this->subject->loadByUsername('invalid-user')); } /** @@ -214,7 +214,7 @@ public function testHasAssigned2Role(): void */ public function testChangeResetPasswordLinkToken(): void { - $this->assertInstanceOf(Mage_Admin_Model_User::class, $this->subject->changeResetPasswordLinkToken('123')); + $this->assertInstanceOf(Subject::class, $this->subject->changeResetPasswordLinkToken('123')); } /** @@ -224,7 +224,7 @@ public function testChangeResetPasswordLinkToken(): void */ public function testIsResetPasswordLinkTokenExpired(bool $expectedResult, array $methods): void { - $mock = $this->getMockBuilder(Mage_Admin_Model_User::class) + $mock = $this->getMockBuilder(Subject::class) ->setMethods([ 'getRpToken', 'getRpTokenCreatedAt', @@ -260,6 +260,6 @@ public function provideIsResetPasswordLinkTokenExpiredData(): Generator */ public function testSendPasswordResetConfirmationEmail(): void { - $this->assertInstanceOf(Mage_Admin_Model_User::class, $this->subject->sendPasswordResetConfirmationEmail()); + $this->assertInstanceOf(Subject::class, $this->subject->sendPasswordResetConfirmationEmail()); } } diff --git a/tests/unit/Mage/Admin/Model/VariableTest.php b/tests/unit/Mage/Admin/Model/VariableTest.php index 194d13db1e7..f5f1b380bf6 100644 --- a/tests/unit/Mage/Admin/Model/VariableTest.php +++ b/tests/unit/Mage/Admin/Model/VariableTest.php @@ -19,12 +19,12 @@ use Generator; use Mage; -use Mage_Admin_Model_Variable; +use Mage_Admin_Model_Variable as Subject; use PHPUnit\Framework\TestCase; class VariableTest extends TestCase { - public Mage_Admin_Model_Variable $subject; + public Subject $subject; public function setUp(): void { @@ -41,7 +41,7 @@ public function setUp(): void */ public function testValidate($expectedResult, string $variableName, string $isAllowed): void { - $mock = $this->getMockBuilder(Mage_Admin_Model_Variable::class) + $mock = $this->getMockBuilder(Subject::class) ->setMethods(['getVariableName', 'getIsAllowed']) ->getMock(); diff --git a/tests/unit/Mage/AdminNotification/Helper/DataTest.php b/tests/unit/Mage/AdminNotification/Helper/DataTest.php index 007a6ca85f3..e026a3c2330 100644 --- a/tests/unit/Mage/AdminNotification/Helper/DataTest.php +++ b/tests/unit/Mage/AdminNotification/Helper/DataTest.php @@ -18,13 +18,13 @@ namespace OpenMage\Tests\Unit\Mage\AdminNotification\Helper; use Mage; -use Mage_AdminNotification_Helper_Data; +use Mage_AdminNotification_Helper_Data as Subject; use Mage_AdminNotification_Model_Inbox; use PHPUnit\Framework\TestCase; class DataTest extends TestCase { - public Mage_AdminNotification_Helper_Data $subject; + public Subject $subject; public function setUp(): void { diff --git a/tests/unit/Mage/AdminNotification/Model/FeedTest.php b/tests/unit/Mage/AdminNotification/Model/FeedTest.php index 2d494dfe344..50a35f91b53 100644 --- a/tests/unit/Mage/AdminNotification/Model/FeedTest.php +++ b/tests/unit/Mage/AdminNotification/Model/FeedTest.php @@ -18,13 +18,13 @@ namespace OpenMage\Tests\Unit\Mage\AdminNotification\Model; use Mage; -use Mage_AdminNotification_Model_Feed; +use Mage_AdminNotification_Model_Feed as Subject; use PHPUnit\Framework\TestCase; use SimpleXMLElement; class FeedTest extends TestCase { - public Mage_AdminNotification_Model_Feed $subject; + public Subject $subject; public function setUp(): void { @@ -47,7 +47,7 @@ public function testGetFeedUrl(): void */ public function testCheckUpdate(): void { - $this->assertInstanceOf(Mage_AdminNotification_Model_Feed::class, $this->subject->checkUpdate()); + $this->assertInstanceOf(Subject::class, $this->subject->checkUpdate()); } /** diff --git a/tests/unit/Mage/Adminhtml/Block/CacheTest.php b/tests/unit/Mage/Adminhtml/Block/CacheTest.php index 71908320381..7bc9be7b6a0 100644 --- a/tests/unit/Mage/Adminhtml/Block/CacheTest.php +++ b/tests/unit/Mage/Adminhtml/Block/CacheTest.php @@ -18,18 +18,17 @@ namespace OpenMage\Tests\Unit\Mage\Adminhtml\Block; use Mage; -use Mage_Adminhtml_Block_Cache; +use Mage_Adminhtml_Block_Cache as Subject; use PHPUnit\Framework\TestCase; class CacheTest extends TestCase { - public Mage_Adminhtml_Block_Cache $subject; + public Subject $subject; public function setUp(): void { Mage::app(); - // phpcs:ignore Ecg.Classes.ObjectInstantiation.DirectInstantiation - $this->subject = new Mage_Adminhtml_Block_Cache(); + $this->subject = new Subject(); } /** diff --git a/tests/unit/Mage/Adminhtml/Block/Customer/Edit/Tab/AddressesTest.php b/tests/unit/Mage/Adminhtml/Block/Customer/Edit/Tab/AddressesTest.php index 34b92b06ec8..e952f787e7e 100644 --- a/tests/unit/Mage/Adminhtml/Block/Customer/Edit/Tab/AddressesTest.php +++ b/tests/unit/Mage/Adminhtml/Block/Customer/Edit/Tab/AddressesTest.php @@ -18,19 +18,18 @@ namespace OpenMage\Tests\Unit\Mage\Adminhtml\Block\Customer\Edit\Tab; use Mage; -use Mage_Adminhtml_Block_Customer_Edit_Tab_Addresses; +use Mage_Adminhtml_Block_Customer_Edit_Tab_Addresses as Subject; use Mage_Customer_Model_Customer; use PHPUnit\Framework\TestCase; class AddressesTest extends TestCase { - public Mage_Adminhtml_Block_Customer_Edit_Tab_Addresses $subject; + public Subject $subject; public function setUp(): void { Mage::app(); - // phpcs:ignore Ecg.Classes.ObjectInstantiation.DirectInstantiation - $this->subject = new Mage_Adminhtml_Block_Customer_Edit_Tab_Addresses(); + $this->subject = new Subject(); } /** @@ -39,19 +38,18 @@ public function setUp(): void */ public function testInitForm(): void { - $mock = $this->getMockBuilder(Mage_Adminhtml_Block_Customer_Edit_Tab_Addresses::class) + $mock = $this->getMockBuilder(Subject::class) ->setMethods(['getRegistryCurrentCustomer', 'isReadonly']) ->getMock(); $mock ->method('getRegistryCurrentCustomer') - // phpcs:ignore Ecg.Classes.ObjectInstantiation.DirectInstantiation ->willReturn(new Mage_Customer_Model_Customer()); $mock ->method('isReadonly') ->willReturn(true); - $this->assertInstanceOf(Mage_Adminhtml_Block_Customer_Edit_Tab_Addresses::class, $mock->initForm()); + $this->assertInstanceOf(Subject::class, $mock->initForm()); } } diff --git a/tests/unit/Mage/Adminhtml/Block/Customer/Edit/Tab/NewsletterTest.php b/tests/unit/Mage/Adminhtml/Block/Customer/Edit/Tab/NewsletterTest.php index 33d9a1b8bd5..7fa0868a854 100644 --- a/tests/unit/Mage/Adminhtml/Block/Customer/Edit/Tab/NewsletterTest.php +++ b/tests/unit/Mage/Adminhtml/Block/Customer/Edit/Tab/NewsletterTest.php @@ -18,19 +18,18 @@ namespace OpenMage\Tests\Unit\Mage\Adminhtml\Block\Customer\Edit\Tab; use Mage; -use Mage_Adminhtml_Block_Customer_Edit_Tab_Newsletter; +use Mage_Adminhtml_Block_Customer_Edit_Tab_Newsletter as Subject; use Mage_Customer_Model_Customer; use PHPUnit\Framework\TestCase; class NewsletterTest extends TestCase { - public Mage_Adminhtml_Block_Customer_Edit_Tab_Newsletter $subject; + public Subject $subject; public function setUp(): void { Mage::app(); - // phpcs:ignore Ecg.Classes.ObjectInstantiation.DirectInstantiation - $this->subject = new Mage_Adminhtml_Block_Customer_Edit_Tab_Newsletter(); + $this->subject = new Subject(); } /** @@ -40,7 +39,7 @@ public function setUp(): void */ public function testInitForm(): void { - $mock = $this->getMockBuilder(Mage_Adminhtml_Block_Customer_Edit_Tab_Newsletter::class) + $mock = $this->getMockBuilder(Subject::class) ->setMethods(['getRegistryCurrentCustomer']) ->getMock(); @@ -49,6 +48,6 @@ public function testInitForm(): void // phpcs:ignore Ecg.Classes.ObjectInstantiation.DirectInstantiation ->willReturn(new Mage_Customer_Model_Customer()); - $this->assertInstanceOf(Mage_Adminhtml_Block_Customer_Edit_Tab_Newsletter::class, $mock->initForm()); + $this->assertInstanceOf(Subject::class, $mock->initForm()); } } diff --git a/tests/unit/Mage/Adminhtml/Block/System/Cache/Form/FormTest.php b/tests/unit/Mage/Adminhtml/Block/System/Cache/Form/FormTest.php index 6ce95285fd4..8e94fc326a1 100644 --- a/tests/unit/Mage/Adminhtml/Block/System/Cache/Form/FormTest.php +++ b/tests/unit/Mage/Adminhtml/Block/System/Cache/Form/FormTest.php @@ -18,18 +18,17 @@ namespace OpenMage\Tests\Unit\Mage\Adminhtml\Block\System\Cache\Form; use Mage; -use Mage_Adminhtml_Block_System_Cache_Form; +use Mage_Adminhtml_Block_System_Cache_Form as Subject; use PHPUnit\Framework\TestCase; class FormTest extends TestCase { - public Mage_Adminhtml_Block_System_Cache_Form $subject; + public Subject $subject; public function setUp(): void { Mage::app(); - // phpcs:ignore Ecg.Classes.ObjectInstantiation.DirectInstantiation - $this->subject = new Mage_Adminhtml_Block_System_Cache_Form(); + $this->subject = new Subject(); } /** @@ -37,6 +36,6 @@ public function setUp(): void */ public function testInitForm(): void { - $this->assertInstanceOf(Mage_Adminhtml_Block_System_Cache_Form::class, $this->subject->initForm()); + $this->assertInstanceOf(Subject::class, $this->subject->initForm()); } } diff --git a/tests/unit/Mage/Adminhtml/Block/System/Config/Form/FormTest.php b/tests/unit/Mage/Adminhtml/Block/System/Config/Form/FormTest.php index db3e41430fe..aea02165241 100644 --- a/tests/unit/Mage/Adminhtml/Block/System/Config/Form/FormTest.php +++ b/tests/unit/Mage/Adminhtml/Block/System/Config/Form/FormTest.php @@ -18,18 +18,17 @@ namespace OpenMage\Tests\Unit\Mage\Adminhtml\Block\System\Config\Form; use Mage; -use Mage_Adminhtml_Block_System_Config_Form; +use Mage_Adminhtml_Block_System_Config_Form as Subject; use PHPUnit\Framework\TestCase; class FormTest extends TestCase { - public Mage_Adminhtml_Block_System_Config_Form $subject; + public Subject $subject; public function setUp(): void { Mage::app(); - // phpcs:ignore Ecg.Classes.ObjectInstantiation.DirectInstantiation - $this->subject = new Mage_Adminhtml_Block_System_Config_Form(); + $this->subject = new Subject(); } /** @@ -37,6 +36,6 @@ public function setUp(): void */ public function testInitForm(): void { - $this->assertInstanceOf(Mage_Adminhtml_Block_System_Config_Form::class, $this->subject->initForm()); + $this->assertInstanceOf(Subject::class, $this->subject->initForm()); } } diff --git a/tests/unit/Mage/Adminhtml/Block/System/Convert/Gui/Edit/Tab/ViewTest.php b/tests/unit/Mage/Adminhtml/Block/System/Convert/Gui/Edit/Tab/ViewTest.php index 6c004239908..040cb925445 100644 --- a/tests/unit/Mage/Adminhtml/Block/System/Convert/Gui/Edit/Tab/ViewTest.php +++ b/tests/unit/Mage/Adminhtml/Block/System/Convert/Gui/Edit/Tab/ViewTest.php @@ -18,19 +18,18 @@ namespace OpenMage\Tests\Unit\Mage\Adminhtml\Block\System\Convert\Gui\Edit\Tab; use Mage; -use Mage_Adminhtml_Block_System_Convert_Gui_Edit_Tab_View; +use Mage_Adminhtml_Block_System_Convert_Gui_Edit_Tab_View as Subject; use Mage_Dataflow_Model_Profile; use PHPUnit\Framework\TestCase; class ViewTest extends TestCase { - public Mage_Adminhtml_Block_System_Convert_Gui_Edit_Tab_View $subject; + public Subject $subject; public function setUp(): void { Mage::app(); - // phpcs:ignore Ecg.Classes.ObjectInstantiation.DirectInstantiation - $this->subject = new Mage_Adminhtml_Block_System_Convert_Gui_Edit_Tab_View(); + $this->subject = new Subject(); } /** @@ -39,15 +38,14 @@ public function setUp(): void */ public function testInitForm(): void { - $mock = $this->getMockBuilder(Mage_Adminhtml_Block_System_Convert_Gui_Edit_Tab_View::class) + $mock = $this->getMockBuilder(Subject::class) ->setMethods(['getRegistryCurrentConvertProfile']) ->getMock(); $mock ->method('getRegistryCurrentConvertProfile') - // phpcs:ignore Ecg.Classes.ObjectInstantiation.DirectInstantiation ->willReturn(new Mage_Dataflow_Model_Profile()); - $this->assertInstanceOf(Mage_Adminhtml_Block_System_Convert_Gui_Edit_Tab_View::class, $mock->initForm()); + $this->assertInstanceOf(Subject::class, $mock->initForm()); } } diff --git a/tests/unit/Mage/Adminhtml/Block/System/Convert/Profile/Edit/Tab/EditTest.php b/tests/unit/Mage/Adminhtml/Block/System/Convert/Profile/Edit/Tab/EditTest.php index 67b4fa7dba7..c3c6ea0471c 100644 --- a/tests/unit/Mage/Adminhtml/Block/System/Convert/Profile/Edit/Tab/EditTest.php +++ b/tests/unit/Mage/Adminhtml/Block/System/Convert/Profile/Edit/Tab/EditTest.php @@ -18,19 +18,18 @@ namespace OpenMage\Tests\Unit\Mage\Adminhtml\Block\System\Convert\Profile\Edit\Tab; use Mage; -use Mage_Adminhtml_Block_System_Convert_Profile_Edit_Tab_Edit; +use Mage_Adminhtml_Block_System_Convert_Profile_Edit_Tab_Edit as Subject; use Mage_Dataflow_Model_Profile; use PHPUnit\Framework\TestCase; class EditTest extends TestCase { - public Mage_Adminhtml_Block_System_Convert_Profile_Edit_Tab_Edit $subject; + public Subject $subject; public function setUp(): void { Mage::app(); - // phpcs:ignore Ecg.Classes.ObjectInstantiation.DirectInstantiation - $this->subject = new Mage_Adminhtml_Block_System_Convert_Profile_Edit_Tab_Edit(); + $this->subject = new Subject(); } /** @@ -39,15 +38,14 @@ public function setUp(): void */ public function testInitForm(): void { - $mock = $this->getMockBuilder(Mage_Adminhtml_Block_System_Convert_Profile_Edit_Tab_Edit::class) + $mock = $this->getMockBuilder(Subject::class) ->setMethods(['getRegistryCurrentConvertProfile']) ->getMock(); $mock ->method('getRegistryCurrentConvertProfile') - // phpcs:ignore Ecg.Classes.ObjectInstantiation.DirectInstantiation ->willReturn(new Mage_Dataflow_Model_Profile()); - $this->assertInstanceOf(Mage_Adminhtml_Block_System_Convert_Profile_Edit_Tab_Edit::class, $mock->initForm()); + $this->assertInstanceOf(Subject::class, $mock->initForm()); } } diff --git a/tests/unit/Mage/Adminhtml/Block/TemplateTest.php b/tests/unit/Mage/Adminhtml/Block/TemplateTest.php index ea770f2e441..fc8de04ecfc 100644 --- a/tests/unit/Mage/Adminhtml/Block/TemplateTest.php +++ b/tests/unit/Mage/Adminhtml/Block/TemplateTest.php @@ -17,20 +17,21 @@ namespace OpenMage\Tests\Unit\Mage\Adminhtml\Block; -use Generator; use Mage; -use Mage_Adminhtml_Block_Template; +use Mage_Adminhtml_Block_Template as Subject; +use OpenMage\Tests\Unit\Traits\DataProvider\Mage\Core\CoreTrait; use PHPUnit\Framework\TestCase; class TemplateTest extends TestCase { - public Mage_Adminhtml_Block_Template $subject; + use CoreTrait; + + public Subject $subject; public function setUp(): void { Mage::app(); - // phpcs:ignore Ecg.Classes.ObjectInstantiation.DirectInstantiation - $this->subject = new Mage_Adminhtml_Block_Template(); + $this->subject = new Subject(); } /** @@ -56,22 +57,6 @@ public function testIsOutputEnabled(bool $expectedResult, ?string $moduleName): $this->assertSame($expectedResult, $this->subject->isOutputEnabled($moduleName)); } - public function provideIsOutputEnabled(): Generator - { - yield 'null' => [ - true, - null, #Mage_Adminhtml - ]; - yield 'Mage_Core' => [ - true, - 'Mage_Core', - ]; - yield 'Not_Exist' => [ - false, - 'Not_Exist', - ]; - } - /** * @group Mage_Adminhtml * @group Mage_Adminhtml_Block diff --git a/tests/unit/Mage/Adminhtml/Block/Widget/Grid/ColumnTest.php b/tests/unit/Mage/Adminhtml/Block/Widget/Grid/ColumnTest.php index f5589b383c2..02dd8e3ae1f 100644 --- a/tests/unit/Mage/Adminhtml/Block/Widget/Grid/ColumnTest.php +++ b/tests/unit/Mage/Adminhtml/Block/Widget/Grid/ColumnTest.php @@ -17,17 +17,16 @@ namespace OpenMage\Tests\Unit\Mage\Adminhtml\Block\Widget\Grid; -use Mage_Adminhtml_Block_Widget_Grid_Column; +use Mage_Adminhtml_Block_Widget_Grid_Column as Subject; use PHPUnit\Framework\TestCase; class ColumnTest extends TestCase { - public Mage_Adminhtml_Block_Widget_Grid_Column $subject; + public Subject $subject; public function setUp(): void { - // phpcs:ignore Ecg.Classes.ObjectInstantiation.DirectInstantiation - $this->subject = new Mage_Adminhtml_Block_Widget_Grid_Column(); + $this->subject = new Subject(); } /** diff --git a/tests/unit/Mage/Adminhtml/Block/Widget/GridTest.php b/tests/unit/Mage/Adminhtml/Block/Widget/GridTest.php index 2be3fd4f0a1..57bee349342 100644 --- a/tests/unit/Mage/Adminhtml/Block/Widget/GridTest.php +++ b/tests/unit/Mage/Adminhtml/Block/Widget/GridTest.php @@ -19,18 +19,17 @@ use Generator; use Mage; -use Mage_Adminhtml_Block_Widget_Grid; +use Mage_Adminhtml_Block_Widget_Grid as Subject; use PHPUnit\Framework\TestCase; class GridTest extends TestCase { - public Mage_Adminhtml_Block_Widget_Grid $subject; + public Subject $subject; public function setUp(): void { Mage::app(); - // phpcs:ignore Ecg.Classes.ObjectInstantiation.DirectInstantiation - $this->subject = new Mage_Adminhtml_Block_Widget_Grid(); + $this->subject = new Subject(); } /** diff --git a/tests/unit/Mage/Adminhtml/Helper/AddressesTest.php b/tests/unit/Mage/Adminhtml/Helper/AddressesTest.php index 2d2f8f0d296..c00118baada 100644 --- a/tests/unit/Mage/Adminhtml/Helper/AddressesTest.php +++ b/tests/unit/Mage/Adminhtml/Helper/AddressesTest.php @@ -19,13 +19,13 @@ use Generator; use Mage; -use Mage_Adminhtml_Helper_Addresses; +use Mage_Adminhtml_Helper_Addresses as Subject; use Mage_Customer_Model_Attribute; use PHPUnit\Framework\TestCase; class AddressesTest extends TestCase { - public Mage_Adminhtml_Helper_Addresses $subject; + public Subject $subject; public function setUp(): void { @@ -51,7 +51,7 @@ public function testProcessStreetAttribute(int $expectedResult, int $lines): voi public function provideProcessStreetAttribute(): Generator { yield 'default' => [ - Mage_Adminhtml_Helper_Addresses::DEFAULT_STREET_LINES_COUNT, + Subject::DEFAULT_STREET_LINES_COUNT, 0, ]; yield 'custom' => [ diff --git a/tests/unit/Mage/Adminhtml/Helper/CatalogTest.php b/tests/unit/Mage/Adminhtml/Helper/CatalogTest.php index e1bb60f7120..1cb1c363a8c 100644 --- a/tests/unit/Mage/Adminhtml/Helper/CatalogTest.php +++ b/tests/unit/Mage/Adminhtml/Helper/CatalogTest.php @@ -18,12 +18,12 @@ namespace OpenMage\Tests\Unit\Mage\Adminhtml\Helper; use Mage; -use Mage_Adminhtml_Helper_Catalog; +use Mage_Adminhtml_Helper_Catalog as Subject; use PHPUnit\Framework\TestCase; class CatalogTest extends TestCase { - public Mage_Adminhtml_Helper_Catalog $subject; + public Subject $subject; public function setUp(): void { @@ -38,7 +38,7 @@ public function setUp(): void */ public function testSetAttributeTabBlock(): void { - $this->assertInstanceOf(Mage_Adminhtml_Helper_Catalog::class, $this->subject->setAttributeTabBlock('')); + $this->assertInstanceOf(Subject::class, $this->subject->setAttributeTabBlock('')); } /** @@ -48,7 +48,7 @@ public function testSetAttributeTabBlock(): void */ public function testSetCategoryAttributeTabBlock(): void { - $this->assertInstanceOf(Mage_Adminhtml_Helper_Catalog::class, $this->subject->setCategoryAttributeTabBlock('')); + $this->assertInstanceOf(Subject::class, $this->subject->setCategoryAttributeTabBlock('')); } /** diff --git a/tests/unit/Mage/Adminhtml/Helper/ConfigTest.php b/tests/unit/Mage/Adminhtml/Helper/ConfigTest.php index c697b408bf4..78c04518855 100644 --- a/tests/unit/Mage/Adminhtml/Helper/ConfigTest.php +++ b/tests/unit/Mage/Adminhtml/Helper/ConfigTest.php @@ -19,12 +19,12 @@ use Generator; use Mage; -use Mage_Adminhtml_Helper_Config; +use Mage_Adminhtml_Helper_Config as Subject; use PHPUnit\Framework\TestCase; class ConfigTest extends TestCase { - public Mage_Adminhtml_Helper_Config $subject; + public Subject $subject; public function setUp(): void { diff --git a/tests/unit/Mage/Adminhtml/Helper/Dashboard/DataTest.php b/tests/unit/Mage/Adminhtml/Helper/Dashboard/DataTest.php index 5fe9707c10a..8e6d9f24190 100644 --- a/tests/unit/Mage/Adminhtml/Helper/Dashboard/DataTest.php +++ b/tests/unit/Mage/Adminhtml/Helper/Dashboard/DataTest.php @@ -18,13 +18,13 @@ namespace OpenMage\Tests\Unit\Mage\Adminhtml\Helper\Dashboard; use Mage; -use Mage_Adminhtml_Helper_Dashboard_Data; +use Mage_Adminhtml_Helper_Dashboard_Data as Subject; use Mage_Core_Model_Resource_Store_Collection; use PHPUnit\Framework\TestCase; class DataTest extends TestCase { - public Mage_Adminhtml_Helper_Dashboard_Data $subject; + public Subject $subject; public function setUp(): void { diff --git a/tests/unit/Mage/Adminhtml/Helper/DataTest.php b/tests/unit/Mage/Adminhtml/Helper/DataTest.php index 07b6d6e9518..bb2d62877f1 100644 --- a/tests/unit/Mage/Adminhtml/Helper/DataTest.php +++ b/tests/unit/Mage/Adminhtml/Helper/DataTest.php @@ -18,12 +18,12 @@ namespace OpenMage\Tests\Unit\Mage\Adminhtml\Helper; use Mage; -use Mage_Adminhtml_Helper_Data; +use Mage_Adminhtml_Helper_Data as Subject; use PHPUnit\Framework\TestCase; class DataTest extends TestCase { - public Mage_Adminhtml_Helper_Data $subject; + public Subject $subject; public function setUp(): void { diff --git a/tests/unit/Mage/Adminhtml/Helper/JsTest.php b/tests/unit/Mage/Adminhtml/Helper/JsTest.php index c9cfc2b5b05..973f3a98930 100644 --- a/tests/unit/Mage/Adminhtml/Helper/JsTest.php +++ b/tests/unit/Mage/Adminhtml/Helper/JsTest.php @@ -19,12 +19,12 @@ use Generator; use Mage; -use Mage_Adminhtml_Helper_Js; +use Mage_Adminhtml_Helper_Js as Subject; use PHPUnit\Framework\TestCase; class JsTest extends TestCase { - public Mage_Adminhtml_Helper_Js $subject; + public Subject $subject; public function setUp(): void { diff --git a/tests/unit/Mage/Adminhtml/Helper/Media/JsTest.php b/tests/unit/Mage/Adminhtml/Helper/Media/JsTest.php index 6d9264b447c..ff17b3b317e 100644 --- a/tests/unit/Mage/Adminhtml/Helper/Media/JsTest.php +++ b/tests/unit/Mage/Adminhtml/Helper/Media/JsTest.php @@ -18,12 +18,12 @@ namespace OpenMage\Tests\Unit\Mage\Adminhtml\Helper\Media; use Mage; -use Mage_Adminhtml_Helper_Media_Js; +use Mage_Adminhtml_Helper_Media_Js as Subject; use PHPUnit\Framework\TestCase; class JsTest extends TestCase { - public Mage_Adminhtml_Helper_Media_Js $subject; + public Subject $subject; public function setUp(): void { diff --git a/tests/unit/Mage/Adminhtml/Helper/SalesTest.php b/tests/unit/Mage/Adminhtml/Helper/SalesTest.php index ecc1f5bd660..1e8da01ba12 100644 --- a/tests/unit/Mage/Adminhtml/Helper/SalesTest.php +++ b/tests/unit/Mage/Adminhtml/Helper/SalesTest.php @@ -19,12 +19,12 @@ use Generator; use Mage; -use Mage_Adminhtml_Helper_Sales; +use Mage_Adminhtml_Helper_Sales as Subject; use PHPUnit\Framework\TestCase; class SalesTest extends TestCase { - public Mage_Adminhtml_Helper_Sales $subject; + public Subject $subject; public function setUp(): void { diff --git a/tests/unit/Mage/Catalog/Helper/CategoryTest.php b/tests/unit/Mage/Catalog/Helper/CategoryTest.php index b7d5a37d768..14fa24fc2d6 100644 --- a/tests/unit/Mage/Catalog/Helper/CategoryTest.php +++ b/tests/unit/Mage/Catalog/Helper/CategoryTest.php @@ -18,12 +18,12 @@ namespace OpenMage\Tests\Unit\Mage\Catalog\Helper; use Mage; -use Mage_Catalog_Helper_Category; +use Mage_Catalog_Helper_Category as Subject; use PHPUnit\Framework\TestCase; class CategoryTest extends TestCase { - public Mage_Catalog_Helper_Category $subject; + public Subject $subject; public function setUp(): void { diff --git a/tests/unit/Mage/Catalog/Helper/DataTest.php b/tests/unit/Mage/Catalog/Helper/DataTest.php index 5979f4ac3fd..2cd5e2fdba7 100644 --- a/tests/unit/Mage/Catalog/Helper/DataTest.php +++ b/tests/unit/Mage/Catalog/Helper/DataTest.php @@ -19,13 +19,13 @@ use Generator; use Mage; -use Mage_Catalog_Helper_Data; +use Mage_Catalog_Helper_Data as Subject; use Mage_Catalog_Model_Template_Filter; use PHPUnit\Framework\TestCase; class DataTest extends TestCase { - public Mage_Catalog_Helper_Data $subject; + public Subject $subject; public function setUp(): void { diff --git a/tests/unit/Mage/Catalog/Helper/MapTest.php b/tests/unit/Mage/Catalog/Helper/MapTest.php index f7425b2b79b..c2ec84f5c3b 100644 --- a/tests/unit/Mage/Catalog/Helper/MapTest.php +++ b/tests/unit/Mage/Catalog/Helper/MapTest.php @@ -18,12 +18,12 @@ namespace OpenMage\Tests\Unit\Mage\Catalog\Helper; use Mage; -use Mage_Catalog_Helper_Map; +use Mage_Catalog_Helper_Map as Subject; use PHPUnit\Framework\TestCase; class MapTest extends TestCase { - public Mage_Catalog_Helper_Map $subject; + public Subject $subject; public function setUp(): void { diff --git a/tests/unit/Mage/Catalog/Helper/Product/UrlTest.php b/tests/unit/Mage/Catalog/Helper/Product/UrlTest.php index 9aa95935e2d..992482f4b53 100644 --- a/tests/unit/Mage/Catalog/Helper/Product/UrlTest.php +++ b/tests/unit/Mage/Catalog/Helper/Product/UrlTest.php @@ -19,12 +19,12 @@ use Generator; use Mage; -use Mage_Catalog_Helper_Product_Url; +use Mage_Catalog_Helper_Product_Url as Subject; use PHPUnit\Framework\TestCase; class UrlTest extends TestCase { - public Mage_Catalog_Helper_Product_Url $subject; + public Subject $subject; public function setUp(): void { diff --git a/tests/unit/Mage/Catalog/Helper/ProductTest.php b/tests/unit/Mage/Catalog/Helper/ProductTest.php index c07fd077d9c..7910f8eba9a 100644 --- a/tests/unit/Mage/Catalog/Helper/ProductTest.php +++ b/tests/unit/Mage/Catalog/Helper/ProductTest.php @@ -19,12 +19,12 @@ use Generator; use Mage; -use Mage_Catalog_Helper_Product; +use Mage_Catalog_Helper_Product as Subject; use PHPUnit\Framework\TestCase; class ProductTest extends TestCase { - public Mage_Catalog_Helper_Product $subject; + public Subject $subject; public function setUp(): void { diff --git a/tests/unit/Mage/Catalog/Model/CategoryTest.php b/tests/unit/Mage/Catalog/Model/CategoryTest.php index 8d05796a494..8735898b686 100644 --- a/tests/unit/Mage/Catalog/Model/CategoryTest.php +++ b/tests/unit/Mage/Catalog/Model/CategoryTest.php @@ -9,7 +9,7 @@ * * @category OpenMage * @package OpenMage_Tests - * @copyright Copyright (c) 2024 The OpenMage Contributors (https://www.openmage.org) + * @copyright Copyright (c) 2024-2025 The OpenMage Contributors (https://www.openmage.org) * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -17,19 +17,19 @@ namespace OpenMage\Tests\Unit\Mage\Catalog\Model; -use Generator; use Mage; -use Mage_Catalog_Model_Category; +use Mage_Catalog_Model_Category as Subject; use Mage_Catalog_Model_Category_Url; use Mage_Catalog_Model_Resource_Product_Collection; use Mage_Catalog_Model_Url; +use OpenMage\Tests\Unit\Traits\DataProvider\Mage\Catalog\CatalogTrait; use PHPUnit\Framework\TestCase; class CategoryTest extends TestCase { - public const TEST_STRING = 'a & B, x%, ä, ö, ü'; + use CatalogTrait; - public Mage_Catalog_Model_Category $subject; + public Subject $subject; public function setUp(): void { @@ -88,7 +88,7 @@ public function testValidate(): void */ public function testAfterCommitCallback(): void { - $this->assertInstanceOf(Mage_Catalog_Model_Category::class, $this->subject->afterCommitCallback()); + $this->assertInstanceOf(Subject::class, $this->subject->afterCommitCallback()); } /** @@ -122,18 +122,6 @@ public function testGetUrlModel(): void public function testFormatUrlKey($expectedResult, ?string $locale): void { $this->subject->setLocale($locale); - $this->assertSame($expectedResult, $this->subject->formatUrlKey(self::TEST_STRING)); - } - - public function provideFormatUrlKey(): Generator - { - yield 'null locale' => [ - 'a-b-x-a-o-u', - null, - ]; - yield 'de_DE' => [ - 'a-und-b-x-prozent-ae-oe-ue', - 'de_DE', - ]; + $this->assertSame($expectedResult, $this->subject->formatUrlKey($this->getTestString())); } } diff --git a/tests/unit/Mage/Catalog/Model/ProductTest.php b/tests/unit/Mage/Catalog/Model/ProductTest.php index 1dd18388274..5bc6d03b502 100644 --- a/tests/unit/Mage/Catalog/Model/ProductTest.php +++ b/tests/unit/Mage/Catalog/Model/ProductTest.php @@ -9,7 +9,7 @@ * * @category OpenMage * @package OpenMage_Tests - * @copyright Copyright (c) 2024 The OpenMage Contributors (https://www.openmage.org) + * @copyright Copyright (c) 2024-2025 The OpenMage Contributors (https://www.openmage.org) * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -17,21 +17,23 @@ namespace OpenMage\Tests\Unit\Mage\Catalog\Model; -use Generator; use Mage; -use Mage_Catalog_Model_Product; +use Mage_Catalog_Model_Product as Subject; use Mage_Catalog_Model_Product_Link; use Mage_Catalog_Model_Product_Type_Abstract; use Mage_Catalog_Model_Product_Url; use Mage_Catalog_Model_Resource_Product_Collection; use Mage_Catalog_Model_Url; +use OpenMage\Tests\Unit\Traits\DataProvider\Base\BoolTrait; +use OpenMage\Tests\Unit\Traits\DataProvider\Mage\Catalog\CatalogTrait; use PHPUnit\Framework\TestCase; class ProductTest extends TestCase { - public const TEST_STRING = 'a & B, x%, ä, ö, ü'; + use BoolTrait; + use CatalogTrait; - public Mage_Catalog_Model_Product $subject; + public Subject $subject; public function setUp(): void { @@ -73,7 +75,7 @@ public function testGetUrlModel(): void */ public function testValidate(): void { - $this->assertInstanceOf(Mage_Catalog_Model_Product::class, $this->subject->validate()); + $this->assertInstanceOf(Subject::class, $this->subject->validate()); } /** @@ -101,7 +103,7 @@ public function testValidate(): void */ public function testSetPriceCalculation(): void { - $this->assertInstanceOf(Mage_Catalog_Model_Product::class, $this->subject->setPriceCalculation()); + $this->assertInstanceOf(Subject::class, $this->subject->setPriceCalculation()); } /** @@ -123,7 +125,7 @@ public function testGetStatus(): void } /** - * @dataProvider provideTypeInstanceData + * @dataProvider provideBool * @group Mage_Catalog * @group Mage_Catalog_Model */ @@ -132,16 +134,6 @@ public function testGetTypeInstance(bool $singleton): void $this->assertInstanceOf(Mage_Catalog_Model_Product_Type_Abstract::class, $this->subject->getTypeInstance($singleton)); } - public function provideTypeInstanceData(): Generator - { - yield 'singleton false' => [ - true, - ]; - yield 'singleton true' => [ - true, - ]; - } - /** * @group Mage_Catalog * @group Mage_Catalog_Model @@ -166,7 +158,7 @@ public function testGetDefaultAttributeSetId(): void */ public function testAfterCommitCallback(): void { - $this->assertInstanceOf(Mage_Catalog_Model_Product::class, $this->subject->afterCommitCallback()); + $this->assertInstanceOf(Subject::class, $this->subject->afterCommitCallback()); } /** @@ -177,18 +169,6 @@ public function testAfterCommitCallback(): void public function testFormatUrlKey($expectedResult, ?string $locale): void { $this->subject->setLocale($locale); - $this->assertSame($expectedResult, $this->subject->formatUrlKey(self::TEST_STRING)); - } - - public function provideFormatUrlKey(): Generator - { - yield 'null locale' => [ - 'a-b-x-a-o-u', - null, - ]; - yield 'de_DE' => [ - 'a-und-b-x-prozent-ae-oe-ue', - 'de_DE', - ]; + $this->assertSame($expectedResult, $this->subject->formatUrlKey($this->getTestString())); } } diff --git a/tests/unit/Mage/Catalog/Model/Resource/Eav/AttributeTest.php b/tests/unit/Mage/Catalog/Model/Resource/Eav/AttributeTest.php index 2b0a588e64a..2d57ed1762d 100644 --- a/tests/unit/Mage/Catalog/Model/Resource/Eav/AttributeTest.php +++ b/tests/unit/Mage/Catalog/Model/Resource/Eav/AttributeTest.php @@ -17,14 +17,16 @@ namespace OpenMage\Tests\Unit\Mage\Catalog\Model\Resource\Eav; -use Generator; use Mage; -use Mage_Catalog_Model_Resource_Eav_Attribute; +use Mage_Catalog_Model_Resource_Eav_Attribute as Subject; +use OpenMage\Tests\Unit\Traits\DataProvider\Mage\Core\CoreTrait; use PHPUnit\Framework\TestCase; class AttributeTest extends TestCase { - public Mage_Catalog_Model_Resource_Eav_Attribute $subject; + use CoreTrait; + + public Subject $subject; public function setUp(): void { @@ -45,20 +47,4 @@ public function testGetStoreId($expectedResult, $withStoreId): void } $this->assertSame($expectedResult, $this->subject->getStoreId()); } - - public function provideGetStoreId(): Generator - { - yield 'string' => [ - 1, - '1', - ]; - yield 'int' => [ - 1, - 1, - ]; - yield 'no store id' => [ - null, - null, - ]; - } } diff --git a/tests/unit/Mage/Catalog/Model/UrlTest.php b/tests/unit/Mage/Catalog/Model/UrlTest.php index 261385a8a4f..ce3a2acf505 100644 --- a/tests/unit/Mage/Catalog/Model/UrlTest.php +++ b/tests/unit/Mage/Catalog/Model/UrlTest.php @@ -9,7 +9,7 @@ * * @category OpenMage * @package OpenMage_Tests - * @copyright Copyright (c) 2024 The OpenMage Contributors (https://www.openmage.org) + * @copyright Copyright (c) 2024-2025 The OpenMage Contributors (https://www.openmage.org) * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -19,17 +19,20 @@ use Generator; use Mage; -use Mage_Catalog_Model_Url; +use Mage_Catalog_Model_Url as Subject; use Mage_Core_Exception; +use OpenMage\Tests\Unit\Traits\DataProvider\Base\IntOrNullTrait; +use OpenMage\Tests\Unit\Traits\DataProvider\Mage\Catalog\CatalogTrait; use PHPUnit\Framework\TestCase; use Symfony\Component\String\Slugger\AsciiSlugger; use Varien_Object; class UrlTest extends TestCase { - public const TEST_STRING = '--a & B, x% @ ä ö ü ™--'; + use CatalogTrait; + use IntOrNullTrait; - public Mage_Catalog_Model_Url $subject; + public Subject $subject; public function setUp(): void { @@ -47,27 +50,13 @@ public function testGetStoreRootCategory(): void } /** - * @dataProvider provideRefreshRewrites - * + * @dataProvider provideIntOrNull * @group Mage_Catalog * @group Mage_Catalog_Model */ public function testRefreshRewrites(?int $storeId): void { - $this->assertInstanceOf(Mage_Catalog_Model_Url::class, $this->subject->refreshRewrites($storeId)); - } - - public function provideRefreshRewrites(): Generator - { - yield 'w/o storeId' => [ - null, - ]; - yield 'w/ valid storeId' => [ - 1, - ]; - yield 'w/ invalid storeId' => [ - 999, - ]; + $this->assertInstanceOf(Subject::class, $this->subject->refreshRewrites($storeId)); } /** @@ -140,34 +129,10 @@ public function provideGeneratePathData(): Generator * @group Mage_Catalog * @group Mage_Catalog_Model */ - public function testFormatUrlKey($expectedResult, string $locale): void + public function testFormatUrlKey($expectedResult, ?string $locale): void { $this->subject->setLocale($locale); - $this->assertSame($expectedResult, $this->subject->formatUrlKey(self::TEST_STRING)); - } - - public function provideFormatUrlKey(): Generator - { - yield 'de_DE' => [ - 'a-und-b-x-prozent-at-ae-oe-ue-tm', - 'de_DE', - ]; - yield 'en_US' => [ - 'a-and-b-x-percent-at-a-o-u-tm', - 'en_US', - ]; - yield 'es_ES' => [ - 'a-et-b-x-por-ciento-at-a-o-u-tm', - 'es_ES', - ]; - yield 'fr_FR' => [ - 'a-et-b-x-pour-cent-at-a-o-u-tm', - 'fr_FR', - ]; - yield 'it_IT' => [ - 'a-e-b-x-per-cento-at-a-o-u-tm', - 'it_IT', - ]; + $this->assertSame($expectedResult, $this->subject->formatUrlKey($this->getTestString())); } /** diff --git a/tests/unit/Mage/Cms/Block/BlockTest.php b/tests/unit/Mage/Cms/Block/BlockTest.php index 7c073a8dce8..5fac0f46736 100644 --- a/tests/unit/Mage/Cms/Block/BlockTest.php +++ b/tests/unit/Mage/Cms/Block/BlockTest.php @@ -9,7 +9,7 @@ * * @category OpenMage * @package OpenMage_Tests - * @copyright Copyright (c) 2024 The OpenMage Contributors (https://www.openmage.org) + * @copyright Copyright (c) 2024-2025 The OpenMage Contributors (https://www.openmage.org) * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -17,34 +17,26 @@ namespace OpenMage\Tests\Unit\Mage\Cms\Block; -use Generator; -use Mage_Cms_Block_Block; +use Mage_Cms_Block_Block as Subject; +use OpenMage\Tests\Unit\Traits\DataProvider\Base\NumericStringTrait; use PHPUnit\Framework\TestCase; class BlockTest extends TestCase { + use NumericStringTrait; + /** - * @dataProvider provideGetCacheKeyInfoData + * @dataProvider provideNumericString * @group Mage_Cms * @group Mage_Cms_Block */ public function testGetCacheKeyInfo(string $blockId): void { - $mock = $this->getMockBuilder(Mage_Cms_Block_Block::class) + $mock = $this->getMockBuilder(Subject::class) ->setMethods(['getBlockId']) ->getMock(); $mock->method('getBlockId')->willReturn($blockId); $this->assertIsArray($mock->getCacheKeyInfo()); } - - public function provideGetCacheKeyInfoData(): Generator - { - yield 'valid block ID' => [ - '2', - ]; - yield 'invalid block ID' => [ - '0', - ]; - } } diff --git a/tests/unit/Mage/Cms/Block/PageTest.php b/tests/unit/Mage/Cms/Block/PageTest.php index 0532d87118f..aa637f47c2d 100644 --- a/tests/unit/Mage/Cms/Block/PageTest.php +++ b/tests/unit/Mage/Cms/Block/PageTest.php @@ -9,7 +9,7 @@ * * @category OpenMage * @package OpenMage_Tests - * @copyright Copyright (c) 2024 The OpenMage Contributors (https://www.openmage.org) + * @copyright Copyright (c) 2024-2025 The OpenMage Contributors (https://www.openmage.org) * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -17,35 +17,27 @@ namespace OpenMage\Tests\Unit\Mage\Cms\Block; -use Generator; -use Mage_Cms_Block_Page; +use Mage_Cms_Block_Page as Subject; use Mage_Cms_Model_Page; +use OpenMage\Tests\Unit\Traits\DataProvider\Base\NumericStringTrait; use PHPUnit\Framework\TestCase; class PageTest extends TestCase { + use NumericStringTrait; + /** - * @dataProvider provideGetPageData + * @dataProvider provideNumericString * @group Mage_Cms * @group Mage_Cms_Block */ public function testGetPage(string $pageId): void { - $mock = $this->getMockBuilder(Mage_Cms_Block_Page::class) + $mock = $this->getMockBuilder(Subject::class) ->setMethods(['getPageId']) ->getMock(); $mock->method('getPageId')->willReturn($pageId); $this->assertInstanceOf(Mage_Cms_Model_Page::class, $mock->getPage()); } - - public function provideGetPageData(): Generator - { - yield 'valid page ID' => [ - '2', - ]; - yield 'invalid page ID' => [ - '0', - ]; - } } diff --git a/tests/unit/Mage/Cms/Block/Widget/BlockTest.php b/tests/unit/Mage/Cms/Block/Widget/BlockTest.php index e8f4cc7cff0..3893735d9d5 100644 --- a/tests/unit/Mage/Cms/Block/Widget/BlockTest.php +++ b/tests/unit/Mage/Cms/Block/Widget/BlockTest.php @@ -9,7 +9,7 @@ * * @category OpenMage * @package OpenMage_Tests - * @copyright Copyright (c) 2024 The OpenMage Contributors (https://www.openmage.org) + * @copyright Copyright (c) 2024-2025 The OpenMage Contributors (https://www.openmage.org) * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -17,30 +17,31 @@ namespace OpenMage\Tests\Unit\Mage\Cms\Block\Widget; -use Generator; use Mage; -use Mage_Cms_Block_Widget_Block; +use Mage_Cms_Block_Widget_Block as Subject; +use OpenMage\Tests\Unit\Traits\DataProvider\Base\NumericStringTrait; use PHPUnit\Framework\TestCase; class BlockTest extends TestCase { - public Mage_Cms_Block_Widget_Block $subject; + use NumericStringTrait; + + public Subject $subject; public function setUp(): void { Mage::app(); - // phpcs:ignore Ecg.Classes.ObjectInstantiation.DirectInstantiation - $this->subject = new Mage_Cms_Block_Widget_Block(); + $this->subject = new Subject(); } /** - * @dataProvider provideGetCacheKeyInfoData + * @dataProvider provideNumericString * @group Mage_Cms * @group Mage_Cms_Block */ public function testGetCacheKeyInfo(string $blockId): void { - $mock = $this->getMockBuilder(Mage_Cms_Block_Widget_Block::class) + $mock = $this->getMockBuilder(Subject::class) ->setMethods(['getBlockId']) ->getMock(); @@ -48,16 +49,6 @@ public function testGetCacheKeyInfo(string $blockId): void $this->assertIsArray($mock->getCacheKeyInfo()); } - public function provideGetCacheKeyInfoData(): Generator - { - yield 'valid block ID' => [ - '2', - ]; - yield 'invalid block ID' => [ - '0', - ]; - } - /** * @group Mage_Cms * @group Mage_Cms_Block diff --git a/tests/unit/Mage/Cms/Block/Widget/Page/LinkTest.php b/tests/unit/Mage/Cms/Block/Widget/Page/LinkTest.php index 78fb452c578..fbd6c7f841d 100644 --- a/tests/unit/Mage/Cms/Block/Widget/Page/LinkTest.php +++ b/tests/unit/Mage/Cms/Block/Widget/Page/LinkTest.php @@ -18,18 +18,17 @@ namespace OpenMage\Tests\Unit\Mage\Cms\Block\Widget\Page; use Mage; -use Mage_Cms_Block_Widget_Page_Link; +use Mage_Cms_Block_Widget_Page_Link as Subject; use PHPUnit\Framework\TestCase; class LinkTest extends TestCase { - public Mage_Cms_Block_Widget_Page_Link $subject; + public Subject $subject; public function setUp(): void { Mage::app(); - // phpcs:ignore Ecg.Classes.ObjectInstantiation.DirectInstantiation - $this->subject = new Mage_Cms_Block_Widget_Page_Link(); + $this->subject = new Subject(); } /** diff --git a/tests/unit/Mage/Cms/Helper/DataTest.php b/tests/unit/Mage/Cms/Helper/DataTest.php index 953c9267e55..ae858e4e951 100644 --- a/tests/unit/Mage/Cms/Helper/DataTest.php +++ b/tests/unit/Mage/Cms/Helper/DataTest.php @@ -18,7 +18,7 @@ namespace OpenMage\Tests\Unit\Mage\Cms\Helper; use Mage; -use Mage_Cms_Helper_Data; +use Mage_Cms_Helper_Data as Subject; use PHPUnit\Framework\TestCase; use Varien_Filter_Template; @@ -26,7 +26,7 @@ class DataTest extends TestCase { public const TEST_STRING = '1234567890'; - public Mage_Cms_Helper_Data $subject; + public Subject $subject; public function setUp(): void { diff --git a/tests/unit/Mage/Cms/Helper/PageTest.php b/tests/unit/Mage/Cms/Helper/PageTest.php index 3c53643771e..472fb1f6c24 100644 --- a/tests/unit/Mage/Cms/Helper/PageTest.php +++ b/tests/unit/Mage/Cms/Helper/PageTest.php @@ -17,14 +17,16 @@ namespace OpenMage\Tests\Unit\Mage\Cms\Helper; -use Generator; use Mage; -use Mage_Cms_Helper_Page; +use Mage_Cms_Helper_Page as Subject; +use OpenMage\Tests\Unit\Traits\DataProvider\Mage\Cms\CmsTrait; use PHPUnit\Framework\TestCase; class PageTest extends TestCase { - public Mage_Cms_Helper_Page $subject; + use CmsTrait; + + public Subject $subject; public function setUp(): void { @@ -39,35 +41,6 @@ public function setUp(): void */ public function testGetUsedInStoreConfigPaths(array $expectedResult, ?array $path): void { - $this->assertSame($expectedResult, Mage_Cms_Helper_Page::getUsedInStoreConfigPaths($path)); - } - - public function provideGetUsedInStoreConfigPaths(): Generator - { - yield 'null' => [ - [], - null, - ]; - yield 'empty array' => [ - [ - 0 => Mage_Cms_Helper_Page::XML_PATH_NO_ROUTE_PAGE, - 1 => Mage_Cms_Helper_Page::XML_PATH_NO_COOKIES_PAGE, - 2 => Mage_Cms_Helper_Page::XML_PATH_HOME_PAGE, - ], - [], - ]; - yield 'custom paths' => [ - [ - 0 => Mage_Cms_Helper_Page::XML_PATH_NO_ROUTE_PAGE, - 1 => Mage_Cms_Helper_Page::XML_PATH_NO_COOKIES_PAGE, - 2 => Mage_Cms_Helper_Page::XML_PATH_HOME_PAGE, - 3 => 'my/first/path', - 4 => 'my/second/path', - ], - [ - 'my/first/path', - 'my/second/path', - ], - ]; + $this->assertSame($expectedResult, Subject::getUsedInStoreConfigPaths($path)); } } diff --git a/tests/unit/Mage/Cms/Helper/Wysiwyg/ImagesTest.php b/tests/unit/Mage/Cms/Helper/Wysiwyg/ImagesTest.php index a365b4a2696..c52b75ed32c 100644 --- a/tests/unit/Mage/Cms/Helper/Wysiwyg/ImagesTest.php +++ b/tests/unit/Mage/Cms/Helper/Wysiwyg/ImagesTest.php @@ -17,17 +17,17 @@ namespace OpenMage\Tests\Unit\Mage\Cms\Helper\Wysiwyg; -use Generator; use Mage; -use Mage_Cms_Helper_Wysiwyg_Images; +use Mage_Cms_Helper_Wysiwyg_Images as Subject; use Mage_Cms_Model_Wysiwyg_Images_Storage; +use OpenMage\Tests\Unit\Traits\DataProvider\Mage\Cms\CmsTrait; use PHPUnit\Framework\TestCase; class ImagesTest extends TestCase { - public const TEST_STRING = '0123456789'; + use CmsTrait; - public Mage_Cms_Helper_Wysiwyg_Images $subject; + public Subject $subject; public function setUp(): void { @@ -68,7 +68,7 @@ public function testGetStorage(): void */ public function testIdEncode(): void { - $this->assertIsString($this->subject->idEncode(self::TEST_STRING)); + $this->assertIsString($this->subject->idEncode($this->getTestString())); } /** @@ -77,11 +77,11 @@ public function testIdEncode(): void */ public function testIdDecode(): void { - $this->assertIsString($this->subject->idDecode(self::TEST_STRING)); + $this->assertIsString($this->subject->idDecode($this->getTestString())); } /** - * @dataProvider provideGetShortFilenameData + * @dataProvider provideGetShortFilename * @group Mage_Cms * @group Mage_Cms_Helper */ @@ -89,18 +89,4 @@ public function testGetShortFilename(string $expectedResult, string $filename, i { $this->assertSame($expectedResult, $this->subject->getShortFilename($filename, $maxLength)); } - - public function provideGetShortFilenameData(): Generator - { - yield 'full length' => [ - '0123456789', - self::TEST_STRING, - 20, - ]; - yield 'truncated' => [ - '01234...', - self::TEST_STRING, - 5, - ]; - } } diff --git a/tests/unit/Mage/Cms/Model/PageTest.php b/tests/unit/Mage/Cms/Model/PageTest.php index c7eac7484a2..499b78164dc 100644 --- a/tests/unit/Mage/Cms/Model/PageTest.php +++ b/tests/unit/Mage/Cms/Model/PageTest.php @@ -18,13 +18,13 @@ namespace OpenMage\Tests\Unit\Mage\Cms\Model; use Mage; -use Mage_Cms_Model_Page; +use Mage_Cms_Model_Page as Subject; use Mage_Core_Model_Resource_Db_Collection_Abstract; use PHPUnit\Framework\TestCase; class PageTest extends TestCase { - public Mage_Cms_Model_Page $subject; + public Subject $subject; public function setUp(): void { @@ -38,8 +38,8 @@ public function setUp(): void */ public function testLoad(): void { - $this->assertInstanceOf(Mage_Cms_Model_Page::class, $this->subject->load(null)); - $this->assertInstanceOf(Mage_Cms_Model_Page::class, $this->subject->load(2)); + $this->assertInstanceOf(Subject::class, $this->subject->load(null)); + $this->assertInstanceOf(Subject::class, $this->subject->load(2)); } /** diff --git a/tests/unit/Mage/Cms/Model/Wysiwyg/ConfigTest.php b/tests/unit/Mage/Cms/Model/Wysiwyg/ConfigTest.php index d9a8f55b2b7..a9dd5c2f8ae 100644 --- a/tests/unit/Mage/Cms/Model/Wysiwyg/ConfigTest.php +++ b/tests/unit/Mage/Cms/Model/Wysiwyg/ConfigTest.php @@ -18,7 +18,7 @@ namespace OpenMage\Tests\Unit\Mage\Cms\Model\Wysiwyg; use Mage; -use Mage_Cms_Model_Wysiwyg_Config; +use Mage_Cms_Model_Wysiwyg_Config as Subject; use PHPUnit\Framework\TestCase; use Varien_Object; @@ -26,7 +26,7 @@ class ConfigTest extends TestCase { public const TEST_STRING = '0123456789'; - public Mage_Cms_Model_Wysiwyg_Config $subject; + public Subject $subject; public function setUp(): void { diff --git a/tests/unit/Mage/Cms/Model/Wysiwyg/Images/StorageTest.php b/tests/unit/Mage/Cms/Model/Wysiwyg/Images/StorageTest.php index 7316f8b8131..d665a4404ed 100644 --- a/tests/unit/Mage/Cms/Model/Wysiwyg/Images/StorageTest.php +++ b/tests/unit/Mage/Cms/Model/Wysiwyg/Images/StorageTest.php @@ -20,14 +20,12 @@ use Mage; use Mage_Adminhtml_Model_Session; use Mage_Cms_Helper_Wysiwyg_Images; -use Mage_Cms_Model_Wysiwyg_Images_Storage; +use Mage_Cms_Model_Wysiwyg_Images_Storage as Subject; use PHPUnit\Framework\TestCase; class StorageTest extends TestCase { - public const TEST_STRING = '0123456789'; - - public Mage_Cms_Model_Wysiwyg_Images_Storage $subject; + public Subject $subject; public function setUp(): void { diff --git a/tests/unit/Mage/Core/Helper/CookieTest.php b/tests/unit/Mage/Core/Helper/CookieTest.php index df3dfdf03d6..76612ec3c3a 100644 --- a/tests/unit/Mage/Core/Helper/CookieTest.php +++ b/tests/unit/Mage/Core/Helper/CookieTest.php @@ -18,12 +18,12 @@ namespace OpenMage\Tests\Unit\Mage\Core\Helper; use Mage; -use Mage_Core_Helper_Cookie; +use Mage_Core_Helper_Cookie as Subject; use PHPUnit\Framework\TestCase; class CookieTest extends TestCase { - public Mage_Core_Helper_Cookie $subject; + public Subject $subject; public function setUp(): void { diff --git a/tests/unit/Mage/Core/Helper/DataTest.php b/tests/unit/Mage/Core/Helper/DataTest.php index f6971a6dfef..c316cb22f56 100644 --- a/tests/unit/Mage/Core/Helper/DataTest.php +++ b/tests/unit/Mage/Core/Helper/DataTest.php @@ -19,18 +19,17 @@ use Generator; use Mage; -use Mage_Core_Helper_Data; +use Mage_Core_Helper_Data as Subject; use Mage_Core_Model_Encryption; use Mage_Core_Model_Locale; use PHPUnit\Framework\TestCase; use Varien_Crypt_Mcrypt; -use Varien_Date; class DataTest extends TestCase { public const TEST_STRING = '1234567890'; - public Mage_Core_Helper_Data $subject; + public Subject $subject; public function setUp(): void { diff --git a/tests/unit/Mage/Core/Helper/HintTest.php b/tests/unit/Mage/Core/Helper/HintTest.php index d22a496c76c..0113107aac4 100644 --- a/tests/unit/Mage/Core/Helper/HintTest.php +++ b/tests/unit/Mage/Core/Helper/HintTest.php @@ -18,14 +18,12 @@ namespace OpenMage\Tests\Unit\Mage\Core\Helper; use Mage; -use Mage_Core_Helper_Hint; +use Mage_Core_Helper_Hint as Subject; use PHPUnit\Framework\TestCase; class HintTest extends TestCase { - public const TEST_STRING = '1234567890'; - - public Mage_Core_Helper_Hint $subject; + public Subject $subject; public function setUp(): void { diff --git a/tests/unit/Mage/Core/Helper/JsTest.php b/tests/unit/Mage/Core/Helper/JsTest.php index 3b91670668c..843eb1cbbcd 100644 --- a/tests/unit/Mage/Core/Helper/JsTest.php +++ b/tests/unit/Mage/Core/Helper/JsTest.php @@ -18,14 +18,14 @@ namespace OpenMage\Tests\Unit\Mage\Core\Helper; use Mage; -use Mage_Core_Helper_Js; +use Mage_Core_Helper_Js as Subject; use PHPUnit\Framework\TestCase; class JsTest extends TestCase { public const TEST_URL = 'foo'; - public Mage_Core_Helper_Js $subject; + public Subject $subject; public function setUp(): void { diff --git a/tests/unit/Mage/Core/Helper/PurifierTest.php b/tests/unit/Mage/Core/Helper/PurifierTest.php index 52df239776e..83e7127d529 100644 --- a/tests/unit/Mage/Core/Helper/PurifierTest.php +++ b/tests/unit/Mage/Core/Helper/PurifierTest.php @@ -19,14 +19,12 @@ use Generator; use Mage; -use Mage_Core_Helper_Purifier; +use Mage_Core_Helper_Purifier as Subject; use PHPUnit\Framework\TestCase; class PurifierTest extends TestCase { - public const TEST_STRING = '1234567890'; - - public Mage_Core_Helper_Purifier $subject; + public Subject $subject; public function setUp(): void { diff --git a/tests/unit/Mage/Core/Helper/SecurityTest.php b/tests/unit/Mage/Core/Helper/SecurityTest.php index 4082e0c0fde..8e0771de454 100644 --- a/tests/unit/Mage/Core/Helper/SecurityTest.php +++ b/tests/unit/Mage/Core/Helper/SecurityTest.php @@ -22,7 +22,7 @@ use Mage_Core_Block_Abstract; use Mage_Core_Block_Template; use Mage_Core_Exception; -use Mage_Core_Helper_Security; +use Mage_Core_Helper_Security as Subject; use Mage_Page_Block_Html_Topmenu_Renderer; use PHPUnit\Framework\TestCase; @@ -30,7 +30,7 @@ class SecurityTest extends TestCase { - public Mage_Core_Helper_Security $subject; + public Subject $subject; public function setUp(): void { @@ -77,9 +77,7 @@ public function testValidateAgainstBlockMethodBlacklist( public function forbiddenBlockMethodsDataProvider(): Generator { - // phpcs:ignore Ecg.Classes.ObjectInstantiation.DirectInstantiation $topmenu = new Mage_Page_Block_Html_Topmenu_Renderer(); - // phpcs:ignore Ecg.Classes.ObjectInstantiation.DirectInstantiation $template = new Mage_Core_Block_Template(); yield [ $template, diff --git a/tests/unit/Mage/Core/Helper/StringTest.php b/tests/unit/Mage/Core/Helper/StringTest.php index 45b4aac2ab9..5d32349c83b 100644 --- a/tests/unit/Mage/Core/Helper/StringTest.php +++ b/tests/unit/Mage/Core/Helper/StringTest.php @@ -19,7 +19,7 @@ use Mage; use Mage_Core_Helper_Array; -use Mage_Core_Helper_String; +use Mage_Core_Helper_String as Subject; use PHPUnit\Framework\TestCase; class StringTest extends TestCase @@ -28,7 +28,7 @@ class StringTest extends TestCase public const TEST_STRING_JSON = '{"name":"John", "age":30, "car":null}'; - public Mage_Core_Helper_String $subject; + public Subject $subject; public function setUp(): void { diff --git a/tests/unit/Mage/Core/Helper/UnserializeArrayTest.php b/tests/unit/Mage/Core/Helper/UnserializeArrayTest.php index 8803897b14a..ef5e54deab0 100644 --- a/tests/unit/Mage/Core/Helper/UnserializeArrayTest.php +++ b/tests/unit/Mage/Core/Helper/UnserializeArrayTest.php @@ -20,13 +20,12 @@ use Exception; use Generator; use Mage; -use Mage_Core_Helper_UnserializeArray; +use Mage_Core_Helper_UnserializeArray as Subject; use PHPUnit\Framework\TestCase; -use Varien_Object; class UnserializeArrayTest extends TestCase { - public Mage_Core_Helper_UnserializeArray $subject; + public Subject $subject; public function setUp(): void { diff --git a/tests/unit/Mage/Core/Helper/UrlTest.php b/tests/unit/Mage/Core/Helper/UrlTest.php index 7d5c1fb0f13..311e852e381 100644 --- a/tests/unit/Mage/Core/Helper/UrlTest.php +++ b/tests/unit/Mage/Core/Helper/UrlTest.php @@ -19,7 +19,7 @@ use Generator; use Mage; -use Mage_Core_Helper_Url; +use Mage_Core_Helper_Url as Subject; use PHPUnit\Framework\TestCase; class UrlTest extends TestCase @@ -38,7 +38,7 @@ class UrlTest extends TestCase public const TEST_URL_PUNY = 'https://XN--example.com?foo=bar&BOO=baz'; - public Mage_Core_Helper_Url $subject; + public Subject $subject; public function setUp(): void { diff --git a/tests/unit/Mage/Core/Model/AppTest.php b/tests/unit/Mage/Core/Model/AppTest.php index 728392a18f4..c88ef46bbee 100644 --- a/tests/unit/Mage/Core/Model/AppTest.php +++ b/tests/unit/Mage/Core/Model/AppTest.php @@ -7,16 +7,19 @@ use Generator; use Mage; use Mage_Core_Exception; -use Mage_Core_Model_App; +use Mage_Core_Model_App as Subject; use Mage_Core_Model_Store; use Mage_Core_Model_Store_Exception; use Mage_Core_Model_Store_Group; use Mage_Core_Model_Website; +use OpenMage\Tests\Unit\Traits\DataProvider\Mage\Core\CoreTrait; use PHPUnit\Framework\TestCase; class AppTest extends TestCase { - public Mage_Core_Model_App $subject; + use CoreTrait; + + public Subject $subject; public function setUp(): void { @@ -24,6 +27,7 @@ public function setUp(): void } /** + * @dataProvider provideGetStoreConfig * @dataProvider provideGetStore * @group Mage_Core * @group Mage_Core_Model @@ -42,31 +46,13 @@ public function testGetStore($id): void public function provideGetStore(): Generator { - yield 'null' => [ - null, - ]; - yield 'true' => [ - true, - ]; - yield 'false' => [ - false, - ]; - yield 'int valid' => [ - 1, - ]; - yield 'int invalid (exception)' => [ - 999, - ]; - yield 'string' => [ - '1', - ]; yield 'Mage_Core_Model_Store' => [ - // phpcs:ignore Ecg.Classes.ObjectInstantiation.DirectInstantiation new Mage_Core_Model_Store(), ]; } /** + * @dataProvider provideGetStoreConfig * @dataProvider provideGetWebsite * @group Mage_Core * @group Mage_Core_Model @@ -85,31 +71,13 @@ public function testGetWebsite($id): void public function provideGetWebsite(): Generator { - yield 'null' => [ - null, - ]; - yield 'true' => [ - true, - ]; - yield 'false' => [ - false, - ]; - yield 'int valid' => [ - 1, - ]; - yield 'int invalid (exception)' => [ - 999, - ]; - yield 'string' => [ - '1', - ]; yield 'Mage_Core_Model_Website' => [ - // phpcs:ignore Ecg.Classes.ObjectInstantiation.DirectInstantiation new Mage_Core_Model_Website(), ]; } /** + * @dataProvider provideGetStoreConfig * @dataProvider provideGetGroup * @group Mage_Core * @group Mage_Core_Model @@ -128,26 +96,7 @@ public function testGetGroup($id): void public function provideGetGroup(): Generator { - yield 'null' => [ - null, - ]; - yield 'true' => [ - true, - ]; - yield 'false' => [ - false, - ]; - yield 'int valid' => [ - 1, - ]; - yield 'int invalid (exception)' => [ - 999, - ]; - yield 'string' => [ - '1', - ]; yield 'Mage_Core_Model_Store_Group' => [ - // phpcs:ignore Ecg.Classes.ObjectInstantiation.DirectInstantiation new Mage_Core_Model_Store_Group(), ]; } diff --git a/tests/unit/Mage/Core/Model/ConfigTest.php b/tests/unit/Mage/Core/Model/ConfigTest.php index b34c1f983bf..28e24abdeb5 100644 --- a/tests/unit/Mage/Core/Model/ConfigTest.php +++ b/tests/unit/Mage/Core/Model/ConfigTest.php @@ -18,12 +18,12 @@ namespace OpenMage\Tests\Unit\Mage\Core\Model; use Mage; -use Mage_Core_Model_Config; +use Mage_Core_Model_Config as Subject; use PHPUnit\Framework\TestCase; class ConfigTest extends TestCase { - public Mage_Core_Model_Config $subject; + public Subject $subject; public function setUp(): void { diff --git a/tests/unit/Mage/Core/Model/LocaleTest.php b/tests/unit/Mage/Core/Model/LocaleTest.php index 0275f145e72..32f41b52a46 100644 --- a/tests/unit/Mage/Core/Model/LocaleTest.php +++ b/tests/unit/Mage/Core/Model/LocaleTest.php @@ -17,14 +17,16 @@ namespace OpenMage\Tests\Unit\Mage\Core\Model; -use Generator; use Mage; -use Mage_Core_Model_Locale; +use Mage_Core_Model_Locale as Subject; +use OpenMage\Tests\Unit\Traits\DataProvider\Mage\Catalog\Model\LocaleTrait; use PHPUnit\Framework\TestCase; class LocaleTest extends TestCase { - public Mage_Core_Model_Locale $subject; + use LocaleTrait; + + public Subject $subject; public function setUp(): void { @@ -42,32 +44,4 @@ public function testGetNumber(?float $expectedResult, $value): void { $this->assertSame($expectedResult, $this->subject->getNumber($value)); } - - public function provideGetNumberData(): Generator - { - yield 'array' => [ - 1.0, - [1], - ]; - yield 'int' => [ - 1.0, - 1, - ]; - yield 'string' => [ - 1.0, - '1', - ]; - yield 'string comma' => [ - 1.0, - '1,0', - ]; - yield 'string dot' => [ - 1.0, - '1.0', - ]; - yield 'null' => [ - null, - null, - ]; - } } diff --git a/tests/unit/Mage/Core/Model/Security/HtmlEscapedStringTest.php b/tests/unit/Mage/Core/Model/Security/HtmlEscapedStringTest.php index 2b540c5a216..f3c4d7162ef 100644 --- a/tests/unit/Mage/Core/Model/Security/HtmlEscapedStringTest.php +++ b/tests/unit/Mage/Core/Model/Security/HtmlEscapedStringTest.php @@ -18,14 +18,14 @@ namespace OpenMage\Tests\Unit\Mage\Core\Model\Security; use Generator; -use Mage_Core_Model_Security_HtmlEscapedString; +use Mage_Core_Model_Security_HtmlEscapedString as Subject; use PHPUnit\Framework\TestCase; class HtmlEscapedStringTest extends TestCase { public const TEST_STRING = 'This is a bold string'; - public Mage_Core_Model_Security_HtmlEscapedString $subject; + public Subject $subject; /** * @dataProvider provideHtmlEscapedStringAsStringData @@ -35,7 +35,7 @@ class HtmlEscapedStringTest extends TestCase */ public function testToSting(string $expectedResult, string $string, ?array $allowedTags): void { - $this->subject = new Mage_Core_Model_Security_HtmlEscapedString($string, $allowedTags); + $this->subject = new Subject($string, $allowedTags); $this->assertSame($expectedResult, $this->subject->__toString()); } @@ -47,7 +47,7 @@ public function testToSting(string $expectedResult, string $string, ?array $allo */ public function testGetUnescapedValue(string $expectedResult, string $string, ?array $allowedTags): void { - $this->subject = new Mage_Core_Model_Security_HtmlEscapedString($string, $allowedTags); + $this->subject = new Subject($string, $allowedTags); $this->assertSame($expectedResult, $this->subject->getUnescapedValue()); } diff --git a/tests/unit/Mage/Core/Model/StoreTest.php b/tests/unit/Mage/Core/Model/StoreTest.php index 371ca160d4f..fdbbc00f77a 100644 --- a/tests/unit/Mage/Core/Model/StoreTest.php +++ b/tests/unit/Mage/Core/Model/StoreTest.php @@ -17,14 +17,16 @@ namespace OpenMage\Tests\Unit\Mage\Core\Model; -use Generator; use Mage; -use Mage_Core_Model_Store; +use Mage_Core_Model_Store as Subject; +use OpenMage\Tests\Unit\Traits\DataProvider\Mage\Core\CoreTrait; use PHPUnit\Framework\TestCase; class StoreTest extends TestCase { - public Mage_Core_Model_Store $subject; + use CoreTrait; + + public Subject $subject; public function setUp(): void { @@ -34,27 +36,16 @@ public function setUp(): void /** * @covers Mage_Core_Model_Store::getId() - * @dataProvider provideGetId + * @dataProvider provideGetStoreId + * @param string|int|null $withStore * @group Mage_Core * @group Mage_Core_Model */ - public function testGetId(?int $expectedResult, ?string $withStore): void + public function testGetId(?int $expectedResult, $withStore): void { if ($withStore) { $this->subject->setData('store_id', $withStore); } $this->assertSame($expectedResult, $this->subject->getId()); } - - public function provideGetId(): Generator - { - yield 'store id' => [ - 1, - '1', - ]; - yield 'no store id' => [ - null, - null, - ]; - } } diff --git a/tests/unit/Mage/Core/Model/UrlTest.php b/tests/unit/Mage/Core/Model/UrlTest.php index 86841586f7b..e7ef38908fe 100644 --- a/tests/unit/Mage/Core/Model/UrlTest.php +++ b/tests/unit/Mage/Core/Model/UrlTest.php @@ -18,12 +18,12 @@ namespace OpenMage\Tests\Unit\Mage\Core\Model; use Mage; -use Mage_Core_Model_Url; +use Mage_Core_Model_Url as Subject; use PHPUnit\Framework\TestCase; class UrlTest extends TestCase { - public Mage_Core_Model_Url $subject; + public Subject $subject; public function setUp(): void { diff --git a/tests/unit/Mage/Core/Model/VariableTest.php b/tests/unit/Mage/Core/Model/VariableTest.php index d27e4608d9e..9199a9adca0 100644 --- a/tests/unit/Mage/Core/Model/VariableTest.php +++ b/tests/unit/Mage/Core/Model/VariableTest.php @@ -18,12 +18,12 @@ namespace OpenMage\Tests\Unit\Mage\Core\Model; use Mage; -use Mage_Core_Model_Variable; +use Mage_Core_Model_Variable as Subject; use PHPUnit\Framework\TestCase; class VariableTest extends TestCase { - public Mage_Core_Model_Variable $subject; + public Subject $subject; public function setUp(): void { diff --git a/tests/unit/Mage/Core/Model/WebsiteTest.php b/tests/unit/Mage/Core/Model/WebsiteTest.php index 401db8568b5..569a7ee67a2 100644 --- a/tests/unit/Mage/Core/Model/WebsiteTest.php +++ b/tests/unit/Mage/Core/Model/WebsiteTest.php @@ -20,14 +20,14 @@ use Mage; use Mage_Core_Model_Resource_Store_Collection; use Mage_Core_Model_Resource_Store_Group_Collection; -use Mage_Core_Model_Website; +use Mage_Core_Model_Website as Subject; use Mage_Directory_Model_Currency; use PHPUnit\Framework\TestCase; use Varien_Db_Select; class WebsiteTest extends TestCase { - public Mage_Core_Model_Website $subject; + public Subject $subject; public function setUp(): void { @@ -41,8 +41,8 @@ public function setUp(): void */ public function testLoad(): void { - $this->assertInstanceOf(Mage_Core_Model_Website::class, $this->subject->load(1)); - $this->assertInstanceOf(Mage_Core_Model_Website::class, $this->subject->load('default')); + $this->assertInstanceOf(Subject::class, $this->subject->load(1)); + $this->assertInstanceOf(Subject::class, $this->subject->load('default')); } /** @@ -51,8 +51,8 @@ public function testLoad(): void */ public function testLoadConfig(): void { - $this->assertInstanceOf(Mage_Core_Model_Website::class, $this->subject->loadConfig('1')); - $this->assertInstanceOf(Mage_Core_Model_Website::class, $this->subject->loadConfig('default')); + $this->assertInstanceOf(Subject::class, $this->subject->loadConfig('1')); + $this->assertInstanceOf(Subject::class, $this->subject->loadConfig('default')); } /** diff --git a/tests/unit/Mage/Customer/Model/Convert/Adapter/CustomerTest.php b/tests/unit/Mage/Customer/Model/Convert/Adapter/CustomerTest.php index c81f5d7deb8..4f37d1ffd55 100644 --- a/tests/unit/Mage/Customer/Model/Convert/Adapter/CustomerTest.php +++ b/tests/unit/Mage/Customer/Model/Convert/Adapter/CustomerTest.php @@ -18,13 +18,13 @@ namespace OpenMage\Tests\Unit\Mage\Customer\Model\Convert\Adapter; use Mage; -use Mage_Customer_Model_Convert_Adapter_Customer; +use Mage_Customer_Model_Convert_Adapter_Customer as Subject; use PHPUnit\Framework\TestCase; use Throwable; class CustomerTest extends TestCase { - public Mage_Customer_Model_Convert_Adapter_Customer $subject; + public Subject $subject; public function setUp(): void { @@ -143,6 +143,6 @@ public function testSaveRow(): void 'firstname' => 'John', 'lastname' => 'Doe', ]; - $this->assertInstanceOf(Mage_Customer_Model_Convert_Adapter_Customer::class, $this->subject->saveRow($data)); + $this->assertInstanceOf(Subject::class, $this->subject->saveRow($data)); } } diff --git a/tests/unit/Mage/Customer/Model/CustomerTest.php b/tests/unit/Mage/Customer/Model/CustomerTest.php index e6d4cb953eb..28d25c2a7a1 100644 --- a/tests/unit/Mage/Customer/Model/CustomerTest.php +++ b/tests/unit/Mage/Customer/Model/CustomerTest.php @@ -18,13 +18,12 @@ namespace OpenMage\Tests\Unit\Mage\Customer\Model; use Mage; -use Mage_Customer_Model_Customer; +use Mage_Customer_Model_Customer as Subject; use PHPUnit\Framework\TestCase; -use Throwable; class CustomerTest extends TestCase { - public Mage_Customer_Model_Customer $subject; + public Subject $subject; public function setUp(): void { diff --git a/tests/unit/Mage/Directory/Block/DataTest.php b/tests/unit/Mage/Directory/Block/DataTest.php index daed12f4dfa..efa0f9999b5 100644 --- a/tests/unit/Mage/Directory/Block/DataTest.php +++ b/tests/unit/Mage/Directory/Block/DataTest.php @@ -17,23 +17,20 @@ namespace OpenMage\Tests\Unit\Mage\Directory\Block; -use Generator; use Mage; -use Mage_Directory_Block_Data; +use Mage_Directory_Block_Data as Subject; use Mage_Directory_Model_Resource_Country_Collection; use Mage_Directory_Model_Resource_Region_Collection; use PHPUnit\Framework\TestCase; class DataTest extends TestCase { - public const TEST_STRING = '1234567890'; - - public Mage_Directory_Block_Data $subject; + public Subject $subject; public function setUp(): void { Mage::app(); - $this->subject = new Mage_Directory_Block_Data(); + $this->subject = new Subject(); } /** diff --git a/tests/unit/Mage/Directory/Helper/DataTest.php b/tests/unit/Mage/Directory/Helper/DataTest.php index 40e082c39d2..e638168617e 100644 --- a/tests/unit/Mage/Directory/Helper/DataTest.php +++ b/tests/unit/Mage/Directory/Helper/DataTest.php @@ -9,7 +9,7 @@ * * @category OpenMage * @package OpenMage_Tests - * @copyright Copyright (c) 2024 The OpenMage Contributors (https://www.openmage.org) + * @copyright Copyright (c) 2024-2025 The OpenMage Contributors (https://www.openmage.org) * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -19,16 +19,14 @@ use Generator; use Mage; -use Mage_Directory_Helper_Data; +use Mage_Directory_Helper_Data as Subject; use Mage_Directory_Model_Resource_Country_Collection; use Mage_Directory_Model_Resource_Region_Collection; use PHPUnit\Framework\TestCase; class DataTest extends TestCase { - public const TEST_STRING = '1234567890'; - - public Mage_Directory_Helper_Data $subject; + public Subject $subject; public function setUp(): void { @@ -121,7 +119,7 @@ public function testIsZipCodeOptional(): void public function testGetCountriesWithStatesRequired($expectedResult, bool $asJson): void { $result = $this->subject->getCountriesWithStatesRequired($asJson); - if (defined('USES_SAMPLEDATA') && USES_SAMPLEDATA === true) { + if (defined('DATA_MAY_CHANGED')) { $asJson ? $this->assertIsString($result) : $this->assertIsArray($result); } else { $this->assertSame($expectedResult, $result); diff --git a/tests/unit/Mage/Downloadable/Helper/FileTest.php b/tests/unit/Mage/Downloadable/Helper/FileTest.php index e636c7dcdbf..1ae59909153 100644 --- a/tests/unit/Mage/Downloadable/Helper/FileTest.php +++ b/tests/unit/Mage/Downloadable/Helper/FileTest.php @@ -9,7 +9,7 @@ * * @category OpenMage * @package OpenMage_Tests - * @copyright Copyright (c) 2024 The OpenMage Contributors (https://www.openmage.org) + * @copyright Copyright (c) 2024-2025 The OpenMage Contributors (https://www.openmage.org) * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -17,14 +17,16 @@ namespace OpenMage\Tests\Unit\Mage\Downloadable\Helper; -use Generator; use Mage; -use Mage_Downloadable_Helper_File; +use Mage_Downloadable_Helper_File as Subject; +use OpenMage\Tests\Unit\Traits\DataProvider\Mage\Downloadable\DownloadableTrait; use PHPUnit\Framework\TestCase; class FileTest extends TestCase { - public Mage_Downloadable_Helper_File $subject; + use DownloadableTrait; + + public Subject $subject; public function setUp(): void { @@ -43,33 +45,4 @@ public function testGetFilePath(string $expectedResult, string $path, ?string $f $result = $this->subject->getFilePath($path, $file); $this->assertSame($expectedResult, $result); } - - public function provideGetFilePathData(): Generator - { - yield 'strings path and strings file' => [ - 'path' . DS . 'file', - 'path', - 'file', - ]; - yield 'strings path and strings file with slash' => [ - 'path' . DS . 'file', - 'path', - '/file', - ]; - yield 'string path and null file' => [ - 'path' . DS, - 'path', - null, - ]; - yield 'string path and empty file' => [ - 'path' . DS, - 'path', - '', - ]; - yield 'strings path and strings file named 0' => [ - 'path' . DS . '0', - 'path', - '0', - ]; - } } diff --git a/tests/unit/Mage/Index/Model/ProcessTest.php b/tests/unit/Mage/Index/Model/ProcessTest.php new file mode 100644 index 00000000000..298200f3ca5 --- /dev/null +++ b/tests/unit/Mage/Index/Model/ProcessTest.php @@ -0,0 +1,60 @@ +subject = Mage::getModel('index/process'); + } + + /** + * + * @group Mage_Index + * @group Mage_Index_Model + */ + // public function testReindexEverything(): void + // { + // $this->subject->setIndexerCode('html'); + // $this->assertInstanceOf(Mage_Index_Model_Process::class, $this->subject->reindexEverything()); + // } + // public function testDisableIndexerKeys(): void + // { + // $this->subject->setIndexerCode('html'); + // $this->assertInstanceOf(Mage_Index_Model_Process::class, $this->subject->disableIndexerKeys()); + // } + // public function testEnableIndexerKeys(): void + // { + // $this->subject->setIndexerCode('html'); + // $this->assertInstanceOf(Mage_Index_Model_Process::class, $this->subject->enableIndexerKeys()); + // } + public function testGetUnprocessedEventsCollection(): void + { + $this->subject->setIndexerCode('html'); + $this->assertInstanceOf(Mage_Index_Model_Resource_Event_Collection::class, $this->subject->getUnprocessedEventsCollection()); + } +} diff --git a/tests/unit/Mage/Log/Helper/DataTest.php b/tests/unit/Mage/Log/Helper/DataTest.php index e942649ed4d..0787cd757c1 100644 --- a/tests/unit/Mage/Log/Helper/DataTest.php +++ b/tests/unit/Mage/Log/Helper/DataTest.php @@ -19,12 +19,12 @@ use Generator; use Mage; -use Mage_Log_Helper_Data; +use Mage_Log_Helper_Data as Subject; use PHPUnit\Framework\TestCase; class DataTest extends TestCase { - public Mage_Log_Helper_Data $subject; + public Subject $subject; public function setUp(): void { diff --git a/tests/unit/Mage/Log/Model/AggregationTest.php b/tests/unit/Mage/Log/Model/AggregationTest.php index 129d0f39c1a..238233acff6 100644 --- a/tests/unit/Mage/Log/Model/AggregationTest.php +++ b/tests/unit/Mage/Log/Model/AggregationTest.php @@ -18,12 +18,12 @@ namespace OpenMage\Tests\Unit\Mage\Log\Model; use Mage; -use Mage_Log_Model_Aggregation; +use Mage_Log_Model_Aggregation as Subject; use PHPUnit\Framework\TestCase; class AggregationTest extends TestCase { - public Mage_Log_Model_Aggregation $subject; + public Subject $subject; public function setUp(): void { diff --git a/tests/unit/Mage/Log/Model/CronTest.php b/tests/unit/Mage/Log/Model/CronTest.php index e32f95bd266..fa8433f37fd 100644 --- a/tests/unit/Mage/Log/Model/CronTest.php +++ b/tests/unit/Mage/Log/Model/CronTest.php @@ -18,12 +18,12 @@ namespace OpenMage\Tests\Unit\Mage\Log\Model; use Mage; -use Mage_Log_Model_Cron; +use Mage_Log_Model_Cron as Subject; use PHPUnit\Framework\TestCase; class CronTest extends TestCase { - public Mage_Log_Model_Cron $subject; + public Subject $subject; public function setUp(): void { @@ -37,6 +37,6 @@ public function setUp(): void */ public function testLogClean(): void { - $this->assertInstanceOf(Mage_Log_Model_Cron::class, $this->subject->logClean()); + $this->assertInstanceOf(Subject::class, $this->subject->logClean()); } } diff --git a/tests/unit/Mage/Log/Model/CustomerTest.php b/tests/unit/Mage/Log/Model/CustomerTest.php index f029c6c759b..ffd035ef148 100644 --- a/tests/unit/Mage/Log/Model/CustomerTest.php +++ b/tests/unit/Mage/Log/Model/CustomerTest.php @@ -18,12 +18,12 @@ namespace OpenMage\Tests\Unit\Mage\Log\Model; use Mage; -use Mage_Log_Model_Customer; +use Mage_Log_Model_Customer as Subject; use PHPUnit\Framework\TestCase; class CustomerTest extends TestCase { - public Mage_Log_Model_Customer $subject; + public Subject $subject; public function setUp(): void { @@ -37,7 +37,7 @@ public function setUp(): void */ public function testGetLoginAtTimestamp(): void { - $mock = $this->getMockBuilder(Mage_Log_Model_Customer::class) + $mock = $this->getMockBuilder(Subject::class) ->setMethods(['getLoginAt']) ->getMock(); diff --git a/tests/unit/Mage/Log/Model/LogTest.php b/tests/unit/Mage/Log/Model/LogTest.php index d8581165a59..0cb17c2820a 100644 --- a/tests/unit/Mage/Log/Model/LogTest.php +++ b/tests/unit/Mage/Log/Model/LogTest.php @@ -18,12 +18,12 @@ namespace OpenMage\Tests\Unit\Mage\Log\Model; use Mage; -use Mage_Log_Model_Log; +use Mage_Log_Model_Log as Subject; use PHPUnit\Framework\TestCase; class LogTest extends TestCase { - public Mage_Log_Model_Log $subject; + public Subject $subject; public function setUp(): void { @@ -37,6 +37,6 @@ public function setUp(): void */ public function testClean(): void { - $this->assertInstanceOf(Mage_Log_Model_Log::class, $this->subject->clean()); + $this->assertInstanceOf(Subject::class, $this->subject->clean()); } } diff --git a/tests/unit/Mage/Log/Model/VisitorTest.php b/tests/unit/Mage/Log/Model/VisitorTest.php index 675d0e995a9..528d1f2d543 100644 --- a/tests/unit/Mage/Log/Model/VisitorTest.php +++ b/tests/unit/Mage/Log/Model/VisitorTest.php @@ -18,12 +18,12 @@ namespace OpenMage\Tests\Unit\Mage\Log\Model; use Mage; -use Mage_Log_Model_Visitor; +use Mage_Log_Model_Visitor as Subject; use PHPUnit\Framework\TestCase; class VisitorTest extends TestCase { - public Mage_Log_Model_Visitor $subject; + public Subject $subject; public function setUp(): void { @@ -39,7 +39,7 @@ public function setUp(): void */ public function testInitServerData(): void { - $this->assertInstanceOf(Mage_Log_Model_Visitor::class, $this->subject->initServerData()); + $this->assertInstanceOf(Subject::class, $this->subject->initServerData()); } /** diff --git a/tests/unit/Mage/Page/Block/Html/HeadTest.php b/tests/unit/Mage/Page/Block/Html/HeadTest.php index 6e9a70f8c1c..96d1cfedba5 100644 --- a/tests/unit/Mage/Page/Block/Html/HeadTest.php +++ b/tests/unit/Mage/Page/Block/Html/HeadTest.php @@ -18,18 +18,17 @@ namespace OpenMage\Tests\Unit\Mage\Page\Block\Html; use Mage; -use Mage_Page_Block_Html_Head; +use Mage_Page_Block_Html_Head as Subject; use PHPUnit\Framework\TestCase; class HeadTest extends TestCase { - public Mage_Page_Block_Html_Head $subject; + public Subject $subject; public function setUp(): void { Mage::app(); - // phpcs:ignore Ecg.Classes.ObjectInstantiation.DirectInstantiation - $this->subject = new Mage_Page_Block_Html_Head(); + $this->subject = new Subject(); } /** @@ -38,7 +37,7 @@ public function setUp(): void */ public function testAddCss(): void { - $this->assertInstanceOf(Mage_Page_Block_Html_Head::class, $this->subject->addCss('test')); + $this->assertInstanceOf(Subject::class, $this->subject->addCss('test')); } /** @@ -47,7 +46,7 @@ public function testAddCss(): void */ public function testAddJs(): void { - $this->assertInstanceOf(Mage_Page_Block_Html_Head::class, $this->subject->addJs('test')); + $this->assertInstanceOf(Subject::class, $this->subject->addJs('test')); } /** @@ -56,7 +55,7 @@ public function testAddJs(): void */ public function testAddCssIe(): void { - $this->assertInstanceOf(Mage_Page_Block_Html_Head::class, $this->subject->addCssIe('test')); + $this->assertInstanceOf(Subject::class, $this->subject->addCssIe('test')); } /** @@ -65,7 +64,7 @@ public function testAddCssIe(): void */ public function testAddJsIe(): void { - $this->assertInstanceOf(Mage_Page_Block_Html_Head::class, $this->subject->addJsIe('test')); + $this->assertInstanceOf(Subject::class, $this->subject->addJsIe('test')); } /** @@ -74,6 +73,6 @@ public function testAddJsIe(): void */ public function testAddLinkRel(): void { - $this->assertInstanceOf(Mage_Page_Block_Html_Head::class, $this->subject->addLinkRel('test', 'ref')); + $this->assertInstanceOf(Subject::class, $this->subject->addLinkRel('test', 'ref')); } } diff --git a/tests/unit/Mage/Page/Block/Html/HeaderTest.php b/tests/unit/Mage/Page/Block/Html/HeaderTest.php index 4c7ec711c38..06c0fcae93a 100644 --- a/tests/unit/Mage/Page/Block/Html/HeaderTest.php +++ b/tests/unit/Mage/Page/Block/Html/HeaderTest.php @@ -19,18 +19,17 @@ use Mage; use Mage_Core_Model_Security_HtmlEscapedString; -use Mage_Page_Block_Html_Header; +use Mage_Page_Block_Html_Header as Subject; use PHPUnit\Framework\TestCase; class HeaderTest extends TestCase { - public Mage_Page_Block_Html_Header $subject; + public Subject $subject; public function setUp(): void { Mage::app(); - // phpcs:ignore Ecg.Classes.ObjectInstantiation.DirectInstantiation - $this->subject = new Mage_Page_Block_Html_Header(); + $this->subject = new Subject(); } /** @@ -48,7 +47,7 @@ public function setUp(): void */ public function testSetLogo(): void { - $this->assertInstanceOf(Mage_Page_Block_Html_Header::class, $this->subject->setLogo('src', 'alt')); + $this->assertInstanceOf(Subject::class, $this->subject->setLogo('src', 'alt')); } /** diff --git a/tests/unit/Mage/Page/Block/HtmlTest.php b/tests/unit/Mage/Page/Block/HtmlTest.php index 677c0626fa1..e3ea305fd4e 100644 --- a/tests/unit/Mage/Page/Block/HtmlTest.php +++ b/tests/unit/Mage/Page/Block/HtmlTest.php @@ -18,18 +18,17 @@ namespace OpenMage\Tests\Unit\Mage\Page\Block; use Mage; -use Mage_Page_Block_Html; +use Mage_Page_Block_Html as Subject; use PHPUnit\Framework\TestCase; class HtmlTest extends TestCase { - public Mage_Page_Block_Html $subject; + public Subject $subject; public function setUp(): void { Mage::app(); - // phpcs:ignore Ecg.Classes.ObjectInstantiation.DirectInstantiation - $this->subject = new Mage_Page_Block_Html(); + $this->subject = new Subject(); } /** diff --git a/tests/unit/Mage/Page/Block/RedirectTest.php b/tests/unit/Mage/Page/Block/RedirectTest.php index 9e71dbbf0a4..474121bbda1 100644 --- a/tests/unit/Mage/Page/Block/RedirectTest.php +++ b/tests/unit/Mage/Page/Block/RedirectTest.php @@ -18,18 +18,17 @@ namespace OpenMage\Tests\Unit\Mage\Page\Block; use Mage; -use Mage_Page_Block_Redirect; +use Mage_Page_Block_Redirect as Subject; use PHPUnit\Framework\TestCase; class RedirectTest extends TestCase { - public Mage_Page_Block_Redirect $subject; + public Subject $subject; public function setUp(): void { Mage::app(); - // phpcs:ignore Ecg.Classes.ObjectInstantiation.DirectInstantiation - $this->subject = new Mage_Page_Block_Redirect(); + $this->subject = new Subject(); } /** diff --git a/tests/unit/Mage/Page/Block/SwitchTest.php b/tests/unit/Mage/Page/Block/SwitchTest.php index e11becdaacd..37c271d5acb 100644 --- a/tests/unit/Mage/Page/Block/SwitchTest.php +++ b/tests/unit/Mage/Page/Block/SwitchTest.php @@ -18,18 +18,17 @@ namespace OpenMage\Tests\Unit\Mage\Page\Block; use Mage; -use Mage_Page_Block_Switch; +use Mage_Page_Block_Switch as Subject; use PHPUnit\Framework\TestCase; class SwitchTest extends TestCase { - public Mage_Page_Block_Switch $subject; + public Subject $subject; public function setUp(): void { Mage::app(); - // phpcs:ignore Ecg.Classes.ObjectInstantiation.DirectInstantiation - $this->subject = new Mage_Page_Block_Switch(); + $this->subject = new Subject(); } /** diff --git a/tests/unit/Mage/Page/Helper/LayoutTest.php b/tests/unit/Mage/Page/Helper/LayoutTest.php index d9b5ede225a..454d39b2b10 100644 --- a/tests/unit/Mage/Page/Helper/LayoutTest.php +++ b/tests/unit/Mage/Page/Helper/LayoutTest.php @@ -18,12 +18,12 @@ namespace OpenMage\Tests\Unit\Mage\Page\Helper; use Mage; -use Mage_Page_Helper_Layout; +use Mage_Page_Helper_Layout as Subject; use PHPUnit\Framework\TestCase; class LayoutTest extends TestCase { - public Mage_Page_Helper_Layout $subject; + public Subject $subject; public function setUp(): void { diff --git a/tests/unit/Mage/Page/Model/ConfigTest.php b/tests/unit/Mage/Page/Model/ConfigTest.php index 26f9a1ebb14..3405e1fd507 100644 --- a/tests/unit/Mage/Page/Model/ConfigTest.php +++ b/tests/unit/Mage/Page/Model/ConfigTest.php @@ -18,12 +18,12 @@ namespace OpenMage\Tests\Unit\Mage\Page\Model; use Mage; -use Mage_Page_Model_Config; +use Mage_Page_Model_Config as Subject; use PHPUnit\Framework\TestCase; class ConfigTest extends TestCase { - public Mage_Page_Model_Config $subject; + public Subject $subject; public function setUp(): void { diff --git a/tests/unit/Mage/Page/Model/Source/LayoutTest.php b/tests/unit/Mage/Page/Model/Source/LayoutTest.php index 6fd2b8a58a3..cb244aae8e0 100644 --- a/tests/unit/Mage/Page/Model/Source/LayoutTest.php +++ b/tests/unit/Mage/Page/Model/Source/LayoutTest.php @@ -18,12 +18,12 @@ namespace OpenMage\Tests\Unit\Mage\Page\Model\Source; use Mage; -use Mage_Page_Model_Source_Layout; +use Mage_Page_Model_Source_Layout as Subject; use PHPUnit\Framework\TestCase; class LayoutTest extends TestCase { - public Mage_Page_Model_Source_Layout $subject; + public Subject $subject; public function setUp(): void { diff --git a/tests/unit/Mage/Reports/Helper/DataTest.php b/tests/unit/Mage/Reports/Helper/DataTest.php new file mode 100644 index 00000000000..c3f43af7ce5 --- /dev/null +++ b/tests/unit/Mage/Reports/Helper/DataTest.php @@ -0,0 +1,81 @@ +subject = Mage::helper('reports/data'); + } + + /** + * @covers Mage_Core_Helper_Abstract::isModuleEnabled() + * @group Mage_Reports + * @group Mage_Reports_Helper + */ + public function testIsModuleEnabled(): void + { + $this->assertTrue($this->subject->isModuleEnabled()); + } + + /** + * @covers Mage_Reports_Helper_Data::isReportsEnabled() + * @group Mage_Reports + * @group Mage_Reports_Helper + */ + public function testIsReportsEnabled(): void + { + $this->assertTrue($this->subject->isReportsEnabled()); + } + + /** + * @covers Mage_Reports_Helper_Data::getIntervals() + * @dataProvider provideReportsDateIntervals + * @group Mage_Reports + * @group Mage_Reports_Helper + */ + public function testGetIntervals($expectedResult, $from, $to, $period): void + { + $this->assertCount($expectedResult, $this->subject->getIntervals($from, $to, $period)); + } + + /** + * @covers Mage_Reports_Helper_Data::prepareIntervalsCollection() + * @dataProvider provideReportsDateIntervals + * @doesNotPerformAssertions + * @group Mage_Reports + * @group Mage_Reports_Helper + */ + public function testPrepareIntervalsCollection($expectedResult, $from, $to, $period): void + { + $collection = new Varien_Data_Collection(); + $this->subject->prepareIntervalsCollection($collection, $from, $to, $period); + } +} diff --git a/tests/unit/Mage/Reports/Model/Resource/Report/CollectionTest.php b/tests/unit/Mage/Reports/Model/Resource/Report/CollectionTest.php new file mode 100644 index 00000000000..90627e494a9 --- /dev/null +++ b/tests/unit/Mage/Reports/Model/Resource/Report/CollectionTest.php @@ -0,0 +1,169 @@ +subject = Mage::getModel('reports/resource_report_collection'); + } + + /** + * @covers Mage_Reports_Model_Resource_Report_Collection::setPeriod() + * @group Mage_Reports + * @group Mage_Reports_Model + */ + public function testSetPeriod(): void + { + $this->assertInstanceOf(Subject::class, $this->subject->setPeriod(1)); + } + + /** + * @covers Mage_Reports_Model_Resource_Report_Collection::setInterval() + * @group Mage_Reports + * @group Mage_Reports_Model + */ + public function testIsModuleEnabled(): void + { + $this->assertInstanceOf(Subject::class, $this->subject->setInterval(1, 1)); + } + + /** + * @dataProvider provideReportsDateIntervals + * @group Mage_Reports + * @group Mage_Reports_Model + */ + public function testGetIntervals(): void + { + $this->subject->setInterval(1, 1); + $this->assertIsArray($this->subject->getIntervals()); + } + + /** + * @covers Mage_Reports_Model_Resource_Report_Collection::getPeriods() + * @group Mage_Reports + * @group Mage_Reports_Model + */ + public function testGetPeriods(): void + { + $this->assertIsArray($this->subject->getPeriods()); + } + + /** + * @covers Mage_Reports_Model_Resource_Report_Collection::setStoreIds() + * @group Mage_Reports + * @group Mage_Reports_Model + */ + public function testSetStoreIds(): void + { + $this->assertInstanceOf(Subject::class, $this->subject->setStoreIds([])); + } + + /** + * @covers Mage_Reports_Model_Resource_Report_Collection::getStoreIds() + * @group Mage_Reports + * @group Mage_Reports_Model + */ + public function testGetStoreIds(): void + { + $this->assertNull($this->subject->getStoreIds()); + } + + /** + * @covers Mage_Reports_Model_Resource_Report_Collection::getSize() + * @group Mage_Reports + * @group Mage_Reports_Model + */ + public function testGetSize(): void + { + $this->assertIsInt($this->subject->getSize()); + } + /** + * @covers Mage_Reports_Model_Resource_Report_Collection::setPageSize() + * @group Mage_Reports + * @group Mage_Reports_Model + */ + public function testSetPageSize(): void + { + $this->assertInstanceOf(Subject::class, $this->subject->setPageSize(1)); + } + + /** + * @covers Mage_Reports_Model_Resource_Report_Collection::getPageSize() + * @group Mage_Reports + * @group Mage_Reports_Model + */ + public function testGetPageSize(): void + { + $this->assertNull($this->subject->getPageSize()); + } + + /** + * @group Mage_Reports + * @group Mage_Reports_Model + */ + public function testInitReport($modelClass = ''): void + { + $this->assertInstanceOf(Subject::class, $this->subject->initReport($modelClass)); + } + + /** + * @group Mage_Reports + * @group Mage_Reports_Model + */ + public function testGetReportFull(): void + { + $this->markTestIncomplete(); + // @phpstan-ignore-next-line + $this->assertInstanceOf(Mage_Reports_Model_Report::class, $this->subject->getReportFull(1, 1)); + } + + /** + * @group Mage_Reports + * @group Mage_Reports_Model + */ + public function testGetReport(): void + { + $this->markTestIncomplete(); + // @phpstan-ignore-next-line + $this->assertInstanceOf(Mage_Reports_Model_Report::class, $this->subject->getReport(1, 1)); + } + + /** + * @group Mage_Reports + * @group Mage_Reports_Model + */ + public function testTimeShift(): void + { + $this->markTestIncomplete(); + // @phpstan-ignore-next-line + $this->assertSame($this->subject->timeShift('')); + } +} diff --git a/tests/unit/Mage/Rule/Model/AbstractTest.php b/tests/unit/Mage/Rule/Model/AbstractTest.php new file mode 100644 index 00000000000..8e003410bdd --- /dev/null +++ b/tests/unit/Mage/Rule/Model/AbstractTest.php @@ -0,0 +1,230 @@ +subject = $this->getMockForAbstractClass(Subject::class); + } + + /** + * @group Mage_Rule + * @group Mage_Rule_Model + */ + public function testGetProductFlatSelect(): void + { + try { + $this->assertInstanceOf(Varien_Db_Select::class, $this->subject->getProductFlatSelect(0)); + } catch (Mage_Core_Exception $exception) { + $this->assertSame('Resource is not set.', $exception->getMessage()); + } + } + + /** + * @dataProvider provideBool + * @group Mage_Rule + * @group Mage_Rule_Model + */ + public function testGetConditions(bool $empty): void + { + if (!$empty) { + $this->subject->setConditions(new Mage_Rule_Model_Condition_Combine()); + } + + try { + $this->assertInstanceOf(Mage_Rule_Model_Condition_Combine::class, $this->subject->getConditions()); + } catch (Error $error) { + $this->assertSame('Call to a member function setRule() on null', $error->getMessage()); + } + } + + /** + * @dataProvider provideBool + * @group Mage_Rule + * @group Mage_Rule_Model + */ + public function testGetActions(bool $empty): void + { + if (!$empty) { + $this->subject->setActions(new Mage_Rule_Model_Action_Collection()); + } + + try { + $this->assertInstanceOf(Mage_Rule_Model_Action_Collection::class, $this->subject->getActions()); + } catch (Error $error) { + $this->assertSame('Call to a member function setRule() on null', $error->getMessage()); + } + } + + /** + * @group Mage_Rule + * @group Mage_Rule_Model + */ + public function testGetForm(): void + { + $this->assertInstanceOf(Varien_Data_Form::class, $this->subject->getForm()); + } + + /** + * @group Mage_Rule + * @group Mage_Rule_Model + */ + public function testLoadPost(array $data = []): void + { + $this->assertInstanceOf(Subject::class, $this->subject->loadPost($data)); + } + + /** + * @covers Mage_Rule_Model_Abstract::validate() + * @dataProvider provideValidateData + * @group Mage_Rule + * @group Mage_Rule_Model + */ + public function testValidate($expectedResul, ?array $data = null): void + { + $object = new Varien_Object($data); + try { + $this->assertSame($expectedResul, $this->subject->validate($object)); + } catch (Error $error) { + $this->assertSame('Call to a member function setRule() on null', $error->getMessage()); + } + + } + + /** + * @dataProvider provideValidateData + * @group Mage_Rule + * @group Mage_Rule_Model + */ + public function testValidateData($expectedResul, ?array $data = null): void + { + if (PHP_VERSION_ID >= 80300 && version_compare(InstalledVersions::getPrettyVersion('shardj/zf1-future'), '1.24.2', '<=')) { + $this->markTestSkipped(); + } + + $object = new Varien_Object($data); + $this->assertSame($expectedResul, $this->subject->validateData($object)); + } + + /** + * @covers Mage_Rule_Model_Abstract::isDeleteable() + * @group Mage_Rule + * @group Mage_Rule_Model + */ + public function testIsDeleteable(): void + { + $this->assertIsBool($this->subject->isDeleteable()); + } + + /** + * @covers Mage_Rule_Model_Abstract::setIsDeleteable() + * @dataProvider provideBool + * @group Mage_Rule + * @group Mage_Rule_Model + */ + public function testSetIsDeleteable(bool $value): void + { + $this->assertInstanceOf(Subject::class, $this->subject->setIsDeleteable($value)); + } + + /** + * @covers Mage_Rule_Model_Abstract::isReadonly() + * @group Mage_Rule + * @group Mage_Rule_Model + */ + public function testIsReadonly(): void + { + $this->assertIsBool($this->subject->isReadonly()); + } + + /** + * @covers Mage_Rule_Model_Abstract::setIsReadonly() + * @dataProvider provideBool + * @group Mage_Rule + * @group Mage_Rule_Model + */ + public function testSetIsReadonly(bool $value): void + { + $this->assertInstanceOf(Subject::class, $this->subject->setIsReadonly($value)); + } + + /** + * @group Mage_Rule + * @group Mage_Rule_Model + */ + public function testGetWebsiteIds(): void + { + try { + $this->assertIsArray($this->subject->getWebsiteIds()); + } catch (Mage_Core_Exception $exception) { + $this->assertSame('Resource is not set.', $exception->getMessage()); + } + } + + /** + * @covers Mage_Rule_Model_Abstract::asString() + * @group Mage_Rule + * @group Mage_Rule_Model + */ + public function testAsString(): void + { + $this->assertSame('', $this->subject->asString()); + } + + /** + * @covers Mage_Rule_Model_Abstract::asHtml() + * @group Mage_Rule + * @group Mage_Rule_Model + */ + public function testAsHtml(): void + { + $this->assertSame('', $this->subject->asHtml()); + } + + /** + * @covers Mage_Rule_Model_Abstract::asArray() + * @group Mage_Rule + * @group Mage_Rule_Model + */ + public function testAsArray(): void + { + $this->assertSame([], $this->subject->asArray()); + } +} diff --git a/tests/unit/Mage/Rule/Model/EnvironmentTest.php b/tests/unit/Mage/Rule/Model/EnvironmentTest.php new file mode 100644 index 00000000000..8fdae735880 --- /dev/null +++ b/tests/unit/Mage/Rule/Model/EnvironmentTest.php @@ -0,0 +1,43 @@ +subject = Mage::getModel('rule/environment'); + } + + /** + * @covers Mage_Rule_Model_Environment::collect() + * @group Mage_Rule + * @group Mage_Rule_Model + */ + public function testGetConditionsInstance(): void + { + $this->assertInstanceOf(Subject::class, $this->subject->collect()); + } +} diff --git a/tests/unit/Mage/Rule/Model/RuleTest.php b/tests/unit/Mage/Rule/Model/RuleTest.php new file mode 100644 index 00000000000..636199a4bbc --- /dev/null +++ b/tests/unit/Mage/Rule/Model/RuleTest.php @@ -0,0 +1,55 @@ +subject = Mage::getModel('rule/rule'); + } + + /** + * @covers Mage_Rule_Model_Rule::getConditionsInstance() + * @group Mage_Rule + * @group Mage_Rule_Model + */ + public function testGetConditionsInstance(): void + { + $this->assertInstanceOf(Mage_Rule_Model_Condition_Combine::class, $this->subject->getConditionsInstance()); + } + + /** + * @covers Mage_Rule_Model_Rule::getActionsInstance() + * @group Mage_Rule + * @group Mage_Rule_Model + */ + public function testGetActionsInstance(): void + { + $this->assertInstanceOf(Mage_Rule_Model_Action_Collection::class, $this->subject->getActionsInstance()); + } +} diff --git a/tests/unit/Mage/Sales/Block/Order/Item/Renderer/DefaultTest.php b/tests/unit/Mage/Sales/Block/Order/Item/Renderer/DefaultTest.php new file mode 100644 index 00000000000..ee0d091914f --- /dev/null +++ b/tests/unit/Mage/Sales/Block/Order/Item/Renderer/DefaultTest.php @@ -0,0 +1,44 @@ +subject = new Subject(); + } + + /** + * @covers Mage_Sales_Block_Order_Item_Renderer_Default::setItem() + * @group Mage_Sales + * @group Mage_Sales_Block + */ + public function testSetItem(): void + { + $this->assertInstanceOf(Subject::class, $this->subject->setItem(new Varien_Object())); + } +} diff --git a/tests/unit/Mage/Sitemap/Model/SitemapTest.php b/tests/unit/Mage/Sitemap/Model/SitemapTest.php index d72d3fb4451..2f1baf1cd2b 100644 --- a/tests/unit/Mage/Sitemap/Model/SitemapTest.php +++ b/tests/unit/Mage/Sitemap/Model/SitemapTest.php @@ -18,12 +18,14 @@ namespace OpenMage\Tests\Unit\Mage\Sitemap\Model; use Mage; -use Mage_Sitemap_Model_Sitemap; +use Mage_Sitemap_Model_Sitemap as Subject; use PHPUnit\Framework\TestCase; class SitemapTest extends TestCase { - public Mage_Sitemap_Model_Sitemap $subject; + public const SITEMAP_FILE = '???phpunit.sitemap.xml'; + + public Subject $subject; public function setUp(): void { @@ -37,7 +39,7 @@ public function setUp(): void */ public function testGetPreparedFilename(): void { - $mock = $this->getMockBuilder(Mage_Sitemap_Model_Sitemap::class) + $mock = $this->getMockBuilder(Subject::class) ->setMethods(['getSitemapFilename']) ->getMock(); @@ -47,15 +49,34 @@ public function testGetPreparedFilename(): void /** * @group Mage_Sitemap + * @group Mage_Sitemap + * @group Mage_Sitemap_Model * @group Mage_Sitemap_Model + * @todo test content of xml + * @todo test validation */ public function testGenerateXml(): void { - $mock = $this->getMockBuilder(Mage_Sitemap_Model_Sitemap::class) + $mock = $this->getMockBuilder(Subject::class) + ->setMethods(['isDeleted']) # do not save to DB ->setMethods(['getSitemapFilename']) ->getMock(); - $mock->method('getSitemapFilename')->willReturn('text.xml'); - $this->assertInstanceOf(Mage_Sitemap_Model_Sitemap::class, $mock->generateXml()); + $mock->method('isDeleted')->willReturn(true); + $mock->method('getSitemapFilename')->willReturn(self::SITEMAP_FILE); + $result = $mock->generateXml(); + $this->assertInstanceOf(Subject::class, $result); + $this->assertFileExists(self::SITEMAP_FILE); + unlink(self::SITEMAP_FILE); + } + + /** + * @group Mage_Sitemap + * @group Mage_Sitemap_Model + */ + public function testGetSitemapConfig(): void + { + $result = $this->subject->getSitemapConfig('page', []); + $this->assertCount(3, $result); } } diff --git a/tests/unit/Mage/Tax/Helper/DataTest.php b/tests/unit/Mage/Tax/Helper/DataTest.php index c2606070696..3130b5bad77 100644 --- a/tests/unit/Mage/Tax/Helper/DataTest.php +++ b/tests/unit/Mage/Tax/Helper/DataTest.php @@ -9,7 +9,7 @@ * * @category OpenMage * @package OpenMage_Tests - * @copyright Copyright (c) 2024 The OpenMage Contributors (https://www.openmage.org) + * @copyright Copyright (c) 2024-2025 The OpenMage Contributors (https://www.openmage.org) * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -19,14 +19,14 @@ use Generator; use Mage; -use Mage_Tax_Helper_Data; +use Mage_Tax_Helper_Data as Subject; use Mage_Tax_Model_Calculation; use Mage_Tax_Model_Config; use PHPUnit\Framework\TestCase; class DataTest extends TestCase { - public Mage_Tax_Helper_Data $subject; + public Subject $subject; public function setUp(): void { @@ -158,9 +158,10 @@ public function testGetPriceFormat(): void */ public function testGetTaxRatesByProductClass(): void { - $expectedResult = defined('USES_SAMPLEDATA') && USES_SAMPLEDATA === true ? - '{"value_2":9,"value_4":0,"value_6":0}' : '{"value_2":8.25,"value_4":0}'; - $this->assertSame($expectedResult, $this->subject->getTaxRatesByProductClass()); + if (defined('DATA_MAY_CHANGED')) { + $this->markTestSkipped(); + } + $this->assertSame('{"value_2":8.25,"value_4":0}', $this->subject->getTaxRatesByProductClass()); } /** @@ -170,9 +171,10 @@ public function testGetTaxRatesByProductClass(): void */ public function testGetAllRatesByProductClass(): void { - $expectedResult = defined('USES_SAMPLEDATA') && USES_SAMPLEDATA === true ? - '{"value_2":9,"value_4":0,"value_6":0}' : '{"value_2":8.25,"value_4":0}'; - $this->assertSame($expectedResult, $this->subject->getAllRatesByProductClass()); + if (defined('DATA_MAY_CHANGED')) { + $this->markTestSkipped(); + } + $this->assertSame('{"value_2":8.25,"value_4":0}', $this->subject->getAllRatesByProductClass()); } /** diff --git a/tests/unit/Mage/Uploader/Block/AbstractTest.php b/tests/unit/Mage/Uploader/Block/AbstractTest.php index c2295e61356..56f5c2588a0 100644 --- a/tests/unit/Mage/Uploader/Block/AbstractTest.php +++ b/tests/unit/Mage/Uploader/Block/AbstractTest.php @@ -18,7 +18,7 @@ namespace OpenMage\Tests\Unit\Mage\Uploader\Block; use Mage; -use Mage_Uploader_Block_Abstract; +use Mage_Uploader_Block_Abstract as Subject; use Mage_Uploader_Model_Config_Browsebutton; use Mage_Uploader_Model_Config_Misc; use Mage_Uploader_Model_Config_Uploader; @@ -26,12 +26,12 @@ class AbstractTest extends TestCase { - public Mage_Uploader_Block_Abstract $subject; + public Subject $subject; public function setUp(): void { Mage::app(); - $this->subject = $this->getMockForAbstractClass(Mage_Uploader_Block_Abstract::class); + $this->subject = $this->getMockForAbstractClass(Subject::class); } /** diff --git a/tests/unit/Mage/Uploader/Helper/DataTest.php b/tests/unit/Mage/Uploader/Helper/DataTest.php index e0f7f53a26b..591686c376d 100644 --- a/tests/unit/Mage/Uploader/Helper/DataTest.php +++ b/tests/unit/Mage/Uploader/Helper/DataTest.php @@ -18,12 +18,12 @@ namespace OpenMage\Tests\Unit\Mage\Uploader\Helper; use Mage; -use Mage_Uploader_Helper_Data; +use Mage_Uploader_Helper_Data as Subject; use PHPUnit\Framework\TestCase; class DataTest extends TestCase { - public Mage_Uploader_Helper_Data $subject; + public Subject $subject; public function setUp(): void { diff --git a/tests/unit/Mage/Uploader/Helper/FileTest.php b/tests/unit/Mage/Uploader/Helper/FileTest.php index c6f0124a30a..3926d5b72bd 100644 --- a/tests/unit/Mage/Uploader/Helper/FileTest.php +++ b/tests/unit/Mage/Uploader/Helper/FileTest.php @@ -9,7 +9,7 @@ * * @category OpenMage * @package OpenMage_Tests - * @copyright Copyright (c) 2024 The OpenMage Contributors (https://www.openmage.org) + * @copyright Copyright (c) 2024-2025 The OpenMage Contributors (https://www.openmage.org) * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -17,15 +17,17 @@ namespace OpenMage\Tests\Unit\Mage\Uploader\Helper; -use Generator; use Mage; use Mage_Core_Model_Config; -use Mage_Uploader_Helper_File; +use Mage_Uploader_Helper_File as Subject; +use OpenMage\Tests\Unit\Traits\DataProvider\Mage\Uploader\UploaderTrait; use PHPUnit\Framework\TestCase; class FileTest extends TestCase { - public Mage_Uploader_Helper_File $subject; + use UploaderTrait; + + public Subject $subject; public function setUp(): void { @@ -50,34 +52,6 @@ public function testGetMimeTypeFromExtensionList(array $expectedResult, $extensi $this->assertSame($expectedResult, $this->subject->getMimeTypeFromExtensionList($extensionsList)); } - public function provideGetMimeTypeFromExtensionListData(): Generator - { - yield 'string exists' => [ - [ - 0 => 'application/vnd.lotus-1-2-3', - ], - '123', - ]; - yield 'string not exists' => [ - [ - 0 => 'application/octet-stream', - ], - 'not-exists', - ]; - yield 'array' => [ - [ - 0 => 'application/vnd.lotus-1-2-3', - 1 => 'application/octet-stream', - 2 => 'application/octet-stream', - ], - [ - '123', - 'not-exists', - 'test-new-node', - ], - ]; - } - /** * @group Mage_Uploader * @group Mage_Uploader_Helper @@ -102,7 +76,7 @@ public function testGetUploadMaxSize(): void */ public function testGetDataMaxSize(): void { - $mock = $this->getMockBuilder(Mage_Uploader_Helper_File::class) + $mock = $this->getMockBuilder(Subject::class) ->setMethods(['getPostMaxSize', 'getUploadMaxSize']) ->getMock(); @@ -118,31 +92,11 @@ public function testGetDataMaxSize(): void */ public function testGetDataMaxSizeInBytes(int $expectedResult, string $maxSize): void { - $mock = $this->getMockBuilder(Mage_Uploader_Helper_File::class) + $mock = $this->getMockBuilder(Subject::class) ->setMethods(['getDataMaxSize']) ->getMock(); $mock->expects($this->once())->method('getDataMaxSize')->willReturn($maxSize); $this->assertSame($expectedResult, $mock->getDataMaxSizeInBytes()); } - - public function provideGetDataMaxSizeInBytesData(): Generator - { - yield 'no unit' => [ - 1024, - '1024', - ]; - yield 'kilobyte' => [ - 1024, - '1K', - ]; - yield 'megabyte' => [ - 1048576, - '1M', - ]; - yield 'gigabyte' => [ - 1073741824, - '1G', - ]; - } } diff --git a/tests/unit/Traits/DataProvider/Base/BoolTrait.php b/tests/unit/Traits/DataProvider/Base/BoolTrait.php new file mode 100644 index 00000000000..d7c32d61cb8 --- /dev/null +++ b/tests/unit/Traits/DataProvider/Base/BoolTrait.php @@ -0,0 +1,33 @@ + [ + true, + ]; + yield 'false' => [ + false, + ]; + } +} diff --git a/tests/unit/Traits/DataProvider/Base/IntOrNullTrait.php b/tests/unit/Traits/DataProvider/Base/IntOrNullTrait.php new file mode 100644 index 00000000000..fb6f10ff5bf --- /dev/null +++ b/tests/unit/Traits/DataProvider/Base/IntOrNullTrait.php @@ -0,0 +1,36 @@ + [ + null, + ]; + yield 'expexted int' => [ + 1, + ]; + yield 'not expexted int' => [ + 99999, + ]; + } +} diff --git a/tests/unit/Traits/DataProvider/Base/ModulesTrait.php b/tests/unit/Traits/DataProvider/Base/ModulesTrait.php new file mode 100644 index 00000000000..2db0882beaf --- /dev/null +++ b/tests/unit/Traits/DataProvider/Base/ModulesTrait.php @@ -0,0 +1,104 @@ +provideAllModules(); + + foreach ($modules as $idx => $module) { + if (in_array($module, $disabled)) { + unset($modules[$idx]); + } + } + return $modules; + } +} diff --git a/tests/unit/Traits/DataProvider/Base/NumericStringTrait.php b/tests/unit/Traits/DataProvider/Base/NumericStringTrait.php new file mode 100644 index 00000000000..be8b005d3b8 --- /dev/null +++ b/tests/unit/Traits/DataProvider/Base/NumericStringTrait.php @@ -0,0 +1,33 @@ + [ + '0', + ]; + yield 'non-zero' => [ + '1', + ]; + } +} diff --git a/tests/unit/Traits/DataProvider/Mage/Catalog/CatalogTrait.php b/tests/unit/Traits/DataProvider/Mage/Catalog/CatalogTrait.php new file mode 100644 index 00000000000..689a47e6124 --- /dev/null +++ b/tests/unit/Traits/DataProvider/Mage/Catalog/CatalogTrait.php @@ -0,0 +1,58 @@ + [ + 'a-b-x-a-o-u-tm', + null, + ]; + yield 'de_DE' => [ + 'a-und-b-x-prozent-at-ae-oe-ue-tm', + 'de_DE', + ]; + yield 'en_US' => [ + 'a-and-b-x-percent-at-a-o-u-tm', + 'en_US', + ]; + yield 'es_ES' => [ + 'a-et-b-x-por-ciento-at-a-o-u-tm', + 'es_ES', + ]; + yield 'fr_FR' => [ + 'a-et-b-x-pour-cent-at-a-o-u-tm', + 'fr_FR', + ]; + yield 'it_IT' => [ + 'a-e-b-x-per-cento-at-a-o-u-tm', + 'it_IT', + ]; + } + + public function getTestString(): string + { + return static::$testString; + } +} diff --git a/tests/unit/Traits/DataProvider/Mage/Catalog/Model/LocaleTrait.php b/tests/unit/Traits/DataProvider/Mage/Catalog/Model/LocaleTrait.php new file mode 100644 index 00000000000..bf49b4ffa37 --- /dev/null +++ b/tests/unit/Traits/DataProvider/Mage/Catalog/Model/LocaleTrait.php @@ -0,0 +1,51 @@ + [ + 1.0, + [1], + ]; + yield 'int' => [ + 1.0, + 1, + ]; + yield 'string' => [ + 1.0, + '1', + ]; + yield 'string comma' => [ + 1.0, + '1,0', + ]; + yield 'string dot' => [ + 1.0, + '1.0', + ]; + yield 'null' => [ + null, + null, + ]; + } +} diff --git a/tests/unit/Traits/DataProvider/Mage/Cms/CmsTrait.php b/tests/unit/Traits/DataProvider/Mage/Cms/CmsTrait.php new file mode 100644 index 00000000000..3807b8c4d9e --- /dev/null +++ b/tests/unit/Traits/DataProvider/Mage/Cms/CmsTrait.php @@ -0,0 +1,73 @@ + Mage_Cms_Helper_Page::XML_PATH_NO_ROUTE_PAGE, + 1 => Mage_Cms_Helper_Page::XML_PATH_NO_COOKIES_PAGE, + 2 => Mage_Cms_Helper_Page::XML_PATH_HOME_PAGE, + ]; + + yield 'null' => [ + [], + null, + ]; + yield 'empty array' => [ + $default, + [], + ]; + + $custom = [ + 'my/first/path', + 'my/second/path', + ]; + + yield 'custom paths' => [ + array_merge($default, $custom), + $custom, + ]; + } + + public function provideGetShortFilename(): Generator + { + yield 'full length' => [ + '0123456789', + $this->getTestString(), + 20, + ]; + yield 'truncated' => [ + '01234...', + $this->getTestString(), + 5, + ]; + } + + public function getTestString(): string + { + return static::$testString; + } +} diff --git a/tests/unit/Traits/DataProvider/Mage/Core/CoreTrait.php b/tests/unit/Traits/DataProvider/Mage/Core/CoreTrait.php new file mode 100644 index 00000000000..26a1728fc50 --- /dev/null +++ b/tests/unit/Traits/DataProvider/Mage/Core/CoreTrait.php @@ -0,0 +1,84 @@ + [ + true, + null, #Mage_Adminhtml + ]; + + foreach ($this->provideAllActiveModules() as $module) { + yield $module => [ + true, + $module, + ]; + } + + yield 'Not_Exist' => [ + false, + 'Not_Exist', + ]; + } + + public function provideGetStoreConfig(): Generator + { + yield 'null' => [ + null, + ]; + yield 'true' => [ + true, + ]; + yield 'false' => [ + false, + ]; + yield 'int valid' => [ + 1, + ]; + yield 'int invalid (exception)' => [ + 999, + ]; + yield 'string' => [ + '1', + ]; + } + + public function provideGetStoreId(): Generator + { + yield 'string' => [ + 1, + '1', + ]; + yield 'int' => [ + 1, + 1, + ]; + yield 'null' => [ + null, + null, + ]; + } +} diff --git a/tests/unit/Traits/DataProvider/Mage/Downloadable/DownloadableTrait.php b/tests/unit/Traits/DataProvider/Mage/Downloadable/DownloadableTrait.php new file mode 100644 index 00000000000..a1c75389603 --- /dev/null +++ b/tests/unit/Traits/DataProvider/Mage/Downloadable/DownloadableTrait.php @@ -0,0 +1,52 @@ + [ + 'path' . DS . 'file', + 'path', + 'file', + ]; + yield 'strings path and strings file with slash' => [ + 'path' . DS . 'file', + 'path', + '/file', + ]; + yield 'string path and null file' => [ + 'path' . DS, + 'path', + null, + ]; + yield 'string path and empty file' => [ + 'path' . DS, + 'path', + '', + ]; + yield 'strings path and strings file named 0' => [ + 'path' . DS . '0', + 'path', + '0', + ]; + } +} diff --git a/tests/unit/Traits/DataProvider/Mage/Reports/ReportsTrait.php b/tests/unit/Traits/DataProvider/Mage/Reports/ReportsTrait.php new file mode 100644 index 00000000000..93280195af3 --- /dev/null +++ b/tests/unit/Traits/DataProvider/Mage/Reports/ReportsTrait.php @@ -0,0 +1,135 @@ + [ + 0, + '', + '', + Mage_Reports_Helper_Data::REPORT_PERIOD_TYPE_DAY, + ]; + yield $prefix . 'no from' => [ + 0, + '', + '2025-01-01', + Mage_Reports_Helper_Data::REPORT_PERIOD_TYPE_DAY, + ]; + + if (!defined('DATA_MAY_CHANGED')) { + yield $prefix . 'no to' => [ + 0, + '2025-01-01', + '', + Mage_Reports_Helper_Data::REPORT_PERIOD_TYPE_DAY, + ]; + } + + yield $prefix . 'same day' => [ + 1, + '2025-01-01', + '2025-01-01', + Mage_Reports_Helper_Data::REPORT_PERIOD_TYPE_DAY, + ]; + yield $prefix . 'same and next day' => [ + 2, + '2025-01-01', + '2025-01-02', + Mage_Reports_Helper_Data::REPORT_PERIOD_TYPE_DAY, + ]; + yield $prefix . 'same and previous day' => [ + 0, + '2025-01-02', + '2025-01-01', + Mage_Reports_Helper_Data::REPORT_PERIOD_TYPE_DAY, + ]; + yield $prefix . 'year 2025' => [ + 365, + '2025-01-01', + '2025-12-31', + Mage_Reports_Helper_Data::REPORT_PERIOD_TYPE_DAY, + ]; + yield $prefix . 'year 2026' => [ + 365, + '2026-01-01', + '2026-12-31', + Mage_Reports_Helper_Data::REPORT_PERIOD_TYPE_DAY, + ]; + yield $prefix . 'year 2027' => [ + 365, + '2027-01-01', + '2027-12-31', + Mage_Reports_Helper_Data::REPORT_PERIOD_TYPE_DAY, + ]; + yield $prefix . 'year 2028' => [ + 366, + '2028-01-01', + '2028-12-31', + Mage_Reports_Helper_Data::REPORT_PERIOD_TYPE_DAY, + ]; + + $prefix = Mage_Reports_Helper_Data::REPORT_PERIOD_TYPE_MONTH . ': '; + + yield $prefix . 'year 2025 full' => [ + 12, + '2025-01-01', + '2025-12-31', + Mage_Reports_Helper_Data::REPORT_PERIOD_TYPE_MONTH, + ]; + yield $prefix . 'year 2025, half january' => [ + 12, + '2025-01-15', + '2025-12-31', + Mage_Reports_Helper_Data::REPORT_PERIOD_TYPE_MONTH, + ]; + yield $prefix . 'year 2025, half december' => [ + 12, + '2025-01-01', + '2025-12-15', + Mage_Reports_Helper_Data::REPORT_PERIOD_TYPE_MONTH, + ]; + $prefix = Mage_Reports_Helper_Data::REPORT_PERIOD_TYPE_YEAR . ': '; + + yield $prefix . 'same year' => [ + 0, + '2025-01-01', + '2025-12-31', + Mage_Reports_Helper_Data::REPORT_PERIOD_TYPE_YEAR, + ]; + yield $prefix . 'year 2025 and next' => [ + 1, + '2025-01-15', + '2026-12-31', + Mage_Reports_Helper_Data::REPORT_PERIOD_TYPE_YEAR, + ]; + yield $prefix . 'year 2025, half december 2026' => [ + 1, + '2025-01-01', + '2026-12-15', + Mage_Reports_Helper_Data::REPORT_PERIOD_TYPE_YEAR, + ]; + } +} diff --git a/tests/unit/Traits/DataProvider/Mage/Rule/RuleTrait.php b/tests/unit/Traits/DataProvider/Mage/Rule/RuleTrait.php new file mode 100644 index 00000000000..9aeb560c67d --- /dev/null +++ b/tests/unit/Traits/DataProvider/Mage/Rule/RuleTrait.php @@ -0,0 +1,82 @@ + [ + true, + ]; + + yield 'object with equal date' => [ + true, + [ + 'from_date' => '1', + 'to_date' => '1', + ], + ]; + yield 'object with valid date' => [ + true, + [ + 'from_date' => '1', + 'to_date' => '2', + ], + ]; + yield 'object with invalid date' => [ + [ + 0 => 'End Date must be greater than Start Date.', + ], + [ + 'from_date' => '2', + 'to_date' => '1', + ], + ]; + yield 'object with empty website ids' => [ + [ + 0 => 'Websites must be specified.', + ], + [ + 'website_ids' => '', + ], + ]; + yield 'object with not empty website ids' => [ + true, + [ + 'website_ids' => '1', + ], + ]; + yield 'object with empty customer group ids' => [ + [ + 0 => 'Customer Groups must be specified.', + ], + [ + 'customer_group_ids' => '', + ], + ]; + yield 'object with not empty customer group ids' => [ + true, + [ + 'customer_group_ids' => '1', + ], + ]; + } +} diff --git a/tests/unit/Traits/DataProvider/Mage/Uploader/UploaderTrait.php b/tests/unit/Traits/DataProvider/Mage/Uploader/UploaderTrait.php new file mode 100644 index 00000000000..dd1c9a51abb --- /dev/null +++ b/tests/unit/Traits/DataProvider/Mage/Uploader/UploaderTrait.php @@ -0,0 +1,71 @@ + [ + [ + 0 => 'application/vnd.lotus-1-2-3', + ], + '123', + ]; + yield 'string not exists' => [ + [ + 0 => 'application/octet-stream', + ], + 'not-exists', + ]; + yield 'array' => [ + [ + 0 => 'application/vnd.lotus-1-2-3', + 1 => 'application/octet-stream', + 2 => 'application/octet-stream', + ], + [ + '123', + 'not-exists', + 'test-new-node', + ], + ]; + } + + public function provideGetDataMaxSizeInBytesData(): Generator + { + yield 'no unit' => [ + 1024, + '1024', + ]; + yield 'kilobyte' => [ + 1024, + '1K', + ]; + yield 'megabyte' => [ + 1048576, + '1M', + ]; + yield 'gigabyte' => [ + 1073741824, + '1G', + ]; + } +} diff --git a/tests/unit/Varien/ObjectTest.php b/tests/unit/Varien/ObjectTest.php index a35a8088bd4..febf2645aca 100644 --- a/tests/unit/Varien/ObjectTest.php +++ b/tests/unit/Varien/ObjectTest.php @@ -226,7 +226,7 @@ public function testGetSetUnsData(): void $this->assertTrue($this->subject->isEmpty()); try { - /** @phpstan-ignore-next-line */ + // @phpstan-ignore-next-line $this->subject->notData(); $this->fail('Invalid __call'); } catch (Varien_Exception $exception) {