Take a look at the WordPress core setup with PHPUnit: https://make.wordpress.org/core/handbook/testing/automated-testing/phpunit/
Using this process rather than rolling your own allows you to leverage the boostrapping (and other customization) specific for WordPress.
From the Codex:
When
phpunit
is invoked, the test suite runs a script that sets up a
default installation of WordPress, with a configuration similar to
what you get with the GUI install. Before any tests are run, the
following steps take place:
- WordPress is bootstrapped (by including
wp-settings.php
). This means that all tests run after the entire WP bootstrap (throughwp_loaded
).- All default content is deleted. This includes sample posts and pages, but does not include the default user or the ‘Uncategorized’ category.
Hope that helps!
Related Posts:
- WordPress Themes and PHP unit
- How to create a test that calls is_front_page in phpunit?
- Why Can’t PHPUnit UnitTest My WordPress Website
- Setting Up PHPUnit tests for WP development on Windows
- WordPress and WordPress-test-lib not getting added to tmp folder
- Query both first_name and last_name from wp_usermeta at the same time
- Hide old attachments from wp media library
- Image Upload “exceeds the maximum upload size for this site”, but php.ini is correct
- simple wordpress ajax plugin not working when not logged in
- Audio Player not loading when the content is loaded through Ajax, MediaElement.js no applied
- Customizer Show/Hide Logo and Site Title
- Notice: Constant already defined in wp-config.php on (non-existent) line?
- body_class filter – Is there a better way to write this code?
- A Specific Blog post to be assigned as the landing page of my wordpress blog
- How to create post thumbnail
- Sort registered users by post count? (inside admin dashboard)
- Query String being Removed Creating a Pagination Issue within a Custom Plugin
- The custom logo, site title, and description doesn’t appear at the same time
- How to change a public function inside a class of a plugin?
- Removing unneccessary p-tags (Not every p)
- Create a hierarchical taxonomy list in WordPress
- Randomly Assign an Image’s Alt Text Based on Data From Post
- How can I Add a variable PHP in the Menu Nav
- Pull the content out of a page
- Adding an Avatar to the Top Nav Bar
- How to add seperate classes to no-search-result and found-search-result pages on wordrpess search – is_search()
- Edit incorrect password message WordPress
- A non-numeric value encountered in /wp-includes/functions.php on line 68
- XAMPP-VM Mac OS Mojave wordpress debugging using XDebug
- How to get original custom taxonomy slug after the slug has been rewritten?
- Ajax load more button for comments wordpress
- WordPress & Fastcgi proper setup?
- Update user profile information from functions.php
- Checkbox doesn’t stay checked, conten
- How do I Import / Upload Files with jQuery AJAX?
- Theme requires allow_url_include = on in php.ini
- Variable not staying set
- How to set the WordPress logo programmatically with PHP
- Add login hyperlink to secondary navigation menu
- Warning: Illegal string offset on theme options page [closed]
- List all blogs, but exclude the main site
- How to specify the path for require_once in a child theme?
- How to pass a variable to get_template_part that’s updated every time the template part is called?
- $_SESSION variable not saving on page refresh or new page
- Form search query – displaying ACF “Post Object” field as results
- Add additional functions file instead of functions.php
- How do I create a secondary version of the_content
- Extract links from content
- get_page_template_slug returns incorrect path
- Sorting dynamic select/dropdown for Contact Form 7 of Modern Tribe Events posts
- Change page password every day (predictable password ;) )
- How do i add slugs to a URL, but still redirecting to the same page
- Noindex subscriber author page
- Action Hook Inside WordPress Plugin Shortcode
- Changes made on php.ini have no effect on wordpress
- implementing a jQuery “click to expand” link in WordPress [closed]
- Fatal error: Cannot redeclare comment_theme()
- Add a select-option to the default widgets
- WP-Bakery – Add custom colors to buttons with template colors
- WordPress low speed after migrating to new host
- How to show 1 random post result without using an array?
- Show all people who commented on all posts by an author
- Commenting requires wordpress login, wordpress discussion and post comments tick boxes are checked
- My top header looks different on single pages but is fine on the home page
- Using php code inside style tag
- How to pass values from one function to the other using an array variable
- Custom global variable not working in function
- dynamic php menu with hidden sub-categories only showing when the category name is clicked
- How to change the content width using php?
- get_the_author_meta( ‘ID’ ) just return 1
- Add widget area from visual editor
- Register/enqueue scripts only on certain admin pages
- Site title not showing. Please help me
- Email always ends up in spam
- How to link featured images in single.php for only non-logged-in users?
- Grouping posts by date
- WordPress Redirect / Add_Rewrite_Rule – Non Index.php Page
- Target a specific container to style on WordPress storefront theme
- Search the post using get_search_form()
- Need to Echo A Url path to show on a wordpress page
- Adding custom PHP to existing loop in Genesis
- index.php navigation
- How can I move the posted-on date above the post and below the entry-header?
- wp_nav_menu doesn’t work in a duplicate server
- ‘posts_per_page’ in costum page type
- WordPress upload images not displaying
- how to exclude admin page from add_rewrite_rule in wordpress
- How to use ‘depth’?
- Pagination on Custom Loop
- MySQL Engine vs. Charset
- Passing multiple variables through url (php)
- Query Concatenation
- Link a lightbox thumbnail to a post instead of opening the lightbox
- Too few arguments at registering new templates in my plugin
- inner-wrap div pushing custom table far down on page
- Remove Woocommerce product from cart with ajax/fetch
- Automatically change insurance quantity based on cart total [closed]
- I want to lists posts in wordpress to nearest location entered by the user
- How to edit a widget code?
- Hide ‘Downloadable’ and ‘Virtual’ checkbox options from Woocommerce Variations?