Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added more PhpUnit tests #4236

Merged
merged 40 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
9466a80
Updated tests
sreichel Sep 30, 2024
9d32ba5
Typo
sreichel Sep 30, 2024
9f52d94
Docs
sreichel Sep 30, 2024
93155dc
Fixe test
sreichel Sep 30, 2024
bc69376
ddev commands
sreichel Sep 30, 2024
3b8f825
Docs
sreichel Sep 30, 2024
0aab349
phpstan.baseline
sreichel Sep 30, 2024
ad70216
composer.lock
sreichel Sep 30, 2024
5d485de
Added tests
sreichel Sep 30, 2024
321b544
phpcs
sreichel Sep 30, 2024
4c68908
Updated test: pass invalid storeId
sreichel Sep 30, 2024
2d1969f
Bugfix: Mage_Catalog_Model_Url::refreshRewrites()
sreichel Sep 30, 2024
ea06b7b
Updated test
sreichel Sep 30, 2024
21f29a2
Updated test
sreichel Sep 30, 2024
a31ab10
Updated tests
sreichel Oct 1, 2024
b76af2c
Updated tests
sreichel Oct 1, 2024
aea0871
Merge remote-tracking branch 'origin/phpunit' into phpunit
sreichel Oct 1, 2024
cd03fc9
Merge branch 'main' into phpunit
sreichel Oct 2, 2024
4368716
Merge branch 'main' into phpunit
sreichel Oct 8, 2024
915a974
return int for store_id
sreichel Oct 9, 2024
9fe3ea8
Merge branch 'main' into phpunit
sreichel Oct 9, 2024
f13001d
updated tests
sreichel Oct 9, 2024
b331ed8
Merge remote-tracking branch 'origin/phpunit' into phpunit
sreichel Oct 9, 2024
323b7c7
Merge branch 'main' into phpunit
sreichel Oct 9, 2024
bf7757c
Merge branch 'main' into phpunit
sreichel Oct 13, 2024
080b6f6
Merge branch 'main' into phpunit
sreichel Oct 14, 2024
437c5d2
Merge branch 'main' into phpunit
sreichel Oct 14, 2024
bfd5297
cs [skip ci]
sreichel Oct 14, 2024
b72f35d
Mage_Eav_Model_Entity_Type fixes
sreichel Oct 16, 2024
4a38080
phpstan fixed errors
sreichel Oct 16, 2024
9eee918
Merge branch 'main' into phpunit
sreichel Oct 16, 2024
edd44b0
Merge branch 'main' into phpunit
sreichel Oct 16, 2024
83eb7b7
Merge remote-tracking branch 'origin/phpunit' into phpunit
sreichel Oct 16, 2024
4809a08
updated tests
sreichel Oct 16, 2024
4371d80
Merge branch 'main' into phpunit
sreichel Oct 16, 2024
aa4b27a
Merge branch 'main' into phpunit
sreichel Oct 18, 2024
0cb8539
Merge branch 'main' into phpunit
sreichel Oct 18, 2024
1b46390
Merge branch 'main' into phpunit
sreichel Oct 18, 2024
96bf962
Merge branch 'main' into phpunit
sreichel Oct 23, 2024
c877370
reverted
sreichel Oct 25, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .ddev/commands/web/phpunit-coverage
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
## Example: ddev phpunit-coverage

enable_xdebug
XDEBUG_MODE=coverage php vendor/bin/phpunit --testdox
XDEBUG_MODE=coverage php vendor/bin/phpunit "$@" --testdox
disable_xdebug
2 changes: 1 addition & 1 deletion .ddev/commands/web/phpunit-coverage-local
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
## Example: ddev phpunit-coverage-local

enable_xdebug
XDEBUG_MODE=coverage php vendor/bin/phpunit --coverage-html build/coverage --testdox
XDEBUG_MODE=coverage php vendor/bin/phpunit --coverage-html build/coverage "$@" --testdox
disable_xdebug
2 changes: 1 addition & 1 deletion .github/workflows/rector.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:

jobs:
rector:
name: Validation
name: Rector
runs-on: [ubuntu-latest]

steps:
Expand Down
291 changes: 3 additions & 288 deletions .phpstan.dist.baseline.neon

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion app/code/core/Mage/Admin/Model/Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ protected function _construct()
}

/**
* @return array|bool
* @return array|true
* @throws Exception
* @throws Zend_Validate_Exception
*/
Expand Down
9 changes: 7 additions & 2 deletions app/code/core/Mage/Admin/Model/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ public function getAclRole()
}

/**
* Authenticate user name and password and save loaded record
* Authenticate username and password and save loaded record
*
* @param string $username
* @param string $password
Expand All @@ -384,7 +384,7 @@ public function authenticate($username, $password)
$this->loadByUsername($username);
$sensitive = ($config) ? $username == $this->getUsername() : true;

if ($sensitive && $this->getId() && Mage::helper('core')->validateHash($password, $this->getPassword())) {
if ($sensitive && $this->getId() && $this->validatePasswordHash($password, $this->getPassword())) {
if ($this->getIsActive() != '1') {
Mage::throwException(Mage::helper('adminhtml')->__('This account is inactive.'));
}
Expand All @@ -411,6 +411,11 @@ public function authenticate($username, $password)
return $result;
}

public function validatePasswordHash(string $string1, string $string2): bool
{
return Mage::helper('core')->validateHash($string1, $string2);
}

/**
* Login user
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ public function getJsTemplateName()
if ($templateCode === null) {
return '';
}
// phpcs:ignore Ecg.Security.ForbiddenFunction.Found
return addcslashes($this->escapeHtml($templateCode), "\"\r\n\\");
}

Expand Down
1 change: 1 addition & 0 deletions app/code/core/Mage/Api2/Model/Route/ApiType.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public function __construct(
?Zend_Translate $translator = null,
$locale = null
) {
// phpcs:ignore Ecg.Security.ForbiddenFunction.Found
parent::__construct([Mage_Api2_Model_Route_Abstract::PARAM_ROUTE => str_replace('.php', '', basename(getenv('SCRIPT_FILENAME'))) . '/:api_type']);
}
}
1 change: 0 additions & 1 deletion app/code/core/Mage/Bundle/Model/Product/Price.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ public function getTotalBundleItemsPrice($product, $qty = null)
$selectionIds = unserialize($customOption->getValue(), ['allowed_classes' => false]);
/** @var Mage_Bundle_Model_Product_Type $productType */
$productType = $product->getTypeInstance(true);
/** @var Mage_Bundle_Model_Resource_Selection_Collection $selections */
$selections = $productType->getSelectionsByIds($selectionIds, $product);
$selections->addTierPriceData();
Mage::dispatchEvent('prepare_catalog_product_collection_prices', [
Expand Down
4 changes: 2 additions & 2 deletions app/code/core/Mage/Captcha/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function isEnabled(): bool
* Get Captcha
*
* @param string $formId
* @return Mage_Captcha_Model_Interface
* @return Mage_Captcha_Model_Zend
*/
public function getCaptcha($formId)
{
Expand All @@ -76,7 +76,7 @@ public function getCaptcha($formId)
/**
* Returns value of the node with respect to current area (frontend or backend)
*
* @param string $id The last part of XML_PATH_$area_CAPTCHA_ constant (case insensitive)
* @param string $id The last part of XML_PATH_$area_CAPTCHA_ constant (case-insensitive)
* @param Mage_Core_Model_Store $store
* @return Mage_Core_Model_Config_Element
*/
Expand Down
4 changes: 2 additions & 2 deletions app/code/core/Mage/Catalog/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class Mage_Catalog_Helper_Data extends Mage_Core_Helper_Abstract
/**
* Breadcrumb Path cache
*
* @var string
* @var string|array<string, array<string, string|null>>
*/
protected $_categoryPath;

Expand Down Expand Up @@ -236,7 +236,7 @@ public function isPriceGlobal()
/**
* Indicate whether to save URL Rewrite History or not (create redirects to old URLs)
*
* @param int $storeId Store View
* @param null|string|bool|int|Mage_Core_Model_Store $storeId Store View
* @return bool
*/
public function shouldSaveUrlRewritesHistory($storeId = null)
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Catalog/Model/Api/Resource.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ protected function _isAllowedAttribute($attribute, $attributes = null)

/**
* Retrieves store id from store code, if no store id specified,
* it use seted session or admin store
* it uses set session or admin store
*
* @param string|int $store
* @return int
Expand Down
4 changes: 2 additions & 2 deletions app/code/core/Mage/Catalog/Model/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -441,14 +441,14 @@ public function getLayoutUpdateHandle()
/**
* Return store id.
*
* If store id is underfined for category return current active store id
* If store id is undefined for category return current active store id
*
* @return int
*/
public function getStoreId()
{
if ($this->hasData('store_id')) {
return $this->_getData('store_id');
return (int)$this->_getData('store_id');
}
return Mage::app()->getStore()->getId();
}
Expand Down
12 changes: 7 additions & 5 deletions app/code/core/Mage/Catalog/Model/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@
* @method string getMetaDescription()
* @method string getMetaKeyword()
* @method string getMetaTitle()
* @method $this hasMsrpEnabled(bool $value)
* @method $this hasMsrpEnabled()
* @method bool getMsrpEnabled()
* @method string getMsrpDisplayActualPriceType()
*
Expand Down Expand Up @@ -365,7 +365,7 @@ protected function _initOldFieldsMap()
public function getStoreId()
{
if ($this->hasData('store_id')) {
return $this->getData('store_id');
return (int)$this->getData('store_id');
}
return Mage::app()->getStore()->getId();
}
Expand Down Expand Up @@ -417,7 +417,7 @@ public function validate()
/**
* Get product name
*
* @return string
* @return string|null
*/
public function getName()
{
Expand All @@ -442,16 +442,18 @@ public function getPrice()
* Set Price calculation flag
*
* @param bool $calculate
* @return $this
*/
public function setPriceCalculation($calculate = true)
{
$this->_calculatePrice = $calculate;
return $this;
}

/**
* Get product type identifier
*
* @return string
* @return string|null
*/
public function getTypeId()
{
Expand Down Expand Up @@ -876,7 +878,7 @@ public function cleanCache()
/**
* Get product price model
*
* @return Mage_Catalog_Model_Product_Type_Price|Mage_Bundle_Model_Product_Price
* @return Mage_Bundle_Model_Product_Price
*/
public function getPriceModel()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,16 +237,6 @@ public function addAttributeToSelect($attribute = '*')
return $this;
}

/**
* Retrieve resource instance
*
* @inheritDoc
*/
public function getResource()
{
return parent::getResource();
}

/**
* Add attribute to sort order
*
Expand Down Expand Up @@ -325,6 +315,7 @@ public function addPathsFilter($paths)
$select = $this->getSelect();
$cond = [];
foreach ($paths as $path) {
// phpcs:ignore Ecg.Sql.SlowQuery.SlowRawSql
$cond[] = $this->getResource()->getReadConnection()->quoteInto('main_table.path LIKE ?', "$path%");
}
if ($cond) {
Expand Down
7 changes: 6 additions & 1 deletion app/code/core/Mage/Catalog/Model/Resource/Category/Tree.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public function __construct()
*/
public function setStoreId($storeId)
{
$this->_storeId = (int) $storeId;
$this->_storeId = $storeId;
return $this;
}

Expand Down Expand Up @@ -467,13 +467,15 @@ public function loadByIds($ids, $addCollectionData = true, $updateAnchorProductC
->where('entity_id IN (?)', $ids);
$where = [$levelField . '=0' => true];

// phpcs:ignore Ecg.Performance.FetchAll.Found
foreach ($this->_conn->fetchAll($select) as $item) {
if (!preg_match("#^[0-9\/]+$#", $item['path'])) {
$item['path'] = '';
}
$pathIds = explode('/', $item['path']);
$level = (int)$item['level'];
while ($level > 0) {
// phpcs:ignore Ecg.Performance.Loop.ArraySize
$pathIds[count($pathIds) - 1] = '%';
$path = implode('/', $pathIds);
$where["$levelField=$level AND $pathField LIKE '$path'"] = true;
Expand All @@ -493,6 +495,7 @@ public function loadByIds($ids, $addCollectionData = true, $updateAnchorProductC
$select->where(implode(' OR ', $where));

// get array of records and add them as nodes to the tree
// phpcs:ignore Ecg.Performance.FetchAll.Found
$arrNodes = $this->_conn->fetchAll($select);
if (!$arrNodes) {
return false;
Expand Down Expand Up @@ -535,6 +538,7 @@ public function loadBreadcrumbsArray($path, $addCollectionData = true, $withRoot
$select
->where('e.entity_id IN(?)', $pathIds)
->order($this->_conn->getLengthSql('e.path') . ' ' . Varien_Db_Select::SQL_ASC);
// phpcs:ignore Ecg.Performance.FetchAll.Found
$result = $this->_conn->fetchAll($select);
$this->_updateAnchorProductCount($result);
}
Expand Down Expand Up @@ -623,6 +627,7 @@ protected function _createCollectionDataSelect($sorted = true, $optionalAttribut
['COUNT(DISTINCT scp.product_id)']
)
->where('see.entity_id = e.entity_id')
// phpcs:ignore Ecg.Sql.SlowQuery.SlowRawSql
->orWhere('see.path LIKE ?', $subConcat);
$select->columns(['product_count' => $subSelect]);

Expand Down
4 changes: 2 additions & 2 deletions app/code/core/Mage/Catalog/Model/Url.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ protected function _addCategoryUrlPath($category)
* Retrieve stores array or store model
*
* @param int|null $storeId
* @return Mage_Core_Model_Store|array
* @return Mage_Core_Model_Store|Mage_Core_Model_Store[]
*/
public function getStores($storeId = null)
{
Expand Down Expand Up @@ -211,7 +211,7 @@ public function setShouldSaveRewritesHistory($flag)
/**
* Indicate whether to save URL Rewrite History or not (create redirects to old URLs)
*
* @param int $storeId Store View
* @param null|string|bool|int|Mage_Core_Model_Store $storeId Store View
* @return bool
*/
public function getShouldSaveRewritesHistory($storeId = null)
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Checkout/Model/Api/Resource.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ protected function _isQuoteExist($quoteId)

/**
* Retrieves store id from store code, if no store id specified,
* it use set session or admin store
* it uses set session or admin store
*
* @param string|int $store
* @return int
Expand Down
3 changes: 2 additions & 1 deletion app/code/core/Mage/Core/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ public function getVersionHash(Mage_Core_Model_Encryption $encryptionModel)
/**
* Retrieve store identifier
*
* @param mixed $store
* @param bool|int|Mage_Core_Model_Store|null|string $store
* @return int
*/
public function getStoreId($store = null)
Expand Down Expand Up @@ -842,6 +842,7 @@ public function mergeFiles(
}
// phpcs:ignore Ecg.Security.ForbiddenFunction.Found
$contents = file_get_contents($file) . "\n";
// phpcs:ignore Ecg.Security.ForbiddenFunction.Found
if ($beforeMergeCallback && is_callable($beforeMergeCallback)) {
// phpcs:ignore Ecg.Security.ForbiddenFunction.Found
$contents = call_user_func($beforeMergeCallback, $file, $contents);
Expand Down
6 changes: 3 additions & 3 deletions app/code/core/Mage/Core/Helper/String.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Mage_Core_Helper_String extends Mage_Core_Helper_Abstract
* Truncate a string to a certain length if necessary, appending the $etc string.
* $remainder will contain the string that has been replaced with $etc.
*
* @param string $string
* @param string|null $string
* @param int $length
* @param string $etc
* @param string &$remainder
Expand Down Expand Up @@ -241,7 +241,7 @@ public function str_split($str, $length = 1, $keepWords = false, $trim = false,
/**
* Split words
*
* @param string $str The source string
* @param string|null $str The source string
* @param bool $uniqueOnly Unique words only
* @param int $maxWordLength Limit words count
* @param string $wordSeparatorRegexp
Expand Down Expand Up @@ -513,7 +513,7 @@ public function uniOrd($c)

/**
* UnSerialize string
* @param string $str
* @param string|null $str
* @return mixed|null
* @throws Exception
*/
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Core/Model/Abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ abstract class Mage_Core_Model_Abstract extends Varien_Object
/**
* Original data that was loaded
*
* @var array
* @var array|null
*/
protected $_origData;

Expand Down
Loading
Loading