woocommerce/src
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
..
Admin Added handling to prevent namespace conflicts with included packages 2020-04-28 14:04:00 -07:00
Blocks Added handling to prevent namespace conflicts with included packages 2020-04-28 14:04:00 -07:00
Testing/CodeHacking Improvements on the code hacker. 2020-05-20 09:56:26 +02:00
Autoloader.php Add dedicated Packages loader and Autoloader to init functionality 2019-06-25 13:13:04 +01:00
Packages.php change the namespace of the WC Admin Package class 2020-02-24 22:56:32 -04:00
README.md Updated the minimum PHP version to 7.0 2020-04-06 17:07:33 -07:00

README.md

WooCommerce src files

This directory is home to new WooCommerce class files under the \Automattic\WooCommerce\ namespace using PSR-4 file naming. This is to take full advantage of autoloading.

Currently, these classes have a PHP 7.0 requirement. No required core classes will be added here until this PHP version is enforced. If running an older version of PHP, these class files will not be used.

Installing Composer

Composer is used to generate autoload class-maps for the files here. The stable release of WooCommerce comes with the autoloader, however, if you're running a development version you'll need to use Composer.

If you don't have Composer installed, go and check how to install Composer and then continue here.

Installing packages

To install the packages WooCommerce requires, from the main directory run:

composer install

To update packages run:

composer update

If you add a class to WooCommerce and want to ensure it's included in the autoloader class-maps, run:

composer dump-autoload

Using classes

To use something a namespaced class you have to declare it at the top of the file before any other instruction, and then use it in the code. For example:

use Automattic\WooCommerce\TestClass;

// other code...

$test_class = new TestClass();

If you need to rule out conflicts, you can alias it:

use Automattic\WooCommerce\TestClass as Test_Class_Alias;

// other code...

$test_class = new Test_Class_Alias();