Commit Graph

3 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 1a68abbc28 Miscellaneous code hacking fixes:
- Fix how CodeHackerTestHook::executeBeforeTest parses the test name,
  to account for warnings and tests with data sets.

- CodeHackerTestHook now includes a executeAfterTest hook that
  disables the code hacker (needed to prevent it from inadvertently
  altering further tests). Also, clear_hacks is executed in
  executeBeforeTest for the same reason.

- CodeHacker gets restore, clear_hacks and is_enabled methods
  to support the changes in CodeHackerTestHook.

- FunctionsMockerHack fixed so that it doesn't modify strings
  that are class method definitions.

- Added the WC_Unit_Test_Case::file_copy method, it must be used
  instead of the PHP built-in "copy" in tests, otherwise tests
  that run with the code hacker active will fail.
  This is something to investigate.
2020-05-20 09:56:25 +02:00
Christopher Allford b5bd8225e8 Moved PHPUnit suite into tests/legacy 2020-04-24 13:53:40 -07:00