Skip to content

Commit f30028b

Browse files
Copilotsreichel
andauthored
Make all PHPUnit data providers static (PHPUnit 10+ compatibility) (#5486)
* Initial plan * Make all PHPUnit data provider methods static for PHPUnit 10+ compatibility Agent-Logs-Url: https://github.com/OpenMage/magento-lts/sessions/0ed20cbc-5be3-48bb-b912-3c3d652e7126 Co-authored-by: sreichel <5022236+sreichel@users.noreply.github.com> * Fix $this-> calls in static data provider methods Agent-Logs-Url: https://github.com/OpenMage/magento-lts/sessions/0ed20cbc-5be3-48bb-b912-3c3d652e7126 Co-authored-by: sreichel <5022236+sreichel@users.noreply.github.com> * Fix staticMethod.dynamicCall: use self:: instead of $this-> for static getTestString() in ImagesTest Agent-Logs-Url: https://github.com/OpenMage/magento-lts/sessions/9fa5d994-5e8d-4668-9088-7b9d5bdef1e5 Co-authored-by: sreichel <5022236+sreichel@users.noreply.github.com> * Update copilot-instructions.md with PHPUnit testing standards learned from PR Agent-Logs-Url: https://github.com/OpenMage/magento-lts/sessions/f69826d6-8f46-432e-bc98-5ef558d758c4 Co-authored-by: sreichel <5022236+sreichel@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: sreichel <5022236+sreichel@users.noreply.github.com> Co-authored-by: Sven Reichel <github-sr@hotmail.com>
1 parent b91e9b2 commit f30028b

69 files changed

Lines changed: 137 additions & 127 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/copilot-instructions.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,16 @@ This project aims to provide a stable and secure version of Magento 1.x, with on
6060
- Use strict comparisons (`===` and `!==`) instead of loose comparisons (`==` and `!=`) in new code.
6161
- Avoid using empty() function in new code. Use explicit checks instead.
6262

63+
## PHPUnit Testing Standards
64+
65+
- All PHPUnit data provider methods must be declared `public static` (required by PHPUnit 10+).
66+
- Data provider methods follow the naming convention `provide*` (e.g., `provideValidateData`).
67+
- Inside `static` data provider methods, never use `$this->`. Use `static::` to call other methods from traits or `self::` for calls in the same class.
68+
- When a helper method is made `static` (e.g., a method used inside a data provider), all callers — including regular (non-static) test methods — must also be updated from `$this->method()` to `self::method()`.
69+
- PHPStan is configured with `dynamicCallOnStaticMethod: true` in `.phpstan.dist.neon`. Never call a static method via `$this->` — it will cause a `staticMethod.dynamicCall` error.
70+
- Data provider trait helper methods (e.g., `getAllBlockClasses`, `getTestString`) that are consumed by static data providers must themselves be declared `static`.
71+
- Test class setup should use `setUpBeforeClass()` for shared static state and `setUp()` for per-test instance state.
72+
6373
## UI guidelines
6474

6575
- Do not use prototype libraries. Use modern JavaScript (ES6+) features and libraries.

tests/unit/Base/ClassLoadingTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function testClassExists(bool $expectedResult, string $class): void
2424
self::assertSame($expectedResult, class_exists($class));
2525
}
2626

27-
public function provideClassExistsData(): Generator
27+
public static function provideClassExistsData(): Generator
2828
{
2929
yield 'class exists #1' => [
3030
true,

tests/unit/Base/DefaultConfigTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function testGetStoreConfig(string $expectedResult, string $path, null|bo
2828
}
2929

3030

31-
public function provideGetStoreConfig(): Generator
31+
public static function provideGetStoreConfig(): Generator
3232
{
3333
yield Mage_Adminhtml_Helper_Dashboard_Data::XML_PATH_ENABLE_CHARTS => [
3434
'1',

tests/unit/Base/XmlFileLoadingTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function testXmlReaderIsValid(string $filepath): void
4343
self::assertTrue($xml->isValid());
4444
}
4545

46-
public function provideXmlFiles(): Generator
46+
public static function provideXmlFiles(): Generator
4747
{
4848
$root = realpath(__DIR__ . '/../../../') . '/';
4949

tests/unit/Error/ProcessorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function testGetHostUrl(string $expectedResult, array $serverVars): void
4545
self::assertSame($expectedResult, $this->subject->getHostUrl());
4646
}
4747

48-
public function provideGetHostUrl(): Generator
48+
public static function provideGetHostUrl(): Generator
4949
{
5050
yield 'default' => [
5151
'http://localhost',

tests/unit/Mage/Cms/Helper/Wysiwyg/ImagesTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,15 @@ public function testGetStorage(): void
5858
*/
5959
public function testIdEncode(): void
6060
{
61-
self::assertIsString(self::$subject->idEncode($this->getTestString()));
61+
self::assertIsString(self::$subject->idEncode(self::getTestString()));
6262
}
6363

6464
/**
6565
* @group Helper
6666
*/
6767
public function testIdDecode(): void
6868
{
69-
self::assertIsString(self::$subject->idDecode($this->getTestString()));
69+
self::assertIsString(self::$subject->idDecode(self::getTestString()));
7070
}
7171

7272
/**

tests/unit/Traits/DataProvider/Base/BoolTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
trait BoolTrait
1717
{
18-
public function provideBool(): Generator
18+
public static function provideBool(): Generator
1919
{
2020
yield 'true' => [
2121
true,

tests/unit/Traits/DataProvider/Base/IntOrNullTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
trait IntOrNullTrait
1717
{
18-
public function provideIntOrNull(): Generator
18+
public static function provideIntOrNull(): Generator
1919
{
2020
yield 'null' => [
2121
null,

tests/unit/Traits/DataProvider/Base/ModulesTrait.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ trait ModulesTrait
2121
/**
2222
* @return array<int, string>
2323
*/
24-
final public function provideAllModules(): array
24+
final public static function provideAllModules(): array
2525
{
2626
return [
2727
'Mage_Admin',
@@ -86,10 +86,10 @@ final public function provideAllModules(): array
8686
];
8787
}
8888

89-
public function provideAllActiveModules(): array
89+
public static function provideAllActiveModules(): array
9090
{
9191
$disabled = static::$disabledModules;
92-
$modules = $this->provideAllModules();
92+
$modules = static::provideAllModules();
9393

9494
foreach ($modules as $idx => $module) {
9595
if (in_array($module, $disabled)) {

tests/unit/Traits/DataProvider/Base/NumericStringTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
trait NumericStringTrait
1717
{
18-
public function provideNumericString(): Generator
18+
public static function provideNumericString(): Generator
1919
{
2020
yield 'zero' => [
2121
'0',

0 commit comments

Comments
 (0)