From 12c1909ded9481c70361706b986e9d252bb78d51 Mon Sep 17 00:00:00 2001 From: Sven Reichel Date: Wed, 15 Jan 2025 21:52:41 +0100 Subject: [PATCH] sonar-2 --- app/code/core/Mage/Index/Model/Process.php | 4 ++ tests/unit/Mage/Index/Model/ProcessTest.php | 65 ++++++++++++++----- tests/unit/Mage/Reports/Helper/DataTest.php | 4 +- .../Model/Resource/Report/CollectionTest.php | 8 ++- tests/unit/Mage/Rule/Model/AbstractTest.php | 10 +-- tests/unit/Mage/Tax/Helper/DataTest.php | 6 +- 6 files changed, 70 insertions(+), 27 deletions(-) diff --git a/app/code/core/Mage/Index/Model/Process.php b/app/code/core/Mage/Index/Model/Process.php index 0021f06b82e..a3a30851dd8 100644 --- a/app/code/core/Mage/Index/Model/Process.php +++ b/app/code/core/Mage/Index/Model/Process.php @@ -219,6 +219,7 @@ public function reindexAll() * Check and using depends processes * * @return $this + * @throws Exception */ public function reindexEverything() { @@ -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() { @@ -561,6 +563,7 @@ public function setAllowTableChanges($value = true) * Disable keys in index table * * @return $this + * @throws Mage_Core_Exception */ public function disableIndexerKeys() { @@ -575,6 +578,7 @@ public function disableIndexerKeys() * Enable keys in index table * * @return $this + * @throws Mage_Core_Exception */ public function enableIndexerKeys() { diff --git a/tests/unit/Mage/Index/Model/ProcessTest.php b/tests/unit/Mage/Index/Model/ProcessTest.php index 298200f3ca5..874eeb06b25 100644 --- a/tests/unit/Mage/Index/Model/ProcessTest.php +++ b/tests/unit/Mage/Index/Model/ProcessTest.php @@ -18,12 +18,15 @@ namespace OpenMage\Tests\Unit\Mage\Index\Model; use Mage; +use Mage_Core_Exception; use Mage_Index_Model_Process as Subject; use Mage_Index_Model_Resource_Event_Collection; use PHPUnit\Framework\TestCase; class ProcessTest extends TestCase { + public const INDEXER_MODEL_IS_NOT_DEFINED = 'Indexer model is not defined.'; + public Subject $subject; public function setUp(): void @@ -33,25 +36,55 @@ public function setUp(): void } /** - * * @group Mage_Index * @group Mage_Index_Model */ - // public function testReindexEverything(): void - // { - // $this->subject->setIndexerCode('html'); - // $this->assertInstanceOf(Mage_Index_Model_Process::class, $this->subject->reindexEverything()); - // } - // public function testDisableIndexerKeys(): void - // { - // $this->subject->setIndexerCode('html'); - // $this->assertInstanceOf(Mage_Index_Model_Process::class, $this->subject->disableIndexerKeys()); - // } - // public function testEnableIndexerKeys(): void - // { - // $this->subject->setIndexerCode('html'); - // $this->assertInstanceOf(Mage_Index_Model_Process::class, $this->subject->enableIndexerKeys()); - // } + public function testReindexEverything(): void + { + $this->subject->setIndexerCode('html'); + + try { + $this->assertInstanceOf(Subject::class, $this->subject->reindexEverything()); + } catch (Mage_Core_Exception $exception) { + $this->assertSame(self::INDEXER_MODEL_IS_NOT_DEFINED, $exception->getMessage()); + } + } + + /** + * @group Mage_Index + * @group Mage_Index_Model + */ + public function testDisableIndexerKeys(): void + { + $this->subject->setIndexerCode('html'); + + try { + $this->assertInstanceOf(Subject::class, $this->subject->disableIndexerKeys()); + } catch (Mage_Core_Exception $exception) { + $this->assertSame(self::INDEXER_MODEL_IS_NOT_DEFINED, $exception->getMessage()); + } + + } + + /** + * @group Mage_Index + * @group Mage_Index_Model + */ + public function testEnableIndexerKeys(): void + { + $this->subject->setIndexerCode('html'); + + try { + $this->assertInstanceOf(Subject::class, $this->subject->enableIndexerKeys()); + } catch (Mage_Core_Exception $exception) { + $this->assertSame(self::INDEXER_MODEL_IS_NOT_DEFINED, $exception->getMessage()); + } + } + + /** + * @group Mage_Index + * @group Mage_Index_Model + */ public function testGetUnprocessedEventsCollection(): void { $this->subject->setIndexerCode('html'); diff --git a/tests/unit/Mage/Reports/Helper/DataTest.php b/tests/unit/Mage/Reports/Helper/DataTest.php index da9a77ffa87..6407fab46bb 100644 --- a/tests/unit/Mage/Reports/Helper/DataTest.php +++ b/tests/unit/Mage/Reports/Helper/DataTest.php @@ -66,7 +66,7 @@ public function testIsReportsEnabled(): void public function testGetIntervals($expectedResult, $from, $to, $period): void { if (PHP_VERSION_ID >= 80300 && version_compare(InstalledVersions::getPrettyVersion('shardj/zf1-future'), '1.24.2', '<=')) { - $this->markTestSkipped(); + $this->markTestSkipped('see https://github.com/Shardj/zf1-future/pull/465'); } try { @@ -85,7 +85,7 @@ public function testGetIntervals($expectedResult, $from, $to, $period): void */ public function testPrepareIntervalsCollection($expectedResult, $from, $to, $period): void { - $this->markTestIncomplete(); + $this->markTestIncomplete('Test needs to be reviewed.'); // @phpstan-ignore-next-line $this->subject->prepareIntervalsCollection(new Varien_Data_Collection(), $from, $to, $period); } diff --git a/tests/unit/Mage/Reports/Model/Resource/Report/CollectionTest.php b/tests/unit/Mage/Reports/Model/Resource/Report/CollectionTest.php index 1e57a1b8088..dc6ab6340da 100644 --- a/tests/unit/Mage/Reports/Model/Resource/Report/CollectionTest.php +++ b/tests/unit/Mage/Reports/Model/Resource/Report/CollectionTest.php @@ -28,6 +28,8 @@ class CollectionTest extends TestCase { use ReportsTrait; + public const SKIP_INCOMPLETE_MESSAGE = 'Test needs to be reviewed.'; + public Subject $subject; public function setUp(): void @@ -147,7 +149,7 @@ public function testInitReport($modelClass = ''): void */ public function testGetReportFull(): void { - $this->markTestIncomplete(); + $this->markTestIncomplete(self::SKIP_INCOMPLETE_MESSAGE); // @phpstan-ignore-next-line $this->assertInstanceOf(Mage_Reports_Model_Report::class, $this->subject->getReportFull(1, 1)); } @@ -158,7 +160,7 @@ public function testGetReportFull(): void */ public function testGetReport(): void { - $this->markTestIncomplete(); + $this->markTestIncomplete(self::SKIP_INCOMPLETE_MESSAGE); // @phpstan-ignore-next-line $this->assertInstanceOf(Mage_Reports_Model_Report::class, $this->subject->getReport(1, 1)); } @@ -169,7 +171,7 @@ public function testGetReport(): void */ public function testTimeShift(): void { - $this->markTestIncomplete(); + $this->markTestIncomplete(self::SKIP_INCOMPLETE_MESSAGE); // @phpstan-ignore-next-line $this->assertSame($this->subject->timeShift('')); } diff --git a/tests/unit/Mage/Rule/Model/AbstractTest.php b/tests/unit/Mage/Rule/Model/AbstractTest.php index a20121fe0d8..e2adf84cd3b 100644 --- a/tests/unit/Mage/Rule/Model/AbstractTest.php +++ b/tests/unit/Mage/Rule/Model/AbstractTest.php @@ -36,6 +36,8 @@ class AbstractTest extends TestCase use BoolTrait; use RuleTrait; + public const CALL_TO_A_MEMBER_FUNCTION_SET_RULE_ON_NULL = 'Call to a member function setRule() on null'; + public Subject $subject; public function setUp(): void @@ -71,7 +73,7 @@ public function testGetConditions(bool $empty): void try { $this->assertInstanceOf(Mage_Rule_Model_Condition_Combine::class, $this->subject->getConditions()); } catch (Error $error) { - $this->assertSame('Call to a member function setRule() on null', $error->getMessage()); + $this->assertSame(self::CALL_TO_A_MEMBER_FUNCTION_SET_RULE_ON_NULL, $error->getMessage()); } } @@ -89,7 +91,7 @@ public function testGetActions(bool $empty): void try { $this->assertInstanceOf(Mage_Rule_Model_Action_Collection::class, $this->subject->getActions()); } catch (Error $error) { - $this->assertSame('Call to a member function setRule() on null', $error->getMessage()); + $this->assertSame(self::CALL_TO_A_MEMBER_FUNCTION_SET_RULE_ON_NULL, $error->getMessage()); } } @@ -123,7 +125,7 @@ public function testValidate($expectedResul, ?array $data = null): void try { $this->assertSame($expectedResul, $this->subject->validate($object)); } catch (Error $error) { - $this->assertSame('Call to a member function setRule() on null', $error->getMessage()); + $this->assertSame(self::CALL_TO_A_MEMBER_FUNCTION_SET_RULE_ON_NULL, $error->getMessage()); } } @@ -136,7 +138,7 @@ public function testValidate($expectedResul, ?array $data = null): void public function testValidateData($expectedResul, ?array $data = null): void { if (PHP_VERSION_ID >= 80300 && version_compare(InstalledVersions::getPrettyVersion('shardj/zf1-future'), '1.24.2', '<=')) { - $this->markTestSkipped(); + $this->markTestSkipped('see https://github.com/Shardj/zf1-future/pull/465'); } $object = new Varien_Object($data); $this->assertSame($expectedResul, $this->subject->validateData($object)); diff --git a/tests/unit/Mage/Tax/Helper/DataTest.php b/tests/unit/Mage/Tax/Helper/DataTest.php index 3130b5bad77..c09fa730d57 100644 --- a/tests/unit/Mage/Tax/Helper/DataTest.php +++ b/tests/unit/Mage/Tax/Helper/DataTest.php @@ -28,6 +28,8 @@ class DataTest extends TestCase { public Subject $subject; + public const SKIP_WITH_LOCAL_DATA = 'Constant DATA_MAY_CHANGED is defined.'; + public function setUp(): void { Mage::app(); @@ -159,7 +161,7 @@ public function testGetPriceFormat(): void public function testGetTaxRatesByProductClass(): void { if (defined('DATA_MAY_CHANGED')) { - $this->markTestSkipped(); + $this->markTestSkipped(self::SKIP_WITH_LOCAL_DATA); } $this->assertSame('{"value_2":8.25,"value_4":0}', $this->subject->getTaxRatesByProductClass()); } @@ -172,7 +174,7 @@ public function testGetTaxRatesByProductClass(): void public function testGetAllRatesByProductClass(): void { if (defined('DATA_MAY_CHANGED')) { - $this->markTestSkipped(); + $this->markTestSkipped(self::SKIP_WITH_LOCAL_DATA); } $this->assertSame('{"value_2":8.25,"value_4":0}', $this->subject->getAllRatesByProductClass()); }