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

Codeception 2.3.2 Breaks Yii2 migration #14226

Closed
dbd5 opened this Issue May 28, 2017 · 10 comments

Comments

Projects
None yet
6 participants
@dbd5

dbd5 commented May 28, 2017

What steps will reproduce the problem?

I'm not sure this issue is systematic or directly dependent on developer code so I can at best present the facts about the state of the environment and what triggered the error

  1. Setup Yii2 Advanced project
  2. Check that codeception/codeception and codeception/base version = 2.3.1
  3. Run Composer update and check that codeception/codeception and codeception/base version = 2.3.2
  4. Create some migration script (./Yii migrate/create ...)
  5. Run ./Yii migrate/up

What is the expected result?

The migration should run and make relevant changes to the database schema

What do you get instead?

The following error is thrown (Note that all the code referred to in the error tree is core Yii2 or generated automatically by Composer);

PHP Fatal error: Cannot declare class Codeception\TestCase\Test, because the name is already in use in /var/www/cbt/vendor/codeception/base/shim.php on line 58
PHP Stack trace:
PHP 1. {main}() /var/www/cbt/yii:0
PHP 2. require() /var/www/cbt/yii:14
PHP 3. ComposerAutoloaderInit667629522034f7e7b1cef1939dc2d30f::getLoader() /var/www/cbt/vendor/autoload.php:7
PHP 4. composerRequire667629522034f7e7b1cef1939dc2d30f() /var/www/cbt/vendor/composer/autoload_real.php:56

Fatal error: Cannot declare class Codeception\TestCase\Test, because the name is already in use in /var/www/cbt/vendor/codeception/base/shim.php on line 58

Additional info

The only work around I could find is to roll back to a backup and then set version constraints on composer.json as follows so that codeception is not updated to 2.3.2 when I do composer update;

    "codeception/codeception": "2.3.1",
    "codeception/specify": "^0.4.3",
    "codeception/base": "2.3.1",
    "codeception/verify": "~0.3.1"
Q A
Yii version 2.0.11.2
PHP version PHP 7.1.3-3+deb.sury.org~trusty+1
Operating system Ubuntu 14.04.5 LTS

@samdark samdark added the Codeception label May 28, 2017

@samdark

This comment has been minimized.

Show comment
Hide comment
@samdark

samdark May 28, 2017

Member

Are you sure that when trying to migrate database Codeception errors? These two facts should not be related.

Member

samdark commented May 28, 2017

Are you sure that when trying to migrate database Codeception errors? These two facts should not be related.

@yii-bot

This comment has been minimized.

Show comment
Hide comment
@yii-bot

yii-bot May 28, 2017

Thanks for posting in our issue tracker.
In order to properly assist you, we need additional information:

  • When does the issue occur?
  • What do you see?
  • What was the expected result?
  • Can you supply us with a stacktrace? (optional)
  • Do you have exact code to reproduce it? Maybe a PHPUnit tests that fails? (optional)

Thanks!

This is an automated comment, triggered by adding the label status:need more info.

yii-bot commented May 28, 2017

Thanks for posting in our issue tracker.
In order to properly assist you, we need additional information:

  • When does the issue occur?
  • What do you see?
  • What was the expected result?
  • Can you supply us with a stacktrace? (optional)
  • Do you have exact code to reproduce it? Maybe a PHPUnit tests that fails? (optional)

Thanks!

This is an automated comment, triggered by adding the label status:need more info.

@dbd5

This comment has been minimized.

Show comment
Hide comment
@dbd5

dbd5 May 28, 2017

@samdark ,

I was puzzled as well because I can't make out any dependence between migrate and Codeception. I can only confirm the state of my environment, I rolled back to backup which had 2.3.1 a couple of times and each time tested that migration works on 2.3.1 but fails once you run composer update to take Codeception to 2.3.2. Here's the trace;

[01:59 PM]-[vagrant@localhost]-[/var/www/test]
$ composer update
Cannot load Xdebug - it was already loaded
The "extra.asset-installer-paths" option is deprecated, use the "config.fxp-asset.installer-paths" option
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 2 installs, 7 updates, 0 removals

  • Updating nox-it/yii2-nox (1.0.7 => 1.0.8): Loading from cache
  • Updating nox-it/yii2-nox-mvc (1.0.9 => 1.1.0): Loading from cache
  • Updating nox-it/yii2-nox-user-agent-parser (1.5.4 => 1.5.5): Loading from cache
  • Updating codeception/codeception (2.3.1 => 2.3.2): Loading from cache
  • Updating codeception/base (2.3.1 => 2.3.2): Loading from cache
  • Updating kartik-v/bootstrap-fileinput (v4.4.0 => v4.4.1): Loading from cache
  • Updating kartik-v/yii2-widget-fileinput (v1.0.5 => v1.0.6): Loading from cache
  • Installing bower-asset/js-cropbox (0.12.1): Loading from cache
  • Installing bupy7/yii2-widget-cropbox (5.1.1): Loading from cache
    Generating autoload files

[02:15 PM]-[vagrant@localhost]-[/var/www/test]
$ ./yii migrate/up
Cannot load Xdebug - it was already loaded
PHP Fatal error: Cannot declare class Codeception\TestCase\Test, because the name is already in use in /var/www/test/vendor/codeception/base/shim.php on line 58
PHP Stack trace:
PHP 1. {main}() /var/www/test/yii:0
PHP 2. require() /var/www/test/yii:14
PHP 3. ComposerAutoloaderInit667629522034f7e7b1cef1939dc2d30f::getLoader() /var/www/test/vendor/autoload.php:7
PHP 4. composerRequire667629522034f7e7b1cef1939dc2d30f() /var/www/test/vendor/composer/autoload_real.php:56

Fatal error: Cannot declare class Codeception\TestCase\Test, because the name is already in use in /var/www/test/vendor/codeception/base/shim.php on line 58

Call Stack:
0.0004 352632 1. {main}() /var/www/test/yii:0
0.0012 353808 2. require('/var/www/test/vendor/autoload.php') /var/www/test/yii:14
0.0020 369088 3. ComposerAutoloaderInit667629522034f7e7b1cef1939dc2d30f::getLoader() /var/www/test/vendor/autoload.php:7
0.0651 3819992 4. composerRequire667629522034f7e7b1cef1939dc2d30f() /var/www/test/vendor/composer/autoload_real.php:56

dbd5 commented May 28, 2017

@samdark ,

I was puzzled as well because I can't make out any dependence between migrate and Codeception. I can only confirm the state of my environment, I rolled back to backup which had 2.3.1 a couple of times and each time tested that migration works on 2.3.1 but fails once you run composer update to take Codeception to 2.3.2. Here's the trace;

[01:59 PM]-[vagrant@localhost]-[/var/www/test]
$ composer update
Cannot load Xdebug - it was already loaded
The "extra.asset-installer-paths" option is deprecated, use the "config.fxp-asset.installer-paths" option
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 2 installs, 7 updates, 0 removals

  • Updating nox-it/yii2-nox (1.0.7 => 1.0.8): Loading from cache
  • Updating nox-it/yii2-nox-mvc (1.0.9 => 1.1.0): Loading from cache
  • Updating nox-it/yii2-nox-user-agent-parser (1.5.4 => 1.5.5): Loading from cache
  • Updating codeception/codeception (2.3.1 => 2.3.2): Loading from cache
  • Updating codeception/base (2.3.1 => 2.3.2): Loading from cache
  • Updating kartik-v/bootstrap-fileinput (v4.4.0 => v4.4.1): Loading from cache
  • Updating kartik-v/yii2-widget-fileinput (v1.0.5 => v1.0.6): Loading from cache
  • Installing bower-asset/js-cropbox (0.12.1): Loading from cache
  • Installing bupy7/yii2-widget-cropbox (5.1.1): Loading from cache
    Generating autoload files

[02:15 PM]-[vagrant@localhost]-[/var/www/test]
$ ./yii migrate/up
Cannot load Xdebug - it was already loaded
PHP Fatal error: Cannot declare class Codeception\TestCase\Test, because the name is already in use in /var/www/test/vendor/codeception/base/shim.php on line 58
PHP Stack trace:
PHP 1. {main}() /var/www/test/yii:0
PHP 2. require() /var/www/test/yii:14
PHP 3. ComposerAutoloaderInit667629522034f7e7b1cef1939dc2d30f::getLoader() /var/www/test/vendor/autoload.php:7
PHP 4. composerRequire667629522034f7e7b1cef1939dc2d30f() /var/www/test/vendor/composer/autoload_real.php:56

Fatal error: Cannot declare class Codeception\TestCase\Test, because the name is already in use in /var/www/test/vendor/codeception/base/shim.php on line 58

Call Stack:
0.0004 352632 1. {main}() /var/www/test/yii:0
0.0012 353808 2. require('/var/www/test/vendor/autoload.php') /var/www/test/yii:14
0.0020 369088 3. ComposerAutoloaderInit667629522034f7e7b1cef1939dc2d30f::getLoader() /var/www/test/vendor/autoload.php:7
0.0651 3819992 4. composerRequire667629522034f7e7b1cef1939dc2d30f() /var/www/test/vendor/composer/autoload_real.php:56

@samdark

This comment has been minimized.

Show comment
Hide comment
@samdark

samdark May 28, 2017

Member

Are you able to reproduce it w/ clean basic project template?

Member

samdark commented May 28, 2017

Are you able to reproduce it w/ clean basic project template?

@dbd5

This comment has been minimized.

Show comment
Hide comment
@dbd5

dbd5 May 28, 2017

My project is using the Advanced template so it is impossible to recast it with the basic template.

If however you just want us to import the basic template and attempt to reproduce, we need to find a way to make the state of the project similar to what we are trying to reproduce so it will be a comparison of apples and apples. For instance we must take composer to 2.3.1 and run a migration and then take composer to 2.3.2 and run the migration again.

If you provide me some guidance to take composer to 2.3.1, I can try

dbd5 commented May 28, 2017

My project is using the Advanced template so it is impossible to recast it with the basic template.

If however you just want us to import the basic template and attempt to reproduce, we need to find a way to make the state of the project similar to what we are trying to reproduce so it will be a comparison of apples and apples. For instance we must take composer to 2.3.1 and run a migration and then take composer to 2.3.2 and run the migration again.

If you provide me some guidance to take composer to 2.3.1, I can try

@samdark

This comment has been minimized.

Show comment
Hide comment
@samdark

samdark May 28, 2017

Member

Should be easy. Open composer.json, find "codeception/base" and make it look like:

"codeception/base": "2.3.1",

or

"codeception/base": "2.3.2",

Then do composer update.

Member

samdark commented May 28, 2017

Should be easy. Open composer.json, find "codeception/base" and make it look like:

"codeception/base": "2.3.1",

or

"codeception/base": "2.3.2",

Then do composer update.

@samdark samdark closed this May 28, 2017

@samdark samdark reopened this May 28, 2017

@dbd5

This comment has been minimized.

Show comment
Hide comment
@dbd5

dbd5 May 29, 2017

Hello @samdark ,

I have reproduced the issue successfully on a clean install of the basic template, this is how I tested.

ROUND 1

  1. Install the basic template
    $ composer create-project --prefer-dist --stability=dev yiisoft/yii2-app-basic basic
  2. Update config/db.php to setup DB connection
  3. Create a migration folder
  4. Place a migration script in migration folder
  5. Apply migration
    ./yii migrate/up
    ROUND 1 RESULT - MIGRATION WORKED AS EXPECTED

ROUND 2

  1. Roll back migration from ROUND 1
    ./yii migrate/down
  2. Add the following to composer to JSON (because they are in composer of the test project where this bug was detected)
    ...
    "nox-it/yii2-nox-user-agent-parser": "",
    "bupy7/yii2-widget-cropbox": "
    "
  3. RUN composer update to install the extensions
  4. Apply migration to check if extensions break Migration
    ./yii migrate/up
    ROUND 2 RESULT - MIGRATION WORKED AS EXPECTED

ROUND 3

  1. Roll back migration from ROUND 2
    ./yii migrate/down
  2. Update composer to take Codeception to 2.3.1
    ...
    "codeception/codeception": "2.3.1",
    "codeception/base": "2.3.1",
  3. RUN composer update
  4. Apply migration to check if codeception 2.3.1 break Migration
    ./yii migrate/up
    ROUND 3 RESULT - MIGRATION WORKED AS EXPECTED

ROUND 4

  1. Roll back migration from ROUND 3
    ./yii migrate/down
  2. Update composer to take Codeception to 2.3.2
    ...
    "codeception/codeception": "2.3.2",
    "codeception/base": "2.3.2",
  3. RUN composer update
  4. Apply migration to check if codeception 2.3.2 break Migration
    ./yii migrate/up
    ROUND 4 RESULT - MIGRATION FAILED WITH THE SAME ERRORS AS REPORTED, SEE TRACE BELOW

[09:10 AM]-[vagrant@localhost]-[/var/www/basic]
$ ./yii migrate/up
Cannot load Xdebug - it was already loaded
PHP Fatal error: Cannot declare class Codeception\TestCase\Test, because the name is already in use in /var/www/basic/vendor/codeception/base/shim.php on line 58
PHP Stack trace:
PHP 1. {main}() /var/www/basic/yii:0
PHP 2. require() /var/www/basic/yii:14
PHP 3. ComposerAutoloaderInit0ad5dd5f9500528eaf1e5fb573516faa::getLoader() /var/www/basic/vendor/autoload.php:7
PHP 4. composerRequire0ad5dd5f9500528eaf1e5fb573516faa() /var/www/basic/vendor/composer/autoload_real.php:56

Fatal error: Cannot declare class Codeception\TestCase\Test, because the name is already in use in /var/www/basic/vendor/codeception/base/shim.php on line 58

Call Stack:
0.0003 351144 1. {main}() /var/www/basic/yii:0
0.0009 352320 2. require('/var/www/basic/vendor/autoload.php') /var/www/basic/yii:14
0.0015 367600 3. ComposerAutoloaderInit0ad5dd5f9500528eaf1e5fb573516faa::getLoader() /var/www/basic/vendor/autoload.php:7
0.0576 3682080 4. composerRequire0ad5dd5f9500528eaf1e5fb573516faa() /var/www/basic/vendor/composer/autoload_real.php:56

Conclusion
I suggest it is safe to conclude that codeception 2.3.2 is at fault here pending code review

dbd5 commented May 29, 2017

Hello @samdark ,

I have reproduced the issue successfully on a clean install of the basic template, this is how I tested.

ROUND 1

  1. Install the basic template
    $ composer create-project --prefer-dist --stability=dev yiisoft/yii2-app-basic basic
  2. Update config/db.php to setup DB connection
  3. Create a migration folder
  4. Place a migration script in migration folder
  5. Apply migration
    ./yii migrate/up
    ROUND 1 RESULT - MIGRATION WORKED AS EXPECTED

ROUND 2

  1. Roll back migration from ROUND 1
    ./yii migrate/down
  2. Add the following to composer to JSON (because they are in composer of the test project where this bug was detected)
    ...
    "nox-it/yii2-nox-user-agent-parser": "",
    "bupy7/yii2-widget-cropbox": "
    "
  3. RUN composer update to install the extensions
  4. Apply migration to check if extensions break Migration
    ./yii migrate/up
    ROUND 2 RESULT - MIGRATION WORKED AS EXPECTED

ROUND 3

  1. Roll back migration from ROUND 2
    ./yii migrate/down
  2. Update composer to take Codeception to 2.3.1
    ...
    "codeception/codeception": "2.3.1",
    "codeception/base": "2.3.1",
  3. RUN composer update
  4. Apply migration to check if codeception 2.3.1 break Migration
    ./yii migrate/up
    ROUND 3 RESULT - MIGRATION WORKED AS EXPECTED

ROUND 4

  1. Roll back migration from ROUND 3
    ./yii migrate/down
  2. Update composer to take Codeception to 2.3.2
    ...
    "codeception/codeception": "2.3.2",
    "codeception/base": "2.3.2",
  3. RUN composer update
  4. Apply migration to check if codeception 2.3.2 break Migration
    ./yii migrate/up
    ROUND 4 RESULT - MIGRATION FAILED WITH THE SAME ERRORS AS REPORTED, SEE TRACE BELOW

[09:10 AM]-[vagrant@localhost]-[/var/www/basic]
$ ./yii migrate/up
Cannot load Xdebug - it was already loaded
PHP Fatal error: Cannot declare class Codeception\TestCase\Test, because the name is already in use in /var/www/basic/vendor/codeception/base/shim.php on line 58
PHP Stack trace:
PHP 1. {main}() /var/www/basic/yii:0
PHP 2. require() /var/www/basic/yii:14
PHP 3. ComposerAutoloaderInit0ad5dd5f9500528eaf1e5fb573516faa::getLoader() /var/www/basic/vendor/autoload.php:7
PHP 4. composerRequire0ad5dd5f9500528eaf1e5fb573516faa() /var/www/basic/vendor/composer/autoload_real.php:56

Fatal error: Cannot declare class Codeception\TestCase\Test, because the name is already in use in /var/www/basic/vendor/codeception/base/shim.php on line 58

Call Stack:
0.0003 351144 1. {main}() /var/www/basic/yii:0
0.0009 352320 2. require('/var/www/basic/vendor/autoload.php') /var/www/basic/yii:14
0.0015 367600 3. ComposerAutoloaderInit0ad5dd5f9500528eaf1e5fb573516faa::getLoader() /var/www/basic/vendor/autoload.php:7
0.0576 3682080 4. composerRequire0ad5dd5f9500528eaf1e5fb573516faa() /var/www/basic/vendor/composer/autoload_real.php:56

Conclusion
I suggest it is safe to conclude that codeception 2.3.2 is at fault here pending code review

@dbd5

This comment has been minimized.

Show comment
Hide comment
@dbd5

dbd5 May 29, 2017

Additional Note - What happens if we roll back to Codeception 2.3.1

ROUND 5

  1. Roll back migration from ROUND 4
    ./yii migrate/down
  2. Update composer to take Codeception back to 2.3.1
    ...
    "codeception/codeception": "2.3.1",
    "codeception/base": "2.3.1",
  3. RUN composer update
  4. Apply migration to check if codeception 2.3.1 break Migration
    ./yii migrate/up
    ROUND 5 RESULT - MIGRATION WORKED FLAWLESSLY

dbd5 commented May 29, 2017

Additional Note - What happens if we roll back to Codeception 2.3.1

ROUND 5

  1. Roll back migration from ROUND 4
    ./yii migrate/down
  2. Update composer to take Codeception back to 2.3.1
    ...
    "codeception/codeception": "2.3.1",
    "codeception/base": "2.3.1",
  3. RUN composer update
  4. Apply migration to check if codeception 2.3.1 break Migration
    ./yii migrate/up
    ROUND 5 RESULT - MIGRATION WORKED FLAWLESSLY

@samdark samdark self-assigned this May 29, 2017

@samdark samdark added this to the 2.0.12 milestone May 29, 2017

@Naktibalda

This comment has been minimized.

Show comment
Hide comment

Probably it was caused by Codeception/Codeception#4262

@Faryshta

This comment has been minimized.

Show comment
Hide comment
@Faryshta

Faryshta Jun 1, 2017

Contributor

this indeed seems like a codeception issue with class loading

Contributor

Faryshta commented Jun 1, 2017

this indeed seems like a codeception issue with class loading

@cebe cebe closed this Jun 1, 2017

@cebe cebe removed this from the 2.0.12 milestone Jun 1, 2017

DavertMik added a commit to Codeception/Codeception that referenced this issue Jun 1, 2017

DavertMik added a commit to Codeception/Codeception that referenced this issue Jun 1, 2017

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