-
Notifications
You must be signed in to change notification settings - Fork 1
Integration Test: Configuration
These exercises cover tests for module configuration
- how to create a Magento 2 integration test
- how to use the object manager in integration tests
- how to find relevant interfaces to retrieve framework information
Create a new module in app/code/TddWizard/ExerciseModule
.
The essential files in any Magento module are registration.php
and module.xml
to define and activate the module.
Even for those, you can start with a test.
Use Magento\Framework\Module\ModuleList
to test if the module is enabled. Create registration.php and module.xml to make the test pass.
You can go a step further and test, if the module is enabled in the real environment, not only in the test environment, where all installed modules are enabled by default. This is explained in The Skeleton Module Kata by Vinai Kopp (Code).
When configuring a plugin we can test if it is registered correctly. You will create a before plugin for \Magento\Customer\Api\CustomerRepositoryInterface::save()
.
Use Magento\Framework\Interception\PluginListInterface
to get the registered plugins in the test. Create di.xml
with the plugin definition to make the test pass. Your plugin method can stay empty at this point.
Now do the same for a preference, for Magento\Customer\Api\Data\Customer
. Use \Magento\Framework\ObjectManager\ConfigInterface
to get all preferences. Update di.xml
with a custom preference to make the test pass. Your class can be simply a child of the core class without additional code at this point.
- Hire me to come to your company: https://www.integer-net.com/services/magento-training-courses/#M2-test
- Subscribe to the Test Driven Magento newsletter to get notified about other possibilities: http://tddwizard.com/