Web API functional testing
Web API functional testing
The Web API testing framework allows you to test Magento Web API from the client application point of view. The tests can be used with either REST or SOAP. The REST or SOAP adapter that runs the tests is specified in PHPUnit configuration. See How to Run the Tests for more information.
The Web API functional testing framework depends on the integration testing framework and reuses most of classes implemented there.
Custom Annotations for Data Fixtures
In the Web API functional tests only, the custom annotation
@magentoApiDataFixture is available for declaring fixtures. The difference of this annotation from
@magentoDataFixture is that the fixture will be committed and accessible during HTTP requests made within the test body. The usage rules of
@magentoApiDataFixture are the same as
@magentoDataFixture usage rules.
If data was added to the DB using
@magentoApiDataFixture, it will not be automatically cleared after test execution. The data is cleared when
@magentoDataFixture is used.
Do not define fixtures in
dev/tests/api-functional. Instead, they must be taken from
dev/tests/integration. The integration framework defines most necessary fixtures, and they should be reused during Web API functional testing. If the existing set of fixtures is insufficient, add new fixtures under
dev/tests/integration. The fixtures will then be available for both testing frameworks.
To keep your test environment clean, clear all entities created in fixture files or within tests itself from the DB after test execution. This can be done either directly in tearDown or by a corresponding rollback for the fixture file. This file should be named the same as a fixture, but with
How to Create a New Test
All Web API functional tests should inherit from the generic test case
Magento\TestFramework\TestCase\WebapiAbstract. It defines the
_webApiCall() method, which should be used to perform Web API calls from tests. Clients of
_webApiCall() are unaware of which adapter will be used to perform remote call.
The test above should is able to test SOAP and REST depending on what adapter is currently used by testing framework. $serviceInfo format is defined by Web API client adapter interface:
How to Run the Tests
Install the PHP Soap extension.
php_soap.soto your PHP extensions directory. Edit your
php.inifile and enable the PHP Soap extension. Usually this means deleting the leading semi-colon in front of the extension. Then restart Apache.
Before running the functional tests you need to clear your cache. Now you are ready to run the tests.
Running the Tests
/dev/tests/api-functional/phpunit.xmla. Specify your Magento instance URL as a value of
phpunit.xml. b. Choose the required Web API adapter,
soap, to be used and specify it in
Configure your DB connection and install settings in
/dev/tests/api-functional/config/install-config-mysql.php. Specify the Magento database. The base URL to access this Magento instance must be specified in