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!
02.
Tests, Assertions & Coding
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!
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
}
}
22 Comments
(base) shubham@Shubhams-MacBook-Air phpUnit % ./vendor/bin/simple-phpunit
PHPUnit 8.5.19 by Sebastian Bergmann and contributors.
No tests executed!
(base) shubham@Shubhams-MacBook-Air phpUnit %
I wrote the same tests but the tests are not getting executed idk why?
Hey Shubham,
Please, double check your PHPUnit config file that should be in your project root folder called phpunit.xml or phpunit.xml.dist. There you specify where your tests live and what to execute and how, see related video https://symfonycasts.com/sc...
Or, you can specify what to execute in the command, e.g:
$ ./vendor/bin/simple-phpunit path/to/your/test/file.php
Also, double-check that you extend the correct file in your test file, it should be "\PHPUnit\Framework\TestCase" class, but may depends on your PHPUnit version.
Cheers!
Hi , I am PHP fresher and i would like to study on this course. But i am not able to download the course code to start.
Does anyone have same issue or know the solution to fix it?
BTW, i did buy the access.
Thank you very much!
Hey Peter,
We're sorry about that. Hm, I just double-checked and course code download works for me on this course. Are you sure you're logged in in your account that has active subscription? Do you see the "Course code" item when you press "Download" button in the top right corner? Is it active, like can you press on it? Any errors? Probably your browser's security does not allow to download the file, please look closer on any notifications popping up in your browser - you may need to allow it manually. Or, as an alternative solution, try to download course code in a different browser. Does it help!
Please, let us know if you still have this problem!
Cheers!
Hello,
when testing the testThatYourComputerWorks() function everything is OK, but I get an error when testing the testSettingLength() function.
I get this message:
PHP Fatal error: Uncaught Error: Class 'PHPUnit\Framework\ExceptionWrapper' not found in /var/www/knp.phpunit/vendor/phpunit/phpunit/src/Framework/TestResult.php:745
can you please help me?
thank you
I also passing this tutorial on Vagrant with Ubuntu in a box. My working version of simple LAMP (with PHP 7.2 on ubuntu/xenial64):
https://bitbucket.org/renta...
https://bitbucket.org/renta...
Hey chieroz
Can you tell me how are you executing your tests (which command are you running)?
And, which versions of PHP and PHPUnit are you using?
Cheers!
Hello Diego,
I am using a Vagrant VM with Ubuntu 16.04 on a host with OSX 10.13.1
in the guest machine I have PHP 7.1, PHPUnit 6.4.4
I am just following the tutorial, so I execute phpunit with: ./vendor/bin/phpunit
this is the full error:
vagrant@vagrant:/var/www/knp.phpunit$ ./vendor/bin/phpunit
PHPUnit 6.4.4 by Sebastian Bergmann and contributors.
FPHP Fatal error: Uncaught Error: Class 'PHPUnit\Framework\ExceptionWrapper' not found in /var/www/knp.phpunit/vendor/phpunit/phpunit/src/Framework/TestResult.php:745
Stack trace:
#0 /var/www/knp.phpunit/vendor/phpunit/phpunit/src/Framework/TestCase.php(894): PHPUnit\Framework\TestResult->run(Object(Tests\AppBundle\Entity\DinosaurTest))
#1 /var/www/knp.phpunit/vendor/phpunit/phpunit/src/Framework/TestSuite.php(744): PHPUnit\Framework\TestCase->run(Object(PHPUnit\Framework\TestResult))
#2 /var/www/knp.phpunit/vendor/phpunit/phpunit/src/Framework/TestSuite.php(744): PHPUnit\Framework\TestSuite->run(Object(PHPUnit\Framework\TestResult))
#3 /var/www/knp.phpunit/vendor/phpunit/phpunit/src/TextUI/TestRunner.php(537): PHPUnit\Framework\TestSuite->run(Object(PHPUnit\Framework\TestResult))
#4 /var/www/knp.phpunit/vendor/phpunit/phpunit/src/TextUI/Command.php(195): PHPUnit\TextUI\TestRunner->doRun(Object(PHPUnit\Framework\TestSuite), Array, true)
#5 /var/www/knp.phpunit/vendor/phpunit/phpunit/src/TextUI/Command.php(148): PHPUnit\TextUI\ in /var/www/knp.phpunit/vendor/phpunit/phpunit/src/Framework/TestResult.php on line 745
Thank you for your attention.
Carlo
Hmm, interesting... I would like to see your phpunit.xml and composer.json files too (maybe you can upload them to the cloud)
BTW, try extending from this class instead `\PHPUnit_Framework_TestCase`, I believe it will work, but it should work with the other class as well
Hello Diego, here are my two files:
https://www.dropbox.com/s/p...
https://www.dropbox.com/s/4...
Thank you for your attention
c
Hmm, your files look good to me. Try running "composer update" and double check your namespaces
Did extending from `\PHPUnit_Framework_TestCase` class work?
Well, this is REALLY weird.
extending from `\PHPUnit_Framework_TestCase` class did not work
after that, I tried with "composer update" and after that I did not get the error message but a quite creepy "You need to set up the project dependencies using Composer: composer install" message
Obviously enough, I run "composer install" and nothing happened but I realized that the symlink ./vendor/bin/phpunit got broken. I deleted everything in the ./vendor folder. again, I get the Class 'PHPUnit\Framework\ExceptionWrapper' not found message.
I even tried to destroy and rebuild the VM with no success. maybe I can try with a different distro, but it seems a little paranoid.
next step: banging my head against the wall... ;-)
thank you for your help
carlo
hahaha, before smashing your head against a wall, let's try something else.
Change your PHPUnit version to "^6.3" instead of 6.4, maybe there is something in that version that is causing this weird behaviour
BINGO!
with phpunit 6.3.1 everything works.
I built another VM, this time with CentOS 7 and php 7.1: in this environment PHPUnit 6.4 works perfectly
thank you for your help. have a nice day
Yes!! I'm so glad to hear you could fix it, and this is very interesting, because PHPUnit 6.4 version was in someway incompatible with your old VM setup
Cheers!
I think Ubuntu is somewhat incompatible because I built a fresh VM with no success while CentOS 7 + PHP7.1 + PHPUnit 6.4.* is OK
cheers!!!
chieroz if it is a development environment I strongly advise you to switch Docker. It took me a lot of pain and time to switch it but I finally automated a docker for development. Check it out. https://github.com/yahyaert...
For some reason I don't have an auto completion for "assertTrue" method. But after I wrote it manually, PhpStorm identified the method properly. Do you have any ideas of why it might be?
Yo boykodev!
Hmm. I don't know :/. It's possible that PhpStorm sees 2 copies of PHPUnit in your project for some reason - it's the only thing I can think of. If you hold Ctrl (or Cmd on a mac) and click the
TestCaseclass, does it open that file immediately? If so... then... my theory is wrong and I don't know! But if it asks you to choose between 2 different files, then that's it! And in that case, on copy should probably be ignored (not sure why there would be 2 anyways)Cheers!
It goes straight to the class. However, autocompletion does work after pressing (Ctrl + Space), I think it's called "explicitly invoked completion".
Hello,
I didn't know where to mention it so :
- there's a little error, if you search for "$dinosuar", you'll find it :)
- there's an "i" in capital letter surrounded by an tag which makes it look like a "/" -> I found it disturbing
Hey Mykel Chang!
This is a *great* place to mention it :). I've just made the fixes - https://github.com/knpunive... - thanks!
And that was fast! We haven't technically even released this chapter yet ;).
Cheers!
"Houston: no signs of life"
Start the conversation!