Chapters
29 Chapters
|
2:54:09
|
Login to bookmark this video
-
Course Code
Subscribe to download the code!Compatible PHP versions: ^7.0, <7.4
Subscribe to download the code!Compatible PHP versions: ^7.0, <7.4
-
This Video
Subscribe to download the video!
Subscribe to download the video!
-
Subtitles
Subscribe to download the subtitles!
Subscribe to download the subtitles!
-
Course Script
Subscribe to download the script!
Subscribe to download the script!
16.
Full Mock Example
Scroll down to the script below, click on any sentence (including terminal blocks) to jump to that spot in the video!
Subscribe to jump to this part in the video!
Keep on Learning!
If you liked what you've learned so far, dive in! Subscribe to get access to this tutorial plus video, code and script downloads.
While the fundamentals of PHPUnit haven't changed, this tutorial *is* built on an older version of Symfony and PHPUnit.
What PHP libraries does this tutorial use?
// composer.json
{
"require": {
"php": "^7.0, <7.4",
"composer/package-versions-deprecated": "^1.11", // 1.11.99
"doctrine/doctrine-bundle": "^1.6", // 1.10.3
"doctrine/orm": "^2.5", // v2.7.2
"incenteev/composer-parameter-handler": "^2.0", // v2.1.2
"sensio/distribution-bundle": "^5.0.19", // v5.0.21
"sensio/framework-extra-bundle": "^3.0.2", // v3.0.28
"symfony/monolog-bundle": "^3.1.0", // v3.1.2
"symfony/polyfill-apcu": "^1.0", // v1.6.0
"symfony/swiftmailer-bundle": "^2.3.10", // v2.6.7
"symfony/symfony": "3.3.*", // v3.3.13
"twig/twig": "^1.0||^2.0" // v2.4.4
},
"require-dev": {
"doctrine/data-fixtures": "^1.3", // 1.3.3
"doctrine/doctrine-fixtures-bundle": "^2.3", // v2.4.1
"liip/functional-test-bundle": "^1.8", // 1.8.0
"phpunit/phpunit": "^6.3", // 6.5.2
"sensio/generator-bundle": "^3.0", // v3.1.6
"symfony/phpunit-bridge": "^3.0" // v3.4.30
}
}
4 Comments
array_rand returns int so there is bug, securityName should be string not int
$securityName = array_rand(['Fence', 'Electric fence', 'Guard tower']); <br />$security = new Security($securityName, true, $enclosure);maybe
$securityName = ['Fence', 'Electric fence', 'Guard tower'][random_int(0, 2)];Hey manhee ,
Ah, you're totally right! That's our mistake and I just fixed it. Thank you for reporting it and even providing a solution! Though, I used a slightly different one:
There're 2 lines instead of one, but it's more flexible because we don't need to worry about array size, i.e. I can easily add/remove elements from the array and it will work perfectly.
Cheers!
I had a question long time ago. I have heard that we should not mock what we do not own. Like here EntityRepositoryInterface. So is this really good to mock it? I am also mokcing it because I am not sure if we should really create the adapter for entity repository, maybe it would make too much unnecesarry code. I do not see problems with mocking entity repository, but still feel I might be doing not best way if I mock it.
Hey Lijana Z.
Nice question, and the answer depends on what are you testing. In unit testing, you may want to mock all the external services that you don't care about their functionality, but if it is an integration test, then you will want to test at a general level, that all the interactions between objects (layers) works properly.
So, first, you have to identify what kind of test are you doing, then, what piece of functionality you are interested in. After that, you will have a clearer image of what you need to test and what not
Cheers!
"Houston: no signs of life"
Start the conversation!