Unit testing a plugin with a theme dependency
Unit testing a plugin with a theme dependency
Unit testing a plugin with a theme dependency
Am I testing this right?
Underscores Theme Unit Testing – Catching Untitled Posts
Coverage in integration tests
In your test, you can create a post, start output buffering with ob_start(), output post content as usual, get output buffer into your variable with ob_end_clean(). Now your can process real post output string and compare it with the expected value.
If you’re on Windows, open wp-tests-config.php and change the ABSPATH with absolute path to your TEMP folder. For example: define( ‘ABSPATH’, ‘C:\Users\{User}\AppData\Local\Temp/wordpress/’ ); I changed this and phpunit worked! This code is on line 7 in %TEMP%/wordpress-tests-lib/wp-tests-config.php
You just need to define the MZMBO_UnitTestCase class as abstract: abstract class MZMBO_UnitTestCase extends WP_UnitTestCase { public function el($message){ file_put_contents(‘./log_’.date(“j.n.Y”).’.log’, $message, FILE_APPEND); } }
The best solution I’ve found is to make a symlink from the plugin directory to the actual location of the /wordpress-tests-lib/. At least in the case of VS Code, the symlink seems to help it “find” the files and incorporate them into autocomplete etc. I’m still having bugs but this is the best I could … Read more
One way could be to use classes and objects. It’s more efficient considering reusability, collective work and more. I don’t think it’s bad to use global variables if you know what you’re doing. So I would recommand you to use OOP (object oriented programming) especially with inheritance and polymorphism.
If I undertsand correctly, what you are searching for is a good library for creating stubs and mocks. If you use PHPUnit, it has a features for that. See https://phpunit.de/manual/current/en/test-doubles.html#test-doubles For example, let’s assume you have a class like this: namespace MyApp; class MyCustomUser { public function __construct(\WP_User $user) { $this->user = $user; } public … Read more