Skip to content

Commit ab1d4f5

Browse files
authored
PHPUnit: added/updated tests (#4758)
* tests * rector * updated test groups * updated tests * updated tests * updated tests * updated tests * updated tests * updated tests * updated tests * updated tests * updated tests * updated tests * updated tests * update * update * update * update * update * typo * updated tests * updated tests * updated tests * updated tests * sonar 1 * sonar 2 * phpcs/phpstan * sonar 4 * sonar 5 * sonar 6 * phpcs * copyright, ref #4767 * added Makefile * merge fix * reverted all changes to core files * Revert "reverted all changes to core files" This reverts commit 63e5f77.
1 parent 11a4abf commit ab1d4f5

File tree

183 files changed

+4982
-3361
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

183 files changed

+4982
-3361
lines changed

.gitattributes

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323

2424
/README.md export-ignore
2525

26+
/Makefile export-ignore
27+
2628
# Enforce checkout with linux lf consistent over all platforms
2729
*.html text eol=lf
2830
*.css text eol=lf

.github/workflows/phpunit.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ jobs:
9999
phpunit-result-cache-
100100
101101
- name: Run phpUnit
102-
run: php vendor/bin/phpunit --configuration .phpunit.dist.xml
102+
run: php vendor/bin/phpunit --configuration .phpunit.dist.xml --testsuite Base,Error,Mage,Varien
103103

104104
- name: Save result cache
105105
uses: actions/cache/save@v4

.php-cs-fixer.dist.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// PHP84: Adds or removes ? before single type declarations or |null at the end of union types when parameters have a default null value.
1616
'nullable_type_declaration_for_default_null_value' => true,
1717
// Calls to PHPUnit\Framework\TestCase static methods must all be of the same type, either $this->, self:: or static::
18-
'php_unit_test_case_static_method_calls' => ['call_type' => 'this'],
18+
'php_unit_test_case_static_method_calls' => ['call_type' => 'static'],
1919
// Convert double quotes to single quotes for simple strings.
2020
'single_quote' => true,
2121
// Arguments lists, array destructuring lists, arrays that are multi-line, match-lines and parameters lists must have a trailing comma.

.phpunit.dist.xml

+75
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,81 @@
3131
<testsuite name="Mage">
3232
<directory>tests/unit/Mage</directory>
3333
</testsuite>
34+
<testsuite name="Mage_Admin">
35+
<directory>tests/unit/Mage/Admin</directory>
36+
</testsuite>
37+
<testsuite name="Mage_Adminhtml">
38+
<directory>tests/unit/Mage/Adminhtml</directory>
39+
</testsuite>
40+
<testsuite name="Mage_AdminNotification">
41+
<directory>tests/unit/Mage/AdminNotification</directory>
42+
</testsuite>
43+
<testsuite name="Mage_Api">
44+
<directory>tests/unit/Mage/Api</directory>
45+
</testsuite>
46+
<testsuite name="Mage_Catalog">
47+
<directory>tests/unit/Mage/Catalog</directory>
48+
</testsuite>
49+
<testsuite name="Mage_Cms">
50+
<directory>tests/unit/Mage/Cms</directory>
51+
</testsuite>
52+
<testsuite name="Mage_Contacts">
53+
<directory>tests/unit/Mage/Contacts</directory>
54+
</testsuite>
55+
<testsuite name="Mage_Core">
56+
<directory>tests/unit/Mage/Core</directory>
57+
</testsuite>
58+
<testsuite name="Mage_Customer">
59+
<directory>tests/unit/Mage/Customer</directory>
60+
</testsuite>
61+
<testsuite name="Mage_Directory">
62+
<directory>tests/unit/Mage/Directory</directory>
63+
</testsuite>
64+
<testsuite name="Mage_Downloadable">
65+
<directory>tests/unit/Mage/Downloadable</directory>
66+
</testsuite>
67+
<testsuite name="Mage_Eav">
68+
<directory>tests/unit/Mage/Eav</directory>
69+
</testsuite>
70+
<testsuite name="Mage_GiftMessage">
71+
<directory>tests/unit/Mage/GiftMessage</directory>
72+
</testsuite>
73+
<testsuite name="Mage_Index">
74+
<directory>tests/unit/Mage/Index</directory>
75+
</testsuite>
76+
<testsuite name="Mage_Log">
77+
<directory>tests/unit/Mage/Log</directory>
78+
</testsuite>
79+
<testsuite name="Mage_Newsletter">
80+
<directory>tests/unit/Mage/Newsletter</directory>
81+
</testsuite>
82+
<testsuite name="Mage_Page">
83+
<directory>tests/unit/Mage/Page</directory>
84+
</testsuite>
85+
<testsuite name="Mage_Reports">
86+
<directory>tests/unit/Mage/Reports</directory>
87+
</testsuite>
88+
<testsuite name="Mage_Review">
89+
<directory>tests/unit/Mage/Review</directory>
90+
</testsuite>
91+
<testsuite name="Mage_Rule">
92+
<directory>tests/unit/Mage/Rule</directory>
93+
</testsuite>
94+
<testsuite name="Mage_Sales">
95+
<directory>tests/unit/Mage/Sales</directory>
96+
</testsuite>
97+
<testsuite name="Mage_Sitemap">
98+
<directory>tests/unit/Mage/Sitemap</directory>
99+
</testsuite>
100+
<testsuite name="Mage_Tax">
101+
<directory>tests/unit/Mage/Tax</directory>
102+
</testsuite>
103+
<testsuite name="Mage_Uploader">
104+
<directory>tests/unit/Mage/Uploader</directory>
105+
</testsuite>
106+
<testsuite name="Mage_Wishlist">
107+
<directory>tests/unit/Mage/Wishlist</directory>
108+
</testsuite>
34109
<testsuite name="Varien">
35110
<directory>tests/unit/Varien</directory>
36111
</testsuite>

.rector.php

+3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Rector\Php82\Rector as Php82;
1818
use Rector\Php83\Rector as Php83;
1919
use Rector\Php84\Rector as Php84;
20+
use Rector\PHPUnit\CodeQuality\Rector\Class_\PreferPHPUnitThisCallRector;
2021
use Rector\TypeDeclaration\Rector as TypeDeclaration;
2122

2223
try {
@@ -49,6 +50,8 @@
4950
Php80\Class_\ClassPropertyAssignToConstructorPromotionRector::class, # todo: wait for php80
5051
Php80\Class_\StringableForToStringRector::class, # todo: wait for php80
5152
TypeDeclaration\ClassMethod\ReturnNeverTypeRector::class,
53+
# use static methods
54+
PreferPHPUnitThisCallRector::class,
5255
__DIR__ . '/shell/translations.php',
5356
__DIR__ . '/shell/update-copyright.php',
5457
__DIR__ . '/tests/unit/Mage/Reports/Model/Resource/Report/CollectionTest.php',

Makefile

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
mkdocs-serve:
2+
@if command -v mkdocs >/dev/null ; then \
3+
mkdocs serve; \
4+
else \
5+
echo "mkdocs is not installed, see https://docs.openmage.org/developers/mkdocs/" && exit 2; \
6+
fi; \
7+
8+
phpunit-serve:
9+
@if test -f build/coverage/index.html ; then \
10+
xdg-open build/coverage/index.html; \
11+
else \
12+
echo "phpunit coverage not found, run \"composer run phpunit:coverage-local\"" && exit 2; \
13+
fi; \

app/code/core/Mage/Adminhtml/Block/Cache/Grid.php

+6-7
Original file line numberDiff line numberDiff line change
@@ -107,15 +107,14 @@ public function decorateStatus($value, $row, $column, $isExport)
107107
{
108108
$class = '';
109109
if (isset($this->_invalidatedTypes[$row->getId()])) {
110-
$cell = '<span class="grid-severity-minor"><span>' . $this->__('Invalidated') . '</span></span>';
110+
$class = self::CSS_SEVERITY_MINOR;
111+
$value = $this->__('Invalidated');
112+
} elseif ($row->getStatus()) {
113+
$class = self::CSS_SEVERITY_NOTICE;
111114
} else {
112-
if ($row->getStatus()) {
113-
$cell = '<span class="grid-severity-notice"><span>' . $value . '</span></span>';
114-
} else {
115-
$cell = '<span class="grid-severity-critical"><span>' . $value . '</span></span>';
116-
}
115+
$class = self::CSS_SEVERITY_CRITICAL;
117116
}
118-
return $cell;
117+
return sprintf(self::PATTERN_SEVERITY, $class, $value);
119118
}
120119

121120
/**

app/code/core/Mage/Adminhtml/Block/Permissions/OrphanedResource/Grid.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
* @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
1616
*/
1717

18+
use Mage_Adminhtml_Block_Widget_Grid_Massaction_Abstract as MassAction;
19+
1820
/**
1921
* Adminhtml permissions orphanedResource grid
2022
*
@@ -75,7 +77,7 @@ protected function _prepareMassaction()
7577
$this->setMassactionIdField('resource_id');
7678
$this->getMassactionBlock()->setFormFieldName('resource_id');
7779

78-
$this->getMassactionBlock()->addItem('delete', [
80+
$this->getMassactionBlock()->addItem(MassAction::DELETE, [
7981
'label' => Mage::helper('adminhtml')->__('Delete'),
8082
'url' => $this->getUrl('*/*/massDelete'),
8183
'confirm' => Mage::helper('adminhtml')->__('Are you sure you want to do this?'),

app/code/core/Mage/Adminhtml/Block/Widget/Grid.php

+6
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@
2525
*/
2626
class Mage_Adminhtml_Block_Widget_Grid extends Mage_Adminhtml_Block_Widget
2727
{
28+
public const PATTERN_SEVERITY = '<span class="%s"><span>%s</span></span>';
29+
public const CSS_SEVERITY_CRITICAL = 'grid-severity-critical';
30+
public const CSS_SEVERITY_MAJOR = 'grid-severity-major';
31+
public const CSS_SEVERITY_MINOR = 'grid-severity-minor';
32+
public const CSS_SEVERITY_NOTICE = 'grid-severity-notice';
33+
2834
/**
2935
* Columns array
3036
*

app/code/core/Mage/Cms/Block/Widget/Page/Link.php

+20-6
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ public function getHref()
6868
* as parameter or retrieve page title from DB using passed identifier or page id.
6969
*
7070
* @return string
71+
* @throws Mage_Core_Model_Store_Exception
7172
*/
7273
public function getTitle()
7374
{
@@ -77,10 +78,9 @@ public function getTitle()
7778
// compare to null used here bc user can specify blank title
7879
$this->_title = $this->getData('title');
7980
} elseif ($this->getData('page_id')) {
80-
$this->_title = Mage::getResourceSingleton('cms/page')->getCmsPageTitleById($this->getData('page_id'));
81+
$this->_title = $this->getCmsPageTitleById($this->getData('page_id'));
8182
} elseif ($this->getData('href')) {
82-
$this->_title = Mage::getResourceSingleton('cms/page')->setStore(Mage::app()->getStore())
83-
->getCmsPageTitleByIdentifier($this->getData('href'));
83+
$this->_title = $this->getCmsPageTitleByIdentifier($this->getData('href'));
8484
}
8585
}
8686

@@ -93,6 +93,7 @@ public function getTitle()
9393
* if title will be blank string, page identifier will be used.
9494
*
9595
* @return string
96+
* @throws Mage_Core_Model_Store_Exception
9697
*/
9798
public function getAnchorText()
9899
{
@@ -101,14 +102,27 @@ public function getAnchorText()
101102
} elseif ($this->getTitle()) {
102103
$this->_anchorText = $this->getTitle();
103104
} elseif ($this->getData('href')) {
104-
$this->_anchorText = Mage::getResourceSingleton('cms/page')->setStore(Mage::app()->getStore())
105-
->getCmsPageTitleByIdentifier($this->getData('href'));
105+
$this->_anchorText = $this->getCmsPageTitleByIdentifier($this->getData('href'));
106106
} elseif ($this->getData('page_id')) {
107-
$this->_anchorText = Mage::getResourceSingleton('cms/page')->getCmsPageTitleById($this->getData('page_id'));
107+
$this->_anchorText = $this->getCmsPageTitleById($this->getData('page_id'));
108108
} else {
109109
$this->_anchorText = $this->getData('href');
110110
}
111111

112112
return $this->_anchorText;
113113
}
114+
115+
protected function getCmsPageTitleById(int|string $pageId): string
116+
{
117+
return Mage::getResourceSingleton('cms/page')->getCmsPageTitleById($pageId);
118+
}
119+
120+
/**
121+
* @throws Mage_Core_Model_Store_Exception
122+
*/
123+
protected function getCmsPageTitleByIdentifier(int|string $identifier): string
124+
{
125+
return Mage::getResourceSingleton('cms/page')->setStore(Mage::app()->getStore())
126+
->getCmsPageTitleByIdentifier($identifier);
127+
}
114128
}

app/code/core/Mage/Core/Helper/Array.php

+3-5
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,10 @@ public function mergeRecursiveWithoutOverwriteNumKeys(array $baseArray, array $m
3838
} else {
3939
$baseArray[$key] = $value;
4040
}
41+
} elseif ($key) {
42+
$baseArray[$key] = $value;
4143
} else {
42-
if ($key) {
43-
$baseArray[$key] = $value;
44-
} else {
45-
$baseArray[] = $value;
46-
}
44+
$baseArray[] = $value;
4745
}
4846
}
4947

app/code/core/Mage/Index/Block/Adminhtml/Process/Grid.php

+10-8
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public function __construct()
5252
* Prepare grid collection
5353
*
5454
* @return $this
55+
* @throws Exception
5556
*/
5657
protected function _prepareCollection()
5758
{
@@ -66,6 +67,7 @@ protected function _prepareCollection()
6667
* Add name and description to collection elements
6768
*
6869
* @return $this
70+
* @throws Mage_Core_Exception
6971
*/
7072
protected function _afterLoadCollection()
7173
{
@@ -89,10 +91,10 @@ protected function _afterLoadCollection()
8991
* Prepare grid columns
9092
*
9193
* @return $this
94+
* @throws Exception
9295
*/
9396
protected function _prepareColumns()
9497
{
95-
$baseUrl = $this->getUrl();
9698
$this->addColumn('indexer_code', [
9799
'header' => Mage::helper('index')->__('Index'),
98100
'width' => '180',
@@ -183,16 +185,16 @@ public function decorateStatus($value, $row, $column, $isExport)
183185
$class = '';
184186
switch ($row->getStatus()) {
185187
case Mage_Index_Model_Process::STATUS_PENDING:
186-
$class = 'grid-severity-notice';
188+
$class = self::CSS_SEVERITY_NOTICE;
187189
break;
188190
case Mage_Index_Model_Process::STATUS_RUNNING:
189-
$class = 'grid-severity-major';
191+
$class = self::CSS_SEVERITY_MAJOR;
190192
break;
191193
case Mage_Index_Model_Process::STATUS_REQUIRE_REINDEX:
192-
$class = 'grid-severity-critical';
194+
$class = self::CSS_SEVERITY_CRITICAL;
193195
break;
194196
}
195-
return '<span class="' . $class . '"><span>' . $value . '</span></span>';
197+
return sprintf(self::PATTERN_SEVERITY, $class, $value);
196198
}
197199

198200
/**
@@ -210,13 +212,13 @@ public function decorateUpdateRequired($value, $row, $column, $isExport)
210212
$class = '';
211213
switch ($row->getUpdateRequired()) {
212214
case 0:
213-
$class = 'grid-severity-notice';
215+
$class = self::CSS_SEVERITY_NOTICE;
214216
break;
215217
case 1:
216-
$class = 'grid-severity-critical';
218+
$class = self::CSS_SEVERITY_CRITICAL;
217219
break;
218220
}
219-
return '<span class="' . $class . '"><span>' . $value . '</span></span>';
221+
return sprintf(self::PATTERN_SEVERITY, $class, $value);
220222
}
221223

222224
/**

app/code/core/Mage/Index/Model/Indexer.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public function getProcessesCollection()
8484
* Get index process by specific id
8585
*
8686
* @param int $processId
87-
* @return Mage_Index_Model_Process | false
87+
* @return Mage_Index_Model_Process|false
8888
*/
8989
public function getProcessById($processId)
9090
{

app/code/core/Mage/Index/Model/Process.php

+6
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
* @method string getIndexCode()
2424
* @method string getIndexerCode()
2525
* @method $this setIndexerCode(string $value)
26+
* @method string getName()
27+
* @method $this setName(string $value)
28+
* @method string getDescription()
29+
* @method $this setDescription(string $value)
2630
* @method string getStatus()
2731
* @method $this setStatus(string $value)
2832
* @method string getStartedAt()
@@ -33,6 +37,8 @@
3337
* @method $this setMode(string $value)
3438
* @method bool getForcePartialReindex()
3539
* @method $this setForcePartialReindex(bool $value)
40+
* @method int getUpdateRequired()
41+
* @method $this setUpdateRequired(int $value)
3642
*/
3743
class Mage_Index_Model_Process extends Mage_Core_Model_Abstract
3844
{

app/code/core/Mage/Reports/Model/Resource/Report/Collection.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class Mage_Reports_Model_Resource_Report_Collection
3939
/**
4040
* Report period
4141
*
42-
* @var int
42+
* @var string
4343
*/
4444
protected $_period;
4545

@@ -76,7 +76,7 @@ protected function _construct() {}
7676
/**
7777
* Set period
7878
*
79-
* @param int $period
79+
* @param string $period
8080
* @return $this
8181
*/
8282
public function setPeriod($period)

0 commit comments

Comments
 (0)