Skip to content
This repository was archived by the owner on Nov 10, 2022. It is now read-only.

Conversation

@MattGeri
Copy link
Contributor

@MattGeri MattGeri commented Apr 6, 2016

@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

  • 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?

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 \;"
Copy link
Contributor

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.

Copy link
Contributor

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
    )
done

It would be ideal of this logic wasn't duplicated in multiple places, but a refactor would be complicated.

Copy link
Contributor

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?
@MattGeri MattGeri force-pushed the bugfix/nested-phpunit-support branch from 37534c8 to 437bcbe Compare April 12, 2016 08:44
* 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
@MattGeri
Copy link
Contributor Author

@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

@MattGeri
Copy link
Contributor Author

Hey @westonruter, wondering if you've had a chance to look at this yet? Thanks.

done
}

function check_should_execute {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooooh. I like this.

MattGeri added 5 commits May 2, 2016 14:16
* 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
* 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
Copy link
Contributor Author

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?

Copy link
Contributor

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:

  1. You have repo for a theme or plugin project which has a phpunit.xml or phpunit.xml.dist in its root. There wouldn't be nested unit test suites in this case.
  2. You have a repo containing an entire site project, with wp-content and all, and in this case there would be no root phpunit.xml config, but there would be nested unit test suites.

@valendesigns am I missing another scenario?

@MattGeri
Copy link
Contributor Author

MattGeri commented Jun 6, 2016

@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.

@westonruter
Copy link
Contributor

Closed in favor of local PR: #187

@westonruter westonruter closed this Jun 7, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants