Skip to content

#async-import/issues/207: Provide the ability to check errors in WebAPI tests in a single approach for different adapters (SOAP/REST) #24792

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 8, 2019

Conversation

naydav
Copy link
Contributor

@naydav naydav commented Sep 30, 2019

Summary (*)

https://github.com/magento/async-import/issues/207
Provide the ability to check errors in WebAPI tests in a single approach for different adapters (SOAP/REST)

Examples (*)

Now need to duplicate code in each testcase when you need check nested errors

/**
     * @param array $serviceInfo
     * @param array $data
     * @param array $expectedErrorData
     * @return void
     * @throws \Exception
     */
    private function assertWebApiCallErrors(array $serviceInfo, array $data, array $expectedErrorData)
    {
        try {
            $this->_webApiCall($serviceInfo, $data);
            $this->fail('Expected throwing exception');
        } catch (\Exception $e) {
            if (TESTS_WEB_API_ADAPTER === self::ADAPTER_REST) {
                self::assertEquals($expectedErrorData, $this->processRestExceptionResult($e));
                self::assertEquals(Exception::HTTP_BAD_REQUEST, $e->getCode());
            } elseif (TESTS_WEB_API_ADAPTER === self::ADAPTER_SOAP) {
                $this->assertInstanceOf('SoapFault', $e);
                $expectedWrappedErrors = [];
                foreach ($expectedErrorData['errors'] as $error) {
                    // @see \Magento\TestFramework\TestCase\WebapiAbstract::getActualWrappedErrors()
                    $expectedWrappedError = [
                        'message' => $error['message'],
                    ];
                    if (isset($error['parameters'])) {
                        $expectedWrappedError['params'] = $error['parameters'];
                    }
                    $expectedWrappedErrors[] = $expectedWrappedError;
                }
                $this->checkSoapFault($e, $expectedErrorData['message'], 'env:Sender', [], $expectedWrappedErrors);
            } else {
                throw $e;
            }
        }
    }

Proposed solution

Move common code in \Magento\TestFramework\TestCase\WebapiAbstract
Moving to a separate class is hard due to using a lot of protected methods (requires full refactoring of WebapiAbstract)

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)

…PI tests in a single approach for different adapters (SOAP/REST)
@naydav naydav requested a review from paliarush as a code owner September 30, 2019 16:49
@m2-assistant
Copy link

m2-assistant bot commented Sep 30, 2019

Hi @naydav. Thank you for your contribution
Here is some useful tips how you can test your changes using Magento test environment.
Add the comment under your pull request to deploy test or vanilla Magento instance:

  • @magento give me test instance - deploy test instance based on PR changes
  • @magento give me 2.3-develop instance - deploy vanilla Magento instance

For more details, please, review the Magento Contributor Guide documentation.

@magento-cicd2
Copy link
Contributor

magento-cicd2 commented Sep 30, 2019

CLA assistant check
All committers have signed the CLA.

@magento-engcom-team
Copy link
Contributor

Hi @VladimirZaets, thank you for the review.
ENGCOM-5984 has been created to process this Pull Request
✳️ @VladimirZaets, could you please add one of the following labels to the Pull Request?

Label Description
Auto-Tests: Covered All changes in Pull Request is covered by auto-tests
Auto-Tests: Not Covered Changes in Pull Request requires coverage by auto-tests
Auto-Tests: Not Required Changes in Pull Request does not require coverage by auto-tests

@engcom-Alfa
Copy link
Contributor

✔️ QA Passed

@sidolov sidolov added the Auto-Tests: Not Required Changes in Pull Request does not require coverage by auto-tests label Oct 2, 2019
magento-engcom-team pushed a commit that referenced this pull request Oct 8, 2019
…rrors in WebAPI tests in a single approach for different adapters (SOAP/REST) #24792
@magento-engcom-team magento-engcom-team merged commit 9598e57 into magento:2.3-develop Oct 8, 2019
@m2-assistant
Copy link

m2-assistant bot commented Oct 8, 2019

Hi @naydav, thank you for your contribution!
Please, complete Contribution Survey, it will take less than a minute.
Your feedback will help us to improve contribution process.

@magento-engcom-team magento-engcom-team added this to the Release: 2.3.4 milestone Oct 8, 2019
@VladimirZaets VladimirZaets added Auto-Tests: Covered All changes in Pull Request is covered by auto-tests and removed Auto-Tests: Not Required Changes in Pull Request does not require coverage by auto-tests labels Nov 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Auto-Tests: Covered All changes in Pull Request is covered by auto-tests Progress: accept Release Line: 2.3
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants