Commit Graph

8 Commits

Author SHA1 Message Date
Nestor Soriano 8a60e7e147
Move code hacker resetting from BeforeTestHook to setUp
The code hacker needs to be reset before each test. This was done via
a couple of classes implementeing BeforeTestHook, those were registered
in phpunit.xml.

The problem is that the PHPUnit version used for WooCommerce unit test
has recently been changed from 7.5 to 6.5 for compatibility with
PHP 7.0, and hook classes were introduced in PHPUnit 7. Thus no hooks
were ran, the code hacker wasn't reset, that caused some functions
to remain hacked between tests, and this made some tests to fail.

The solution is to move the code hacker reset to the setUp method
in the base unit test class.
2021-04-12 12:42:39 +02:00
Nestor Soriano bcf24f0f8c
Fix unit test problems in PHP 7.0.
This includes removing two array_merge and array_merge_eecursive
statements in the code hacker, that apparently were working differently
in PHP 7.0.
2021-04-12 12:42:39 +02:00
Claudio Sanches d48f1d4e2e Fixed package tag usage 2020-08-05 13:36:24 -03:00
Nestor Soriano 29cf161415 Small changes after review feedback:
- Method and class renames.
- Removed unnecessary autoloader registration.
- Add a unit test for classes with non-object type hints
  in constructor arguments.
2020-07-24 09:24:06 +02:00
Nestor Soriano 1684ce08b3 Removed annotations as we're not going to use them. 2020-07-24 09:24:06 +02:00
Nestor Soriano c1ed403dd0 Add `@public` to `FunctionsMockerHack`.
Also to a couple of methods related to the code hacker.
2020-07-24 09:24:06 +02:00
Nestor Soriano bfda3f9938 Code hacker resdesign for single-load of code files.
The code hacker as originally designed, as a mechanism that allowed
to enable hacks at the individual test level, is flawed because it
assumes that code files are loaded before each test, but actually
the PHP engine loads code files only once.

Therefore this commit redesigns it so that the two existing main hacks,
the functions mocker and the static methods hacker, are applied
to all the relevant functions and classes at bootstrap time, and
mocks for each individual function/method can be registered at the
beginning of each test. See README for the full details.
2020-06-02 19:06:53 +02:00
Nestor Soriano 2a68bb018d 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.
2020-05-20 09:57:39 +02:00