Skip to content

Commit

Permalink
PhpUnit: updated and added tests (#4454)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
sreichel authored Feb 6, 2025
1 parent 9bdf9ec commit eb0e774
Show file tree
Hide file tree
Showing 119 changed files with 2,200 additions and 844 deletions.
2 changes: 1 addition & 1 deletion .ddev/commands/web/phpunit
Original file line number Diff line number Diff line change
Expand Up @@ -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 "$@"
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 --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
2 changes: 2 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
'modernize_types_casting' => true,
// PHP84: Adds or removes ? before single type declarations or |null at the end of union types when parameters have a default null value.
'nullable_type_declaration_for_default_null_value' => true,
// Calls to PHPUnit\Framework\TestCase static methods must all be of the same type, either $this->, self:: or static::
'php_unit_test_case_static_method_calls' => ['call_type' => 'this'],
// Convert double quotes to single quotes for simple strings.
'single_quote' => true,
// Arguments lists, array destructuring lists, arrays that are multi-line, match-lines and parameters lists must have a trailing comma.
Expand Down
12 changes: 0 additions & 12 deletions .phpstan.dist.baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -5070,18 +5070,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
Expand Down
2 changes: 2 additions & 0 deletions .phpstan.dist.neon
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ parameters:
- app/design/frontend/rwd/default/template/reports/widget/compared/content/compared_grid.phtml
- app/design/frontend/rwd/default/template/reports/widget/compared/content/compared_list.phtml
- app/design/install/default/default/template/page.phtml
-
identifier: phpunit.coversMethod
tmpDir: .phpstan.cache
level: 5
checkFunctionNameCase: true
Expand Down
4 changes: 4 additions & 0 deletions .phpunit.dist.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
<env name="NO_XHGUI" value="1"/>
</php>

<extensions>
<extension class="OpenMage\Tests\Unit\LongRunningTestAlert" />
</extensions>

<testsuites>
<testsuite name="Base">
<directory>tests/unit/Base</directory>
Expand Down
28 changes: 8 additions & 20 deletions .rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
use Rector\CodeQuality\Rector as CodeQuality;
use Rector\DeadCode\Rector as DeadCode;
use Rector\Config\RectorConfig;
use Rector\PHPUnit\Set\PHPUnitSetList;
use Rector\Set\ValueObject\SetList;
use Rector\TypeDeclaration\Rector as TypeDeclaration;

return RectorConfig::configure()
Expand All @@ -17,6 +19,11 @@
CodeQuality\If_\SimplifyIfReturnBoolRector::class,
__DIR__ . '/shell/translations.php',
__DIR__ . '/shell/update-copyright.php.php',
__DIR__ . '/tests/unit/Mage/Reports/Model/Resource/Report/CollectionTest.php',
])
->withSets([
PHPUnitSetList::PHPUNIT_90,
SetList::PRIVATIZATION,
])
->withRules([
CodeQuality\BooleanNot\ReplaceMultipleBooleanNotRector::class,
Expand All @@ -34,23 +41,4 @@
DeadCode\ClassMethod\RemoveUselessReturnTagRector::class,
DeadCode\Property\RemoveUselessVarTagRector::class,
TypeDeclaration\ClassMethod\ReturnNeverTypeRector::class,
])
->withPreparedSets(
false,
false,
false,
false,
true,
false,
false,
false,
false,
false,
false,
true,
false,
false,
false,
false,
true,
);
]);
4 changes: 4 additions & 0 deletions app/code/core/Mage/Index/Model/Process.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ public function reindexAll()
* Check and using depends processes
*
* @return $this
* @throws Exception
*/
public function reindexEverything()
{
Expand Down Expand Up @@ -282,6 +283,7 @@ public function processEvent(Mage_Index_Model_Event $event)
* Get Indexer strategy object
*
* @return Mage_Index_Model_Indexer_Abstract
* @throws Mage_Core_Exception
*/
public function getIndexer()
{
Expand Down Expand Up @@ -561,6 +563,7 @@ public function setAllowTableChanges($value = true)
* Disable keys in index table
*
* @return $this
* @throws Mage_Core_Exception
*/
public function disableIndexerKeys()
{
Expand All @@ -575,6 +578,7 @@ public function disableIndexerKeys()
* Enable keys in index table
*
* @return $this
* @throws Mage_Core_Exception
*/
public function enableIndexerKeys()
{
Expand Down
18 changes: 13 additions & 5 deletions app/code/core/Mage/Reports/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,15 @@ public function isReportsEnabled()
*
* @param string $from
* @param string $to
* @param string $period
* @param self::REPORT_PERIOD_TYPE_* $period
* @return array
* @throws Zend_Date_Exception
*/
public function getIntervals($from, $to, $period = self::REPORT_PERIOD_TYPE_DAY)
{
$intervals = [];
$dateStart = null;

if (!$from && !$to) {
return $intervals;
}
Expand All @@ -68,24 +71,29 @@ public function getIntervals($from, $to, $period = self::REPORT_PERIOD_TYPE_DAY)
$dateStart = new Zend_Date(date('Y', $start->getTimestamp()), Varien_Date::DATE_INTERNAL_FORMAT);
}

if (!$period || !$dateStart) {
return $intervals;
}

$dateEnd = new Zend_Date($to, Varien_Date::DATE_INTERNAL_FORMAT);

while ($dateStart->compare($dateEnd) <= 0) {
$time = '';
switch ($period) {
case self::REPORT_PERIOD_TYPE_DAY:
$t = $dateStart->toString('yyyy-MM-dd');
$time = $dateStart->toString('yyyy-MM-dd');
$dateStart->addDay(1);
break;
case self::REPORT_PERIOD_TYPE_MONTH:
$t = $dateStart->toString('yyyy-MM');
$time = $dateStart->toString('yyyy-MM');
$dateStart->addMonth(1);
break;
case self::REPORT_PERIOD_TYPE_YEAR:
$t = $dateStart->toString('yyyy');
$time = $dateStart->toString('yyyy');
$dateStart->addYear(1);
break;
}
$intervals[] = $t;
$intervals[] = $time;
}
return $intervals;
}
Expand Down
28 changes: 14 additions & 14 deletions app/code/core/Mage/Reports/Model/Resource/Report/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand All @@ -145,14 +145,14 @@ public function getIntervals()

$firstInterval = false;
break;
case 'year':
$t['title'] = $dateStart->toString('yyyy');
$t['start'] = ($firstInterval) ? $dateStart->toString('yyyy-MM-dd 00:00:00')
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);
Expand All @@ -164,7 +164,7 @@ public function getIntervals()
$firstInterval = false;
break;
}
$this->_intervals[$t['title']] = $t;
$this->_intervals[$time['title']] = $time;
}
}
return $this->_intervals;
Expand Down
21 changes: 15 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,11 @@
"perftools/php-profiler": "^1.1",
"phpcompatibility/php-compatibility": "^9.3",
"phpmd/phpmd": "^2.13",
"phpstan/extension-installer": "^1.4",
"phpstan/phpstan": "^2.1",
"phpstan/phpstan-phpunit": "^2.0",
"phpunit/phpunit": "^9.6",
"rector/rector": "^2.0.5",
"rector/rector": "^2.0",
"squizlabs/php_codesniffer": "^3.7",
"symplify/vendor-patches": "^11.1"
},
Expand Down Expand Up @@ -135,7 +137,8 @@
"cweagans/composer-patches": true,
"dealerdirect/phpcodesniffer-composer-installer": true,
"magento-hackathon/magento-composer-installer": true,
"openmage/composer-plugin": true
"openmage/composer-plugin": true,
"phpstan/extension-installer": true
},
"platform": {
"php": "7.4"
Expand All @@ -148,11 +151,16 @@
"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"
"rector:fix": "vendor/bin/rector --config .rector.php process",
"test": [
"@php-cs-fixer:test",
"@phpstan",
"@phpunit:test"
]
},
"scripts-descriptions": {
"php-cs-fixer:test": "Run php-cs-fixer",
Expand All @@ -164,6 +172,7 @@
"phpunit:coverage": "Run PHPUnit with code coverage (requires XDEBUG enabled)",
"phpunit:coverage-local": "Run PHPUnit with local HTML code coverage (requires XDEBUG enabled)",
"rector:test": "Run rector",
"rector:fix": "Run rector and fix issues"
"rector:fix": "Run rector and fix issues",
"test": "Run php-cs-fixer, phpstan & phpunit"
}
}
Loading

0 comments on commit eb0e774

Please sign in to comment.