Setting up unit testing with magento2 docker
This post is being edited and refined. It's not complete yet. Changes may occur in the next few days, as I test this out and refine it, and improve the formatting of this post.
If you followed my tutorial to set up your docker container, and now you wish to run Magento2 unit tests, you might notice that running PHPUnit gives an error that it cannot connect to the amqp server, database server, or elasticsearch server.
To resolve these issues, and get magento phpunit up and running follow these steps, assuming you have followed my tutorial.
Open up docker-compose.yml and add the following lines:
: : : - : -
Then run from your console
Now enter the docker database CLI and run the following commands:
Use as password at the password prompt: root
In the database prompt, run the following commands
CREATE DATABASE magento_integration_tests; GRANT ALL ON magento_integration_tests.* TO 'magento2_test_user'@'%' IDENTIFIED BY 'test_me_now';
Now go to your docker/src folder on your local disk where your Magento installation is present.
Open the file docker/src/dev/tests/integration/etc/install-config-mysql.php.dist
Change the contents to
[ => , => , => , => , => , => , => , => , => , => \ \ \ :: , => \ \ \ :: , => \ \ \ :: , => \ \ \ :: , => \ \ \ :: , => , => , => , => , ];
What is changed is that the server names, that were all localhost here, are changed to their respective entries in docker-compose.yml. So the database server is db, elasticsearch is elasticsearch, amqp is rabbitmq. Also, the database user and password are changed
Save the file, and open up a CLI to your server.
Run the following command to start up the testing framework
vendor/bin/phpunit -c dev/tests/integration/phpunit.xml.dist
And then the full and complete test suite will fire up, which will most likely run out of the 2GB of allocated memory.
I am only interested in running tests in my custom test suites, and not in the 12486 tests Magento has for its own software, so this is not a great problem for me to run into.