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

PhpUnit: updated and added tests #4454

Open
wants to merge 34 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
ee90d05
bumped version
sreichel Jan 1, 2025
c21fe6b
updated tests
sreichel Jan 4, 2025
61dd0f6
Merge branch 'main' into phpunit-dates
sreichel Jan 6, 2025
69e65f4
composer update
sreichel Jan 6, 2025
15eb86a
public properties
sreichel Jan 6, 2025
4656238
ignore skipped tests
sreichel Jan 6, 2025
d66a185
cs
sreichel Jan 6, 2025
a95e16b
rector - ignore test
sreichel Jan 8, 2025
3bd4bdf
updated test data provider
sreichel Jan 8, 2025
27f771f
typo [skip ci]
sreichel Jan 8, 2025
f920e44
typo [skip ci]
sreichel Jan 8, 2025
7428edf
Merge remote-tracking branch 'origin/phpunit-dates' into phpunit-dates
sreichel Jan 8, 2025
d0cbc75
ignore test
sreichel Jan 8, 2025
053f670
updated test
sreichel Jan 8, 2025
ded5b56
phpstan baseline
sreichel Jan 8, 2025
0b69d02
updated test
sreichel Jan 8, 2025
cb2b0f6
updated test, ref #4453
sreichel Jan 8, 2025
c2b87c9
removed test, ref #4308
sreichel Jan 8, 2025
00325ee
updated test
sreichel Jan 8, 2025
601c4b0
skip test for php8.3
sreichel Jan 8, 2025
2577267
skip test for php8.3
sreichel Jan 9, 2025
38144fb
workflow fix
sreichel Jan 9, 2025
26c085f
Merge branch 'main' into phpunit-dates
sreichel Jan 15, 2025
726fd27
sonar-1
sreichel Jan 15, 2025
12c1909
sonar-2
sreichel Jan 15, 2025
c18ea6b
Merge branch 'main' into phpunit-dates
sreichel Jan 15, 2025
b18cebd
updated tests
sreichel Jan 15, 2025
1417edb
added phpstan/phpstan-phpunit
sreichel Jan 15, 2025
2b55594
updated php-cs-fixer config
sreichel Jan 15, 2025
c8b2f4f
phpstan
sreichel Jan 15, 2025
c3d6876
rector config
sreichel Jan 15, 2025
e3178a4
fixes tests
sreichel Jan 15, 2025
1ad3559
fixes tests typo
sreichel Jan 15, 2025
a7f3d3e
Merge branch 'main' into phpunit-dates
sreichel Jan 18, 2025
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
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 @@ -56,9 +56,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 @@ -134,7 +136,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 @@ -147,11 +150,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 @@ -163,6 +171,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
Loading