Giter VIP home page Giter VIP logo

Comments (7)

petermorlion avatar petermorlion commented on June 12, 2024 1

Extending WP_Mock's TestCase fixed it (and using WP_Mock 1.0 with PHPUnit 9.6). Thanks for the help!

from wp_mock.

ajaynes-godaddy avatar ajaynes-godaddy commented on June 12, 2024

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.

petermorlion avatar petermorlion commented on June 12, 2024

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.

unfulvio-godaddy avatar unfulvio-godaddy commented on June 12, 2024

@petermorlion

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.

ajaynes-godaddy avatar ajaynes-godaddy commented on June 12, 2024

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.

petermorlion avatar petermorlion commented on June 12, 2024

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.

unfulvio-godaddy avatar unfulvio-godaddy commented on June 12, 2024

@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)

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.