slaff / learnzf2

Learn ZF2: Learning Zend Framework 2 by Example
BSD 3-Clause "New" or "Revised" License
35 stars 28 forks source link

Developement environment preparation #7

Open PauliusMacernis opened 9 years ago

PauliusMacernis commented 9 years ago

I would suggest you to add instructions on how to build the same development environment as yours. For example, a short introduction on virtual box, vagrant or at least puPHPet would be nice to have as a chapter. Why do I say so? I say so because I tried to run unit tests on Windows computer (I use one with Windows 8.1 OS) and then I got some major errors... I was not able to run unit tests the way you wrote (for example, at page 103 of the first edition book). Running the same commands on Linux results in success. This is the place you could read more about the problem I got: http://stackoverflow.com/questions/27999373/why-phpunit-test-does-not-work-zf2

Many thanks for The Book! It helps a lot.

slaff commented 9 years ago

Hi sugalvojau, thanks for the great suggestion! We can think of adding instructions in the website to create such an environment( with Vagrant and Virtualbox ). If there is interest we can include these instructions also in the future versions of the book.

slaff commented 9 years ago

Created the https://github.com/slaff/learnzf2-box repository. The initial version of the Vagrant script will follow soon.

slaff commented 9 years ago

@sugalvojau The box can be downloaded and tested from https://github.com/slaff/learnzf2-box. It would be great if you can test it and give your feedback.

PauliusMacernis commented 9 years ago

Hi slaff, you are quite fast with changes. Happy to see the result. However, running unit tests does not work for me. I get exactly the same result as before (see the previous link to stackoverflow). I am not so sure why I am going into the same situation over and over again, but I have some assumptions on reasons.. I will test more in coming days. Will give a feedback.

PauliusMacernis commented 9 years ago

@slaff The line of composer.json file used in the book: "phpunit/phpunit" : "3.7.*" I am reading the first edition of the book, not so sure if the second edition contains the same line?

I have changed "phpunit/phpunit" : "3.7.*" to "phpunit/phpunit" : "4.5.*" in my own copy of the code as 4.5 version of PHPUnit is the current stable. Then, of course: php composer.phar update Then this one will work nicely: ZF2_PATH=pwd/vendor/zendframework/zendframework/library \php vendor/phpunit/phpunit/phpunit -c module/User/tests/ The command above is not the same as in the book.

Tested on Windows 8.1, Ubuntu Trusty 14.04 LTS x64, the isolated development environment you provide. Works well.

There is also a way to make PHPUnit 3.7.* work on all systems (same systems tested by me), but the command must be changed to: ZF2_PATH=pwd/vendor/zendframework/zendframework/library \php vendor/phpunit/phpunit/composer/bin/phpunit -c module/User/tests/ The command above is not the same as in the book.

So... Here we have two ways mentioned to go with PHPUnit tests to make them work. It is up to you to decide witch of two is better. I would prefer the one with increasing PHPUnit version to 4.5 at the moment.

As far as I have tested the isolated development environment you provide - the environment works well. Of course, except the PHPUnit tests part. By the way, as mentioned in stackowerflow, I have tried running PHPUnit 3.7.* in my shared hosting environment (I believe it has RedHat or CentOS installed) and the examples from the book worked well in that hosting environment.

Environment configuration changes to make the environment fit the latest version of the book (vs.) code changes to make code portable. What is the right way to go?