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
}
}
7 Comments
Hi,
A small question, why on 4:34 on the video test passed? On my screen I see error FATAL: database "app_test" . I didn't find in your config a code where you create "app_test" DB.
I know it's possible to fix by few ways, but I would like to know your solution.
Thank you.
UPD: Ups, I found my bad. You deleted findAll(); I didn't .
Sorry.
Hey Ruslan,
No problem :) Btw, you can use ResetDatabase trait from Foundry lib in your tests to automatically prepare test DB before each test :)
Cheers!
Thank you for your answer.
I know it now, it's in next Chapter 3 :)
Do you know why the docs use
static::getContainer()instead ofself::getContainer()?The first time I read them I took it as the
staticversion would allow access to private services, while theselfversion would not. However, now that I re-read that section, it doesn't seem like that is the case. But I'm still curious whystatic::getContainer()is used whenselfis used forself::bootKernel()in the examples.Hey @jdevine ,
I think that question is answered by PHP, read the difference between
staticandself. Simple answer would be just becausestaticgives you more flexibility and may be useful in some cases. Here're some thoughts:self::getContainer()refers to thegetContainer()method within the class where it is defined. It's resolved at compile-time based on the class where the code is written. Whilestatic::getContainer()refers to thegetContainer()method of the class where it is actually called, which means it supports late static binding. It allows for polymorphism, meaning that if you overridegetContainer()in a subclass,static::getContainer()will refer to the overridden method in that subclass, whereasself::getContainer()would always refer to the method in the parent class.Basically, that's not much important unless you will start to override those methods, but probably mentioning static in docs will help to avoid confusions in more cases.
Cheers!
Hey @Victor,
I am familiar with the difference between the two and when
staticshould be used in place ofself. It's just odd thatstatic::getContainer()is used in the docs here because usually they default to usingselfunless there is a good reason not to do so. I wouldn't imagine that overriding thegetContainermethod of theKernelTestCaseclass in a test class would be a great idea. But maybe there is common case I just haven't encoutered yet.Either way, it's a pretty minor thing. I was just curious what the reasoning behind it was since I don't see
static::used very often in the docs.Thanks!
Hey @jdevine ,
Yeah, I see. Unfortunately, I don't know the exact reasons behind that, most probably it should be mentioned somewhere in PRs, but I wasn't able to find it quickly.
Cheers!
"Houston: no signs of life"
Start the conversation!