I needed to use a class from ZF2 in my Yii project.
I've read probably all there is about this subject and still I needed lots of trial & errors to get it working, probably due to my lack of experience working with namepsaces and ZF2 in general. Also, the resources on the web are all partial, at best. Most simply refer to ZF1 where things are technically different. When I got it all working I decided to record my findings and that's how this article was born. The below recipe is what worked for me, accompanied by relevant comments.
References: This article is partially based on this guide page. Be sure also to consult Zend Framework 2 documentation.
Unfortunately Sebastian Bergmann decided to remove PHPUnit_Story from future PHPUnit versions. Thanks to elvan for pointing me to the relevant comment. As an alternative Behat has been suggested but it seems too bloated for me TBH. There is also PHPSpec but it's non flexible enough for me and tightly bound with English language (What's the purpose of using DSL if customers can't speak English). Since both frameworks are quite young I think I'll just stick to PHPUnit and see what's going on on the BDD frameworks arena. Even PHPUnit_Story parts of this entry are going to be deprecated soon, rest is still valid! When doing TDD, please write tests with design and behaviour of application in mind instead of testing single functions.
Some PHP installations may use a different php.ini file for CLI PHP (command line PHP parser). As a result, when running the model or crud command in yiic shell, you may encounter errors like "YiiBase::include(PDO.php): failed to open stream..." or "...could not find driver", even though the requirement checker confirms you have PDO and the corresponding database driver.