This tutorial uses PHPUnit 9 but works just fine for PHPUnit 10.
// composer.json
{
"require": {
"php": ">=8.1.0",
"ext-ctype": "*",
"ext-iconv": "*",
"doctrine/doctrine-bundle": "^2.8", // 2.10.2
"doctrine/doctrine-migrations-bundle": "^3.2", // 3.2.4
"doctrine/orm": "^2.14", // 2.16.2
"symfony/asset": "6.3.*", // v6.3.0
"symfony/console": "6.3.*", // v6.3.4
"symfony/dotenv": "6.3.*", // v6.3.0
"symfony/flex": "^2", // v2.3.3
"symfony/framework-bundle": "6.3.*", // v6.3.5
"symfony/http-client": "6.3.*", // v6.3.5
"symfony/mailer": "6.3.*", // v6.3.5
"symfony/messenger": "6.3.*", // v6.3.5
"symfony/monolog-bundle": "^3.0", // v3.8.0
"symfony/runtime": "6.3.*", // v6.3.2
"symfony/security-csrf": "6.3.*", // v6.3.2
"symfony/twig-bundle": "6.3.*", // v6.3.0
"symfony/yaml": "6.3.*" // v6.3.3
},
"require-dev": {
"doctrine/doctrine-fixtures-bundle": "^3.4", // 3.4.4
"phpunit/phpunit": "^9.5", // 9.6.13
"symfony/browser-kit": "6.3.*", // v6.3.2
"symfony/css-selector": "6.3.*", // v6.3.2
"symfony/debug-bundle": "6.3.*", // v6.3.2
"symfony/maker-bundle": "^1.48", // v1.51.1
"symfony/phpunit-bridge": "^6.2", // v6.3.2
"symfony/stopwatch": "6.3.*", // v6.3.0
"symfony/web-profiler-bundle": "6.3.*", // v6.3.2
"zenstruck/foundry": "^1.35", // v1.35.0
"zenstruck/mailer-test": "^1.3", // v1.3.0
"zenstruck/messenger-test": "^1.7" // v1.7.3
}
}
10 Comments
Hi,
If I don't use SF binary, and my DB is MySQL.
What is the best way :
I see issue :
./bin/console doctrine:database:create --env=test<br />Could not create databasedb_app_testfor connection named default<br />An exception occurred while executing a query: SQLSTATE[42000]: Syntax error or access violation: 1044 Access denied for user 'app_user'@'%' to database 'db_app_test'BR.
Hey Ruslan,
I would recommend you to start using Symfony binary, but in case can't for some reason, you will need to manually configure your DB credentials so that your application can connect to the DB in the Docker container. As soon as you configure the DB credentials correctly for the DATABASE_URL env var in your
.envfile - it should work well. The error you see relates to the incorrect DB credentials.Cheers!
Sorry, I told about testing only. (.env.test).
We can create new server instance (database-test in docker-composer.yaml) or
DB instance in the same server instance (database in docker-composer.yaml)
Hey Ruslan,
It makes sense to create a DB in the same Docker container, i.e. you have only 1 docker container for the DB server and it contains 2 databases: dev/prod and test. I don't see a value in spinning a completely separate container for tests only while you already have a spinning DB container.
Cheers!
The
appyou highlighted is the user, the database name is theappafter the port and the slash ;)Guilty! 😅
I don't use the Symfony binary (I use DDEV), but I think it should read "symfony console doctrine:[...]" instead of "symfony binary doctrine:[...]" in the script of the 'Creating the database' section of the two console instructions for Doctrine.
You're totally right! I think I said "binary" so many times before that, my brain just stuck with "binary" :p. Fixed now - https://github.com/SymfonyCasts/testing/commit/3117d790e847f17bf9ef6165655e3d7c3e3d5506 - I appreciate the head's up!
Many thanks for the great tutorial. It's already got off to a great start.
However, I noticed a tiny mistake at -3:54. In the "Database_URL" the user is marked, not the table name.
In case a newbie reads this and wonders what I mean: the table name is directly before the "?sslmode" and is also 'app'. The marked app is the DB Username for login.
And I'm really looking forward to chapters 8 and 9. I haven't dealt with this yet and only notice from time to time during manual tests that I've once again made a mistake in combination with TemplatedEmail and the MessageQueue...
Hey @S-H
Yes, in this case we use
appas the Database username and also for the database name. Here is explained how the URL is composed https://www.prisma.io/docs/concepts/database-connectors/postgresql#connection-urlCheers!
"Houston: no signs of life"
Start the conversation!