Move testing tools to the tests/Tools directory

The testing tools (only the code hacker at this time) have been moved
from 'src' to 'tests/Tools', since many opcode cache plugins
load the whole src folder in production.

Also, an extra autoloader is set in the tests bootstrap so that
the 'tests/Tools' directory corresponds, using PSR4, to the
'Automattic\WooCommerce\Testing\Tools' namespace.
This commit is contained in:
Nestor Soriano 2020-05-18 11:31:59 +02:00
parent 0726f71aac
commit 2a68bb018d
12 changed files with 22 additions and 16 deletions

View File

@ -59,5 +59,6 @@
<exclude-pattern>i18n/</exclude-pattern>
<exclude-pattern>src/</exclude-pattern>
<exclude-pattern>tests/php</exclude-pattern>
<exclude-pattern>tests/Tools/</exclude-pattern>
</rule>
</ruleset>

View File

@ -50,6 +50,6 @@
<listener class="SpeedTrapListener" file="tests/legacy/includes/listener-loader.php" />
</listeners>
<extensions>
<extension class="\Automattic\WooCommerce\Testing\CodeHacking\CodeHackerTestHook" />
<extension class="\Automattic\WooCommerce\Testing\Tools\CodeHacking\CodeHackerTestHook" />
</extensions>
</phpunit>

View File

@ -7,7 +7,7 @@
//phpcs:disable WordPress.WP.AlternativeFunctions, WordPress.PHP.NoSilencedErrors.Discouraged
namespace Automattic\WooCommerce\Testing\CodeHacking;
namespace Automattic\WooCommerce\Testing\Tools\CodeHacking;
use \ReflectionObject;
use \ReflectionFunction;

View File

@ -5,7 +5,7 @@
* @package WooCommerce/Testing
*/
namespace Automattic\WooCommerce\Testing\CodeHacking;
namespace Automattic\WooCommerce\Testing\Tools\CodeHacking;
use PHPUnit\Runner\BeforeTestHook;
use PHPUnit\Runner\AfterTestHook;
@ -27,8 +27,8 @@ use Exception;
*
* 2. Add the following to the test classes:
*
* use Automattic\WooCommerce\Testing\CodeHacking\CodeHacker;
* use Automattic\WooCommerce\Testing\CodeHacking\Hacks\...
* use Automattic\WooCommerce\Testing\Tools\CodeHacking\CodeHacker;
* use Automattic\WooCommerce\Testing\Tools\CodeHacking\Hacks\...
*
* public static function before_all($method_name) {
* CodeHacker::add_hack(...);

View File

@ -7,7 +7,7 @@
// phpcs:disable Squiz.Commenting.FunctionComment.Missing
namespace Automattic\WooCommerce\Testing\CodeHacking\Hacks;
namespace Automattic\WooCommerce\Testing\Tools\CodeHacking\Hacks;
/**
* Code hack to bypass finals.

View File

@ -5,7 +5,7 @@
* @package WooCommerce/Testing
*/
namespace Automattic\WooCommerce\Testing\CodeHacking\Hacks;
namespace Automattic\WooCommerce\Testing\Tools\CodeHacking\Hacks;
/**
* Base class to define Hacks for CodeHacker.

View File

@ -7,7 +7,7 @@
// phpcs:disable Squiz.Commenting.FunctionComment.Missing
namespace Automattic\WooCommerce\Testing\CodeHacking\Hacks;
namespace Automattic\WooCommerce\Testing\Tools\CodeHacking\Hacks;
use ReflectionMethod;
use ReflectionClass;

View File

@ -7,7 +7,7 @@
// phpcs:disable Squiz.Commenting.FunctionComment.Missing
namespace Automattic\WooCommerce\Testing\CodeHacking\Hacks;
namespace Automattic\WooCommerce\Testing\Tools\CodeHacking\Hacks;
use ReflectionMethod;
use ReflectionClass;

View File

@ -5,7 +5,7 @@
* @package WooCommerce/Testing
*/
namespace Automattic\WooCommerce\Testing\CodeHacking;
namespace Automattic\WooCommerce\Testing\Tools\CodeHacking;
use ReflectionClass;
use ReflectionMethod;
@ -39,7 +39,7 @@ use ReflectionMethod;
*
* You can use 2 and 3 at the same time, functions have precedence over mock class methods in case of conflict.
*
* @package Automattic\WooCommerce\Testing\CodeHacking
* @package Automattic\WooCommerce\Testing\Tools\CodeHacking
*/
abstract class StaticWrapper {

View File

@ -6,9 +6,10 @@
* @package WooCommerce Tests
*/
use Automattic\WooCommerce\Testing\CodeHacking\CodeHacker;
use Automattic\WooCommerce\Testing\CodeHacking\StaticWrapper;
use Automattic\WooCommerce\Testing\CodeHacking\Hacks\StaticMockerHack;
use Automattic\WooCommerce\Testing\Tools\CodeHacking\CodeHacker;
use Automattic\WooCommerce\Testing\Tools\CodeHacking\StaticWrapper;
use Automattic\WooCommerce\Testing\Tools\CodeHacking\Hacks\StaticMockerHack;
use Composer\Autoload\ClassLoader;
/**
* Class WC_Unit_Tests_Bootstrap
@ -33,11 +34,15 @@ class WC_Unit_Tests_Bootstrap {
* @since 2.2
*/
public function __construct() {
$classLoader = new ClassLoader();
$classLoader->addPsr4("Automattic\\WooCommerce\\Testing\\Tools\\", __DIR__ . '/../Tools', false);
$classLoader->register();
//Includes needed to initialize the static wrapper
$this->tests_dir = dirname( __FILE__ );
$this->plugin_dir = dirname( dirname( $this->tests_dir ) );
$hacking_base = $this->plugin_dir . '/src/Testing/CodeHacking';
$hacking_base = $this->plugin_dir . '/tests/Tools/CodeHacking';
require_once $hacking_base . '/StaticWrapper.php';
require_once $hacking_base . '/CodeHacker.php';
require_once $hacking_base . '/Hacks/CodeHack.php';

View File

@ -5,7 +5,7 @@
* @package WooCommerce\Tests
*/
use Automattic\WooCommerce\Testing\CodeHacking\CodeHacker;
use Automattic\WooCommerce\Testing\Tools\CodeHacking\CodeHacker;
/**
* WC Unit Test Case.