Skip to content

Commit eb0e774

Browse files
authored
PhpUnit: updated and added tests (#4454)
* bumped version * updated tests * composer update * public properties * ignore skipped tests * cs * rector - ignore test * updated test data provider * typo [skip ci] * typo [skip ci] * ignore test * updated test * phpstan baseline * updated test * updated test, ref #4453 * removed test, ref #4308 * updated test * skip test for php8.3 - ref Shardj/zf1-future#465 * skip test for php8.3 - ref Shardj/zf1-future#465 * workflow fix * sonar-1 * sonar-2 * updated tests * added phpstan/phpstan-phpunit * updated php-cs-fixer config * phpstan * rector config * fixes tests * fixes tests typo
1 parent 9bdf9ec commit eb0e774

File tree

119 files changed

+2200
-844
lines changed

Some content is hidden

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

119 files changed

+2200
-844
lines changed

.ddev/commands/web/phpunit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
## Usage: phpunit
55
## Example: ddev phpunit
66

7-
php vendor/bin/phpunit --configuration .phpunit.dist.xml --no-coverage "$@" --testdox
7+
php vendor/bin/phpunit --configuration .phpunit.dist.xml --no-coverage "$@"

.ddev/commands/web/phpunit-coverage-local

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
## Example: ddev phpunit-coverage-local
66

77
enable_xdebug
8-
XDEBUG_MODE=coverage php vendor/bin/phpunit --configuration .phpunit.dist.xml --coverage-html build/coverage --testdox "$@"
8+
XDEBUG_MODE=coverage php vendor/bin/phpunit --configuration .phpunit.dist.xml --coverage-html build/coverage "$@"
99
disable_xdebug

.php-cs-fixer.dist.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
'modernize_types_casting' => true,
1717
// PHP84: Adds or removes ? before single type declarations or |null at the end of union types when parameters have a default null value.
1818
'nullable_type_declaration_for_default_null_value' => true,
19+
// Calls to PHPUnit\Framework\TestCase static methods must all be of the same type, either $this->, self:: or static::
20+
'php_unit_test_case_static_method_calls' => ['call_type' => 'this'],
1921
// Convert double quotes to single quotes for simple strings.
2022
'single_quote' => true,
2123
// Arguments lists, array destructuring lists, arrays that are multi-line, match-lines and parameters lists must have a trailing comma.

.phpstan.dist.baseline.neon

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5070,18 +5070,6 @@ parameters:
50705070
count: 1
50715071
path: app/code/core/Mage/Reports/Block/Product/Abstract.php
50725072

5073-
-
5074-
message: '#^Variable \$dateStart might not be defined\.$#'
5075-
identifier: variable.undefined
5076-
count: 7
5077-
path: app/code/core/Mage/Reports/Helper/Data.php
5078-
5079-
-
5080-
message: '#^Variable \$t might not be defined\.$#'
5081-
identifier: variable.undefined
5082-
count: 1
5083-
path: app/code/core/Mage/Reports/Helper/Data.php
5084-
50855073
-
50865074
message: '#^Property Mage_Reports_Model_Grouped_Collection\:\:\$_resourceCollection \(Mage_Core_Model_Resource_Db_Collection_Abstract\) does not accept Varien_Data_Collection_Db\.$#'
50875075
identifier: assign.propertyType

.phpstan.dist.neon

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@ parameters:
152152
- app/design/frontend/rwd/default/template/reports/widget/compared/content/compared_grid.phtml
153153
- app/design/frontend/rwd/default/template/reports/widget/compared/content/compared_list.phtml
154154
- app/design/install/default/default/template/page.phtml
155+
-
156+
identifier: phpunit.coversMethod
155157
tmpDir: .phpstan.cache
156158
level: 5
157159
checkFunctionNameCase: true

.phpunit.dist.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
<env name="NO_XHGUI" value="1"/>
1818
</php>
1919

20+
<extensions>
21+
<extension class="OpenMage\Tests\Unit\LongRunningTestAlert" />
22+
</extensions>
23+
2024
<testsuites>
2125
<testsuite name="Base">
2226
<directory>tests/unit/Base</directory>

.rector.php

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
use Rector\CodeQuality\Rector as CodeQuality;
66
use Rector\DeadCode\Rector as DeadCode;
77
use Rector\Config\RectorConfig;
8+
use Rector\PHPUnit\Set\PHPUnitSetList;
9+
use Rector\Set\ValueObject\SetList;
810
use Rector\TypeDeclaration\Rector as TypeDeclaration;
911

1012
return RectorConfig::configure()
@@ -17,6 +19,11 @@
1719
CodeQuality\If_\SimplifyIfReturnBoolRector::class,
1820
__DIR__ . '/shell/translations.php',
1921
__DIR__ . '/shell/update-copyright.php.php',
22+
__DIR__ . '/tests/unit/Mage/Reports/Model/Resource/Report/CollectionTest.php',
23+
])
24+
->withSets([
25+
PHPUnitSetList::PHPUNIT_90,
26+
SetList::PRIVATIZATION,
2027
])
2128
->withRules([
2229
CodeQuality\BooleanNot\ReplaceMultipleBooleanNotRector::class,
@@ -34,23 +41,4 @@
3441
DeadCode\ClassMethod\RemoveUselessReturnTagRector::class,
3542
DeadCode\Property\RemoveUselessVarTagRector::class,
3643
TypeDeclaration\ClassMethod\ReturnNeverTypeRector::class,
37-
])
38-
->withPreparedSets(
39-
false,
40-
false,
41-
false,
42-
false,
43-
true,
44-
false,
45-
false,
46-
false,
47-
false,
48-
false,
49-
false,
50-
true,
51-
false,
52-
false,
53-
false,
54-
false,
55-
true,
56-
);
44+
]);

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ public function reindexAll()
219219
* Check and using depends processes
220220
*
221221
* @return $this
222+
* @throws Exception
222223
*/
223224
public function reindexEverything()
224225
{
@@ -282,6 +283,7 @@ public function processEvent(Mage_Index_Model_Event $event)
282283
* Get Indexer strategy object
283284
*
284285
* @return Mage_Index_Model_Indexer_Abstract
286+
* @throws Mage_Core_Exception
285287
*/
286288
public function getIndexer()
287289
{
@@ -561,6 +563,7 @@ public function setAllowTableChanges($value = true)
561563
* Disable keys in index table
562564
*
563565
* @return $this
566+
* @throws Mage_Core_Exception
564567
*/
565568
public function disableIndexerKeys()
566569
{
@@ -575,6 +578,7 @@ public function disableIndexerKeys()
575578
* Enable keys in index table
576579
*
577580
* @return $this
581+
* @throws Mage_Core_Exception
578582
*/
579583
public function enableIndexerKeys()
580584
{

app/code/core/Mage/Reports/Helper/Data.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,15 @@ public function isReportsEnabled()
4444
*
4545
* @param string $from
4646
* @param string $to
47-
* @param string $period
47+
* @param self::REPORT_PERIOD_TYPE_* $period
4848
* @return array
49+
* @throws Zend_Date_Exception
4950
*/
5051
public function getIntervals($from, $to, $period = self::REPORT_PERIOD_TYPE_DAY)
5152
{
5253
$intervals = [];
54+
$dateStart = null;
55+
5356
if (!$from && !$to) {
5457
return $intervals;
5558
}
@@ -68,24 +71,29 @@ public function getIntervals($from, $to, $period = self::REPORT_PERIOD_TYPE_DAY)
6871
$dateStart = new Zend_Date(date('Y', $start->getTimestamp()), Varien_Date::DATE_INTERNAL_FORMAT);
6972
}
7073

74+
if (!$period || !$dateStart) {
75+
return $intervals;
76+
}
77+
7178
$dateEnd = new Zend_Date($to, Varien_Date::DATE_INTERNAL_FORMAT);
7279

7380
while ($dateStart->compare($dateEnd) <= 0) {
81+
$time = '';
7482
switch ($period) {
7583
case self::REPORT_PERIOD_TYPE_DAY:
76-
$t = $dateStart->toString('yyyy-MM-dd');
84+
$time = $dateStart->toString('yyyy-MM-dd');
7785
$dateStart->addDay(1);
7886
break;
7987
case self::REPORT_PERIOD_TYPE_MONTH:
80-
$t = $dateStart->toString('yyyy-MM');
88+
$time = $dateStart->toString('yyyy-MM');
8189
$dateStart->addMonth(1);
8290
break;
8391
case self::REPORT_PERIOD_TYPE_YEAR:
84-
$t = $dateStart->toString('yyyy');
92+
$time = $dateStart->toString('yyyy');
8593
$dateStart->addYear(1);
8694
break;
8795
}
88-
$intervals[] = $t;
96+
$intervals[] = $time;
8997
}
9098
return $intervals;
9199
}

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -116,24 +116,24 @@ public function getIntervals()
116116
$dateStart = new Zend_Date($this->_from);
117117
$dateEnd = new Zend_Date($this->_to);
118118

119-
$t = [];
119+
$time = [];
120120
$firstInterval = true;
121121
while ($dateStart->compare($dateEnd) <= 0) {
122122
switch ($this->_period) {
123-
case 'day':
124-
$t['title'] = $dateStart->toString(Mage::app()->getLocale()->getDateFormat());
125-
$t['start'] = $dateStart->toString('yyyy-MM-dd HH:mm:ss');
126-
$t['end'] = $dateStart->toString('yyyy-MM-dd 23:59:59');
123+
case Mage_Reports_Helper_Data::REPORT_PERIOD_TYPE_DAY:
124+
$time['title'] = $dateStart->toString(Mage::app()->getLocale()->getDateFormat());
125+
$time['start'] = $dateStart->toString('yyyy-MM-dd HH:mm:ss');
126+
$time['end'] = $dateStart->toString('yyyy-MM-dd 23:59:59');
127127
$dateStart->addDay(1);
128128
break;
129-
case 'month':
130-
$t['title'] = $dateStart->toString('MM/yyyy');
131-
$t['start'] = ($firstInterval) ? $dateStart->toString('yyyy-MM-dd 00:00:00')
129+
case Mage_Reports_Helper_Data::REPORT_PERIOD_TYPE_MONTH:
130+
$time['title'] = $dateStart->toString('MM/yyyy');
131+
$time['start'] = ($firstInterval) ? $dateStart->toString('yyyy-MM-dd 00:00:00')
132132
: $dateStart->toString('yyyy-MM-01 00:00:00');
133133

134134
$lastInterval = ($dateStart->compareMonth($dateEnd->getMonth()) == 0);
135135

136-
$t['end'] = ($lastInterval) ? $dateStart->setDay($dateEnd->getDay())
136+
$time['end'] = ($lastInterval) ? $dateStart->setDay($dateEnd->getDay())
137137
->toString('yyyy-MM-dd 23:59:59')
138138
: $dateStart->toString('yyyy-MM-' . date('t', $dateStart->getTimestamp()) . ' 23:59:59');
139139

@@ -145,14 +145,14 @@ public function getIntervals()
145145

146146
$firstInterval = false;
147147
break;
148-
case 'year':
149-
$t['title'] = $dateStart->toString('yyyy');
150-
$t['start'] = ($firstInterval) ? $dateStart->toString('yyyy-MM-dd 00:00:00')
148+
case Mage_Reports_Helper_Data::REPORT_PERIOD_TYPE_YEAR:
149+
$time['title'] = $dateStart->toString('yyyy');
150+
$time['start'] = ($firstInterval) ? $dateStart->toString('yyyy-MM-dd 00:00:00')
151151
: $dateStart->toString('yyyy-01-01 00:00:00');
152152

153153
$lastInterval = ($dateStart->compareYear($dateEnd->getYear()) == 0);
154154

155-
$t['end'] = ($lastInterval) ? $dateStart->setMonth($dateEnd->getMonth())
155+
$time['end'] = ($lastInterval) ? $dateStart->setMonth($dateEnd->getMonth())
156156
->setDay($dateEnd->getDay())->toString('yyyy-MM-dd 23:59:59')
157157
: $dateStart->toString('yyyy-12-31 23:59:59');
158158
$dateStart->addYear(1);
@@ -164,7 +164,7 @@ public function getIntervals()
164164
$firstInterval = false;
165165
break;
166166
}
167-
$this->_intervals[$t['title']] = $t;
167+
$this->_intervals[$time['title']] = $time;
168168
}
169169
}
170170
return $this->_intervals;

0 commit comments

Comments
 (0)