Pro Yearly is on sale from $80 to $50! »

Growing the PHP core - one test at a time

Growing the PHP core - one test at a time

I am a PHP core contributor and you can be too! You think you need to create a RFC for this or write and maintain a PHP extension or even write C code? Fear no more!
In this talk you will learn how you can become a PHP core contributor and give something back to the community by writing tests for PHP core without writing a single line of C code.

Recording at https://nomadphp.com/video/305/Growing-the-PHP-Core--one-Test-at-a-Time

8b8824ec70715f8599896375626c20d9?s=128

Florian Engelhardt

August 20, 2020
Tweet

Transcript

  1. @realFlowControl GROWING THE PHP CORE - ONE TEST AT A

    TIME -
  2. FLORIAN ENGELHARDT FLORIAN ENGELHARDT FLORIAN ENGELHARDT FLORIAN ENGELHARDT FLORIAN ENGELHARDT

  3. HUSBAND AND DAD HUSBAND AND DAD HUSBAND AND DAD HUSBAND

    AND DAD HUSBAND AND DAD
  4. None
  5. Nobody will ever use this — Florian Engelhardt

  6. None
  7. If I have seen further it is only by standing

    on the shoulders of giants — Sir Isaac Newton
  8. PHPTESTFEST 2017 PHPTESTFEST 2017 PHPTESTFEST 2017 PHPTESTFEST 2017 PHPTESTFEST 2017

  9. COMPILING PHP FROM SOURCE COMPILING PHP FROM SOURCE COMPILING PHP

    FROM SOURCE COMPILING PHP FROM SOURCE COMPILING PHP FROM SOURCE * fork before cloning git clone git@github.com:php/php-src.git cd php-src ./buildconf ./configure make -j `nproc` ./sapi/cli/php -v
  10. RUN THE TESTS RUN THE TESTS RUN THE TESTS RUN

    THE TESTS RUN THE TESTS make TEST_PHP_ARGS=-j`nproc` test
  11. BASIC TEST BASIC TEST BASIC TEST BASIC TEST BASIC TEST

    --TEST-- strlen() function --FILE-- <?php var_dump(strlen('Hello World!')); ?> --EXPECT-- int(12)
  12. TEST SECTION TEST SECTION TEST SECTION TEST SECTION TEST SECTION

    simple name for the test longer text goes to DESCRIPTION --TEST-- strlen() function test
  13. SKIPIF SECTION SKIPIF SECTION SKIPIF SECTION SKIPIF SECTION SKIPIF SECTION

    use case: skip if extension is missing skip if output starts with “skip” expect failure if output starts with “xfail” optional --SKIPIF-- <?php if (!extension_loaded('core')) die('Skipped: core extension required.'); ?>
  14. FILE SECTION FILE SECTION FILE SECTION FILE SECTION FILE SECTION

    the actual test PHP code enclosed by PHP tags --FILE-- <?php var_dump(strlen('Hello World!')); ?>
  15. EXPECT SECTION EXPECT SECTION EXPECT SECTION EXPECT SECTION EXPECT SECTION

    expected output from code in FILE section must match actual output exactly to pass --EXPECT-- int(12)
  16. EXPECTF SECTION EXPECTF SECTION EXPECTF SECTION EXPECTF SECTION EXPECTF SECTION

    alternative to EXPECT substitution tags known from printf() are allowed --EXPECTF-- int(%d)
  17. XFAIL SECTION XFAIL SECTION XFAIL SECTION XFAIL SECTION XFAIL SECTION

    use case known upstream bugs test driven development test is expected to fail why it’s expected to fail optional --XFAIL-- This bug might be still open on aix5.2-ppc64 and hpux11.23-ia64
  18. CLEAN SECTION CLEAN SECTION CLEAN SECTION CLEAN SECTION CLEAN SECTION

    use case: clean up after yourself executed after test completes optional --CLEAN-- <?php unlink(__DIR__.'/file.tmp'); ?>
  19. WHAT TO TEST? WHAT TO TEST? WHAT TO TEST? WHAT

    TO TEST? WHAT TO TEST? choose branch (7.1, 7.2, 7.3, 7.4, HEAD) click on coverage gcov.php.net demo
  20. FIND SOMETHING RED FIND SOMETHING RED FIND SOMETHING RED FIND

    SOMETHING RED FIND SOMETHING RED ext/zlib/zlib.c in PHP 7.1
  21. WRITE A TEST WRITE A TEST WRITE A TEST WRITE

    A TEST WRITE A TEST the absence of the Accept-Encoding header the Accept-Encoding being gzip the Accept-Encoding being deflate the Accept-Encoding being anything else
  22. DEMO TIME! DEMO TIME! DEMO TIME! DEMO TIME! DEMO TIME!

  23. TIME FOR THE SOURCE! TIME FOR THE SOURCE! TIME FOR

    THE SOURCE! TIME FOR THE SOURCE! TIME FOR THE SOURCE! or ask the nice fellows over at the source phpc.chat
  24. --TEST-- zlib_get_coding_type() with gzip encoding --SKIPIF-- <?php if (!extension_loaded("zlib")) print

    "skip"; ?> --ENV-- HTTP_ACCEPT_ENCODING=gzip --FILE-- <?php ini_set('zlib.output_compression', 'Off'); $off = zlib_get_coding_type(); ini_set('zlib.output_compression', 'On'); $on = zlib_get_coding_type(); ini_set('zlib.output_compression', 'Off'); var_dump($off); var_dump($on); ?> --EXPECT-- bool(false) string(4) "gzip"
  25. ext/zlib/zlib.c in PHP 7.3

  26. WHAT HAVE WE LEARNED WHAT HAVE WE LEARNED WHAT HAVE

    WE LEARNED WHAT HAVE WE LEARNED WHAT HAVE WE LEARNED what looks simple, might be complex HTTP Request is immutable there are modify handlers for ini settings
  27. WHAT DO YOU GAIN? WHAT DO YOU GAIN? WHAT DO

    YOU GAIN? WHAT DO YOU GAIN? WHAT DO YOU GAIN? PHP will be more stable and reliable deeper understanding of how PHP works internaly phpt test format can be used in PHPUnit
  28. YOU CAN CALL YOURSELF A PHP CORE CONTRIBUTOR! YOU CAN

    CALL YOURSELF A PHP CORE CONTRIBUTOR! YOU CAN CALL YOURSELF A PHP CORE CONTRIBUTOR! YOU CAN CALL YOURSELF A PHP CORE CONTRIBUTOR! YOU CAN CALL YOURSELF A PHP CORE CONTRIBUTOR!
  29. None
  30. FURHTER READINGS FURHTER READINGS FURHTER READINGS FURHTER READINGS FURHTER READINGS

    phptestfest.org qa.php.net dotbox.org