Skip to content
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

expectActionAdded not counting as an assertion when running test #32

Closed
mikeselander opened this issue Jul 2, 2015 · 2 comments
Closed

Comments

@mikeselander
Copy link

I might be a little confused here, but when I run \WP_Mock::expectActionAdded, I get an all OK from the test, but the expectActionAdded calls don't seem to count towards the assertion count. Am I doing something wrong or does that mean they're passing and they would return a PHP error if they weren't?

\WP_Mock::expectActionAdded( 'admin_bar_menu', array( $this->Site_Lockdown, 'page_lockdown_display' ), 500 );
\WP_Mock::expectActionAdded( 'admin_init', array( $this->Site_Lockdown, 'set_lockdown_option' ), 105 );
\WP_Mock::expectActionAdded( 'init', array( $this->Site_Lockdown, 'lockdown_this_thing' ), 105 );
\WP_Mock::expectActionAdded( 'init', array( $this->Site_Lockdown, 'lockdown_actions' ), 5 );
\WP_Mock::expectActionAdded( 'admin_init', array( $this->Site_Lockdown, 'lockdown_actions' ), 5 );

$this->Site_Lockdown->hooks();
@johnpbloch
Copy link
Contributor

You're not doing anything wrong; setting up expectations in WP Mock don't have an impact on assertion counts because they're not really assertions. WP_Mock comes with some custom assertions to use, though, assuming you're using \WP_Mock\Tools\TestCase as the foundation of all your test classes.

$this->assertHooksAdded() // makes sure your expect*Added expectations were honored
$this->assertActionsCalled() // makes sure your expected do_action()s were run
$this->assertConditionsMet() // makes sure all WP Mock expectations have been met

So in your snippet above, I'd just tweak it to be:

\WP_Mock::expectActionAdded( 'admin_bar_menu', array( $this->Site_Lockdown, 'page_lockdown_display' ), 500 );
\WP_Mock::expectActionAdded( 'admin_init', array( $this->Site_Lockdown, 'set_lockdown_option' ), 105 );
\WP_Mock::expectActionAdded( 'init', array( $this->Site_Lockdown, 'lockdown_this_thing' ), 105 );
\WP_Mock::expectActionAdded( 'init', array( $this->Site_Lockdown, 'lockdown_actions' ), 5 );
\WP_Mock::expectActionAdded( 'admin_init', array( $this->Site_Lockdown, 'lockdown_actions' ), 5 );

$this->Site_Lockdown->hooks();

$this->assertHooksAdded();

(And again, this all assumes you're doing MyTestClassTests extends \WP_Mock\Tools\TestCase, not MyTestClassTests extends \PHPUnit_Framework_TestCase. Which you should be.)

@mikeselander
Copy link
Author

Gotcha, that makes sense. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants