bedrock icon indicating copy to clipboard operation
bedrock copied to clipboard

Feature Request: Add first-class support for PHPUnit

Open aaemnnosttv opened this issue 5 years ago ā€¢ 15 comments

Submit a feature request or bug report


Feature Request

Installing, configuring, and running the WordPress core PHPUnit library has always been a pain. This creates an unnecessary barrier for WordPress developers to embrace testing, which is undoubtedly a core component of writing modern web applications.

I've been working on the best way to make the WordPress core PHPUnit library installable via Composer for a while now, and I'm happy to say that it is now just as easy to install as a vanilla Composer package.

I would like to propose the addition of WP PHPUnit to Bedrock's development dependencies, along with the necessary boilerplate for everything else PHPUnit needs to run - including CI configuration. Once Composer dependencies have been installed, and the database created, PHPUnit can be run with a single command out-of-the-box.

I would liken the end goal to be similar to what is part of a fresh installation of Laravel. Structure, dependencies, and a working example test.

Unit tests are not just for plugins/themes. Applications like those built on Bedrock will likely have code which is specific to the application, or not structured as a plugin or theme which should still be tested. Not only that, but testing that your code works as expected in conjunction with all the other dependencies that your application requires is arguably more important than testing that a specific component of it works in isolation.

WP PHPUnit is extremely minimal and is very easy to use compared to the current workflow. It's also fully automated in its maintenance, and completely open-source.

You can see a full working example here: https://github.com/wp-phpunit/example-project Although this isn't based on Bedrock, the setup is even simpler with Bedrock šŸ˜„

If added, WP PHPUnit could be easily removed if undesired without requiring any kind of complicated uninstallation procedure, similar to other components of Bedrock. I think I've made the case that its value as an easily opt-out-able component outweighs the cost one would incur if it were opt-in instead.

Is this something that the team would be receptive to considering a PR for?

Related #106

aaemnnosttv avatar Jul 09 '18 22:07 aaemnnosttv

I'd definitely be interested in this depending on the implementation. Tests are good šŸ‘

If a PR isn't too much trouble, then it would be nice to see and try it out.

swalkinshaw avatar Jul 09 '18 23:07 swalkinshaw

Great! I'll start putting together a PR for this very soon then.

aaemnnosttv avatar Jul 10 '18 09:07 aaemnnosttv

Anything here?

eshimischi avatar Aug 11 '18 17:08 eshimischi

https://github.com/roots/bedrock/pull/366

Iā€™m gonna try to help get this going next week

austinpray avatar Aug 11 '18 17:08 austinpray

Happy to help guys, can also cook in native PHPCS and PHPUnit configuration for Travis CI and codecoverage reporting. Have a look at my repo: https://github.com/koconder/wordpress-test-template and a plugin you can see the Travis CI setup on: https://github.com/koconder/wordpress-test-template Shout if you need me to jump in and build out a PR on-top of any unit tests.

koconder avatar Feb 01 '19 04:02 koconder

+1 testing really should be a opt-out.

chrillep avatar Mar 15 '20 12:03 chrillep

Can we help somehow to push this forward?

mklepaczewski avatar May 01 '21 08:05 mklepaczewski

https://github.com/roots/bedrock/pull/366 was a very good start and it just got stale. @aaemnnosttv are you still interested in reviving that if we provide more support/feedback? If not, someone else can start a new PR based on that one.

Looks like the most contentious part of #366 was the usage of wp-phpunit, so a simpler integration to start with would be most of #366 but just without that.

swalkinshaw avatar May 01 '21 21:05 swalkinshaw

For what it's worth, I managed to import changes from #366 with slight modifications (mostly to config files, due to shifting from define to Config::define) and I can confirm that it still works.

This integration doesn't have to be as simple as composer install. Importing non-contentious changes from #366 and adding # Testing section in readme.md would go a long way.

mklepaczewski avatar May 02 '21 07:05 mklepaczewski

@mklepaczewski do you want to put up a new PR with those minimal changes?

swalkinshaw avatar May 10 '21 14:05 swalkinshaw

Sure, I'll try to prep it within few days. There's not mucg to do there, I'm just quite busy.

mklepaczewski avatar May 10 '21 21:05 mklepaczewski

Hello! Any lead on this addition or a working example from @mklepaczewski ? Really interested in adding to my bedrock wp setup!

vilanle avatar Aug 05 '21 22:08 vilanle

Needs more LOVE ā¤ļø. Testing FTW šŸ„°

chrillep avatar Jun 28 '23 17:06 chrillep

If I said I'll do it then I'll do it, I don't need to be reminded about it every two years.... ;-)

On a more serious note, I scheduled it for the 8th of July.

mklepaczewski avatar Jun 28 '23 19:06 mklepaczewski

Update: I imported changes from #366 into a new branch (it's not released yet) and did some tests. For the most part, it works, but I want to inspect one quirk before I push it. I'm out of time for the task, so it has been rescheduled for July 15th.

mklepaczewski avatar Jul 08 '23 10:07 mklepaczewski