Comments (7)
Extending WP_Mock's TestCase fixed it (and using WP_Mock 1.0 with PHPUnit 9.6). Thanks for the help!
from wp_mock.
Hi @petermorlion:
I can confirm the second test fails when extending PHPUnit\Framework\TestCase
as you have, though it passes if extending WP_Mock's version of TestCase
, which likely points to a bootstrapping issue.
Would you mind sharing the contents of your bootstrap.php
file?
from wp_mock.
Aha, interesting. Although the docs also extend from PHPUnit's TestCase, I believe?
This is my bootstrap.php
:
<?php
// First we need to load the composer autoloader, so we can use WP Mock
require_once dirname(__DIR__) . '/vendor/autoload.php';
// Bootstrap WP_Mock to initialize built-in features
WP_Mock::activateStrictMode();
WP_Mock::bootstrap();
// Define base path
define('WFM_BASE_PATH', dirname(__DIR__) . '/src/');
(the last part is just setting a constant my code sometimes needs)
from wp_mock.
try to add this line before activateStrictMode
:
WP_Mock::setUsePatchwork(true);
edit: sorry probably not needed in your case if you are just using the userFunction
method, sounds like @ajaynes-godaddy suggestion is more on point, and perhaps there's a misconfiguration with WP_Mock and/or PHPUnit that may be causing the issue you're seeing
from wp_mock.
Aha, interesting. Although the docs also extend from PHPUnit's TestCase, I believe?
You're correct. We're actually trying to figure out if there's a undocumented dependency in play here, so knowing how you're bootstrapping gives more insight.
Sorry if it seemed like was implying it was something wrong with your setup, mostly trying to figure out where there's a potential mismatch when using PHPUnit\Framework\TestCase
vs WP_Mock\Tools\TestCase
😉
from wp_mock.
If you want, I created a reproducable sample project. In my project, I use wp_mock 0.4.2 and the sample uses 1.0 but the issue remains either way.
I tried @unfulvio-godaddy 's tip of using Patchwork, but that didn't solve it.
Indeed, if I extend WP_Mock\Tools\TestCase
, the tests pass.
from wp_mock.
@petermorlion the reason the tests are failing is that your are extending PHPUnit's TestCase
class -- please extend \WP_Mock\Tools\TestCase
instead OR ensure you are calling WP_Mock::teardown()
between tests, by adding this method:
public function tearDown() : void
{
parent::tearDown();
WP_Mock::tearDown();
}
Once I apply either change in your test project, the tests are passing and not producing an error anymore.
We need to make this more clear in the docs for people who don't wish to extend WP_Mock provided TestCase class.
from wp_mock.
Related Issues (20)
- WP_Mock TestCase is referencing method removed from PhpUnit
- Move TestCase::mockStaticMethod into trait HOT 1
- WP_Mock should define its own exception objects
- Introduce a builder for WP functions and WP constants mocks
- Remove WP_Mock/Loader
- Change license from GPL 2.0 to BSD-3-Clause HOT 13
- Move documentation over GitBook
- PHP 8.2 Dynamic Property Deprecation HOT 1
- How to Mock wp_send_json_error() HOT 5
- Update GitHub workflow with the setup-php action to run tests in PHP 7.3
- Documentation bug: wp:mock instead of wp_mock HOT 1
- Unexpected use of apply_filters for filter HOT 12
- Update CHANGELOG.md
- Compatibility with PHPUnit 10 HOT 8
- `expectHookNotAdded` should accept priority and arguments parameters with defaults as `expectHookAdded`
- Pass in Closure for Hooks HOT 3
- Compatability with PHP 8.3
- v1.0.1 is not available on Packagist HOT 5
- Latest release has not been published to packagist. HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wp_mock.