Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
PHP Test Fest
Become a core PHP Developer
Who am I?
Lead Developer and Solutions Architect for
DynamicReservations
Writing PHP web apps professionally for 12 yrs
DD...
What is PHPTestFest?
World wide event - Sep to Dec 2017
Write tests for the core of PHP
Meeting Virtually and Physically
P...
Why am I qualified to give this talk?
Because I am a core contributor to PHP
The file I committed
“Hey, I could do that!”
Writing tests in PHP
So easy, even I could do it
Testing in PHP
PHP tests are written as PHPT files
These are just PHP files with extra bits
No C code required!
They’re su...
Walk through an example
--TEST --
Test description
--FILE--
Test contents
--EXPECT--
Expected output
php-src/Zend/tests/nu...
Types of test
1. Basic 2. Error 3. Bug
Running your tests
1. Get your machine setup to run the tests
a. Install docker on your machine
b. Run the following comma...
Debugging failing tests
Running a failing test creates the following file extensions with same name as the test
.out - The...
Example diff file
php-src/Zend/tests/nullable_types/string.phpt php-src/Zend/tests/nullable_types/string.diff
Submitting your test
1. Push your changes to your fork on github
2. Create a PR between your branch and master
3. Wait …
4...
Finding untested code
The whole point of writing a test is to test untested code
Go to http://gcov.php.net/
Look for somet...
The test I wrote
You will not believe how simple it is
How I found curl_share_close needed to be
tested
How I found curl_share_close needed to be
tested
My simple test
What it looks like now
What it looks like now
Tips for navigating the C code
Not as hard as it looks
- PHP_FUNCTION marks the definition of a function
- Look for untest...
Writing a test from scratch
Because a tutorial isn’t complete without a live demo!
(one that will most likely break)
We missed an error case
Missed Error Case
Live demo time
It’s that easy
Today we showed
1. PHPT tests in PHP
2. How to find code to test
3. How to write the tests
4. How to submit...
PHP Test Fest
Day long event in on a Saturday in September (details TBD).
The Dublin PHPTestFest team
https://groups.googl...
Upcoming SlideShare
Loading in …5
×

Php test fest

410 views

Published on

A talk on PHPTestFest, an event PHPDublin is gladly taking part in. Here we show how easy it is to write a test for the core of PHP, letting you become a core PHP developer.

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Php test fest

  1. 1. PHP Test Fest Become a core PHP Developer
  2. 2. Who am I? Lead Developer and Solutions Architect for DynamicReservations Writing PHP web apps professionally for 12 yrs DDD and EventSourcing fanatic (I will talk for hours) Recovered Architecture Astronaut Co-Organiser of PHPDublin @barryosull barry@tercet.io http://dev.to/barryosull http://barryosullivan.me
  3. 3. What is PHPTestFest? World wide event - Sep to Dec 2017 Write tests for the core of PHP Meeting Virtually and Physically PHPDublin is taking part! Day long event, help devs in Ireland write tests
  4. 4. Why am I qualified to give this talk? Because I am a core contributor to PHP
  5. 5. The file I committed
  6. 6. “Hey, I could do that!”
  7. 7. Writing tests in PHP So easy, even I could do it
  8. 8. Testing in PHP PHP tests are written as PHPT files These are just PHP files with extra bits No C code required! They’re super easy to read and write Any PHP developer can do it
  9. 9. Walk through an example --TEST -- Test description --FILE-- Test contents --EXPECT-- Expected output php-src/Zend/tests/nullable_types/string.phpt
  10. 10. Types of test 1. Basic 2. Error 3. Bug
  11. 11. Running your tests 1. Get your machine setup to run the tests a. Install docker on your machine b. Run the following command line curl -s https://raw.githubusercontent.com/herdphp/docker-phpqa/master/bin/installer.sh | bash 2. Fork the PHP-SRC from github 3. Clone to your local machine 4. Create your test file in the tests directory of the file/function you’re testing 5. Run your tests
  12. 12. Debugging failing tests Running a failing test creates the following file extensions with same name as the test .out - The actual output that the PHP code from the --FILE-- section generated .exp - The output we expected from the --EXPECT-- section .diff - A diff file with the actual output compared to the expected output .log - Both actual and expected output in one file .php - The --FILE-- section as a PHP file .sh - A bash script that runs the PHP file in the same environment that run-tests ran it
  13. 13. Example diff file php-src/Zend/tests/nullable_types/string.phpt php-src/Zend/tests/nullable_types/string.diff
  14. 14. Submitting your test 1. Push your changes to your fork on github 2. Create a PR between your branch and master 3. Wait … 4. Celebrate when it’s accepted!
  15. 15. Finding untested code The whole point of writing a test is to test untested code Go to http://gcov.php.net/ Look for something with low coverage Write a test for it!
  16. 16. The test I wrote You will not believe how simple it is
  17. 17. How I found curl_share_close needed to be tested
  18. 18. How I found curl_share_close needed to be tested
  19. 19. My simple test
  20. 20. What it looks like now
  21. 21. What it looks like now
  22. 22. Tips for navigating the C code Not as hard as it looks - PHP_FUNCTION marks the definition of a function - Look for untested function code - Goto the php.net definition for that function - Looks for example code - Use that as a template for your test
  23. 23. Writing a test from scratch Because a tutorial isn’t complete without a live demo! (one that will most likely break)
  24. 24. We missed an error case Missed Error Case
  25. 25. Live demo time
  26. 26. It’s that easy Today we showed 1. PHPT tests in PHP 2. How to find code to test 3. How to write the tests 4. How to submit tests 5. Wrote a test in ~5 minutes In other words:
  27. 27. PHP Test Fest Day long event in on a Saturday in September (details TBD). The Dublin PHPTestFest team https://groups.google.com/a/phpcommunity.org/group/testfest/ #phptestfest https://phptestfest.org/ Michael Flanagan @micflan Bruno Siqueira @brunoric Ken Guest @kenguest Barry O Sullivan @barryosull Joao Paulo V Martins @jpvm Mark Railton @railto

×