09.
Tests with the Container
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.
If you liked what you've learned so far, dive in! Subscribe to get access to this tutorial plus video, code and script downloads.
Whoops, an error! Please, try again later.
9 Comments
Hi,
How do I prevent an entity from being purged by ORMPurger in purgeDatabase()?
I have a couple of cases for that:
1. there are tables I don't want to clear, such as configuration tables.
2. I've got a DTO entity, that gets populated with NEW operator, which ain't got no corresponding table, but is populated by a query that joins several tables.
Thank you!
Yo Vlad!
Hmm, I don't think this is possible - without basically sub-classing the ORMPurger and overriding the purge() method. But I get your use-case - it's really common for "look-up" tables - things that are effectively static, that you don't want to "clean out" every single time. Let me throw out a few options:
1) There must be *some* way that you originally pre-populated these tables - and a new developer would need these (e.g. SQL files) to populate *their* database. You could drop *all* the data, but then execute these SQL files automatically right after the purge
2) Override ORMPurger and avoid dropping the data in those tables. It's possible you'll run into constraint problems, but probably not (I'm guessing your configuration tables don't have foreign key columns to *other* tables that are being cleared).
Hopefully one of these looks appetizing for you - there's unfortunately no little config option for this :)
Cheers!
Hi Ryan,
This can also be accomplished with two entity managers and having the corresponding entities in different subdirectories.
This post talks about it: http://stackoverflow.com/questions/12220198/using-doctrine-2-entity-with-different-databases with two databases, but the same thing can be set up with a single database and two entity managers.
Then in the <strong>purgeDatabase()</strong> method we'd have to purge using one entity manager and skip purging with the other.
Regarding your #1 point, I also have methods that restore the original tables from backup tables using "<strong>INSERT SELECT</strong>" SQL queries:
Thank you!
Ha, very clever Vlad! That makes perfect sense - but I didn't think of it :). I'm not sure if you'll run into issues if you ever need to join across entities in the 2 different entity managers - but this may also not be something you need :).
Thanks for sharing this!
self::bootKernel() not working the error is unable to guess the kernel directory
Hi Theirno!
Hmm! That error comes from inside the KernelTestCase class: https://github.com/symfony/....
Basically, it is looking for your phpunit.xml or phpunit.xml.dist file. What command are you using to execute phpunit? Do you have any non-traditional directory structure?
Cheers!
Hi,
The same issue
Cmd used : php bin/phpunit src/AppBundle/Tests/Controller/Api/ProgrammerControllerTest.php
HI Amine
I was able to make it work, with these steps:
1) Create a phpunit.xml with this content:
2) Run
composer require indigophp/doctrine-annotation-autoload3) Run
composer dump-autoloadHey Amine
Could you try running and see what happens
Cheers!
"Houston: no signs of life"
Start the conversation!