N°9009 Add phpunit test to GetSelectedModules#792
N°9009 Add phpunit test to GetSelectedModules#792Timmy38 wants to merge 4 commits intofeature/uninstallationfrom
Conversation
| 'aExpectedModules' => [], | ||
| 'aExpectedExtensions' => [], | ||
| ], | ||
| 'One extension selected' => [ |
There was a problem hiding this comment.
Independently from the implementation, we should have tests scenarios with multiple extensions selected
| public function ProviderGetSelectedModules() | ||
| { | ||
| return [ | ||
| 'No extension selected' => [ |
There was a problem hiding this comment.
I wonder : do we have other cases with different conditions and same result? How about having test cases with exclusive options ?
c64320b to
7c7dc4d
Compare
There was a problem hiding this comment.
Pull request overview
This PR adds PHPUnit tests for the GetSelectedModules method in the WizStepModulesChoice class. The changes enable testing of module selection logic during the setup/installation process by making the method public, adding validation for empty module arrays, and providing test coverage for basic scenarios.
Changes:
- Added two test methods with a data provider to test the
GetSelectedModulesfunctionality - Changed
GetSelectedModulesvisibility fromprotectedtopublicto enable direct testing - Added validation to throw an exception when a selected extension has an empty modules array
- Initialized the
$aAnalyzeInstallationModulesproperty with an empty array (fixes potential uninitialized property issue in test context) - Updated type hint documentation from
hashtoarrayfor better PHP standards compliance
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| tests/php-unit-tests/unitary-tests/setup/WizStepModulesChoiceTest.php | Added test provider and two test methods covering basic module selection scenarios and exception handling for empty module arrays |
| setup/wizardsteps/WizStepModulesChoice.php | Changed method visibility, added empty modules validation, and initialized property to support testing |
| setup/setuputils.class.inc.php | Updated docblock type hint from deprecated hash to standard array |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| $sDisplayChoices .= '<li>'.$aChoice['title'].'</li>'; | ||
| if (isset($aChoice['modules'])) { | ||
| if (count($aChoice['modules']) === 0) { | ||
| throw new Exception('Setup option does not have any module associated'); |
There was a problem hiding this comment.
The error message 'Setup option does not have any module associated' could be more helpful by including which extension or choice caused the error. Consider adding the extension code or choice title to the error message to help users identify the problematic configuration more easily.
| throw new Exception('Setup option does not have any module associated'); | |
| $sChoiceTitle = isset($aChoice['title']) ? $aChoice['title'] : 'unknown title'; | |
| $sExtensionCode = isset($aChoice['extension_code']) ? $aChoice['extension_code'] : 'unknown extension'; | |
| throw new Exception(sprintf( | |
| 'Setup option "%s" (extension "%s") does not have any module associated', | |
| $sChoiceTitle, | |
| $sExtensionCode | |
| )); |
| 'installed' => false, | ||
| ], | ||
| ]; | ||
| $this->oStep->setExtensionMap(iTopExtensionsMapFake::createFromArray($aExtensionsMapData, )); |
There was a problem hiding this comment.
There is a trailing comma after the array parameter. The createFromArray method signature only has one required parameter. This trailing comma appears to be a typo and should be removed.
| 'installed' => false, | ||
| ], | ||
| ]; | ||
| $this->oStep->setExtensionMap(iTopExtensionsMapFake::createFromArray($aExtensionsMapData, )); |
There was a problem hiding this comment.
There is a trailing comma after the array parameter. The createFromArray method signature only has one required parameter. This trailing comma appears to be a typo and should be removed.
No description provided.