Skip to content

Cover the source-mode gate on composite parent stock status - #3467

Open
brosenberger wants to merge 1 commit into
magento:developfrom
brosenberger:3350-composite-parent-salability-multi-source
Open

brosenberger wants to merge 1 commit into
magento:developfrom
brosenberger:3350-composite-parent-salability-multi-source

Conversation

@brosenberger

Copy link
Copy Markdown

Description (*)

Adds test coverage for the source-mode gate on the composite parent stock status recompute. No production code is changed, and both tests pass against develop unchanged.

InventoryCatalog/Test/Integration/CompositeParentSalabilityOnNonDefaultStockTest is a regression guard for #3350. It puts a configurable's children out of stock on the default source only, while the eu sources backing stock 10 still hold stock, and asserts the parent stays salable in that stock. There is no guard for this today, and the behaviour is easy to break by accident: the test fails as soon as the IsSingleSourceMode gate on the composite parent recompute is removed.

InventoryCatalog/Test/Unit/Plugin/InventoryApi/UpdateCompositeProductStockStatusOnSourceItemsSaveTest documents the gate itself — the recompute runs in single source mode and is deliberately skipped in multi source mode — so the reason for the gate sits next to the code rather than only in issue history. That plugin has no unit coverage today.

I wrote these while investigating whether the gate could be lifted so composite parents are maintained in multi source mode. It cannot, at least not without a design decision; the evidence is in #3466. These tests are the part of that work that is useful on its own.

Fixed Issues (if relevant)

  1. Relates to Composite parent stock status is not maintained in multi source mode, and the three obvious fixes each break something else #3466
  2. Adds a regression guard for Configurable products marked out of stock incorrectly #3350

Manual testing scenarios (*)

  1. Check out develop with no other changes and run both tests. They pass:
    vendor/bin/phpunit -c dev/tests/integration/phpunit.xml.dist \
      <path>/InventoryCatalog/Test/Integration/CompositeParentSalabilityOnNonDefaultStockTest.php
    vendor/bin/phpunit -c dev/tests/unit/phpunit.xml.dist \
      vendor/magento/module-inventory-catalog/Test/Unit/Plugin/InventoryApi/UpdateCompositeProductStockStatusOnSourceItemsSaveTest.php
    
  2. To confirm the regression guard actually guards something, remove the if ($this->isSingleSourceMode->execute()) wrapper in InventoryCatalog/Plugin/InventoryApi/UpdateCompositeProductStockStatusOnSourceItemsSave::afterExecute() and re-run the integration test. It fails with the parent no longer salable in stock 10, which is Configurable products marked out of stock incorrectly #3350.
  3. Restore the wrapper and confirm it passes again.

Note that the MSI integration tests are not picked up by the default integration suite, which globs testsuite and app/code/*/*/Test/Integration, so the path has to be passed explicitly.

Questions or comments

The unit test asserts the current gated behaviour rather than a desired behaviour, on purpose. If the outcome of #3466 is that composite parents should be maintained in multi source mode, that test is the one to update, and it will say clearly what changed.

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds are green)

…atus

Adds a regression guard for magento#3350 and unit coverage of the plugin that carries the
gate. Both pass against develop unchanged; no production code is touched.

CompositeParentSalabilityOnNonDefaultStockTest puts a configurable's children out of
stock on the default source only, while the sources backing a non-default stock still
hold stock, and asserts the parent stays salable in that stock. There is no regression
guard for magento#3350 today, and the behaviour is easy to break: the test fails as soon as
the IsSingleSourceMode gate on the composite parent recompute is removed.

UpdateCompositeProductStockStatusOnSourceItemsSaveTest documents the gate itself - the
recompute runs in single source mode and is skipped in multi source mode - so that the
reason for the gate is visible next to the code rather than only in the issue history.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Ready for Review

Development

Successfully merging this pull request may close these issues.

1 participant