-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add WP PHPUnit #366
Add WP PHPUnit #366
Changes from all commits
66c1be6
0601a4a
907c45f
8f187a4
77a7fb3
1e3eff7
638a721
26fca37
a1d8f35
ebddae3
a935ed2
e7e163d
b139318
0d76595
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,3 +18,6 @@ web/.htaccess | |
# Composer | ||
vendor/* | ||
!vendor/.gitkeep | ||
|
||
# PHPUnit | ||
phpunit.xml |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,10 @@ | |
"forum": "https://discourse.roots.io/category/bedrock" | ||
}, | ||
"config": { | ||
"preferred-install": "dist" | ||
"preferred-install": "dist", | ||
"platform": { | ||
"php": "5.6.32" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should be php 7 or omitted. Omit this if possible. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed. This has to do with PHPUnit more than anything. The reason this is here is so that all dependencies installed will be compatible with PHP 5.6 when it runs on Travis. This is because, even though PHPUnit 5.x is required, because my local version of PHP is 7.2, some of PHPUnit's dependencies will be installed with versions which are not compatible with 5.6. The alternatives to doing this are:
This is a very useful configuration would be something that could be added to the docs, as most users probably aren't using Bedrock in a multi-version environment. Users can (and probably should be) set this to their own value based on their target environment. With PHP 5.6 and 7.0 reaching end of life at the end of the year perhaps this won't be necessary anymore. |
||
} | ||
}, | ||
"repositories": [ | ||
{ | ||
|
@@ -41,7 +44,9 @@ | |
"roots/wp-password-bcrypt": "1.0.0" | ||
}, | ||
"require-dev": { | ||
"squizlabs/php_codesniffer": "^3.0.2" | ||
"phpunit/phpunit": "^5.0", | ||
"squizlabs/php_codesniffer": "^3.0.2", | ||
"wp-phpunit/wp-phpunit": "4.9.7" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Honestly don't really want to be married to wp-phpunit. We should leave this open ended and just give people raw phpunit and let people choose whatever approach they want. eg https://github.com/10up/wp_mock type approach or full on unit + e2e tests and such. @johnpbloch what do you think? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's a fair statement, and I'm probably biased as the package creator, but wp-phpunit is more practical for the average user as it will be what most people are familiar with IMO. I don't think it would be a problem for anyone who is familiar with other testing frameworks to replace and use whatever they want. I think reducing the setup to bare PHPUnit would be less valuable for more people, and wouldn't really make a difference to those who are want to use something else. It's just a boilerplate. No one is married to anything. Of course bare PHPUnit is better than nothing, I think we agree on that. |
||
}, | ||
"extra": { | ||
"installer-paths": { | ||
|
@@ -55,8 +60,12 @@ | |
"post-root-package-install": [ | ||
"php -r \"copy('.env.example', '.env');\"" | ||
], | ||
"test": [ | ||
"phpcs" | ||
] | ||
"test": "phpunit", | ||
"lint": "phpcs" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is a good change |
||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"Tests\\": "tests/src" | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thinking maybe travis db testing integration should be a blog post or something separate. There are many ways to skin this cat (docker, external dbs, etc) so best to leave up to the user's discretion. We shouldn't even need a db for unit tests, that is for e2e tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The database is required by WordPress' test library. I agree that it isn't setup for pure unit testing, but I also think that this kind of higher level testing is more valuable at the application level than pure isolated unit tests.