Giter Club home page Giter Club logo

Comments (3)

BrianHenryIE avatar BrianHenryIE commented on September 27, 2024 2

In the WPLoader module configuration set the backupGlobals, backupStaticAttributes to false; default value is true

This worked great, thanks.

from wp-browser.

lucatume avatar lucatume commented on September 27, 2024

Hi @BrianHenryIE,

the issue arises from the fact that, in v4, I've modified the WPTestCase::$backupGlobals to true; it was false in v3.

In your test cases, an immediate fix for the issue would be to explicitly override the WPTestCase::$backupGlobals property and set it to false.

I've set up a curated list of known offenders in the WPTestCase code, but cannot possibly cover it all.

Why change the $backupGlobals and $backupStaticAttributes properties of the WPTestCase from false (v3) to true (v4)? While the WPTestCase cleanup of global variables covers some, it will mainly cover the ones set and used by WordPress; globals and static properties frequently used to cache values will not be reset, leading to all kinds of difficult-to-track bugs and false results where tests are behaving differently depending on the run order.

Thinking about how to improve on this:

  1. Add backupGlobals and backupStaticAttributes configuration parameters to the WPLoader configuration, default true, to control the behavior of the respective WPTestCase properties.
  2. I like the sweeping cleanup done by the two properties and would like to be able to define what should not be serialized as part of the snapshot procedure PHPUnit uses to back up and restore the global state. I will add the backupGlobalsExcludeList and backupStaticAttributesExcludeList to the configuration of the WPLoader module to add to the respective lists.

In this API, your problem could be solved in two ways:

  1. Disable backup of globals and static attributes:
    config:
      lucatume\WPBrowser\Module\WPLoader:
        backupGlobals: false
        backupStaticAttributes: false
  2. Selectively exclude the problematic class:
     config:
       lucatume\WPBrowser\Module\WPLoader:
         backupStaticAttributesExcludeList:
           WC_Payment_Gateways: ['instance']

This API should provide a flexible approach to handle issues like this one.

from wp-browser.

lucatume avatar lucatume commented on September 27, 2024

I've followed up, in version 4.0.12 on this, to recap the possible approaches to solve the issue:

  1. In the test case override the backupStaticAttributes or backupGlobals properties setting them to false; this could already be done in previous versions.
  2. In the WPLoader module configuration set the backupGlobals, backupStaticAttributes to false; default value is true.
  3. In the WPLoader module configuration set the backupGlobalsExcludeList and backupStaticAttributesExcludeList to add entries to the list of ignored globals and static attributes.

See docs.

from wp-browser.

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.