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

php-src is waiting for your contribution or: Ho...

php-src is waiting for your contribution or: How to Level Up Your PHP Skills with php-src

PHPxTKY June 2025
https://phpxtky.connpass.com/event/352685/

#phpxtky

Avatar for 武田 憲太郎

武田 憲太郎

June 08, 2025
Tweet

More Decks by 武田 憲太郎

Other Decks in Programming

Transcript

  1. Self Introduction‒a little old 2025-06-08 #phpxtky php-src is waiting for

    your contribution 1 • Kentaro Takeda / @KentarouTakeda • 20 years of PHP experience • 2 years of C experience - but that was 30 years ago Honestly, I can't write C anymore • php-src contributor Again, I can't write C!
  2. 4 Ways to Contribute to PHP Development 2025-06-08 #phpxtky php-src

    is waiting for your contribution 3 1. Running test suites in RC and release distributions of PHP 2. Help finding and diagnosing failed tests, see the phpt documentation 3. Filing and resolving bug reports on GitHub Issues. 4. Help maintain and or translate documentation files at the doc-* repositories on github. Check out our guide for contributors. https://www.php.net/get-involved
  3. How to Write PHP Tests •Tests are written in *.phpt

    files. •One file corresponds to one test case. --TEST-- Test Fizz Buzz Function --FILE-- <?php var_dump(fizz_buzz(10)); var_dump(fizz_buzz(11)); var_dump(fizz_buzz(12)); var_dump(fizz_buzz(13)); var_dump(fizz_buzz(14)); var_dump(fizz_buzz(15)); --EXPECT-- string(4) "Buzz" int(11) string(4) "Fizz" int(13) int(14) string(8) "FizzBuzz"
  4. How to Write PHP Tests The TEST Section •Name of

    the test case •Used in the test runner’s output --TEST-- Test Fizz Buzz Function --FILE-- <?php var_dump(fizz_buzz(10)); var_dump(fizz_buzz(11)); var_dump(fizz_buzz(12)); var_dump(fizz_buzz(13)); var_dump(fizz_buzz(14)); var_dump(fizz_buzz(15)); --EXPECT-- string(4) "Buzz" int(11) string(4) "Fizz" int(13) int(14) string(8) "FizzBuzz"
  5. How to Write PHP Tests The FILE Section •You can

    write any PHP code •The test runner executes it --TEST-- Test Fizz Buzz Function --FILE-- <?php var_dump(fizz_buzz(10)); var_dump(fizz_buzz(11)); var_dump(fizz_buzz(12)); var_dump(fizz_buzz(13)); var_dump(fizz_buzz(14)); var_dump(fizz_buzz(15)); --EXPECT-- string(4) "Buzz" int(11) string(4) "Fizz" int(13) int(14) string(8) "FizzBuzz"
  6. How to Write PHP Tests The EXPECT Section •Expected output

    •If the actual output is different, the test fails --TEST-- Test Fizz Buzz Function --FILE-- <?php var_dump(fizz_buzz(10)); var_dump(fizz_buzz(11)); var_dump(fizz_buzz(12)); var_dump(fizz_buzz(13)); var_dump(fizz_buzz(14)); var_dump(fizz_buzz(15)); --EXPECT-- string(4) "Buzz" int(11) string(4) "Fizz" int(13) int(14) string(8) "FizzBuzz"
  7. My Recommended Way to Contribute to php-src 2025-06-08 #phpxtky php-src

    is waiting for your contribution 9 • Run tests on the development version of PHP. • If you find a failing test, investigate and fix it. • Even if tests don't fail, improve the coverage, design, or implementation of tests.
  8. The Current State of php-src Tests 2025-06-08 #phpxtky php-src is

    waiting for your contribution 10 • Tests from over a decade ago sit side by side with recent ones. • All of them require maintaining an "all pass" status.
  9. Barriers for PHP Developers 2025-06-08 #phpxtky php-src is waiting for

    your contribution 11 • Tests with quality standards different from today • Insufficient coverage • Excessive use of the error control operator @ • PHP code written in the style of more than a decade ago • Redundant code • Tests with different execution conditions compared to now • Tests dependent on CI settings • Tests that only run in specific environments • False negative tests
  10. PHP Test Code in phpt A simple structure based on

    one file, one test suite. • Due to the nature of the tests, implementations avoiding advanced features are required. • Even when sharing code, using `require()` is the limit. Requires pure PHP skills that do not depend on any specific framework.
  11. PHP Test Code in phpt Validate output (standard output) against

    input (PHP code, function input) • A format often seen in competitive programming and programming learning sites. • The most basic form, both as a test and as a program. Requires pure implementation skills that do not depend on any specific language.
  12. How to Find the Code You Need 2025-06-08 #phpxtky php-src

    is waiting for your contribution 15 • Identify the extension name from the PHP manual (mainly Introduction or Installing/Configuring).
  13. Test Storage Directories 2025-06-08 #phpxtky php-src is waiting for your

    contribution 16 •Tests for PDO ext/pdo/tests •Tests for any extension: ext/EXTENSION/tests
  14. Test File Names 2025-06-08 #phpxtky php-src is waiting for your

    contribution 17 [FEATURE].phpt • Corresponds to a specific feature gh[NUMBER].phpt • Corresponds to GitHub Issue number • The issue will tell you what the test is about bug_[NUMBER].phpt • Corresponds to tickets in the PHP Bug Tracking System • (It is no longer in use.)
  15. Ex: A Real gh[NUMBER].phpt Test Case 2025-06-08 #phpxtky php-src is

    waiting for your contribution 18 __FILE__ // SNIP echo "dsn with correct password / correct user / incorrect password".PHP_EOL; try { $db = new PDO("{$dsn} password={$password}", $user, 'fuga', [ PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION ]); echo "Connected.".PHP_EOL.PHP_EOL; } catch (PDOException $e) { echo $e->getMessage().PHP_EOL; } echo "dsn with correct credentials / incorrect user / incorrect password".PHP_EOL; try { $db = new PDO("{$dsn} user={$user} password={$password}", 'hoge', 'fuga', [ PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION ]); echo "Connected.".PHP_EOL; } catch (PDOException $e) { echo $e->getMessage().PHP_EOL; } --EXPECT-- dsn without credentials / correct user / correct password Connected. dsn with credentials / no user / no password Connected. dsn with correct user / incorrect user / correct password Connected. dsn with correct password / correct user / incorrect password Connected. dsn with correct credentials / incorrect user / incorrect password Connected. ext/pdo_pgsql/tests/gh12423.phpt
  16. Ex: A Real gh[NUMBER].phpt Test Case 2025-06-08 #phpxtky php-src is

    waiting for your contribution 19 The test case of gh12423.phpt About 10 years ago
  17. How to Discover Features You Can Contribute To 2025-06-08 #phpxtky

    php-src is waiting for your contribution 20 1. Pick a feature you like. 2. Spend about an hour reading its tests. • If it's a test for an Issue or Bug, read the original ticket too. 3. You'll quickly find something you want to fix. • Or, you'll discover a way of using PHP you didn't know about. • Or, you'll find various "reasons" from Issue or pull request information.
  18. How to Set Up a Build Environment 2025-06-08 #phpxtky php-src

    is waiting for your contribution 21 KentarouTakeda/docker-php-src • My personal build environment. • Following the README will set up a complete environment, including external databases. How to Run Tests • ./run-tests.php [phpt file or directory]
  19. How to Learn the Basics 2025-06-08 #phpxtky php-src is waiting

    for your contribution 22 • Building PHP — PHP Internals Book • Official resource on building PHP • Somewhat outdated content (translate version to latest) • Running the test suite — PHP Internals Book • Official resource on running PHP tests
  20. Self Introduction‒latest 2025-06-08 #phpxtky php-src is waiting for your contribution

    23 • 2 years of C experience - but that was 30 years ago Honestly, I can't write C anymore After contributing to testing and CI for a while, • php-src contributor Again, I can't write C! I have reached a point where I can contribute by adding features in C!