Commit Graph

20 Commits

Author SHA1 Message Date
Nestor Soriano 8a7d955253 Improvements on the code hacker.
- Add methods to temporarily disable and reenable the code hacker.

The code hacker is causing issues in some tests that perform
write operations to the local filesystem. Since this happens only
in a few cases, the easiest fix is to temporarily disable the
code hacker when that happens. This commit adds two new methods
for that in `WC_Unit_Test_Case`: `disable_code_hacker` and
`reenable_code_hacker`.

These methods use a disabling requests count so that the hacker
isn't enabled before it should. E.g. you call `disable`, then
a helper method that does `disable` and `enable`, then `enable` -
then only the last `enable` will have effect.

- `CodeHacker::add_hack` has now a boolean `persistent` parameter.
Persistent hacks won't be cleared by `clear_hacks`.

- `CodeHackerTestHook::executeAfterTest` will now disable the hacker
only if no persistent hacks are registered.

- The existing `file_copy` method is made static for consistency.

- `CodeHacker::restore` method renamed to `disable` for clarity.
2020-05-20 09:56:26 +02:00
Nestor Soriano f04089d572 Add function docs to the CodeHacker class. 2020-05-20 09:56:25 +02:00
Nestor Soriano 884fd08462 Add a workaround for code hacking static methods on already loaded files.
The unit testing bootstrap loads and initializes WooCommerce, this
loads a bunch of code files that can't then be hacked in the test hooks.

A workaround is provided in this commit for the case of hacking
static methods. A new StaticWrapper class is created that allows
defining mock methods after the code file has been loaded.
This is applied to all classes from a fixed list in the bootstrap,
before WooCommerce is initialized. The list should be kept up to date
with the list of classes that require such workaround.
2020-05-20 09:56:25 +02:00
Nestor Soriano c7cf39bef4 Add a README file for the code hacker. 2020-05-20 09:56:25 +02:00
Nestor Soriano f0b0822c1c Fix code sniffer errors in CodeHacker and related classes. 2020-05-20 09:56:25 +02:00
Nestor Soriano 57845ef8b8 All code hacking files moved to src\Testing folder. 2020-05-20 09:56:25 +02:00
Christopher Allford 1b2f5ab4ad Added handling to prevent namespace conflicts with included packages
The root namespace of Core is Automattic\WooCommerce, but both the blocks and wc-admin plugins exist in this namespace. In an effort to prevent possible conflicts, we should not allow for overlap in our repository. The rationale behind doing this as opposed to renaming our root namespace feels reasonable. In the case of Blocks, all of the tooling is already set up in their repository, so all blocks should go there anyway. In the case of WC-Admin, we shouldn't be refactoring admin classes, as that would duplicate work done to revamp them entirely.
2020-04-28 14:04:00 -07:00
Vedanshu Jain ee119e0a7e
Revert "Introduce a `reserved stock` class and database table to prevent race conditions during checkout" 2020-04-21 15:37:21 +05:30
Christopher Allford 09df1205de Updated the minimum PHP version to 7.0 2020-04-06 17:07:33 -07:00
Mike Jolley 0cce3c5c45 Missing abspath check 2020-04-03 16:16:20 +01:00
Mike Jolley f248902454 Update versions 2020-04-03 15:56:43 +01:00
Mike Jolley 107879950e Remove get_query_for_stock as it's part of data-store 2020-04-03 15:55:15 +01:00
Mike Jolley c983677a6f Implement stock functions 2020-04-03 15:55:15 +01:00
Mike Jolley d2d0967ac0 Introduce class to handle stock reservation 2020-04-03 15:55:14 +01:00
Ron Rennick 22d5dce682 change the namespace of the WC Admin Package class 2020-02-24 22:56:32 -04:00
Paul Sealock 6c9e78850a wc-admin: Include package 2020-01-16 17:40:30 -07:00
Rodrigo Primo 179dd7003e Fix Generic.Arrays.DisallowShortArraySyntax violations
This commit fixes all violations of the
Generic.Arrays.DisallowShortArraySyntax sniff automatically using
phpcbf.
2019-12-20 14:18:04 -03:00
Mike Jolley 9a8e8dacff Add integration tests 2019-06-25 15:57:44 +01:00
Mike Jolley db6aa55eda Add readme file explaining use of src folder 2019-06-25 13:13:20 +01:00
Mike Jolley f8d6b26e2e Add dedicated Packages loader and Autoloader to init functionality 2019-06-25 13:13:04 +01:00