Flag of Ukraine
SymfonyCasts stands united with the people of Ukraine

PHPUnit: Integration Testing with Live Services

1:02:48

What you'll be learning

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
    }
}
// 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
    }
}

We're back! In episode 1, we walked through the beauty & purity unit testing. But now, we're onto the messier, but super-useful world of integration testing:

  • Integration testing? What is that? When do I need that?
  • Accessing services from the container
  • Clearing the database between tests
  • Seeding the database
  • Foundry Factories & more!
  • Partial Mocking: mock just some dependencies
  • Testing emails
  • Testing messenger messages

Integration tests are fun and are a critical tool to a well-rounded test suite. Let's go!


Your Guides

Jesse Rushlow Ryan Weaver

Buy Access

Join the Conversation?

15
Login or Register to join the conversation
Yuuki-K Avatar

Hello, is there any schedule on when this course is set to release?

4 Reply
Jesse-Rushlow Avatar
Jesse-Rushlow Avatar Jesse-Rushlow | SFCASTS | Yuuki-K | posted 11 months ago

Howdy Yuuki-K,

We do not have a firm release date set quite yet. But, the plan is to have this episode roll out in Q1 2023. Now that the holiday's are behind us and the kids are back in school, I'll be full steam ahead on getting this out the door to every as quick as possible.

Be sure to keep an eye on the @SymfonyCasts & @JesseRushlow Twitter feeds in the coming week's - I'm sure we'll be posting some updates as we get closer to the release of our prehistoric friends...

Cheers!

5 Reply
Mohamed-M Avatar
Mohamed-M Avatar Mohamed-M | posted 9 months ago

Hello, is there any update about the schedule ?

2 Reply

Hey Mohamed,

You can find upcoming tutorials on this page: https://symfonycasts.com/courses?status=upcoming&sort=popular#all

Cheers!

Reply
Jesse-Rushlow Avatar
Jesse-Rushlow Avatar Jesse-Rushlow | SFCASTS | Mohamed-M | posted 9 months ago

Howdy Mohamed-M,

Not yet, but other than we're working on the tutorial as we speak...

Reply
Maverick Avatar

Ping... what is the status?

Reply

Soooooon.... we had some issues, internally. Sorry about the delay! But this will be the next tutorial

2 Reply
Maverick Avatar

Thanks for the quick answer, I'm looking forward to it.

Reply

Thank you very much @Jesse-Rushlow for these tutorials on Unit tests, it's very clear, can't wait to find the rest on integration tests 🤞

1 Reply
Igor-P Avatar

So it's not actually about the full integration testing (with the frontend rendered heavily with js) but about backend application parts interaction?

Reply

Hey Igor,

I know naming may be confusing sometimes. Yeah, that's mostly "backend" integration part, i.e. the one that goes after unit testing. With integration testing you start using real objects and Symfony services as dependencies instead of mocking everything. The part you're talking about (when the frontend rendered heavily with js) is called functional testing, not integration testing.

I hope it's clearer for you now.

Cheers!

Reply
Fabien-G Avatar
Fabien-G Avatar Fabien-G | posted 1 month ago

Hello to the Symfonycast team !

Is there any news about this course?
Has a release date been announced?

Reply
Fabien-G Avatar

Finally ! ;)

Reply

Sorry for the delay, the course is being released now :)

Cheers!

1 Reply
Cat in space

"Houston: no signs of life"
Start the conversation!

userVoice