Questions tagged [unit-tests]

Automated tests for the smallest parts of code.

Filter by
Sorted by
Tagged with
0
votes
0answers
15 views

How do you do TDD with phpunit? It is painfully slow and it almost take 2 mins to initialize the db

I am currently working on wordpress plugin development, i am annoyed by the time taken by phpunit to run the tests, no matter whatever test it needs to run, the initialization time alone take around 2 ...
0
votes
0answers
28 views

Unit Testing in WordPress

I am trying to incorporate Unit Testing into my WordPress plugins and have some questions to see if I'm doing the right approach. On my local setup I have set up PHPUnit for my plugin using the WP-CLI ...
2
votes
1answer
50 views

How to verify meta box is registered in Unit Testing?

I am currently doing TDD with WordPress, in the PHPUnit I need to test if the meta box is actually registered on a method call, I could not find any function in WordPress to do that, so I was trying ...
1
vote
1answer
48 views

How do I phpunit test a post output process?

I like to know how to test the html output of a post. Like WP would output it on the frontend in reality. My specific case at this point is to test oembed caching as I want to test re-caching. AFAIK ...
0
votes
0answers
16 views

Write test for magic method __clone for plugin development

I implemented the Design Pattern Singleton in my Plugin. and I want to test the magic __clone () method to not allow cloning : /** * Cloning is forbidden due to singleton pattern. */ public function ...
0
votes
1answer
79 views

Why is one phpunit test throwing an error on one class when all other classes are similar without error?

I'm working on the Liquid Messages plugin. There are some basic PHPUnit tests existing for it and when I run phpunit all pass except for one. It errors out: There was 1 error: 1) GCS_Async_Test::...
0
votes
1answer
67 views

PHPUnit Testing and woocommerce Constant

I tried to perform a test on the WC_VERSION constant. The main class : class WC_Custom_Variable_Products_Dependencies { /** minimum WooCommerce version required by this plugin */ const ...
0
votes
1answer
34 views

Unit Testing action hook

I want to perform unit tests on a Class, my goal is: I want to check if the plugin is activated or not by using the function: is_plugin_active class WC_Custom_Variable_Products_Dependencies { ...
0
votes
0answers
23 views

How to run phpunit test for all files which wordpress plugin have

I have phpunit tests for plugin and it`s works only for main plugin file (screenshot 1). But I need test all files from plugin. For example I have file in "includes" folder (screenshot 2). And I ...
1
vote
0answers
109 views

Coverage in integration tests

EDIT: I've created the mwe as a small test plugin: https://github.com/dingo-d/test-plugin Original question: I'm writing tests for my plugin and one thing makes no sense to me and I'm not sure if I'm ...
1
vote
2answers
422 views

Unit Test in Wordpress

I work in wordpress with a lot of classes that use wordpress functions and I'd like make unit tests for them. The problem I found is that phpunit doesn't recognize wordpress functions and the tests ...
0
votes
1answer
94 views

Wordpress and Wordpress-test-lib not getting added to tmp folder

I’ve installed the wpcli and php unit testing to my imac and the wordpress and wordpress-test-lib files were added to my tmp folder as they should have. I used this to install the setup. bash bin/...
1
vote
0answers
24 views

Underscores Theme Unit Testing - Catching Untitled Posts

Wordpress 5.0.3 | Underscores Theme I'm unit testing a theme I based on underscores using the wptest.io xml. Underscores does not gracefully catch untitled posts. There is no title in either ...
0
votes
0answers
94 views

Integration test - remove the mu plugins in the test

As a recurring theme these past few questions I asked, I'm doing integration testing and want to check the activate static method that gets called in my register_activation_hook in the main plugin ...
1
vote
0answers
47 views

Am I testing this right?

Since I need to have 100% test coverage for the client, I'm writing integration and unit tests in my plugin. And I have a method in a class that is hooked to admin_menu hook, which adds submenu. ...
1
vote
1answer
134 views

Extending WP_UnitTestCase without any Tests

I want to add some logging to an extension of WP_UnitTestCase. Like this: class MZMBO_UnitTestCase extends WP_UnitTestCase { public function el($message){ file_put_contents('./log_'.date(...
4
votes
0answers
36 views

What is the best way to do unit tests for your plugin in 2018 [closed]

I´m making a wordpress plugin with PHPStorm. This plugin contains a load of files with addons as well and it´s the time to use unit tests to check up before each commit in my github project. I took a ...
0
votes
1answer
282 views

Write integration test for rest_pre_serve_request

I have a method that is hooked to the rest_api_init /** * Set allowed headers for the rest request */ public function set_allowed_rest_headers() { remove_filter( '...
0
votes
1answer
154 views

Integration tests test script enqueue/register fails

This question is related to this SO post I'm testing a plugin, and in it I have public function enqueue_scripts() { $main_style = 'public/scripts/application.js'; wp_register_script( '...
3
votes
2answers
280 views

Revert WordPress default options after a PHPUnit test has run

tl;dr: is there a way to make changes to WordPress options during a PHPUnit test suite execution, and have the changes reverted to the WordPress defaults before the next test suite is executed, ...
5
votes
1answer
479 views

How to set up a user inside unit tests

I want to test some methods in my plugin, and some of them required user to be logged in. I searched everywhere but found nothing of use. I need to test a method that takes in logged in session ...
2
votes
1answer
577 views

Why is WP_Mock not used instead of WP_UnitTestCase for writing unit tests by most plugins?

For writing unit-tests, why do most plugins use WP_UnitTestCase instead of popular libraries like WP_Mock? The reason I am asking this is because WP_UnitTestCase doesn't seem to be a unit test case ...
1
vote
0answers
73 views

Unit testing a plugin with a theme dependency

I wrote a plugin that adds functionality to load a content block (which is a page), and then passes it to a template part, which I did to avoid overloading the core WP global post. I'm trying to unit ...
1
vote
1answer
454 views

How to retain table data in wordpress phpunit tests

I was wondering is there a way that phpunit for woprdress do not delete any data which i created during test?
0
votes
2answers
379 views

PHPUnit via WP-CLI: Warning: Cannot modify header information … bootstrap.php:68

I'm trying to setup unit tests for a plugin I am developing. I just followed the steps at... https://make.wordpress.org/cli/handbook/plugin-unit-tests/ However, when I run phpunit I get the ...
5
votes
1answer
574 views

Writing a unit test for add_menu_page

I am writing a few unit tests for a plugin that I have developed. However I seem to be hung up on testing one (seemingly) simple piece of code. In the plugin I've written I have registered an admin ...
4
votes
1answer
12k views

Access post from post id in URL

I'm doing unit tests for my plugin, and in my unit test, I check some basic things such as posting a custom post type. My script can create new post, and I can retrieve the ID of the posted item (I'm ...
3
votes
2answers
420 views

Is there any way of of making an admin-ajax request without the use of die()?

Pretty much what the title says. I have a custom plugin written, that relies on the use of admin-ajax to handle various forms and actions. That's all working fine, however as the various functions ...
3
votes
0answers
441 views

Setting Up PHPUnit tests for WP development on Windows

I've been following the instructions in this article to try to set up some testing. I got as far as this instruction bash bin/install-wp-tests.sh wordpress_test root 'mypass' localhost latest before ...
0
votes
2answers
112 views

Installing WordPress Theme Unit Data

I'm following the "Building Themes from Scratch Using Underscores (2016)" tutorial on Lynda.com and at around 00:35 he suggests downloading the Theme Unit Test Data from WordPress. I've downloaded the ...
1
vote
2answers
2k views

What is the best way to create a factory for unit test objects?

I am trying to learn TDD and am struggling with creating factories for custom objects. For instance, if I have a custom user type and all users of that type must have a specific capability, it's ...
0
votes
1answer
454 views

How to do an unit test for the admin dashboard

I am trying to do unit test on codeception with wp-browser for a wordpress plugin based on a boilerplate. The problem that is in this line of code I initialize the class for admin only when is not an ...
4
votes
2answers
103 views

What areas to Unit test while building a plugin?

I am a plugin developer with absolutely no industry experience. I have created a simple plugin to add multiple contributors to a post through metabox. I searched through tons of websites and I got to ...
1
vote
1answer
931 views

Error when setting up phpunit tests with wp-cli scaffold

I am trying to figure out the setup for unit tests for wordpress plugins. I am using Ubuntu. So far I have: Local WordPress Installation WP-CLI up and running Installed phpunit used wp scaffold ...
3
votes
1answer
368 views

Using wp_mail during an integration test

I'm working on some tests for WordPress, and I discovered that WordPress' PHPUnit automatically captures and doesn't send emails (using MockPHPMailer) when I try to use wp_mail. I've looked, but I ...
0
votes
1answer
36 views

Set up PHPUnit with WordPress: The WordPress tests are 3 - 4 years old; does it matter?

I'm trying to set up PHPUnit with WordPress, and the tutorial I found tells me to download this repository so that I can bootstrap the WordPress environment to run my tests. The only issue I have is ...
7
votes
1answer
500 views

Unit tests - Dealing with dependencies

This might be seen as a corollary of Testing hooks callback. The issue: I want to test a class which creates a new instance of a My_Notice class defined outside the plugin (let's call it the "Main ...
0
votes
1answer
464 views

Unable to find PHPUnit code coverage stats

Where should I check for the code coverage stats when using PHPUnit for WordPress? My WordPress setup: I have setup WordPress using VVV and my testing suite includes PHPUnit and WP-CLI. How I ...
7
votes
1answer
771 views

Writing test cases for a WordPress Plugin that has translations

What is my aim? I'm looking forward to write test cases for the available translations of a WordPress plugin. My approach: I have setup WordPress using VVV and my testing suite includes PHPUnit and ...
3
votes
2answers
1k views

Install and load additional plugins when running unit tests

I want to write unit tests for a plugin. I have used WP-CLI to scaffold the test WordPress instance and can successfully run tests. The plugin I'm writing unit tests for is a site specific plugin ...
8
votes
1answer
707 views

Proper unit testing in WordPress

There are different threads available for Unit Testing in WordPress. As far as concern, there should be a proper unit testing for every piece of customization done in WordPress. I have checked couple ...
2
votes
2answers
20k views

Fatal error: Maximum execution time of 60 seconds exceeded in H:\wamp\www\custom\wp-includes\class-wp-http-curl.php

I imported the Theme Unit Test xml file with the wordpress importer. But all of the data is imported as pages. I am following an online tutorial to build a wordpress theme development and I believe ...
2
votes
1answer
68 views

Using factory.php outside of trunk for unit testing

I have written a plugin, and am going through the process of setting up some unit tests for it. Inside of my unit tests I am utilizing the WP_UnitTest_Factory class to help with the process of ...
6
votes
1answer
1k views

Wordpress Unit Testing - Cannot Create Tables

I'm using PHPUnit to Unit Test my WP plugin on top of the WP testing suite. Everything works fine except that when I try to create a table via the setUp method, the table doesn't get created. Here's ...
4
votes
3answers
422 views

Unit testing to simulate the loop

How do you construct unit tests with PHPUnit and the WordPress test framework that simulate being in the loop? For instance, if I want to test a function that is only able to be called in the loop ...
1
vote
0answers
86 views

Is there a way to mock update_option for unit testing?

I'm currently building some unit tests, and have just started playing around with WP_Mock. I'd like to test a function that fetches the site description; I want to test if it responds as expected when ...
1
vote
2answers
950 views

PHPUnit test plugin activation

I'm trying to test if my plugin activates properly with PHPUnit. I have used boilerplate structure generated on this site and added this test: class PluginTest extends WP_UnitTestCase { function ...
7
votes
1answer
1k views

When unit testing a plugin, does the plugin need to be in the wp-content/plugins directory of the WordPress tests install?

I'm currently setting up unit testing for my plugin. In my tests/phpunit/bootstrap.php file I have: require_once $wp_tests_dir . '/includes/functions.php'; tests_add_filter( 'muplugins_loaded', ...
3
votes
2answers
489 views

Using Travis CI to run unit tests and running phpunit locally [closed]

Is there a difference between Travis CI running my PHPUnit tests and me using the WP-CLI to generate unit test files and running phpunit locally? I'm wondering if the duplicate effort is necessary or ...
7
votes
1answer
2k views

Unit testing in the WordPress backend (is_admin() is true)

I've asked this on IRC, Twitter, Slack — am utterly astonished by how difficult it is to locate the answer to this: I have a bunch of plugin code that only runs when is_admin() returns true, i.e., ...