Modules SOAP and REST is not working together in 2.2.4 #3512

Closed
eXorus opened this Issue Sep 14, 2016 · 10 comments

Comments

Projects
None yet
3 participants
@eXorus
Contributor

eXorus commented Sep 14, 2016

What are you trying to achieve?

I'm trying to work with SOAP and REST api together with ApiTester.

The only conflict between SOAP and REST is the method seeResponseCodeIs(), maybe we can rename it or use part or any other solution ....

What do you get instead?

Codeception v2.2.3 : OK
Codeception v2.2.4 : KO

./vendor/bin/codecept run api -vvv
Codeception PHP Testing Framework v2.2.4
Powered by PHPUnit 5.4.8 by Sebastian Bergmann and contributors.


  [Codeception\Exception\ModuleConflictException]                              
  REST module conflicts with SOAP                                              
  --                                                                           
  This usually happens when you enable two modules with the same actions but   
  with different backends.                                                     
  For instance, you can't run PhpBrowser, WebDriver, Laravel5 modules in one   
  suite,                                                                       
  as they implement similar methods but use different drivers to execute them  
  .                                                                            
  You can load a part of module (like: ORM) to avoid conflict.                 


Exception trace:
 () at /home/xxx/Code/iwqa_c2.2.4/vendor/codeception/codeception/src/Codeception/Lib/ModuleContainer.php:484
 Codeception\Lib\ModuleContainer->validateConflict() at /home/xxx/Code/iwqa_c2.2.4/vendor/codeception/codeception/src/Codeception/Lib/ModuleContainer.php:464
 Codeception\Lib\ModuleContainer->validateConflicts() at /home/xxx/Code/iwqa_c2.2.4/vendor/codeception/codeception/src/Codeception/SuiteManager.php:70
 Codeception\SuiteManager->__construct() at /home/xxx/Code/iwqa_c2.2.4/vendor/codeception/codeception/src/Codeception/Codecept.php:206
 Codeception\Codecept->runSuite() at /home/xxx/Code/iwqa_c2.2.4/vendor/codeception/codeception/src/Codeception/Codecept.php:178
 Codeception\Codecept->run() at /home/xxx/Code/iwqa_c2.2.4/vendor/codeception/codeception/src/Codeception/Command/Run.php:329
 Codeception\Command\Run->runSuites() at /home/xxx/Code/iwqa_c2.2.4/vendor/codeception/codeception/src/Codeception/Command/Run.php:256
 Codeception\Command\Run->execute() at /home/xxx/Code/iwqa_c2.2.4/vendor/symfony/console/Command/Command.php:256
 Symfony\Component\Console\Command\Command->run() at /home/xxx/Code/iwqa_c2.2.4/vendor/symfony/console/Application.php:818
 Symfony\Component\Console\Application->doRunCommand() at /home/xxx/Code/iwqa_c2.2.4/vendor/symfony/console/Application.php:186
 Symfony\Component\Console\Application->doRun() at /home/xxx/Code/iwqa_c2.2.4/vendor/symfony/console/Application.php:117
 Symfony\Component\Console\Application->run() at /home/xxx/Code/iwqa_c2.2.4/vendor/codeception/codeception/src/Codeception/Application.php:103
 Codeception\Application->run() at /home/xxx/Code/iwqa_c2.2.4/vendor/codeception/codeception/codecept:33

run [--report] [--html [HTML]] [--xml [XML]] [--tap [TAP]] [--json [JSON]] [--colors] [--no-colors] [--silent] [--steps] [-d|--debug] [--coverage [COVERAGE]] [--coverage-html [COVERAGE-HTML]] [--coverage-xml [COVERAGE-XML]] [--coverage-text [COVERAGE-TEXT]] [--no-exit] [-g|--group GROUP] [-s|--skip SKIP] [-x|--skip-group SKIP-GROUP] [--env ENV] [-f|--fail-fast] [--no-rebuild] [--] [<suite>] [<test>]

Provide test source code if related

tests/api/testCest.php

<?php
class testCest
{
    public function testMonitorSoapAndRest(ApiTester $I)
    {
        $I->callSoapMonitor();
        $I->callRestMonitor();
    }
}

tests/_support/Helper/Api.php

<?php
namespace Helper;

class Api extends \Codeception\Module
{
    public function callSoapMonitor()
    {
        $this->getModule('SOAP')->sendSoapRequest('monitor');
        $this->getModule('SOAP')->seeSoapResponseEquals('OK');
    }

    public function callRestMonitor()
    {
        $this->getModule('REST')->sendGET('monitor');
        $this->getModule('REST')->seeResponseContainsJson(['body' => 'OK']);
    }
}

Details

  • PHP Version: 5.6.11
  • Operating System: Ubuntu
  • Installation type: Composer
  • List of installed packages (composer show)
behat/gherkin                      v4.4.2 Gherkin DSL parser for PHP 5.3
codeception/codeception            2.2.4  BDD-style testing framework
doctrine/instantiator              1.0.5  A small, lightweight utility to i...
facebook/webdriver                 1.1.3  A PHP client for WebDriver
flow/jsonpath                      0.3.4  JSONPath implementation for parsi...
fzaninotto/faker                   v1.6.0 Faker is a PHP library that gener...
guzzlehttp/guzzle                  6.2.1  Guzzle is a PHP HTTP client library
guzzlehttp/promises                1.2.0  Guzzle promises library
guzzlehttp/psr7                    1.3.1  PSR-7 message implementation
myclabs/deep-copy                  1.5.3  Create deep copies (clones) of yo...
phpdocumentor/reflection-common    1.0    Common reflection classes used by...
phpdocumentor/reflection-docblock  3.1.0  With this component, a library ca...
phpdocumentor/type-resolver        0.2    
phpspec/prophecy                   v1.6.1 Highly opinionated mocking framew...
phpunit/php-code-coverage          4.0.1  Library that provides collection,...
phpunit/php-file-iterator          1.4.1  FilterIterator implementation tha...
phpunit/php-text-template          1.2.1  Simple template engine.
phpunit/php-timer                  1.0.8  Utility class for timing
phpunit/php-token-stream           1.4.8  Wrapper around PHP's tokenizer ex...
phpunit/phpunit                    5.4.8  The PHP Unit Testing framework.
phpunit/phpunit-mock-objects       3.2.7  Mock Object library for PHPUnit
psr/http-message                   1.0.1  Common interface for HTTP messages
sebastian/code-unit-reverse-lookup 1.0.0  Looks up which function or method...
sebastian/comparator               1.2.0  Provides the functionality to com...
sebastian/diff                     1.4.1  Diff implementation
sebastian/environment              1.3.8  Provides functionality to handle ...
sebastian/exporter                 1.2.2  Provides the functionality to exp...
sebastian/global-state             1.1.1  Snapshotting of global state
sebastian/object-enumerator        1.0.0  Traverses array structures and ob...
sebastian/recursion-context        1.0.2  Provides functionality to recursi...
sebastian/resource-operations      1.0.0  Provides a list of PHP built-in f...
sebastian/version                  2.0.0  Library that helps with managing ...
symfony/browser-kit                v3.1.4 Symfony BrowserKit Component
symfony/console                    v3.1.4 Symfony Console Component
symfony/css-selector               v3.1.4 Symfony CssSelector Component
symfony/dom-crawler                v3.1.4 Symfony DomCrawler Component
symfony/event-dispatcher           v3.1.4 Symfony EventDispatcher Component
symfony/finder                     v3.1.4 Symfony Finder Component
symfony/polyfill-mbstring          v1.2.0 Symfony polyfill for the Mbstring...
symfony/yaml                       v3.1.4 Symfony Yaml Component
tightenco/collect                  v5.3.9 Collect - Illuminate Collections ...
webmozart/assert                   1.1.0  Assertions to validate method inp...
  • Suite configuration:
class_name: ApiTester
modules:
   enabled:
      - Cli:
      - Asserts:
      - PhpBrowser:
         url: localhost
      - REST:
         depends: PhpBrowser
         url: https://api.company.com/FS
      - SOAP:
         depends: PhpBrowser
         url: https://api.company.com
         endpoint: https://api.company.com/services
      - \Helper\Api
@Naktibalda

This comment has been minimized.

Show comment
Hide comment
@Naktibalda

Naktibalda Sep 14, 2016

Member

I don't believe that it worked in 2.2.3, the modules started conflicting in 2.2.0.

Member

Naktibalda commented Sep 14, 2016

I don't believe that it worked in 2.2.3, the modules started conflicting in 2.2.0.

@eXorus

This comment has been minimized.

Show comment
Hide comment
@eXorus

eXorus Sep 15, 2016

Contributor

I was not sure also, but I just try a fresh install and I can confirm that is working very well in 2.2.3:

composer require codeception/codeception:2.2.3
./vendor/bin/codecept bootstrap
./vendor/bin/codecept g:suite api
./vendor/bin/codecept generate:cest api test

Copy and past xml configuration, helper and Cest and the modules are loaded correctly.

In 2.2.4 there are changes in ModuleContainer and I think it's about this.

But I don't care is it possible to do in different way ? What is your solution @Naktibalda ?

Contributor

eXorus commented Sep 15, 2016

I was not sure also, but I just try a fresh install and I can confirm that is working very well in 2.2.3:

composer require codeception/codeception:2.2.3
./vendor/bin/codecept bootstrap
./vendor/bin/codecept g:suite api
./vendor/bin/codecept generate:cest api test

Copy and past xml configuration, helper and Cest and the modules are loaded correctly.

In 2.2.4 there are changes in ModuleContainer and I think it's about this.

But I don't care is it possible to do in different way ? What is your solution @Naktibalda ?

@Naktibalda

This comment has been minimized.

Show comment
Hide comment
@Naktibalda

Naktibalda Sep 15, 2016

Member

I think that a backwards compatible solution would be to create a new method called seeSoapResponseCodeIs but leave the old seeResponseCodeIs in
and add all other methods to @part nonconflicting (please come up with a better name).

seeResponseCodeIs and @part can then be dropped in the next breaking release (2.3 or 3.0).

@DavertMik what do you think?

Member

Naktibalda commented Sep 15, 2016

I think that a backwards compatible solution would be to create a new method called seeSoapResponseCodeIs but leave the old seeResponseCodeIs in
and add all other methods to @part nonconflicting (please come up with a better name).

seeResponseCodeIs and @part can then be dropped in the next breaking release (2.3 or 3.0).

@DavertMik what do you think?

@DavertMik

This comment has been minimized.

Show comment
Hide comment
@DavertMik

DavertMik Sep 15, 2016

Member

It doesn't seem a regular case to me, so maybe you can just create a helper that extends SOAP and override _conflicts method to disable conflict for your case. That's what you can do right now.

Member

DavertMik commented Sep 15, 2016

It doesn't seem a regular case to me, so maybe you can just create a helper that extends SOAP and override _conflicts method to disable conflict for your case. That's what you can do right now.

@DavertMik

This comment has been minimized.

Show comment
Hide comment
@DavertMik

DavertMik Sep 15, 2016

Member

I think that a backwards compatible solution would be to create a new method called seeSoapResponseCodeIs but leave the old seeResponseCodeIs in
and add all other methods to @part nonconflicting (please come up with a better name).

Right now I'm not sure. Name is not really good, and the idea of chanign API just for this one case doesn't seem reasonable. Probably we can come up with something better.

@eXorus

Could you please create a sample project that we could play with to come up with better solution for this case? Unfortunately I don't have SOAP API projects right now, so I need some help from you

Member

DavertMik commented Sep 15, 2016

I think that a backwards compatible solution would be to create a new method called seeSoapResponseCodeIs but leave the old seeResponseCodeIs in
and add all other methods to @part nonconflicting (please come up with a better name).

Right now I'm not sure. Name is not really good, and the idea of chanign API just for this one case doesn't seem reasonable. Probably we can come up with something better.

@eXorus

Could you please create a sample project that we could play with to come up with better solution for this case? Unfortunately I don't have SOAP API projects right now, so I need some help from you

@Naktibalda

This comment has been minimized.

Show comment
Hide comment
@Naktibalda

Naktibalda Sep 15, 2016

Member

Adding Soap to the name would make it consistent with other SoapResponse methods: http://codeception.com/docs/modules/SOAP#seeSoapResponseEquals

Member

Naktibalda commented Sep 15, 2016

Adding Soap to the name would make it consistent with other SoapResponse methods: http://codeception.com/docs/modules/SOAP#seeSoapResponseEquals

@DavertMik

This comment has been minimized.

Show comment
Hide comment
@DavertMik

DavertMik Sep 15, 2016

Member

Adding Soap to the name would make it consistent with other SoapResponse methods:

Ok, maybe you are right. Also seeResponseCode is not used as widely as in REST (as I remember). What I don't like is @part nonconflict. Yeah, how to name it better :(

Member

DavertMik commented Sep 15, 2016

Adding Soap to the name would make it consistent with other SoapResponse methods:

Ok, maybe you are right. Also seeResponseCode is not used as widely as in REST (as I remember). What I don't like is @part nonconflict. Yeah, how to name it better :(

@eXorus

This comment has been minimized.

Show comment
Hide comment
@eXorus

eXorus Sep 15, 2016

Contributor

Thanks a lot for yours replies, it's very useful.

I will try to purpose you a PR with seeSoapResponseCode and I will try to find a way to be compatible with the previous version

Contributor

eXorus commented Sep 15, 2016

Thanks a lot for yours replies, it's very useful.

I will try to purpose you a PR with seeSoapResponseCode and I will try to find a way to be compatible with the previous version

@eXorus

This comment has been minimized.

Show comment
Hide comment
@eXorus

eXorus Sep 15, 2016

Contributor

@DavertMik you don't need to have SOAP Server to test.

tests/api/SoapRestCest.php

<?php

class SoapRestCest
{
    public function testWithoutHelper(ApiTester $I)
    {
        $I->sendSoapRequest('monitor');
        $I->seeResponseCodeIs(404);
    }
    public function testWithHelperSoap(ApiTester $I)
    {
        $I->callSoapMonitor();
    }
    public function testWithHelperRest(ApiTester $I)
    {
        $I->callRestMonitor();
    }
}

tests/_support/Helper/Api.php

<?php
namespace Helper;

class Api extends \Codeception\Module
{

    public function callSoapMonitor()
    {
        $this->getModule('SOAP')->sendSoapRequest('monitor');
        $this->getModule('SOAP')->seeResponseCodeIs(404);
    }

    public function callRestMonitor()
    {
        $this->getModule('REST')->sendGET('monitor');
        $this->getModule('REST')->seeResponseCodeIs(404);
    }
}

tests/api.suite.yml

class_name: ApiTester
modules:
   enabled:
      - SOAP:
         depends: PhpBrowser
         url: https://api.company.com
         endpoint: https://api.company.com/services
      - REST:
         depends: PhpBrowser
         url: https://api.company.com/FS
      - \Helper\Api

So I removed the conflict between SOAP and REST in SOAP Module.

testWithoutHelper : it will take SOAP method or REST methode depends on the order of modules in yml (if REST is the last like here, seeResponseCodeIs will be => REST)

testWithHelperSoap : will work correctly because I precise in the helper the module that I want.

So I just need to add the new method in SOAP module to be able to fix the first wrong case and not be able to be dependant of the order of the module in yml file.

Sounds good to me and you ?

src/Codeception/Module/SOAP.php

    /**
     * Checks response code from server.
     *
     * @param $code
     */
    public function seeSoapResponseCodeIs($code)
    {
        codecept_debug("SOAP Module : seeResponseCodeIs");
        $this->assertEquals(
            $code,
            $this->client->getInternalResponse()->getStatus(),
            "soap response code matches expected"
        );
    }
    /**
     * Checks response code from server.
     *
     * @param $code
     */
    public function seeResponseCodeIs($code)
    {
        codecept_debug("SOAP Module Legacy : seeResponseCodeIs");
        $this->seeSoapResponseCodeIs($code);
    }
Contributor

eXorus commented Sep 15, 2016

@DavertMik you don't need to have SOAP Server to test.

tests/api/SoapRestCest.php

<?php

class SoapRestCest
{
    public function testWithoutHelper(ApiTester $I)
    {
        $I->sendSoapRequest('monitor');
        $I->seeResponseCodeIs(404);
    }
    public function testWithHelperSoap(ApiTester $I)
    {
        $I->callSoapMonitor();
    }
    public function testWithHelperRest(ApiTester $I)
    {
        $I->callRestMonitor();
    }
}

tests/_support/Helper/Api.php

<?php
namespace Helper;

class Api extends \Codeception\Module
{

    public function callSoapMonitor()
    {
        $this->getModule('SOAP')->sendSoapRequest('monitor');
        $this->getModule('SOAP')->seeResponseCodeIs(404);
    }

    public function callRestMonitor()
    {
        $this->getModule('REST')->sendGET('monitor');
        $this->getModule('REST')->seeResponseCodeIs(404);
    }
}

tests/api.suite.yml

class_name: ApiTester
modules:
   enabled:
      - SOAP:
         depends: PhpBrowser
         url: https://api.company.com
         endpoint: https://api.company.com/services
      - REST:
         depends: PhpBrowser
         url: https://api.company.com/FS
      - \Helper\Api

So I removed the conflict between SOAP and REST in SOAP Module.

testWithoutHelper : it will take SOAP method or REST methode depends on the order of modules in yml (if REST is the last like here, seeResponseCodeIs will be => REST)

testWithHelperSoap : will work correctly because I precise in the helper the module that I want.

So I just need to add the new method in SOAP module to be able to fix the first wrong case and not be able to be dependant of the order of the module in yml file.

Sounds good to me and you ?

src/Codeception/Module/SOAP.php

    /**
     * Checks response code from server.
     *
     * @param $code
     */
    public function seeSoapResponseCodeIs($code)
    {
        codecept_debug("SOAP Module : seeResponseCodeIs");
        $this->assertEquals(
            $code,
            $this->client->getInternalResponse()->getStatus(),
            "soap response code matches expected"
        );
    }
    /**
     * Checks response code from server.
     *
     * @param $code
     */
    public function seeResponseCodeIs($code)
    {
        codecept_debug("SOAP Module Legacy : seeResponseCodeIs");
        $this->seeSoapResponseCodeIs($code);
    }
@eXorus

This comment has been minimized.

Show comment
Hide comment
@eXorus

eXorus Sep 20, 2016

Contributor

I had no reply so I will send you the PR, maybe it's better like this to comment the code

Contributor

eXorus commented Sep 20, 2016

I had no reply so I will send you the PR, maybe it's better like this to comment the code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment