
Guzzle is one of the best PHP HTTP clients available and makes sending and dissecting responses a breeze. While it’s perfect for writing small, composable unit tests it can also work perfectly for integration and functional tests. PHPUnit is the gold standard framework for testing PHP projects and there are many testing platforms that work directly with it. It doesn’t help if your unsure about what tools to use to implement testing on new parts of a project.
#Phpunit api code#
Additionally, verify that your functional tests are correctly set up and cover the expected functionality of your module.Testing code is important, but can often feel like a burden or task, especially if you have strict deadlines. If you still face any issues, review your code changes and ensure that all necessary updates have been made to work with the new implementation of the custom_addresses attribute. With the updated implementation, your functional tests should now run without encountering the ReflectionException error. Rerun your functional tests: vendor/bin/phpunit -c $(pwd)/dev/tests/api-functional/phpunit_rest.xml -testsuite testsuite Check that the custom_addresses attribute works as expected when interacting with the Magento\Company\Api\Data\CompanyInterface. Test your module again to ensure that it still functions correctly with the updated implementation. This step generates any necessary dependency injection configurations and optimizes the application's performance. This command ensures that your module's changes are applied to the database schema and data.Ĭompile your code: bin/magento setup:di:compile Run the Magento setup upgrade: bin/magento setup:upgrade Run the following commands to clear generated code and cache to make sure Magento picks up your changes: rm -rf var/cache/* var/page_cache/* generated/code/*
#Phpunit api update#
Make sure to update your code to work with the new implementation of the custom_addresses attribute.Īfter updating your extension_attributes.xml and your implementation of the Magento\Company\Api\Data\CompanyInterface, you should follow these steps to ensure everything works as expected: With these changes, your functional tests should run without the ReflectionException error. Return $this->setData(self::CUSTOM_ADDRESSES, $customAddresses) Public function setCustomAddresses(array $customAddresses): \Magento\Company\Api\Data\CompanyInterface Return $this->_get(self::CUSTOM_ADDRESSES) ?: For example, in your Company model class (which should implement Magento\Company\Api\Data\CompanyInterface), you can implement the getter and setter for the custom_addresses attribute like this: public function getCustomAddresses(): array Then, in your implementation of the Magento\Company\Api\Data\CompanyInterface, use an array to store the custom_addresses attribute. Update your extension_attributes.xml to:

You should define the type as an interface and use an array in your implementation to store multiple instances of the custom address. Instead of specifying the type as an array like this: In this case, the issue appears to be with the type attribute.

The error you're encountering, "ReflectionException: Class 'ModuleName\Customer\Api\CustomAddressInterface' does not exist," is likely due to the way you've defined the extension attribute type in the extension_attributes.xml file.
