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!
18.
Mocking with Prophecy
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
}
}
26 Comments
Hey folks!
If you installed
symfony/phpunit-bridgelike suggested in the first video, you will have to install prophecy too, I didn't have prophecy classes until run:Cheers.
Hi!
Just an update on this old problem :). First, sorry for anyone who it it - we should have added a clear note much earlier. Second, the reason that you don't have Prophecy when you use symfony/phpunit-bridge is that it specifically removes it. It does that for some historical reasons that aren't important. But, you can tell the phpunit-bridge that you do want Prophecy by adding one line to your
phpunit.xml.distfile:If you do this, you should not need to install phpspec/prophecy directly in your app: it will be included normally when the phpunit-bridge downloads phpunit.
Cheers!
Hey Radoje Albijanic
Thanks for informing us about it. We will add a note, so no one else get confused :)
Cheers!
MolloKhan No note in the video ... :)
Hey Nils L.
Can you provide some more info about why it needed? Are you running phpunit directly? or vie Symfony's PHPUnit bridge? Which version of PHPUnit do you have?
Cheers!
sure .. as recommended i use symfony's PHPUnit Bridge "symfony/phpunit-bridge": "^4.0.5".
that installed "phpunit/phpunit": "^7.5"
Hi,
FYI - incorrect video filename
Forget :) we already checked it! Thanks for the reporting!
Cheers!
Hello Mepcuk
Give me please more details what is wrong with it?
Cheers!
Hello there , a question, how would the test of a method like the one I show below be approached:
Any suggestions on how it would be done?
Hey Gonzalo G.
I think I'd test only the state of what it returns instead of the algorithm because it calls a few other methods. I'd pass an input that I already know what the output should be and assert that
Cheers!
Somehow my PhpStorm doesn't fully autocomplete the Prophecy part.
It works:
<br />$this->prophesize(...);<br />It doesn't works:
`
// 1) Argument remains as an undefinied class
// 2) shouldBeCalledTimes is not found too
$em->persist(Argument::type(...))->shouldBeCalledTimes(...)
`
My Setup is as follows:
PHP 7.4.5
PhpStorm 2020.1.2
PHPUnit 8.3
PHP Toolbox 5.1.1
PHPUnit Enhancement 4.1
Anything special you have to do for prophecy support? It isn't working out of the box for me.
Update: well it seems that I don't have the Prophecy classes at all.
$this->prophesize(...); throws Class 'Prophecy\Prophet' not found.Since I am using the course code with phpunit-bridge. and that points out again to the very first comment from Radoje Albijanic about the missing note.
After two years the note is still missing :D
Well though when I try to add prophecy manually
composer require phpspec/prophecyI get a bunch of dependencies conflicts.
Cheers!
Hey Todor!
Yikes! We have a system in place to get notes added to tutorials, but we somehow dropped the ball on this one! My apologies for the trouble :/. As Vladimir mentioned, this could be a PHP 7.4 problem, or it could be something else. If you want to post the dependency error conflict, we can help manager it.
In the mean time, we'll get the note added (we need to play with the code a bit first to make sure we get the note just right).
Cheers!
Hi again weaverryan!
After my research, I've found the problem (and the correct note to add). You should not need to install prophecy manually. That may work, but phpunit already comes with prophecy. The reason that you do not see it is that, when simple-phpunit installs PHPUnit, it removes Prophecy from the install. It does this for some historical reasons related to dependencies. But if you do want prophecy, you can enable it via your phpunit.xml.dist file:
That tells the phpunit-bridge that it's ok to remove symfony/yaml (something it does in older versions) but it should not remove prophecy. Try that and let us know how it works!
Cheers!
Hey Todor
This course is a little bit old and it doesn't support php 7.4. you can see this requirement in
composer.jsonfile. We are trying to improve code delivery to be more strict you can see a tooltip on "Download > Courser code" dropdown menu, but yeah it's just a text tooltip and composer still allows installation.BTW Course code works great on php 7.3 ;) However we can't guarantee that it will work if you update packages to latest version. As I can see you are using PHPUnit 8, but course is based on PHPUnit 6 there can be a lot of differences in code but main principles of testing are same.
Cheers!
Why there are so many errors in this course?
After 2 years, did you find that you have an error code in the last example in this video?
`
$em->persist(Argument::type(Enclosure::class)
Hey alexchromets
Good catch, interesting how it happend :( however we just fixed this code block, so keep eye and feel free to report such cases!
Cheers!
seems like the libraries used in the tutorial a bit dated, for those who's got "Prophecy" classes not found error you need to add it to your project vendors:
composer require phpspec/prophecy
Hey _zippp !
Sorry for the slow reply! We were checking into this. Prophecy comes with PHPUnit automatically... so it's interesting that your app was missing them. What version of PHPUnit are you using
./vendor/bin/phpunit --version? And are you using PHPUnit directly (i.e. you run it via./vendor/bin/phpunit) or are you using it via Symfony's PHPUnit bridge (i.e. you run it withphp bin/phpunit)? Let us know - I'd love to add a note to the tutorial if we need one!Cheers!
There is a typo in subtitles at 0:58 second. It should be use $em = $this->prophesize(EntityManagerInterface::class) instead of use $this->em->prophesize(EntityManagerInterface::class).
Hey Marcel D.
Thanks for informing us about it. We really care about our quality :)
Cheers!
Found two typos:
Missing closing bracket in
`$em->persist(Argument::type(Enclosure::class)
`Missing closing bracket in
`->growFromSpecification(Argument::type('string')
`Fixed now!
Hey @Matt!
Nice catch! We're going to update those ASAP! Thanks for letting us know!
Cheers!
There are two typos here:
$this->em->prophesize(EntityManagerInterface::class) - em is redundant here.
And here closing bracket was missed:
$em->persist(Argument::type(Enclosure::class)
->shouldBeCalledTimes(1);
Thanks toporovvv!
I just fixed it :)
"Houston: no signs of life"
Start the conversation!