Giter Site home page Giter Site logo

Comments (2)

widoz avatar widoz commented on May 22, 2024 1

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.

gmazzap avatar gmazzap commented on May 22, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.