$30 off During Our Annual Pro Sale. View Details »

WP Core Tests vs PHP 8.1

WP Core Tests vs PHP 8.1

Introduction for the live streamed mob programming session of July 30th, 2021, with as the topic: Modernizing the WP Core test suite to allow the tests to run on PHP 8.1.

Slides set forth the problem outline and solution direction applied in the patch which was reviewed during the remainder of the session.

Missed it ? The recording is available as video on demand at https://www.youtube.com/watch?v=SAtiKaUwLU4

Juliette Reinders Folmer

July 30, 2021
Tweet

More Decks by Juliette Reinders Folmer

Other Decks in Programming

Transcript

  1. WP Core Tests vs PHP 8.1
    Juliette Reinders Folmer
    Tweet about it: @jrf_nl

    View Slide

  2. Current Situation
    ▪ Composer
    "phpunit/phpunit":
    "^7.5"
    ▪ Composer lock file
    Continuous Integration:
    ▪ PHP 5.6, 7.0:
    Use PHPUnit 5.7 Phar
    ▪ PHP 7.1 – 7.4:
    Use PHPUnit 7.5 Phar
    ▪ PHP 8.0:
    Use Composer install with
    –ignore-platform-reqs
    Copied in PHPUnit 9.x
    MockObject files

    View Slide

  3. The Problem With the Current Setup
    Testing locally
    against different
    PHP versions
    PHP 8.1 Maintenance burden

    View Slide

  4. PHPUnit Support
    v Compatible with:
    10 PHP >= 8.0
    (expected end of 2021)
    9 PHP >= 7.3
    8 PHP >= 7.2
    7 PHP 7.1, 7.2, 7.3 [EOL]
    6 PHP 7.0, 7.1, 7.2 [EOL]
    5 PHP 5.6, 7.0, 7.1 [EOL]
    Seemann

    View Slide

  5. Making Test Suites PHPUnit Cross-version Compatible
    Renamed/split
    assertion and
    expectation methods
    void return type for
    fixture methods
    (PHPUnit >= 8.0)
    Configuration file
    format change
    (PHPUnit >= 9.3)

    View Slide

  6. PHPUnit vs PHP
    PHPUnit / PHP 5.6 7.0 7.1 7.2 7.3 7.4 8.0 8.1
    5.x
    6.x
    7.x
    8.x 8.6+ ?
    9.x 9.3+ 9.6+ ?
    10.x
    void
    8.5+

    View Slide

  7. What Happened Last Year ? (PHP 8.0)
    Phar
    Version constraint 5.x
    PHPUnit version
    constraints
    Mocking
    Code Coverage
    Composer
    Version constraint 7.x
    --ignore-platform-reqs in CI
    Copied in files from
    PHPUnit 9.x
    Not available on PHP 8.0

    View Slide

  8. PHP 8.1
    vs PHPUnit 7.x
     Config file
     PHPUnit 7.x
    + PHPUnit 7.x dependencies
    incompatible with PHP 8.1
    (and won't be fixed
    anymore)

    View Slide

  9. Constraints
    and
    Wishes
    » Supporting PHP 5.6 + 7.0 still
    required
    » Plugin tests often extend
    WP integration test suite
    » Supporting both PHPUnit PHAR
    + Composer install preferred
    » Make running tests locally
    against different PHP versions
    easier for contributors

    View Slide

  10. WP native
    solution
    PHPUnit
    Polyfills
    Symfony
    Bridge
    Options

    View Slide

  11. PHPUnit Polyfills
    What you get:
    ▪ Polyfills via traits for all new
    assertions and expectations in
    PHPUnit
    ▪ Helper to work round removal
    of assertAttribute*()
    methods
    ▪ An cross-version compatible
    abstract base TestCase (to get
    round void) which includes all
    polyfills
    ▪ A cross-version compatible
    TestListenerImplementation
    Sponsored by:

    View Slide

  12. Action Plan
    ❑Remove composer.lock file
    ❑Use PHPUnit 9.x assertion and expectation
    methods
    ❑Solve void for fixtures
    ❑Remove old work-arounds
    ❑Enable testing against PHP 8.1 in CI
    ❑Fix any and all PHP 8.1 incompatibilities

    View Slide

  13. Follow Along
    ▪ Remove composer.lock
    https://core.trac.wordpress.org/ticket/47381
    Patch: https://github.com/WordPress/wordpress-develop/pull/1511
    ▪ Make test suite compatible with PHPUnit 8.x + 9.x
    https://core.trac.wordpress.org/ticket/46149
    Patches not pulled yet: https://github.com/jrfnl/wordpress-develop-
    official/tree/WIP/all-stacked-in-the-right-order
    ▪ PHP 8.1 fixes
    https://core.trac.wordpress.org/ticket/53635

    View Slide

  14. Open Questions
    ▪ What to do about the Speedtrap listener
    package ?
    ▪ How to handle the stdClass / __invoke()
    warning ?
    ▪ Update the Core Test running and
    contributing docs

    View Slide

  15. Further Reading
    ▪ The Grumpy Programmer's Guide to Testing PHP Applications
    https://grumpy-learning.com/
    ▪ Your Mocks Won't Save You!
    https://24daysindecember.net/2020/12/08/your-mocks-wont-save-you/
    ▪ My Top 10 PHPUnit Tips & Tricks
    https://speakerdeck.com/jrf/my-top-10-phpunit-tips-and-tricks-e6ea54ce-
    2515-4ea9-aacf-9bf7ab3b3141
    ▪ PHPUnit Documentation
    https://phpunit.readthedocs.io/
    ▪ Path Coverage in PHPUnit
    https://doug.codes/php-code-coverage

    View Slide

  16. Tooling
    ▪ PHPUnit Polyfills
    https://packagist.org/packages/yoast/phpunit-polyfills
    ▪ WP Test Utils
    https://packagist.org/packages/yoast/wp-test-utils

    View Slide

  17. Thanks!
    @jrf_nl @jrfnl
    Any
    questions ?
    Slides: https://speakerdeck.com/jrf

    View Slide