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

Cannot redeclare AcceptanceTesterActions #3208

Closed
Breadleyg opened this Issue Jun 11, 2016 · 3 comments

Comments

Projects
None yet
5 participants
@Breadleyg

Breadleyg commented Jun 11, 2016

Somehow we are having trouble enabling these three modules. Yii2 and Webdriver play nicely together but when we add DataFactory we get a duplicate class Exception.

Build runs OK:

Building Actor classes for suites: acceptance, functional, unit
 -> AcceptanceTesterActions.php generated successfully. 0 methods added
\AcceptanceTester includes modules: WebDriver, Yii2, DataFactory
 -> FunctionalTesterActions.php generated successfully. 0 methods added
\FunctionalTester includes modules: Filesystem, Yii2
 -> UnitTesterActions.php generated successfully. 0 methods added
\UnitTester includes modules: 

Our acceptance.suite.yml:

class_name: AcceptanceTester
modules:
    enabled:
      - WebDriver:
           restart: false 
           clear_cookies: false      
           browser: firefox     
           url: http://localurl
      - Yii2:
          part: ORM
          configFile: 'codeception/config/acceptance.php'           
      - DataFactory:
          factories: tests/_support/factories
          depends: Yii2       
env:
    acceptance:
         modules:
            config:
                WebDriver:
                    browser: phantom
                    url: http://accurl

When running:

PHP Fatal error: Cannot redeclare class _generated\AcceptanceTesterActions in /Applications/MAMP/htdocs/invatio/vwp/tests/codeception/_support/_generated/AcceptanceTesterActions.php on line 13

We are using Codeception version 2.2.1.

@beastbytes

This comment has been minimized.

Show comment
Hide comment
@beastbytes

beastbytes Jun 13, 2016

Having exactly the same issue with Yii2 and DataFactory in functional tests

Looking at the stack trace I can see my Cest file is first loaded in Codeception/Lib/Parser::includeFile(), line 197

then it's loaded again from League/FactoryMuffin/FactoryMuffin::loadDirectory() line 351

My functional_suite.yml file is:

class_name: FunctionalTester
modules:
    enabled:
      - Filesystem
      - Yii2
      - DataFactory:
          factories: tests/_support/factories
          depends: Yii2
      - \tests\codeception\frontend\Helper\Factories
    config:
        Yii2:
            configFile: '../config/frontend/functional.php'

beastbytes commented Jun 13, 2016

Having exactly the same issue with Yii2 and DataFactory in functional tests

Looking at the stack trace I can see my Cest file is first loaded in Codeception/Lib/Parser::includeFile(), line 197

then it's loaded again from League/FactoryMuffin/FactoryMuffin::loadDirectory() line 351

My functional_suite.yml file is:

class_name: FunctionalTester
modules:
    enabled:
      - Filesystem
      - Yii2
      - DataFactory:
          factories: tests/_support/factories
          depends: Yii2
      - \tests\codeception\frontend\Helper\Factories
    config:
        Yii2:
            configFile: '../config/frontend/functional.php'

@Naktibalda Naktibalda added this to the 2.2 milestone Jun 13, 2016

@DavertMik DavertMik added BUG 2.2 labels Jun 17, 2016

@DavertMik DavertMik modified the milestones: 2.2.2, 2.2 Jun 17, 2016

@alexjeen

This comment has been minimized.

Show comment
Hide comment
@alexjeen

alexjeen Jun 23, 2016

Contributor

I think I've found the bug. In both the files you specify:

beastbytes: tests/_support/factories
breadleyg: tests/_support/factories

But seeing the code, it expects a path relative to the codeception.yml file. However Yii2 specifies a subfolder in tests (codeception) and that's why it does not work.

Then because Codeception uses realpath:

$this->factoryMuffin->loadFactories(realpath(codecept_root_dir().$factoryPath));

This returns false if the directory does not exist. This results in factoryMuffin to load a empty directory (so basically it tries to load every php file in the Codeception folder). This is why it gets the duplicate class exception.

I will put in a pull request that throws an Exception when the factory folder can not be found and will update the documentation.

Contributor

alexjeen commented Jun 23, 2016

I think I've found the bug. In both the files you specify:

beastbytes: tests/_support/factories
breadleyg: tests/_support/factories

But seeing the code, it expects a path relative to the codeception.yml file. However Yii2 specifies a subfolder in tests (codeception) and that's why it does not work.

Then because Codeception uses realpath:

$this->factoryMuffin->loadFactories(realpath(codecept_root_dir().$factoryPath));

This returns false if the directory does not exist. This results in factoryMuffin to load a empty directory (so basically it tries to load every php file in the Codeception folder). This is why it gets the duplicate class exception.

I will put in a pull request that throws an Exception when the factory folder can not be found and will update the documentation.

@alexjeen alexjeen referenced this issue Jun 23, 2016

Merged

Fixing #3208 #3267

@DavertMik

This comment has been minimized.

Show comment
Hide comment
@DavertMik

DavertMik Jun 24, 2016

Member

@alexjeen thanks for the investigation and solution

Member

DavertMik commented Jun 24, 2016

@alexjeen thanks for the investigation and solution

DavertMik added a commit that referenced this issue Jun 24, 2016

Fixing #3208 (#3267)
* check factory paths

check the factorymuffin paths before including them

* also updated the documentation

* throw ModuleException and clean up code

@DavertMik DavertMik closed this Jun 25, 2016

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