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!
25.
Test Fixtures & Fast Databases!
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
}
}
19 Comments
Hi,
when I try run this test "./vendor/bin/phpunit tests/AppBundle/Controller/DefaultControllerTest.php", it fails with the following error: "BadMethodCallException: doctrine/doctrine-fixtures-bundle must be installed to use this method."
In composer.json I have these versions:
"doctrine/doctrine-fixtures-bundle": "2.3",
"liip/functional-test-bundle": "~2.0@alpha",
"liip/test-fixtures-bundle": "^1.0.0",
"phpunit/phpunit": "^8.5",
"doctrine/data-fixtures": "1.3",
"doctrine/doctrine-bundle": "^1.6".
And In AppKernel.php I've registered these bundles for 'dev' and 'test' environments:
$bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle();
$bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
$bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
$bundles[] = new DoctrineFixturesBundle();
if ('dev' === $this->getEnvironment()) {
$bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
$bundles[] = new Symfony\Bundle\WebServerBundle\WebServerBundle();
}
if ('test' === $this->getEnvironment()) {
$bundles[] = new LiipFunctionalTestBundle();
}
I tried to google for the answer, but didn't find helpful info. Could you help me out to figure out why i get this error, please?
Hey Mr_T
Try to install exact version of fixtures bundle
composer require --dev doctrine/doctrine-fixtures-bundle:2.4.1Cheers!
hey sadikoff
thanks for your reply. I installed the exact version and now I have "doctrine/doctrine-fixtures-bundle": "2.4.1" in composer.json, but I still get the same exact error as before...
If anyone wonders, I've just solved this issue. What I did was to downgrade "phpunit/phpunit" from "^8.5" to "^6.3" and "liip/functional-test-bundle" from "~2.0@alpha" to "^1.8"
hah you did it faster then I get here =) it was tricky... we already tweaked this course install commands to solve most of issues.
Thanks for sharing solution here!
Cheers!
Starting from LiipFunctionTestBundle ^3.0.0 loadFixtures is no longer support.
From de Changelog:
Hey Thomas,
Thank you for sharing this with others!
Cheers!
My pleasure, just helping people get over the same WTF moment I had :)
Hey,
When I load fixtures : php bin/console doctrine:fixtures:load, I have an error message :
[InvalidArgumentException]
Class "AppBundle\DataFixtures\ORM\LoadBasicParkData" can't implement "OrderedFixtureInterface" and "DependentFixtureInterface" at the same time.
I use Symfony 3.3.18 and doctrine-fixtures-bundle": "2.4.1"
You know why ?
Hey Stephane
Yep, you can't implement both interfaces :p
If you are on Symfony3 I believe you should only implement "OrderedFixtureInterface"
Cheers!
Hey Diego,
Thank for your reply. But I don't understand why it's not working because I only copy the files about fixtures from tutorial folder. Normaly the code can work with Sf3 ?
Hey Stephane, actually this course is based on Symfony3.3 so it should just work but I just checked the code and we don't implement both interfaces on fixtures classes, somehow you added it. Just stop implementing
DependentFixtureInterfaceand it should workCheers!
MolloKhan
LoadBasicParkDataextendsDoctrine\Bundle\FixturesBundle\Fixturewhich implementsDependentFixtureInterface...When we remove extended class -
addReferencemethod is no longer available.When we remove implementation of
OrderedFixtureInterface, well it won't be ordered.So it's clearly bug in course code.
Probably you should extend
Doctrine\Common\DataFixtures\AbstractFixture.Hey Kuba,
That was totally a bug, not sure how we missed it when was recording the course. Anyway, it's fixed in the source code and code blocks now. And yes, you're right, we need to extend "Doctrine\Common\DataFixtures\AbstractFixture" instead - good guess! So, it's fixed and I just double checked - fixtures are loaded fine now. Literally, changes were: https://github.com/knpunive...
Thank you for reporting this!
Cheers!
Hey kubaf
Wow, you are totally right. I was on a latest release of DoctrineFixturesBundle where Fixture class doesn't implement DependentFixtureInterface anymore. I think your solution is good enough, just extend from
Doctrine\Common\DataFixtures\AbstractFixtureWe will see what we can do about tutorial's code
Cheers!
Hi!
As of this moment, Symfony 3.3.10 is not supported any more by the latest version of doctrine/doctrine-fixtures-bundle. The version 3.0.4 does support Symfony 3.3.10. So to get this to work, `composer require --dev doctrine/doctrine-fixtures-bundle:3.0.4` should be the full command.
Hey Bojan Đ.
Thanks for sharing information about bundle compatibility.
BTW to follow course code it will be better to use fixtures-bundle version 2.4.1.
Cheers!
Hi guys,
there is a typo in the video filename when you download it.
Cheers
Hey Nicolas!
Thanks for reporting it! Now it's fixed :)
Cheers!
"Houston: no signs of life"
Start the conversation!