PHPQuebec meetup November 2015

Upcoming meetup at PHP Quebec where i will be presenting ways to go from STUPID to SOLID. Hope to see you there!

November 2015 Meeting – From STUPID to SOLID (with a touch of IOC)

Thursday, Nov 5, 2015, 6:30 PM

420 rue Guy Montréal, QC

12 PHPers Attending

The next meeting will be held at Centre on November 5th. Drinks and pizza will be provided by Pronexia.How much? FreeWhen: November 5th, 18:30 for drinks, pizza and networking. 19:00 for the talk.Where: Centre cloud.ca420 GuyMontrealH3J 1S6From STUPID to SOLID (with a touch of IOC)Mathieu DumoulinIn this interactive presentation, …

Check out this Meetup →

Same query runs twice with SoftDeleteable behavior

posted in: Symfony | 0

Today i hit a relatively simple problem where my tests would issue the same query twice and thus return the same result although the result should have been different. The problem is related to the use of the STOF/Doctrine-Bundle-Extension which adds a listener to add a condition to the query i build using the softdeleteable behavior. The problem with this is that if you query the first part of the query, it means that next time you try to get the same query, the query is not updated with the latest timeaware parameter and thus:

SELECT pi FROM PersonalizableItem pi WHERE token = :token

gets changed to

SELECT pi FROM PersonalizableItem pi WHERE token = :token AND (deletedAt is null or deletedAt <= 'some date')

This second query gets cached so the time in “some date” doesn’t change and thus, even if you deleted the item and try to query it again (for testing purposes in my case) then the result is incorrect and your test fails.

To fix, this, substitute the query cache currently used in your application with a VoidCache and this will prevent the query caching from occuring. Obviously, you don’t want and usually don’t need this in the production context, but in a test context, it is very valid and often necessary for integration like tests.

self::$entityManager = static::getSharedKernel()->getContainer()->get('doctrine.orm.default_entity_manager');
self::$entityManager->getConfiguration()->setQueryCacheImpl(new VoidCache());

Symfony 2 serializing nulls or not on demand

posted in: Symfony | 0

Symfony is pretty new to me and i’m learning new stuff everyday. Building this api where i work made me learn that sometimes you may want to have the null serialized and sometimes not. So by default, let’s say you activate it, when you want to deactivate it on the fly, the best way is just to turn on/off the null serialization strategy.


IMO, it’s best to simply always serialize nulls as not all end users will be able to deserialize missing properties or not. If a property is not set, it should still be serialized by default but with a null. It’s a matter of taste i guess, but tecnically speaking, i’d always do that!

1 2 3 4 8