Skip to content
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

"_initialize" method of any module called twice #582

Closed
neoascetic opened this issue Sep 30, 2013 · 6 comments
Closed

"_initialize" method of any module called twice #582

neoascetic opened this issue Sep 30, 2013 · 6 comments

Comments

@neoascetic
Copy link
Contributor

With introducing of global configuration file, we got extra calling of _initialize hook of any registered module, and that can lead to invalid or unwanted behaviour: for example, cleanup and populating of a database with Db module will be performed twice.

As a workaround, for now I run my migrations and data importing from within global bootstrap file.

This need to be fixed. Codeception must provide some information about type of configuration file to the method.

@tiger-seo
Copy link
Member

please, do attach your config

@neoascetic
Copy link
Contributor Author

You can try to reproduce this using Codeception own tests. Add _initialize hook into CliHelper with file_put_contents("foo.txt", "bar\n", FILE_APPEND), and then run tests for cli suite.

After they finished, you might see that "foo.txt" contains two lines of text instead of one.

@DavertMik
Copy link
Member

Wow, that's a strong argument :)

Strange thing that we do strict check of all module callbacks to be executed in right order. You might see a test for those there too. Anyway, thanks. I will try to investigate it.

@DavertMik
Copy link
Member

Nah, did not reproduce it.

I added to CliHelper

<?php
    function _initialize()
    {
        file_put_contents("foo.txt", "bar\n", FILE_APPEND);
    }

?>

Just as you said. Then I ran ./codecept run cli

ANd I got bar in foo.txt

@neoascetic
Copy link
Contributor Author

Hmmm... Sorry for wasting your time. Probably, I was incorrect.

If I reproduce this situation, I'll give you more info and reopen the issue.

@pbtlt
Copy link

pbtlt commented Dec 3, 2013

I have same problem.
Tests run twice when I have global .dist configuration and run all suites at once.
Conditions:
Windows, PHP 5.3.13

#This is a acceptance.suite.dist.yml
class_name: WebGuy
modules:
    enabled:
        - PhpBrowser
        - WebHelper
    config:
        PhpBrowser:
            url: 'http://localhost/'

&

#This is a acceptance.suite.yml
class_name: WebGuy
modules:
    enabled:
        - PhpBrowser
        - WebHelper
    config:
        PhpBrowser:
            url: 'http://test.local/'

&

<?php
#This is a WebFormsAvailableCept.php
$I = new WebGuy($scenario);
$I->am('Web client');
$I->wantTo('Ensure that form available');
$I->amOnPage('/home/form.php');
$I->seeElement('form#form_online');

see below output of run command

/c/wamp/apps/test (codeception)
$ php codecept.phar run
Codeception PHP Testing Framework v1.8.0.1
Powered by PHPUnit 3.7.28 by Sebastian Bergmann.

Acceptance Tests (1) -------------------------------------------------------
Trying to ensure that form available (WebFormsAvailableCept.php)       Fail
----------------------------------------------------------------------------

Acceptance Tests (1) -------------------------------------------------------
Trying to ensure that form available (WebFormsAvailableCept.php)       Fail
----------------------------------------------------------------------------

Functional Tests (0) ------------------------
---------------------------------------------

Unit Tests (0) ------------------------------
---------------------------------------------



Time: 535 ms, Memory: 20.50Mb

If I remove acceptance.suite.dist.yml file, or run only acceptance suite - tests will be execute only once.

/c/wamp/apps/test (codeception)
$ php codecept.phar run acceptance
Codeception PHP Testing Framework v1.8.0.1
Powered by PHPUnit 3.7.28 by Sebastian Bergmann.

Acceptance Tests (1) -------------------------------------------------------
Trying to ensure that form available (WebFormsAvailableCept.php)       Fail
----------------------------------------------------------------------------


Time: 213 ms, Memory: 19.25Mb

DavertMik added a commit that referenced this issue Jan 14, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants