EC-CUBE / EC-CUBE/ec-cube

[4.4.x] テストのフレームワーク結合是正(脆いサービス取得の安定化)

Open
#6,934 0 comments 0 reactions 0 assignees View on GitHub
enhancement test
Dominant language
PHP
Stars
788
Forks
719
Avg merge
4d 4h
Merged PRs (30d)
39

Description

## 背景・目的

Symfony 6→7 移行では、壊れたテストの原因の大半が「テスト対象のロジック」ではなく「フレームワーク/コンテナへの結合部分」だった。次のメジャー追従で同じ作り替えを繰り返さないよう、テストの脆い結合を平時に是正する。BC 破壊を伴わない(`tests/` は `autoload-dev` 限定で非配布)ため 4.4.x マイナーで実施可能。

### 実測(6→7 で実際に壊れたパターン)

- `getContainer()->get(Class::class)` が rector 変換(`ContainerGetNameToTypeInTestsRector`)+ Symfony のサービス登録変化で `ServiceNotFoundException`(例: `MailServiceTest` の event_dispatcher、`ProductControllerTest` の CsrfTokenManager)。
- `EccubeTestCase::cleanUpProperties()` が tearDown で全プロパティに null 代入 → typed property で `TypeError`。

### 現状の結合量(実測)

- `getContainer()->get(Class::class)` 形式が **127件**(安定な文字列サービスID形式は 0件)。
- テスト293件中262件(89.4%)がフレームワーク結合。うち257件は `EccubeTestCase` 経由で、`setUp()` が無条件にカーネル起動・実DB接続・HTTPクライアント生成を実行。

## やること

1. **サービス取得の安定化**: テストの `getContainer()->get(Class::class)` 127件を、追従に強い取得方法へ(安定した公開テストエイリアスの明示登録 / 文字列サービスID / コンストラクタ注入ヘルパへの集約)。
2. **`EccubeTestCase::cleanUpProperties()` の typed-safe 化**: 未初期化の typed property に null 代入して `TypeError` にならないよう修正。

## 完了条件

- [ ] `getContainer()->get(Class::class)` の脆い取得が安定形へ置換されている
- [ ] `cleanUpProperties()` が typed property でも安全
- [ ] フルスイートが緑

## 補足

- 結合は `EccubeTestCase` 基底に埋め込まれているため、個別テストでなく基底の是正が起点。
- これは「ドメイン純粋化(PurchaseFlow の純UT化)」とは別施策。本 Issue はフレームワーク結合テストを追従に強くするもので、純UT化(BC破壊を伴い 4.5 想定)とは切り分ける。

Contributor guide

Open the contributing guide

Research direction

Start with EccubeTestCase, especially cleanUpProperties(), and search the test suite for the 127 getContainer()->get(Class::class) usages. Review the existing test-container setup before choosing a stable retrieval approach. Done means typed properties are safe, fragile service lookups are replaced, and the full test suite is green.

Written by the indexing model from the issue text.

Assessment

Tech stack
php, symfony
Domain
testing
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.