-
Notifications
You must be signed in to change notification settings - Fork 57
Nested PHPUnit Support for Vagrant #165
Conversation
check-diff.sh
Outdated
| if [ -n "$PHPUNIT_CONFIG" ]; then | ||
| vagrant ssh -c "cd $ABSOLUTE_VAGRANT_PATH && phpunit -c $( echo "$PHPUNIT_CONFIG"; )" | ||
| else | ||
| vagrant ssh -c "cd $ABSOLUTE_VAGRANT_PATH && find . -iname phpunit.xml.dist -execdir phpunit \;" |
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.
This will need to use phpunit.xml if it exists, and otherwise fall-back to phpunit.xml.dist, in each directory.
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.
Basically I think the the command passed into vagrant ssh should be some form of:
if [ -n "$PHPUNIT_CONFIG" ] || [ -e phpunit.xml* ]; then
phpunit $( if [ -n "$PHPUNIT_CONFIG" ]; then echo -c "$PHPUNIT_CONFIG"; fi )
fi
for nested_project in $( find $PATH_INCLUDES -name 'phpunit.xml*' -mindepth 2 ! -path '*/vendor/*' -name 'phpunit.xml*' -exec dirname {} \; ); do
(
cd "$nested_project"
phpunit
)
doneIt would be ideal of this logic wasn't duplicated in multiple places, but a refactor would be complicated.
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.
Here's one possibility for a refactor:
vagrant ssh -c "
cd $ABSOLUTE_VAGRANT_PATH;
export DIFF_BASE=$DIFF_BASE;
export DIFF_HEAD=$DIFF_HEAD;
export DEV_LIB_ONLY=phpunit
.git/hooks/pre-commit
"Note the DEV_LIB_ONLY is not currently recognized, but it could be a way to do the inverse of DEV_LIB_SKIP,
Just an idea.
A first attempt at getting PHPUnit to run inside Vagrant on projects which have nested phpunit directories * Need to potentially make the phpunit.xml.dist file dynamic * Should we do the same execution on vassh? Maybe a refactor to make the Vagrant section cleaner and combine both vagrant ssh and vassh * Is there a better implementation than find?
37534c8 to
437bcbe
Compare
* Added a new function to check if a certain check should execute * Added DEV_LIB_ONLY which now allows you to run only specific tests * Updated the code that runs nested tests to remove mindepth as the phpunit config file is in the root
* Updated the documentation for the new DEV_LIB_ONLY environment variable
|
@westonruter that was an excellent suggestion. It works very well and less duplicated code. Would you mind taking a look over my latest implementation? I also rebased the branch against master from upstream |
|
Hey @westonruter, wondering if you've had a chance to look at this yet? Thanks. |
| done | ||
| } | ||
|
|
||
| function check_should_execute { |
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.
Ooooh. I like this.
Inception nested-phpunit-support
* Check if QUnit should be executed before running
* If a config is set, use it * Otherwise, loop through the directories looking for a config file to use
# Conflicts: # check-diff.sh
* Configuring the grunt tasks to be able to be skipped using the check_should_execute method
| echo "## phpunit" | ||
| if [ -n "$( type -t phpunit )" ] && [ -n "$WP_TESTS_DIR" ]; then | ||
| if [ -n "$PHPUNIT_CONFIG" ] || [ -e phpunit.xml* ]; then | ||
| if [ -n "$PHPUNIT_CONFIG" ]; then |
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.
@westonruter @valendesigns I've pushed another fix to stop tests running twice.
I could have misunderstood something in the broader context of WP-Dev-Lib, but what I'm doing is if a PHPUNIT_CONFIG is set, run only that config file, otherwise loop through the project and find the phpunit.xml files and run them one by one.
Thoughts?
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.
@MattGeri I think that should work actually. The two scenarios I am think of for running PHPUnit tests are:
- You have repo for a theme or plugin project which has a
phpunit.xmlorphpunit.xml.distin its root. There wouldn't be nested unit test suites in this case. - You have a repo containing an entire site project, with
wp-contentand all, and in this case there would be no rootphpunit.xmlconfig, but there would be nested unit test suites.
@valendesigns am I missing another scenario?
|
@westonruter @valendesigns Any updates on this? Both SC and BB are experiencing a problem where PHPUnit breaks inside VVV and it seems like this PR also fixes that issue. Happy to make any additional changes if needed, just let me know. |
|
Closed in favor of local PR: #187 |
@westonruter and @valendesigns I've taken a first stab at running nested tests in Vagrant. Here are the commit notes.
A first attempt at getting PHPUnit to run inside Vagrant on projects which have nested phpunit directories