bedrock icon indicating copy to clipboard operation
bedrock copied to clipboard

Add WP PHPUnit

Open aaemnnosttv opened this issue 5 years ago • 6 comments

This is a first draft of a working implementation of what it would look like to integrate WP PHPUnit into Bedrock.

Documentation is not included yet and still needs to be added, but I wanted to get a first round of feedback before writing it.

There are a few things that are somewhat of stylistic preferences, like the exceptions made to the PHPCS rules for tests and the formatting of the example test. This is somewhat bending the rules of the existing ruleset, but I believe it's a common test-specific style.

Apart from that, very little has really changed, as almost everything here are additions.

I look forward to hearing anyone's feedback on the proposed changes.

Resolves #365

aaemnnosttv avatar Jul 10 '18 22:07 aaemnnosttv

Also wow sorry meant to include this in initial review but: thank you so much for putting this together! This is a great start :+1:.

austinpray avatar Jul 11 '18 01:07 austinpray

I haven't taken a look at the code, just jumping in to follow up to @austinpray's comment. I think insofar as the PR improves the compatibility between WP PHPUnit and Bedrock, this is a great initiative. I do tend to agree with the idea of keeping Bedrock testing framework-agnostic. Maybe it would be worth putting some of the more popular testing frameworks (WP Mock, WP PHPUnit, BrainMonkey, etc.) in the suggest block of composer.json with descriptions of their intended use? Just a thought.

johnpbloch avatar Jul 11 '18 01:07 johnpbloch

I mostly agree with @austinpray. I kind of forgot that the WP test unit library is mostly designed for testing WP core itself (for core developers). It's pretty heavy-handed for normal application/project testing.

So having the boilerplate required to make that easier with Bedrock is still useful 👍

swalkinshaw avatar Jul 11 '18 01:07 swalkinshaw

Thank you everyone for your feedback! It seems like everyone is on board with the idea that adding some boilerplate for testing is a step in the right direction but maybe it shouldn't be opinionated in choosing a framework to include boilerplate for.

PHPUnit + wp-phpunit is the best way to test your wordpress installation.

I don't particularly agree with the idea that including a library is making such a statement, nor would I make that claim myself.

The library is really just the WordPress core library that supports running PHPUnit in a WordPress environment. It's just been made easily installable via Composer. I would say that this library is the one that most people are going to be familiar with in a WordPress context (WP CLI scaffolds it, and most articles/resources on testing in WordPress are based on it).

Of course others are available, but I think if Bedrock were to include a more complete testing boilerplate (as proposed) that it offers more value than if it was more barebones. By no means does it lock anyone in to using it or impose anything that isn't easily changeable which I think is the important aspect of the principal of remaining framework agnostic.

With that said, I fully respect the teams decision to keep Bedrock framework agnostic if that's the consensus. In my opinion, including the "official" core library for testing is still relatively framework agnostic because it's part of WordPress core.

Either way, I'm still interested in helping with this initiative in whatever way I can.

aaemnnosttv avatar Jul 11 '18 09:07 aaemnnosttv

~This has been stale for quite some time and there has been much discussion on the subject prior to this PR. What can I do to help this along as I would love to be able to write unit tests for our suite of plugins.~

99linesofcode avatar Jul 28 '19 22:07 99linesofcode

@aaemnnosttv maybe you could make an example project of this instead ? let's say wp-phpunit/example-bedrock-project ?

chrillep avatar Jul 30 '20 07:07 chrillep