I used WP_Mock
for a long time, until I built Brain Monkey to overcome some problems I found working with it.
Using Brain Monkey you can:
use Brain\Monkey\Functions;
Functions::when('get_adjacent_post')->alias(function() {
// mock here...
});
or
Functions::expect('get_adjacent_post')
->atLeast()
->once()
->with( true, '', true, 'topic' )
->andReturnUsing(function( $in_same_term, $excluded_terms, $previous ) {
// mock here
});
This latter syntax comes from Mockery.
Brain Monkey, just like WP_Mock, has an API to also mock WordPress hooks.
Related Posts:
- Where can I find documentation for the WP_UnitTestCase factory classes?
- How to set up a user inside unit tests
- WordPress test environment on windows
- Can I simulate a user being logged in from a WP_UnitTestCase?
- Writing a unit test for add_menu_page
- Can’t get the phpunit core test for WordPress to work [closed]
- struggling to set up WP tests
- How can I properly set up dependencies in automated testing?
- Using factory.php outside of trunk for unit testing
- unit testing admin password
- What is the best way to create a factory for unit test objects?
- PHPUnit Plugin Integration Tests: Getting wordpress-tests-lib PHP into IDE (VS Code)
- Extending WP_UnitTestCase without any Tests
- What make possible unit test plugins?
- Error Testing create_empty_blog() via PHPUnit + Unit Tests
- Write integration test for rest_pre_serve_request
- How to do an unit test for the admin dashboard
- How can I link tests to GitHub issues?
- How do I unit test a plugin with forms?
- Testing hooks callback
- Unit testing in the WordPress backend (is_admin() is true)
- How do I mock HTTP requests for PHPUnit?
- Access post from post id in URL
- Proper unit testing in WordPress
- WordPress Themes and PHP unit
- Unit tests – Dealing with dependencies
- When unit testing a plugin, does the plugin need to be in the wp-content/plugins directory of the WordPress tests install?
- Writing test cases for a WordPress Plugin that has translations
- WordPress Unit Testing – Cannot Create Tables
- Plugin Unit Test for Table and Option Creation
- How to write testable classes in WordPress
- PHPUnit testing WordPress Plugin
- How to create a test that calls is_front_page in phpunit?
- Using wp_mail during an integration test
- Implement phpunit testing on a plugin
- What areas to Unit test while building a plugin?
- Why Can’t PHPUnit UnitTest My WordPress Website
- Unit testing to simulate the loop
- how to test a theme upgrade
- WP_UnitTestCase missing?
- What is the best way to do unit tests for your plugin in 2018 [closed]
- Is there any way of of making an admin-ajax request without the use of die()?
- Using Travis CI to run unit tests and running phpunit locally [closed]
- Revert WordPress default options after a PHPUnit test has run
- Plugin development with unit tests
- Unit testing wordpress plugins with plugin options
- How to properly test a method that is called by an action hook
- Install and load additional plugins when running unit tests
- Unit Testing a Plugin functionality with cron
- PHPUnit test plugin activation
- Installing WordPress Theme Unit Data
- How to add an image for unit testing?
- Fatal error: Maximum execution time of 60 seconds exceeded in H:\wamp\www\custom\wp-includes\class-wp-http-curl.php
- Why is WP_Mock not used instead of WP_UnitTestCase for writing unit tests by most plugins?
- DataBase connection problem with PHPUnit and WordPress
- WordPress function gives different results outside vs inside PHPUnit test
- how to set context in WordPress for unit testing
- Setting Up PHPUnit tests for WP development on Windows
- Testing custom API endpoint with class dependency
- How to verify meta box is registered in Unit Testing?
- Theme unit test data Foreign fonts come in garbled on my machine
- How exactly *does* unit testing work for themes?
- How to initialize something in unit test before the init hook being called?
- Unit Test in WordPress
- How to cancel WordPress’ action/filter when using OOP with anonymous callback
- Error when setting up phpunit tests with wp-cli scaffold
- How do I phpunit test a post output process?
- Coverage in integration tests
- Underscores Theme Unit Testing – Catching Untitled Posts
- Am I testing this right?
- Unit testing a plugin with a theme dependency
- How to retain table data in wordpress phpunit tests
- Is there a way to mock update_option for unit testing?
- WordPress Automatic Testing Probelm
- Using My Own Classes On Wp Unit Tests
- Why is one phpunit test throwing an error on one class when all other classes are similar without error?
- How to import Theme Unit Test on localhost
- Integration tests test script enqueue/register fails
- PHPUnit via WP-CLI: Warning: Cannot modify header information … bootstrap.php:68
- Set up PHPUnit with WordPress: The WordPress tests are 3 – 4 years old; does it matter?
- no_rest_route in Unit Testing for REST endpoint for CPT registered via show_in_rest
- Mocking WP_CLI static methods in unit tests
- How can I enable IDE integration (autocomplete) for WordPress test suite
- PHPUnit Testing and woocommerce Constant
- Unit Testing action hook
- WordPress and WordPress-test-lib not getting added to tmp folder
- Integration test – remove the mu plugins in the test
- Unable to find PHPUnit code coverage stats
- Unregister Settings Error
- Unit Test ignores stubbed method second time around in a dataProvider
- PHPUnit Ajax Serialization of ‘Closure’ is not allowed
- PHPUnit Testing Installation Issue
- Testing Plugin – Install plugin dependencies in testing enviroment