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

Running Codeception Tests Crashes Website Locally #4632

Open
gvwarrior opened this issue Jul 22, 2019 · 11 comments

Comments

@gvwarrior
Copy link

commented Jul 22, 2019

Description

I followed the following guides several times in order to write Tests using Codeception but I encountered an error that I've never seen, and am unable to locate the root cause.

Codeception Install Guides:

The Problem

If attempt to run any test (i.e: codecept run unit ), Codeception prints the following errors to the console.

[craft\errors\DbConnectException]
Craft CMS can’t connect to the database with the credentials in config/db.php.

[yii\db\Exception]
SQLSTATE[HY000] [2002] No such file or directory

[PDOException]
SQLSTATE[HY000] [2002] No such file or directory

Screen Shot 2019-07-22 at 2 55 26 PM

From that moment forward, when I try to visit the site at the base URL that I have always used, I am unable to connect to any page.

Screen Shot 2019-07-22 at 2 59 48 PM

The only solution I can do to get my site back locally is to delete my project locally, and then do a git pull, composer install, ect. After doing that, I can visit the site locally again. But if I try to use Codeception again and following either of these excellent guides, the cycle repeats:

I have done this process several times... From the logs I've placed below, it looks like some sort of authentication error and hopefully, it's from something simple I missed, but it seems extraordinarily tricky.

Thanks for any of your help! Ask if you need anything.

File: tests/_craft/storage/logs/console.log

2019-07-22 18:16:32 [-][-][-][warning][deprecation-error] The auto-generated validation key stored at /Users/gavin/Desktop/Projects/Software/Craft/Production/getFitGrill/getfitgrill/tests/_craft/storage/runtime/validation.key has been deprecated. Copy its value to the “securityKey” config setting in config/general.php.
2019-07-22 18:16:33 [-][-][-][info][yii\db\Command::query] SHOW TABLES
2019-07-22 18:16:33 [-][-][-][info][yii\db\Connection::open] Opening DB connection: mysql:host=localhost;dbname=craft_db_431284;port=3306;
2019-07-22 18:16:33 [-][-][-][profile begin][yii\db\Connection::open] Opening DB connection: mysql:host=localhost;dbname=craft_db_431284;port=3306;
2019-07-22 18:16:33 [-][-][-][profile end][yii\db\Connection::open] Opening DB connection: mysql:host=localhost;dbname=craft_db_431284;port=3306;
2019-07-22 18:16:33 [-][-][-][error][craft\db\Connection::open] SQLSTATE[HY000] [2002] No such file or directory
2019-07-22 18:16:33 [-][-][-][error][craft\db\Connection::open] SQLSTATE[HY000] [2002] No such file or directory
2019-07-22 18:16:32 [-][-][-][info][application] $_GET = []

$_POST = []

$_FILES = []

$_COOKIE = []

$_SERVER = [
    'TERM' => 'xterm-256color'
    'SHELL' => '/bin/bash'
    'TMPDIR' => '/var/folders/lr/c7mvbm8x2wgfx32tn1fskkt00000gn/T/'
    'Apple_PubSub_Socket_Render' => '/private/tmp/com.apple.launchd.CV6Dtx3yRi/Render'
    '__INTELLIJ_COMMAND_HISTFILE__' => '/Users/gavin/Library/Preferences/PhpStorm2018.3/terminal/history/history-7'
    'USER' => 'gavin'
    'SSH_AUTH_SOCK' => '/private/tmp/com.apple.launchd.LjNxmzU93B/Listeners'
    '__CF_USER_TEXT_ENCODING' => '0x1F5:0x0:0x0'
    'PATH' => '/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/gavin/Desktop/Projects/Software/Craft/Production/getFitGrill/getfitgrill/node_modules/.bin'
    'TERMINAL_EMULATOR' => 'JetBrains-JediTerm'
    'PWD' => '/Users/gavin/Desktop/Projects/Software/Craft/Production/getFitGrill/getfitgrill'
    'PROJECT_DIR' => '/Users/gavin/Desktop/Projects/Software/Craft/Production/getFitGrill/getfitgrill'
    'XPC_FLAGS' => '0x0'
    'XPC_SERVICE_NAME' => '0'
    'SHLVL' => '1'
    'HOME' => '/Users/gavin'
    'LOGNAME' => 'gavin'
    'LC_CTYPE' => 'en_US.UTF-8'
    '_' => '/usr/local/bin/codecept'
    'PHP_SELF' => '/usr/local/bin/codecept'
    'SCRIPT_NAME' => 'index.php'
    'SCRIPT_FILENAME' => 'index.php'
    'PATH_TRANSLATED' => '/usr/local/bin/codecept'
    'DOCUMENT_ROOT' => ''
    'REQUEST_TIME_FLOAT' => 1563819392.6099
    'REQUEST_TIME' => 1563819392
    'argv' => [
        0 => '/usr/local/bin/codecept'
        1 => 'run'
        2 => 'unit'
    ]
    'argc' => 3
    'ENVIRONMENT' => 'dev'
    'SECURITY_KEY' => '•••••••••••••••••••••••••••••••••••••'
    'DB_DRIVER' => 'mysql'
    'DB_HOST' => 'localhost'
    'DB_SERVER' => 'localhost'
    'DB_USER' => 'root'
    'DB_PASSWORD' => '••••'
    'DB_NAME' => 'craft_db_431284'
    'DB_DATABASE' => 'craft_db_431284'
    'DB_SCHEMA' => 'public'
    'DB_TABLE_PREFIX' => 'craft_'
    'DB_PORT' => ''
    'BACKUP_COMMAND' => '/Applications/MAMP/Library/bin/mysqldump -h localhost -u root -proot --add-drop-table --comments --create-options --dump-date --no-autocommit --routines --set-charset --triggers --single-transaction --no-data --result-file=\"{file}\" {database} && /Applications/MAMP/Library/bin/mysqldump -h localhost -u root -proot --add-drop-table --comments --create-options --dump-date --no-autocommit --routines --set-charset --triggers --no-create-info --ignore-table={database}.assetindexdata --ignore-table={database}.assettransformindex --ignore-table={database}.cache --ignore-table={database}.sessions --ignore-table={database}.templatecaches --ignore-table={database}.templatecachecriteria --ignore-table={database}.templatecacheelements {database} >> \"{file}\"'
    'RESTORE_COMMAND' => '/Applications/MAMP/Library/bin/mysql -h localhost -u root -proot {database} < \"{file}\"'
    'DEFAULT_SITE_URL' => 'http://localhost'
    'SERVER_NAME' => 'localhost'
    'SERVER_PORT' => '80'
    'HTTPS' => false
    'REMOTE_ADDR' => '1.1.1.1'
    'REMOTE_PORT' => 654321
]
2019-07-22 18:19:56 [-][-][-][warning][deprecation-error] The auto-generated validation key stored at /Users/gavin/Desktop/Projects/Software/Craft/Production/getFitGrill/getfitgrill/tests/_craft/storage/runtime/validation.key has been deprecated. Copy its value to the “securityKey” config setting in config/general.php.
2019-07-22 18:19:56 [-][-][-][info][yii\db\Command::query] SHOW TABLES
2019-07-22 18:19:56 [-][-][-][info][yii\db\Connection::open] Opening DB connection: mysql:host=localhost;dbname=craft_db_431284;port=3306;
2019-07-22 18:19:56 [-][-][-][profile begin][yii\db\Connection::open] Opening DB connection: mysql:host=localhost;dbname=craft_db_431284;port=3306;
2019-07-22 18:19:56 [-][-][-][profile end][yii\db\Connection::open] Opening DB connection: mysql:host=localhost;dbname=craft_db_431284;port=3306;
2019-07-22 18:19:56 [-][-][-][error][craft\db\Connection::open] SQLSTATE[HY000] [2002] No such file or directory
2019-07-22 18:19:56 [-][-][-][error][craft\db\Connection::open] SQLSTATE[HY000] [2002] No such file or directory
2019-07-22 18:19:56 [-][-][-][info][application] $_GET = []

$_POST = []

$_FILES = []

$_COOKIE = []

$_SERVER = [
    'TERM' => 'xterm-256color'
    'SHELL' => '/bin/bash'
    'TMPDIR' => '/var/folders/lr/c7mvbm8x2wgfx32tn1fskkt00000gn/T/'
    'Apple_PubSub_Socket_Render' => '/private/tmp/com.apple.launchd.CV6Dtx3yRi/Render'
    '__INTELLIJ_COMMAND_HISTFILE__' => '/Users/gavin/Library/Preferences/PhpStorm2018.3/terminal/history/history-7'
    'USER' => 'gavin'
    'SSH_AUTH_SOCK' => '/private/tmp/com.apple.launchd.LjNxmzU93B/Listeners'
    '__CF_USER_TEXT_ENCODING' => '0x1F5:0x0:0x0'
    'PATH' => '/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/gavin/Desktop/Projects/Software/Craft/Production/getFitGrill/getfitgrill/node_modules/.bin'
    'TERMINAL_EMULATOR' => 'JetBrains-JediTerm'
    'PWD' => '/Users/gavin/Desktop/Projects/Software/Craft/Production/getFitGrill/getfitgrill'
    'PROJECT_DIR' => '/Users/gavin/Desktop/Projects/Software/Craft/Production/getFitGrill/getfitgrill'
    'XPC_FLAGS' => '0x0'
    'XPC_SERVICE_NAME' => '0'
    'SHLVL' => '1'
    'HOME' => '/Users/gavin'
    'LOGNAME' => 'gavin'
    'LC_CTYPE' => 'en_US.UTF-8'
    '_' => '/usr/local/bin/codecept'
    'PHP_SELF' => '/usr/local/bin/codecept'
    'SCRIPT_NAME' => 'index.php'
    'SCRIPT_FILENAME' => 'index.php'
    'PATH_TRANSLATED' => '/usr/local/bin/codecept'
    'DOCUMENT_ROOT' => ''
    'REQUEST_TIME_FLOAT' => 1563819596.2607
    'REQUEST_TIME' => 1563819596
    'argv' => [
        0 => '/usr/local/bin/codecept'
        1 => 'run'
        2 => 'unit'
    ]
    'argc' => 3
    'ENVIRONMENT' => 'dev'
    'SECURITY_KEY' => '•••••••••••••••••••••••••••••••••••••'
    'DB_DRIVER' => 'mysql'
    'DB_HOST' => 'localhost'
    'DB_SERVER' => 'localhost'
    'DB_USER' => 'root'
    'DB_PASSWORD' => '••••'
    'DB_NAME' => 'craft_db_431284'
    'DB_DATABASE' => 'craft_db_431284'
    'DB_SCHEMA' => 'public'
    'DB_TABLE_PREFIX' => 'craft_'
    'DB_PORT' => ''
    'BACKUP_COMMAND' => '/Applications/MAMP/Library/bin/mysqldump -h localhost -u root -proot --add-drop-table --comments --create-options --dump-date --no-autocommit --routines --set-charset --triggers --single-transaction --no-data --result-file=\"{file}\" {database} && /Applications/MAMP/Library/bin/mysqldump -h localhost -u root -proot --add-drop-table --comments --create-options --dump-date --no-autocommit --routines --set-charset --triggers --no-create-info --ignore-table={database}.assetindexdata --ignore-table={database}.assettransformindex --ignore-table={database}.cache --ignore-table={database}.sessions --ignore-table={database}.templatecaches --ignore-table={database}.templatecachecriteria --ignore-table={database}.templatecacheelements {database} >> \"{file}\"'
    'RESTORE_COMMAND' => '/Applications/MAMP/Library/bin/mysql -h localhost -u root -proot {database} < \"{file}\"'
    'DEFAULT_SITE_URL' => 'http://localhost'
    'SERVER_NAME' => 'test.craftcms.test'
    'SERVER_PORT' => '80'
    'HTTPS' => true
    'REMOTE_ADDR' => '1.1.1.1'
    'REMOTE_PORT' => 654321
]
2019-07-22 19:34:55 [-][-][-][warning][deprecation-error] The auto-generated validation key stored at /Users/gavin/Desktop/Projects/Software/Craft/Production/getFitGrill/getfitgrill/tests/_craft/storage/runtime/validation.key has been deprecated. Copy its value to the “securityKey” config setting in config/general.php.
2019-07-22 19:34:55 [-][-][-][info][yii\db\Command::query] SHOW TABLES
2019-07-22 19:34:55 [-][-][-][info][yii\db\Connection::open] Opening DB connection: mysql:host=127.0.0.1;dbname=craft_db_431284;port=3306;
2019-07-22 19:34:55 [-][-][-][profile begin][yii\db\Connection::open] Opening DB connection: mysql:host=127.0.0.1;dbname=craft_db_431284;port=3306;
2019-07-22 19:34:55 [-][-][-][profile end][yii\db\Connection::open] Opening DB connection: mysql:host=127.0.0.1;dbname=craft_db_431284;port=3306;
2019-07-22 19:34:55 [-][-][-][error][craft\db\Connection::open] SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client
2019-07-22 19:34:55 [-][-][-][error][craft\db\Connection::open] SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client
2019-07-22 19:34:55 [-][-][-][info][application] $_GET = []

$_POST = []

$_FILES = []

$_COOKIE = []

$_SERVER = [
    'TERM' => 'xterm-256color'
    'SSH_AUTH_SOCK' => '/private/tmp/com.apple.launchd.LjNxmzU93B/Listeners'
    '__CF_USER_TEXT_ENCODING' => '0x0:0:0'
    'PATH' => '/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/gavin/Desktop/Projects/Software/Craft/Production/getFitGrill/getfitgrill/node_modules/.bin'
    'HOME' => '/Users/gavin'
    'LC_CTYPE' => 'en_US.UTF-8'
    'MAIL' => '/var/mail/root'
    'LOGNAME' => 'root'
    'USER' => 'root'
    'USERNAME' => 'root'
    'SHELL' => '/bin/sh'
    'SUDO_COMMAND' => './vendor/bin/codecept run unit'
    'SUDO_USER' => 'gavin'
    'SUDO_UID' => '501'
    'SUDO_GID' => '20'
    'PHP_SELF' => './vendor/bin/codecept'
    'SCRIPT_NAME' => 'index.php'
    'SCRIPT_FILENAME' => 'index.php'
    'PATH_TRANSLATED' => './vendor/bin/codecept'
    'DOCUMENT_ROOT' => ''
    'REQUEST_TIME_FLOAT' => 1563824094.9495
    'REQUEST_TIME' => 1563824094
    'argv' => [
        0 => './vendor/bin/codecept'
        1 => 'run'
        2 => 'unit'
    ]
    'argc' => 3
    'ENVIRONMENT' => 'dev'
    'SECURITY_KEY' => '•••••••••••••••••••••••••••••••••••••'
    'DB_DRIVER' => 'mysql'
    'DB_HOST' => '127.0.0.1'
    'DB_SERVER' => '127.0.0.1'
    'DB_USER' => 'root'
    'DB_PASSWORD' => '••••'
    'DB_NAME' => 'craft_db_431284'
    'DB_DATABASE' => 'craft_db_431284'
    'DB_SCHEMA' => 'public'
    'DB_TABLE_PREFIX' => 'craft_'
    'DB_PORT' => ''
    'BACKUP_COMMAND' => '/Applications/MAMP/Library/bin/mysqldump -h localhost -u root -proot --add-drop-table --comments --create-options --dump-date --no-autocommit --routines --set-charset --triggers --single-transaction --no-data --result-file=\"{file}\" {database} && /Applications/MAMP/Library/bin/mysqldump -h localhost -u root -proot --add-drop-table --comments --create-options --dump-date --no-autocommit --routines --set-charset --triggers --no-create-info --ignore-table={database}.assetindexdata --ignore-table={database}.assettransformindex --ignore-table={database}.cache --ignore-table={database}.sessions --ignore-table={database}.templatecaches --ignore-table={database}.templatecachecriteria --ignore-table={database}.templatecacheelements {database} >> \"{file}\"'
    'RESTORE_COMMAND' => '/Applications/MAMP/Library/bin/mysql -h localhost -u root -proot {database} < \"{file}\"'
    'DEFAULT_SITE_URL' => 'http://localhost'
    'SERVER_NAME' => 'localhost'
    'SERVER_PORT' => '80'
    'HTTPS' => false
    'REMOTE_ADDR' => '1.1.1.1'
    'REMOTE_PORT' => 654321
]

composer.json

{
  "require": {
    "craftcms/cms": "^3.1.27",
    "dukt/social": "^2.0.0-beta.14",
    "lukeyouell/craft-mailchimplists": "^1.0.5",
    "craftcms/commerce": "^2.1.6.1",
    "craftcms/ckeditor": "^1.0.0-beta.2",
    "craftcms/contact-form": "^2.2.3",
    "roundhouse/form-builder": "^3.0.14",
    "mattgrayisok/craft-dark-mode": "^1.1.0",
    "craftcms/redactor": "2.3.3.2",
    "craftcms/commerce-stripe": "2.0.1.1",
    "nystudio107/craft-seomatic": "^3.1.50",
    "doublesecretagency/craft-inventory": "^2.0",
    "marionnewlevant/element-link": "1.0.0",
    "superbig/craft3-bugsnag": "2.0.4",
    "verbb/postie": "2.0.3.1",
    "nystudio107/craft-cookies": "^1.1",
    "doublesecretagency/craft-cpcss": "^2.2",
    "verbb/cp-nav": "^2.0",
    "nav33d/craft-activitylog": "^1.0",
    "ether/logs": "^3.0",
    "nystudio107/craft-instantanalytics": "^1.1",
    "superbig/craft-batchpdfexport": "^1.0"
  },
  "autoload": {
    "psr-4": {
      "modules\\custommodule\\" : "modules/custommodule/src/"
    }
  },
  "config": {
    "optimize-autoloader": true,
    "platform": {
      "php": "7.0"
    }
  },
  "scripts": {
    "post-root-package-install": [
      "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
    ]
  },
  "require-dev": {
    "codeception/codeception": "^3.0",
    "vlucas/phpdotenv": "^3.0"
  }
}
@brandonkelly

This comment has been minimized.

Copy link
Member

commented Jul 22, 2019

Are you making any changes to your main .env file in the process? You should only be editing tests/.env when setting up tests.

@gvwarrior

This comment has been minimized.

Copy link
Author

commented Jul 22, 2019

Yup, NO changes to my root .env, I ONLY created test/.env and made both files look nearly identical.

@gvwarrior

This comment has been minimized.

Copy link
Author

commented Jul 22, 2019

Plus each time it crashes I delete everything, git clone, and physically see the site working before running another basic Codeception test, then everything explodes.

@angrybrad

This comment has been minimized.

Copy link
Member

commented Jul 22, 2019

Can you check your web server's error logs? From your screenshot, that looks like a web server generated 500 ISE, so my guess is the underlying error message will be there.

@gvwarrior

This comment has been minimized.

Copy link
Author

commented Jul 22, 2019

Okay, let me grab the MAMP logs.

@gvwarrior

This comment has been minimized.

Copy link
Author

commented Jul 22, 2019

This is the Php log, MySQL log also had some errors
php_error.log

@angrybrad

This comment has been minimized.

Copy link
Member

commented Jul 23, 2019

Can you share the contents of /Users/gavin/Desktop/Projects/Software/Craft/Production/getFitGrill/getfitgrill/web/index.php

@gvwarrior

This comment has been minimized.

Copy link
Author

commented Jul 23, 2019

@angrybrad

This comment has been minimized.

Copy link
Member

commented Jul 24, 2019

Do you have devMode enabled in config/general.php? If you don't can you enable it, then reload http://localhost when it's in that state and see if it gives any more information instead of a generic 500 page?

@gvwarrior

This comment has been minimized.

Copy link
Author

commented Jul 24, 2019

@gtettelaar

This comment has been minimized.

Copy link
Collaborator

commented Aug 12, 2019

@gvwarrior The testing framework is (should be) separated from your main website directory. The only time the testing framework may actually get involved with your production directory/website is if you tell it to use your sites directories through tests/_bootstrap.php. Could you share the tests/_bootstrap.php file?

Also - do you have the projectConfig option enabled in your codeception.yml or unit.suite.yml file?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.