Upgrade to Pro — share decks privately, control downloads, hide ads and more …

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

Florian Engelhardt

August 20, 2020
Tweet

More Decks by Florian Engelhardt

Other Decks in Programming

Transcript

  1. If I have seen further it is only by standing

    on the shoulders of giants — Sir Isaac Newton
  2. 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 [email protected]:php/php-src.git cd php-src ./buildconf ./configure make -j `nproc` ./sapi/cli/php -v
  3. RUN THE TESTS RUN THE TESTS RUN THE TESTS RUN

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

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

    simple name for the test longer text goes to DESCRIPTION --TEST-- strlen() function test
  6. 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.'); ?>
  7. 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!')); ?>
  8. 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)
  9. EXPECTF SECTION EXPECTF SECTION EXPECTF SECTION EXPECTF SECTION EXPECTF SECTION

    alternative to EXPECT substitution tags known from printf() are allowed --EXPECTF-- int(%d)
  10. 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
  11. 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'); ?>
  12. 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
  13. FIND SOMETHING RED FIND SOMETHING RED FIND SOMETHING RED FIND

    SOMETHING RED FIND SOMETHING RED ext/zlib/zlib.c in PHP 7.1
  14. 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
  15. 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
  16. --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"
  17. 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
  18. 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
  19. 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!