This week: Block Patterns, DE{CODE} 2022 recordings, upcoming WordPress anniversary, better WordPress 6.0 performance, and much more…
Josh is a PHP & JavaScript developer from Pittsburgh, PA. Today he is a freelance developer and creator of Plugin Machine, a framework for WordPress plugin development. Previously he was the lead developer of the plugin Caldera Forms and co-founder of CalderaWP. Josh is a total dog person and super-nerd for ecology, crypto, caffeine, music, sci-fi and going on long walks. He lives with his wife Alicia.
👋, Hi I’m Josh Pollock and I’ll be your guest owl for this week. This week I’m going to share five links to help WordPress developers learn to use PHPUnit. Automated tests are code we use to check if our code works as expected. The simplest reason we use automated testing is to prevent errors. But they can also help us profile our code for performance issues or to surface accessibility-related bugs. We can use PHPUnit to run all types of tests unit tests, integration tests, and even end to end tests.
This list is for WordPress developers who write PHP code. But, if you don’t write code, but employ folks who do, try talking to them about automated testing. If they are not using tests, it’s generally because they don’t know how they don’t know what to test or it’s too much work to set up and run them. This week’s Owl will help with that first concern – how to learn. If you’re wondering what to test, I wrote a post on what to test first on on the blog for my new product Plugin Machine, which makes it easier to set up and run test-driven WordPress plugins.
Whether you’re writing plugins, custom themes, or using WordPress as a CMS for a headless site, automated testing is important. This owl focuses on PHPUnit, which is mainly used to test PHP code. I like to use Jest for testing blocks and other javascript code.
We generally use PHPUnit for running “unit tests” and “integration tests.” Unit tests should only test one thing at a time, with no dependencies. Integration tests make sure multiple units work together. The WordPress test suite, which is used to test the PHP code in WordPress core, sets up PHPUnit for integration testing with WordPress. You can use it for your tests, or not. That’s up to you. Here are 5 links to help you learn PHPUnit for WordPress testing:
If you want to write true, isolated unit tests for a WordPress plugin, you’re going to need to structure your code so it’s testable and set up testing doubles to mock other parts of the code, or WordPress core functions. This article walks through each step of the process and discusses the importance of isolation.
If you do want to use the WordPress test suite, which allows you to run tests with WordPress and a MySQL database, this is a short introduction. This post explains what the WordPress test suite does and shows the code you need to get started. It also introduces the various testing utilities that are provided.
One of the super helpful tools that the WordPress testing suite provides are factories. These are functions that add data to the database to test against. For example, if you want to test that a function will get the last 5 posts from two post types, you’re going to need to add a bunch of posts from three or more post types. These factory functions help with that, but are not well documented. This blog is a huge help.
If you’re writing unit tests for a WordPress site, plugin or theme you’re likely going to need to test code that calls functions from WordPress core. For example, how can you test that a filter, which is added conditionally, is added in some cases, but not in others? Mocking WordPress functions, with Mockery and Brain Monkey can help, for both unit tests and integration tests.
The first four posts in this lists were for unit and integration tests, which run your code and check if they produce the expected result. End to end tests on the other hand use an automated browser to go to your site and interact with it. This tests all of the code involved in a feature. Unit and integration testing can be used to test different parts of a complex feature, for example the cart and checkout system on an eCommerce site. This post shows how to use Codeception and wp-browser to test a WooCommerce site.
A great tool has got published on GutenbergHub that allows you to test various Block Patterns without having to install them.
On the De{Code} 2022 website you can finally see all the recordings. Most of them were related to headless WordPress and Gutenberg.
David Bisset has created a website where we can share our thoughts on WordPress, which will be celebrating its 19th anniversary on May 27th.
Jonny Harris shows what changes will be made in WordPress 6.0 in terms of taxonomy performance. Fewer queries and a longer lasting cache are really great news.
Eric Karkovack wonders if freelancers should build their next website using Full Site Editing or not?
After the confusion over MemberPress and how they treat users after the license expires, Dan Knauss wonders what it should look like in the WordPress world.
Anne McCarthy, in the Gutenberg Times, explains the future of Full Site Editing. She also asks for help in finding the problems and obstacles that are holding us back from using FSE.
Iain Poulson and Jonathan Bossenger talked about WordCamps, what their first ones looked like, what they remember best, why it is worth participating in them and how many virtual events they took part in over the last two years.
Matt Medeiros asked Eric Karkovack about how you can earn money as a writer in the WordPress world.
Alexander Stoffel explains the difference between WordPress themes and Statamic Starter Kits.
PHP Foundation has published the first summary of its activities. I hope that thanks to the foundation, PHP will be able to develop even more dynamically.
From non-WordPress topics. Gergely Orosz commented on the recently published postmortem about problems several Atlassian services had lately.