Do you have a bootstrap or something in PHPUnit to create your database or run some migrations? I’m not understanding where the homestead database should be created - your server will not have any databases in it to start with every time your build runs.
Yes, migrations are run in the app after phpunit starts running. Got a trait that migrates the database(s) before all tests start. And then each test is in a transaction.
This feels like one of those things where readers don’t know what config/code to ask you for, but would be able to resolve if it were available in a shell console in front of them
Can you use an SSH console after your failing build to see if you can connect to MySQL from the command line?
You need something like sudo apt-get install -i mysql-client (may need to tweak a bit). And remember that when you have an SSH session, you’re logged into the first container, which does not have any of the binaries in the second container.
docker:
# specify the version you desire here
- image: circleci/php:7.2-apache-stretch-node-browsers
- image: circleci/mysql:5.7
In this configuration, you’ve asked the platform to run your steps in a container based on the first image, and then also spin up the other images. So your tests will run in a container based on the first image, and you will also have a separate container running based on the second image (and so on for any other images).
Mostly that’s correct, see here. They are separate containers, but CircleCI merges their networking stacks together, so localhost is shared.
However, as you rightly say, you can indeed install MySQL in the first container and just run the one. Both approaches will work - use whatever you can get working, or whatever results in the fastest jobs.
If you drop the second container reference and just add a run step to install MySQL server, does that get you any further? Either way, you will need to get an SSH session to see whether your migrations have created a database for you. Are there logs for your migrations?
SQLSTATE[HY000] [2002] Connection refused (SQL: SHOW FULL TABLES WHERE table_type = 'BASE TABLE')
#!/bin/bash -eo pipefail
./vendor/bin/phpunit
PHPUnit 7.0.2 by Sebastian Bergmann and contributors.
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE 63 / 158 ( 39%)
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE 126 / 158 ( 79%)
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE 158 / 158 (100%)
Time: 12.51 seconds, Memory: 102.00MB
There were 158 errors:
1) Tests\Unit\Forms\FormServiceTest::getFormForSubscription_FormCreatedForProduct_ReturnsAformOfType
Illuminate\Database\QueryException: SQLSTATE[HY000] [2002] Connection refused (SQL: SHOW FULL TABLES WHERE table_type = 'BASE TABLE')
/home/circleci/project/vendor/laravel/framework/src/Illuminate/Database/Connection.php:664
/home/circleci/project/vendor/laravel/framework/src/Illuminate/Database/Connection.php:624
/home/circleci/project/vendor/laravel/framework/src/Illuminate/Database/Connection.php:333
Then while ssh-ed:
circleci@140f73468e43:~$ mysql --version
mysql Ver 15.1 Distrib 10.1.26-MariaDB, for debian-linux-gnu (x86_64) using rea dline 5.2
circleci@140f73468e43:~$ mysql -u homestead
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run /mysqld/mysqld.sock' (2 "No such file or directory")
Then this happened
circleci@140f73468e43:~/project$ sudo service mysql status
[info] MariaDB is stopped..
circleci@140f73468e43:~/project$ sudo service mysql start
[ ok ] Starting MariaDB database server: mysqld.
circleci@140f73468e43:~/project$ mysql -u homestead
ERROR 1698 (28000): Access denied for user 'homestead'@'localhost'
circleci@140f73468e43:~/project$ mysql -u root
ERROR 1698 (28000): Access denied for user 'root'@'localhost'
Would you supply a new copy of your entire configuration file? I suspect it has had a number of updates, and I’ve lost track of the state of it
(Aside: would you provide your console logs as formatted text please? Images of text are not compatible with clipboards, screen-readers and search engines, and can make it harder to help. Thanks!)
The installer normally opens an interactive session to get a root password from you, but it will fail because an interactive shell is not available. You have to bypass that.
(Edit: running the separate MySQL container was not wrong, so it’s up to you which avenue to persist with. However, I suspect this fix will get MySQL running in the same container, so give it a try).
No, I’d just set your root password to password. You can then use root and password in your settings to log onto the database. It does not have to be a good password since the database will only live for a few minutes.
No, I think that’s a name for the property you’re specifying. It’s confusing, since there seem to be three things, and you only need two things for a key-value pair! But, hey ho, just try amending your_password as the instructions suggest, and let us know how you get on.