Ever got the message "Fatal error: Out of memory" when running your unit tests? Or do you have to wait for more than 5 minutes for all of your unit tests to complete? We're using Docker to mitigate these and other issues. In this session I will show you how we have split up a single testsuite of 3K+ tests into manageable unit modules which are executed by Docker micro instances in parallel. And with this set up we test our application on the current PHP version, but it also allows us to test against a new major PHP version the moment it is released or even is available in beta.
3. Michelangelo van Dam
‣ Pro PHP consultant at in2it
‣ President of PHPBenelux
‣ Open-Source contributor
‣ Conference Speaker
‣ ZCE and ZF-CE
in itPROFESSIONAL PHP SERVICES
PHPUnit + Docker = 🚗💨 3
5. EXTRAS TO RUN PHPUNIT
www.in2it.be - @in2itvof PHPUnit + Docker = 🚗💨 5
‣ Command-line?
‣ Run from IDE?
‣ Test server?
‣ Jenkins, TeamCity, Bamboo?
‣ Vagrant?
‣ Docker?
https://goo.gl/images/l0HXj7
6. DRAWBACKS
www.in2it.be - @in2itvof PHPUnit + Docker = 🚗💨 6
‣ Takes long time for many tests
‣ Environment not always ready for testing
‣ Tests don’t provide good feedback
https://goo.gl/images/TajZrP
7. SYSTEM FAILURES
www.in2it.be - @in2itvof PHPUnit + Docker = 🚗💨 7
‣ Memory Exhausted
‣ Disk full
‣ No network or network latency
‣ Systems crash
https://goo.gl/images/ruod6b
9. WHAT IS DOCKER?
www.in2it.be - @in2itvof PHPUnit + Docker = 🚗💨 9
‣ Technology platform
‣ Run processes in separate containers
‣ Scales fast and seemlessly
‣ Containers are easy shippable
‣ Best next thing since sliced bread
https://goo.gl/images/xEfLk5
27. WHERE ARE MY FAILURES?
www.in2it.be - @in2itvof PHPUnit + Docker = 🚗💨 27
https://goo.gl/images/VWpYFO
28. www.in2it.be - @in2itvof PHPUnit + Docker = 🚗💨 28
for i in `./vendor/bin/phpunit --list-groups | grep "^
-" | awk {'print $2'}`; do echo $i; done | time
parallel docker run -d -v "$PWD":/var/run/phpunit -w /
var/run/phpunit --name pu-docker-{} php:7.0-cli /var/
run/phpunit/vendor/bin/phpunit --group {} && for i in
`./vendor/bin/phpunit --list-groups | grep "^ -" | awk
{'print $2'}`; do docker wait pu-docker-$i | grep -c 0
> /dev/null || docker logs pu-docker-$i && docker rm -f
pu-docker-$i > /dev/null; done;
29. www.in2it.be - @in2itvof PHPUnit + Docker = 🚗💨 29
‣ loop over our @group list entries
‣ run these in docker (daemonized)
‣ loop over our @group list entries
‣ fetch the exit status of phpunit from the containers
‣ if not 0 -> show us the failure
32. OTHER SCENARIOS
www.in2it.be - @in2itvof PHPUnit + Docker = 🚗💨 32
‣ Test on different PHP versions
‣ Test separation based on TestSuite, Directory, …
‣ Testing long running integration tests separately
‣ Resilience testing
https://goo.gl/images/JnY8yr
34. www.in2it.be - @in2itvof PHPUnit + Docker = 🚗💨 34
PHPUnit/Unit Testing
Ensure your apps are
of high quality
Zend Framework 2/3
Build robust web
applications
Azure PHP
Quick time to market
Scale up and out
jQuery
Professional jQuery
PHP 7
Learn the web language
that powers 80% of the
internet
On-site Training
Personal coaching and
mentoring on-site
Training courses 2016 - 2017