• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

virusword.com

Learn Wordpress

  • Home
  • WordPress Shop
    • Fotopress
    • SEO Tool Kit
    • Social Contact
    • Tag Machine 2
    • Video Profits
  • Latest News
  • WordPress
    • Plugins
    • Themes
    • Tutorials
    • Videos
    • Woocommerce
  • About Us
  • Contact Us
    • Terms of Service
    • Privacy Policy
  • Show Search
Hide Search
Home/Videos/Unit Testing Classes That Add Hooks In WordPress Plugins

Unit Testing Classes That Add Hooks In WordPress Plugins



Unit testing PHP classes that add WordPress hooks can be difficult to test with phpunit. In this video, I show you how I do it. I structure my code so that each part of the process is in its own method and then I use Brain Monkey to mock the WordPress plugins API.

In this video, I write tests for a class that adds an action, and then in the callback for that action, conditionally adds a filter.

๐ŸŒฒ Video about using Mockery: https://www.youtube.com/watch?v=gKLuybs8rNU&list=PLMYaDTqH6yCLb8_AdlDR8Ci_3UZBwBiXQ&index=5
๐ŸŒฒ pre_get_posts documentation: https://developer.wordpress.org/reference/hooks/pre_get_posts/
๐ŸŒฒ Setting up tests with Brain Monkey: https://brain-wp.github.io/BrainMonkey/docs/wordpress-setup.html
๐ŸŒฒ Testing WordPress hooks with Brain Monkey: https://brain-wp.github.io/BrainMonkey/docs/wordpress-hooks-added.html
๐ŸŒฒ Unit testing classes that call functions from WordPress core: https://dev.to/shelob9/unit-testing-classes-that-call-functions-form-wordpress-core-3h5p

source

Written by:
Abdul Wahid
Published on:
April 14, 2024

Categories: VideosTags: wordpress plugins

Primary Sidebar

Wordpress

  • Content Management Systems (2)
  • Digital Marketing (4)
  • Internet Marketing (6)
  • Latest News (458)
  • Online Business (2)
  • Plugins (519)
  • Themes (521)
  • Videos (1,350)
  • Website Development (1)
  • Woocommerce (589)
  • WordPress (6)

Recent Articles

Unlock Your Internet Marketing Success with WordPress: The Ultimate CMS for Achieving Online Goals

WordPress: A Powerhouse for Achieving Internet …

Continue Reading about Unlock Your Internet Marketing Success with WordPress: The Ultimate CMS for Achieving Online Goals

Unlock Your Internet Marketing Potential with WordPress: A Comprehensive Guide

How to Use WordPress to Achieve Your Internet …

Continue Reading about Unlock Your Internet Marketing Potential with WordPress: A Comprehensive Guide

Search our site

Explore more

Get our Wordpress Guide Get Plugins Get Connected

Footer

VirusWord by Promaps, Inc.

Barnes Place
Colombo 7, Western 00700

Copyright © 2025 ยท Promaps, Inc.

Keep In Touch

  • Email
  • Facebook
  • Instagram
  • Pinterest
  • Twitter