Skip to content

Commit

Permalink
sonar-2
Browse files Browse the repository at this point in the history
  • Loading branch information
sreichel committed Jan 15, 2025
1 parent 726fd27 commit 12c1909
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 27 deletions.
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
65 changes: 49 additions & 16 deletions tests/unit/Mage/Index/Model/ProcessTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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');
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/Mage/Reports/Helper/DataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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));
}
Expand All @@ -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));
}
Expand All @@ -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(''));
}
Expand Down
10 changes: 6 additions & 4 deletions tests/unit/Mage/Rule/Model/AbstractTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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());
}
}

Expand All @@ -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());
}
}

Expand Down Expand Up @@ -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());
}

}
Expand All @@ -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));
Expand Down
6 changes: 4 additions & 2 deletions tests/unit/Mage/Tax/Helper/DataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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());
}
Expand All @@ -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());
}
Expand Down

0 comments on commit 12c1909

Please sign in to comment.