-
Notifications
You must be signed in to change notification settings - Fork 30
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
Issue with mocking my functions (Wordpress) #72
Comments
Hi, @FredoNook Brain Monkey is a tool designed to mock functions when those are not available. Because you're using More specifically, the function My guess is that when your |
Hi @gmazzap <?php
/**
* PHPUnit bootstrap file
*
* @package Dirtcraftru
*/
// Require Brain\Monkey
require_once __DIR__ . '/libs/vendor/autoload.php';
$_tests_dir = getenv( 'WP_TESTS_DIR' );
if ( ! $_tests_dir ) {
$_tests_dir = rtrim( sys_get_temp_dir(), '/\\' ) . '/wordpress-tests-lib';
}
if ( ! file_exists( $_tests_dir . '/includes/functions.php' ) ) {
echo "Could not find $_tests_dir/includes/functions.php, have you run bin/install-wp-tests.sh ?" . PHP_EOL;
exit( 1 );
}
// Give access to tests_add_filter() function.
require_once $_tests_dir . '/includes/functions.php';
/**
* Registers theme
*/
function _register_theme() {
$theme_dir = dirname( __DIR__ );
$current_theme = basename( $theme_dir );
$theme_root = dirname( $theme_dir );
add_filter( 'theme_root', function() use ( $theme_root ) {
return $theme_root;
} );
register_theme_directory( $theme_root );
add_filter( 'pre_option_template', function() use ( $current_theme ) {
return $current_theme;
});
add_filter( 'pre_option_stylesheet', function() use ( $current_theme ) {
return $current_theme;
});
}
tests_add_filter( 'muplugins_loaded', '_register_theme' );
// Start up the WP testing environment.
require $_tests_dir . '/includes/bootstrap.php'; About function, yest them are custom functions and written in theme files. |
Closing this issue because there's nothing to do here. Once again, Brain Monkey is a tool to test WordPress code without loading WordPress. If one wants to run integration/e2e tests loading WordPress (which si something that makes ton of sense), then Brain Monkey should not be loaded for those tests. |
I just have to say thank you for this library and for being clear about what it does. I was trying to mock a core wp function using BrainMonkey while including the WordPress library (using the official WordPress PHPUnit testing environment) and now I get what this library is about. Unfortunately, I can't use it since my tests already depend on WordPress but I'll sure consider it in the future for testing WordPress in complete isolation. |
Hello comrades! I have one issue with mocking my functions writen in wordpress theme. For generate base test files i utilize the
wp scraffold
after i add download BrainMonkey by Composer and add to mybootstrap.php
import Composer's autoload:So then i include namespaces in my tests file:
Then i add
setUp()
andtearDown()
methods:Then i add Mockery trait adapter to test class:
use \Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;
Write test for my function mocking another my function:
And after i run PHPUnit tests i have that issue:
Help me please, how fix it. Im little confused because i import
autoload.php
with BrainMonkey by firtst instruction inbootstrap.php
. Thanks a lot.The text was updated successfully, but these errors were encountered: