Skip to:
Content

BuddyPress.org

Opened 10 years ago

Closed 10 years ago

#5727 closed defect (bug) (fixed)

Unit Tests: unset globals when using friends_add_friend() in setUp()

Reported by: djpaul's profile DJPaul Owned by: djpaul's profile djpaul
Milestone: 2.1 Priority: normal
Severity: normal Version:
Component: Build/Test Tools Keywords:
Cc:

Description

If you run this unit test https://gist.github.com/paulgibbs/98890701a68202794570, it will produce the following warnings:

vagrant@vvv:~/wp-content/plugins/buddypress$ phpunit --filter PaulsDopeTest
Installing...
Running as single site... To run multisite, use -c tests/phpunit/multisite.xml
Installing BuddyPress...
Not running ajax tests... To execute these, use --group ajax.
PHPUnit 4.0.14 by Sebastian Bergmann.

Configuration read from /srv/www/wordpress-develop/src/wp-content/plugins/buddypress/phpunit.xml.dist

E

Time: 8.16 seconds, Memory: 28.75Mb

There was 1 error:

1) BP_Tests_PaulIsCool::test_PaulsDopeTest
Undefined property: stdClass::$show_avatars

/srv/www/wordpress-develop/src/wp-content/plugins/buddypress/src/bp-core/bp-core-avatars.php:179
/srv/www/wordpress-develop/src/wp-content/plugins/buddypress/src/bp-core/bp-core-classes.php:813
/srv/www/wordpress-develop/src/wp-content/plugins/buddypress/src/bp-core/bp-core-classes.php:766
/srv/www/wordpress-develop/src/wp-content/plugins/buddypress/src/bp-friends/bp-friends-classes.php:129
/srv/www/wordpress-develop/src/wp-content/plugins/buddypress/src/bp-friends/bp-friends-classes.php:107
/srv/www/wordpress-develop/src/wp-content/plugins/buddypress/src/bp-friends/bp-friends-cache.php:23
/srv/www/wordpress-develop/src/wp-includes/plugin.php:470
/srv/www/wordpress-develop/src/wp-content/plugins/buddypress/src/bp-friends/bp-friends-functions.php:71
/srv/www/wordpress-develop/src/wp-content/plugins/buddypress/tests/phpunit/testcases/activity/paul.php:23
                                   
FAILURES!                          
Tests: 1, Assertions: 0, Errors: 1.
vagrant@vvv:~/wp-content/plugins/buddypress$ 

$bp->avatar->show_avatars isn't set. I am not sure if we are calling this chain of functions too early, or if our BP_UnitTestCase's clean_up_global_scope() approach to resetting globals between tests is too crappy (it kind of is, and most of that's my fault).

Change History (1)

#1 @djpaul
10 years ago

  • Owner set to djpaul
  • Resolution set to fixed
  • Status changed from new to closed

In 8555:

Tests: stop manually resetting $bp->avatar between tests.

This causes tests to fail if those tests call friends_add_friend() inside setUp()
as the $bp->avatar->show_avatars property is unset. Instead, rather than manually
resetting the variable, we'll let bp_core_set_avatar_globals(), via bp_setup_globals
in assertPreConditions(), reset it correctly.

Fixes #5727

Note: See TracTickets for help on using tickets.