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

Rector: updated UnitTests #4391

Merged
merged 6 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
21 changes: 20 additions & 1 deletion .rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,23 @@
DeadCode\ClassMethod\RemoveUselessReturnTagRector::class,
DeadCode\Property\RemoveUselessVarTagRector::class,
TypeDeclaration\ClassMethod\ReturnNeverTypeRector::class,
]);
])
->withPreparedSets(
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
true,
false,
false,
false,
false,
true,
);
12 changes: 4 additions & 8 deletions tests/unit/Base/XmlFileLoadingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

namespace OpenMage\Tests\Unit\Base;

use Generator;
use PHPUnit\Framework\TestCase;
use SimpleXMLElement;
use XMLReader;
Expand Down Expand Up @@ -50,17 +51,12 @@ public function testXmlReaderIsValid(string $filepath): void
$this->assertTrue($xml->isValid());
}

/**
* @return string[][]
*/
public function provideXmlFiles(): array
public function provideXmlFiles(): Generator
{
$root = realpath(__DIR__ . '/../../../') . '/';

return [
'file from vendor directory' => [
$root . 'vendor/shardj/zf1-future/library/Zend/Locale/Data/es_419.xml'
],
yield 'file from vendor directory' => [
$root . 'vendor/shardj/zf1-future/library/Zend/Locale/Data/es_419.xml'
];
}
}
4 changes: 2 additions & 2 deletions tests/unit/Mage/Admin/Model/BlockTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ public function testValidate(array $expectedResult, array $methods): void
])
->getMock();

$mock->expects($this->any())->method('getBlockName')->willReturn($methods['getBlockName']);
$mock->expects($this->any())->method('getIsAllowed')->willReturn($methods['getIsAllowed']);
$mock->method('getBlockName')->willReturn($methods['getBlockName']);
$mock->method('getIsAllowed')->willReturn($methods['getIsAllowed']);
$this->assertEquals($expectedResult, $mock->validate());
}

Expand Down
24 changes: 12 additions & 12 deletions tests/unit/Mage/Admin/Model/UserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ public function testAuthenticate($expectedResult, array $methods): void
])
->getMock();

$mock->expects($this->any())->method('loadByUsername')->willReturnSelf();
$mock->expects($this->any())->method('getId')->willReturn($methods['getId']);
$mock->method('loadByUsername')->willReturnSelf();
$mock->method('getId')->willReturn($methods['getId']);
// $mock->expects($this->any())->method('getUsername')->willReturn($methods['getUsername']);
$mock->expects($this->any())->method('getPassword')->willReturn($methods['getPassword']);
$mock->expects($this->any())->method('validatePasswordHash')->willReturn($methods['validatePasswordHash']);
$mock->expects($this->any())->method('getIsActive')->willReturn($methods['getIsActive']);
$mock->expects($this->any())->method('hasAssigned2Role')->willReturn($methods['hasAssigned2Role']);
$mock->method('getPassword')->willReturn($methods['getPassword']);
$mock->method('validatePasswordHash')->willReturn($methods['validatePasswordHash']);
$mock->method('getIsActive')->willReturn($methods['getIsActive']);
$mock->method('hasAssigned2Role')->willReturn($methods['hasAssigned2Role']);

try {
$this->assertSame($expectedResult, $mock->authenticate($methods['getUsername'], $methods['getPassword']));
Expand Down Expand Up @@ -136,10 +136,10 @@ public function testValidate($expectedResult, array $methods): void
])
->getMock();

$mock->expects($this->any())->method('hasNewPassword')->willReturn($methods['hasNewPassword']);
$mock->expects($this->any())->method('getNewPassword')->willReturn($methods['getNewPassword']);
$mock->expects($this->any())->method('hasPassword')->willReturn($methods['hasPassword']);
$mock->expects($this->any())->method('getPassword')->willReturn($methods['getPassword']);
$mock->method('hasNewPassword')->willReturn($methods['hasNewPassword']);
$mock->method('getNewPassword')->willReturn($methods['getNewPassword']);
$mock->method('hasPassword')->willReturn($methods['hasPassword']);
$mock->method('getPassword')->willReturn($methods['getPassword']);
$this->assertSame($expectedResult, $mock->validate());
}

Expand Down Expand Up @@ -231,8 +231,8 @@ public function testIsResetPasswordLinkTokenExpired(bool $expectedResult, array
])
->getMock();

$mock->expects($this->any())->method('getRpToken')->willReturn($methods['getRpToken']);
$mock->expects($this->any())->method('getRpTokenCreatedAt')->willReturn($methods['getRpTokenCreatedAt']);
$mock->method('getRpToken')->willReturn($methods['getRpToken']);
$mock->method('getRpTokenCreatedAt')->willReturn($methods['getRpTokenCreatedAt']);
$this->assertSame($expectedResult, $mock->isResetPasswordLinkTokenExpired());
}

Expand Down
4 changes: 2 additions & 2 deletions tests/unit/Mage/Admin/Model/VariableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public function testValidate($expectedResult, string $variableName, string $isAl
->setMethods(['getVariableName', 'getIsAllowed'])
->getMock();

$mock->expects($this->any())->method('getVariableName')->willReturn($variableName);
$mock->expects($this->any())->method('getIsAllowed')->willReturn($isAllowed);
$mock->method('getVariableName')->willReturn($variableName);
$mock->method('getIsAllowed')->willReturn($isAllowed);
$this->assertSame($expectedResult, $mock->validate());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ public function testInitForm(): void
->setMethods(['getRegistryCurrentCustomer', 'isReadonly'])
->getMock();

$mock->expects($this->any())
$mock
->method('getRegistryCurrentCustomer')
// phpcs:ignore Ecg.Classes.ObjectInstantiation.DirectInstantiation
->willReturn(new Mage_Customer_Model_Customer());

$mock->expects($this->any())
$mock
->method('isReadonly')
->willReturn(true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function testInitForm(): void
->setMethods(['getRegistryCurrentCustomer'])
->getMock();

$mock->expects($this->any())
$mock
->method('getRegistryCurrentCustomer')
// phpcs:ignore Ecg.Classes.ObjectInstantiation.DirectInstantiation
->willReturn(new Mage_Customer_Model_Customer());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function testInitForm(): void
->setMethods(['getRegistryCurrentConvertProfile'])
->getMock();

$mock->expects($this->any())
$mock
->method('getRegistryCurrentConvertProfile')
// phpcs:ignore Ecg.Classes.ObjectInstantiation.DirectInstantiation
->willReturn(new Mage_Dataflow_Model_Profile());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function testInitForm(): void
->setMethods(['getRegistryCurrentConvertProfile'])
->getMock();

$mock->expects($this->any())
$mock
->method('getRegistryCurrentConvertProfile')
// phpcs:ignore Ecg.Classes.ObjectInstantiation.DirectInstantiation
->willReturn(new Mage_Dataflow_Model_Profile());
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/Mage/Catalog/Helper/Product/UrlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function setUp(): void
public function testGetConvertTable(): void
{
$this->assertIsArray($this->subject->getConvertTable());
$this->assertSame(317, count($this->subject->getConvertTable()));
$this->assertCount(317, $this->subject->getConvertTable());
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/Mage/Catalog/Helper/ProductTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function testCanUseCanonicalTag(): void
*/
public function testGetAttributeInputTypes(int $expectedResult, ?string $inputType = null): void
{
$this->assertSame($expectedResult, count($this->subject->getAttributeInputTypes($inputType)));
$this->assertCount($expectedResult, $this->subject->getAttributeInputTypes($inputType));
}

public function provideGetAttributeInputTypes(): Generator
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/Mage/Cms/Block/BlockTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function testGetCacheKeyInfo(string $blockId): void
->setMethods(['getBlockId'])
->getMock();

$mock->expects($this->any())->method('getBlockId')->willReturn($blockId);
$mock->method('getBlockId')->willReturn($blockId);
$this->assertIsArray($mock->getCacheKeyInfo());
}

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/Mage/Cms/Block/PageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function testGetPage(string $pageId): void
->setMethods(['getPageId'])
->getMock();

$mock->expects($this->any())->method('getPageId')->willReturn($pageId);
$mock->method('getPageId')->willReturn($pageId);
$this->assertInstanceOf(Mage_Cms_Model_Page::class, $mock->getPage());
}

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/Mage/Cms/Block/Widget/BlockTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function testGetCacheKeyInfo(string $blockId): void
->setMethods(['getBlockId'])
->getMock();

$mock->expects($this->any())->method('getBlockId')->willReturn($blockId);
$mock->method('getBlockId')->willReturn($blockId);
$this->assertIsArray($mock->getCacheKeyInfo());
}

Expand Down
4 changes: 2 additions & 2 deletions tests/unit/Mage/Core/Helper/EnvironmentConfigLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public function testEnvOverridesForValidConfigKeys(array $config): void
$valueAfterOverride = $xml->getNode($configPath);

// assert
$this->assertNotEquals((string)$defaultValue, (string)$valueAfterOverride, 'Default value was not overridden.');
$this->assertNotSame((string)$defaultValue, (string)$valueAfterOverride, 'Default value was not overridden.');
}

public function envOverridesCorrectConfigKeysDataProvider(): Generator
Expand Down Expand Up @@ -222,7 +222,7 @@ public function testEnvDoesNotOverrideForInvalidConfigKeys(array $config): void
}

// assert
$this->assertTrue(!str_contains('value_will_not_be_changed', (string)$valueAfterCheck), 'Default value was wrongfully overridden.');
$this->assertFalse(str_contains('value_will_not_be_changed', (string)$valueAfterCheck), 'Default value was wrongfully overridden.');
}

public function envDoesNotOverrideOnWrongConfigKeysDataProvider(): Generator
Expand Down
104 changes: 46 additions & 58 deletions tests/unit/Mage/Core/Helper/SecurityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

namespace OpenMage\Tests\Unit\Mage\Core\Helper;

use Generator;
use Mage;
use Mage_Core_Block_Abstract;
use Mage_Core_Block_Template;
Expand All @@ -37,29 +38,22 @@ public function setUp(): void
}

/**
* @return array<int|string, array<int, array<empty, empty>|Mage_Page_Block_Html_Topmenu_Renderer|Mage_Core_Block_Template|string>>
*
* @group Mage_Core
* @group Mage_Core_Helper
*/
public function validateAgainstBlockMethodBlacklistDataProvider(): array
public function validateAgainstBlockMethodBlacklistDataProvider(): Generator
{
// phpcs:ignore Ecg.Classes.ObjectInstantiation.DirectInstantiation
$topmenu = new Mage_Page_Block_Html_Topmenu_Renderer();
// phpcs:ignore Ecg.Classes.ObjectInstantiation.DirectInstantiation
$template = new Mage_Core_Block_Template();

return [
[
$topmenu,
'setData',
[]
],
[
$template,
'setData',
[]
],
yield [
$topmenu,
'setData',
[]
];
yield [
$template,
'setData',
[]
];
}

Expand All @@ -80,52 +74,46 @@ public function testValidateAgainstBlockMethodBlacklist(
$this->subject->validateAgainstBlockMethodBlacklist($block, $method, $args);
}

/**
* @return array<int|string, array<int, array<empty, empty>|Mage_Page_Block_Html_Topmenu_Renderer|Mage_Core_Block_Template|string>>
*/
public function forbiddenBlockMethodsDataProvider(): array
public function forbiddenBlockMethodsDataProvider(): Generator
{
// phpcs:ignore Ecg.Classes.ObjectInstantiation.DirectInstantiation
$topmenu = new Mage_Page_Block_Html_Topmenu_Renderer();
// phpcs:ignore Ecg.Classes.ObjectInstantiation.DirectInstantiation
$template = new Mage_Core_Block_Template();

return [
[
$template,
'fetchView',
[]
],
[
$topmenu,
'fetchView',
[]
],
[
$topmenu,
'render',
[]
],
[
$template,
'Mage_Core_Block_Template::fetchView',
[]
],
[
$topmenu,
'Mage_Page_Block_Html_Topmenu_Renderer::fetchView',
[]
],
'parent class name is passed as second arg' => [
$topmenu,
'Mage_Core_Block_Template::fetchView',
[]
],
'parent class name is passed as second arg2' => [
$topmenu,
'Mage_Core_Block_Template::render',
[]
],
yield [
$template,
'fetchView',
[]
];
yield [
$topmenu,
'fetchView',
[]
];
yield [
$topmenu,
'render',
[]
];
yield [
$template,
'Mage_Core_Block_Template::fetchView',
[]
];
yield [
$topmenu,
'Mage_Page_Block_Html_Topmenu_Renderer::fetchView',
[]
];
yield 'parent class name is passed as second arg' => [
$topmenu,
'Mage_Core_Block_Template::fetchView',
[]
];
yield 'parent class name is passed as second arg2' => [
$topmenu,
'Mage_Core_Block_Template::render',
[]
];
}

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/Mage/Log/Model/CustomerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function testGetLoginAtTimestamp(): void

$this->assertNull($mock->getLoginAtTimestamp());

$mock->expects($this->any())->method('getLoginAt')->willReturn(true);
$mock->method('getLoginAt')->willReturn(true);
$this->assertIsInt($mock->getLoginAtTimestamp());
}
}
4 changes: 2 additions & 2 deletions tests/unit/Mage/Sitemap/Model/SitemapTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function testGetPreparedFilename(): void
->setMethods(['getSitemapFilename'])
->getMock();

$mock->expects($this->any())->method('getSitemapFilename')->willReturn('text.xml');
$mock->method('getSitemapFilename')->willReturn('text.xml');
$this->assertIsString($mock->getPreparedFilename());
}

Expand All @@ -55,7 +55,7 @@ public function testGenerateXml(): void
->setMethods(['getSitemapFilename'])
->getMock();

$mock->expects($this->any())->method('getSitemapFilename')->willReturn('text.xml');
$mock->method('getSitemapFilename')->willReturn('text.xml');
$this->assertInstanceOf(Mage_Sitemap_Model_Sitemap::class, $mock->generateXml());
}
}
Loading