Skip to content

Commit

Permalink
fix(WPTestCase) exclude WooCommerce unserializables from backup
Browse files Browse the repository at this point in the history
  • Loading branch information
lucatume committed Sep 18, 2023
1 parent 45eac99 commit 1f6a3a9
Show file tree
Hide file tree
Showing 9 changed files with 106 additions and 5,173 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ This project adheres to [Semantic Versioning](http://semver.org/).

## [unreleased] Unreleased

### Fixed

- Exclude some WooCommerce global values and static attributes from backup to avoid fatals.

## [4.0.1] 2023-09-15;

### Added
Expand Down
12 changes: 11 additions & 1 deletion src/TestCase/WPTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,22 @@ class WPTestCase extends Unit
'wp_current_filter',
'wp_filter',
'wp_object_cache',
'wp_meta_keys'
'wp_meta_keys',
// WooCommerce.
'woocommerce',
];

// Backup, and reset, static class attributes between tests.
protected $backupStaticAttributes = true;

// A list of static attributes that should not be backed up as they are wired to explode when doing so.
protected $backupStaticAttributesExcludeList = [
// WooCommerce.
'WooCommerce' => ['_instance'],
'Automattic\WooCommerce\Internal\Admin\FeaturePlugin' => ['instance'],
'Automattic\WooCommerce\RestApi\Server' => ['instance']
];

/**
* @var array<string,WP_UnitTestCase>
*/
Expand Down
23 changes: 23 additions & 0 deletions tests/_support/TestCase/WooCommerceLoadTestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace lucatume\WPBrowser\Tests\TestCase;

use lucatume\WPBrowser\TestCase\WPTestCase;

class WooCommerceLoadTestCase extends WPTestCase
{
public function testWordPressLoadedCorrectly(): void
{
$this->assertTrue(function_exists('do_action'));
}

public function testWooCommerceIsActivated(): void
{
$this->assertTrue(is_plugin_active('woocommerce/woocommerce.php'));
}

public function testWooCommerceFunctionsExist(): void
{
$this->assertTrue(function_exists('wc_get_product'));
}
}
Loading

0 comments on commit 1f6a3a9

Please sign in to comment.