Comments (2)
Hi @emeraldjava you can patch the add_shortcode
with the function when
or in case you need expectation with expect
.
The differences are:
With when
you patch the function because you need a returned value or simply you need the function exists when called, for more info see https://brain-wp.github.io/BrainMonkey/docs/functions-when.html
With expect
you can ensure your logic is respected and also you can use the expectations to actually tests as part of the assertions.
For example, if you want to be sure a certain function is called and how many times and with which arguments to ensure the correctness of your logic.
For more info about https://brain-wp.github.io/BrainMonkey/docs/functions-expect.html
In your case (even if I think better to introduce the shortcode into a different method raither than the constructor) you can use when
.
For example:
use \Brain\Monkey\Functions;
class MyTest extends TestCase {
public function testSomething() {
Functions\when('add_shortcode')
->justReturn(true);
// ... The rest of the logic
}
}
I used to call justReturn
to return a simple value even though in this case you don't need to check against anything.
But if you want to ensure the add_shortcode
is called, you can for example:
use \Brain\Monkey\Functions;
class MyTest extends TestCase {
public function testSomething() {
Functions\expect('add_shortcode')
->twice()
->with(\Mockery::type('string'), \Mockery::type('array'));
// ... The rest of the logic
}
}
from brainmonkey.
This is a pretty specific question, so I doubt it could be useful for others. I'm closing it to keep issue list cleaner.
from brainmonkey.
Related Issues (20)
- Release 2.6.1 ? HOT 15
- The file that defines <Namespace::method> was included earlier than Patchwork. This is likely a result of an improper setup; see readme for details. HOT 2
- Add more utilities to stub WordPress functions HOT 3
- Old site? HOT 4
- A never-returning function must not return in ... HOT 10
- Best approach to mock functions after require_once. HOT 2
- Support for PHPUnit 10 HOT 3
- Calling functions that use named arguments is not supported HOT 1
- How to set expectations for inside anonymous functions HOT 2
- Provide test case classes for PHPUnit HOT 6
- Packagist is serving version 2.5.0 ? HOT 1
- has_filter/has_action return true instead of the hook priority HOT 7
- WP: adding mocks for some miscellaneous functions HOT 1
- Why expect function works unexpectedly? HOT 4
- Mocks for deep arguments in the function doesn't work HOT 5
- Testing w/o class or class instantiation within plugin HOT 2
- Adding Monkey\setUp() and tearDown() fails otherwise passing tests HOT 3
- has_filter doen't work with type hints with namespaces HOT 10
- Correct use of patchwork.json to redefine internal functions? HOT 4
- Docs site not up-to-date HOT 4
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 brainmonkey.