CogsAwareRestControllerTrait.php
1 year ago
CogsAwareTrait.php
1 year ago
CogsAwareUnitTestSuiteTrait.php
1 year ago
CostOfGoodsSoldController.php
9 months ago
CogsAwareUnitTestSuiteTrait.php
42 lines
| 1 | <?php |
| 2 | declare( strict_types=1 ); |
| 3 | |
| 4 | namespace Automattic\WooCommerce\Internal\CostOfGoodsSold; |
| 5 | |
| 6 | /** |
| 7 | * Trait with common functionality for unit tests related to the Cost of Goods Sold feature. |
| 8 | */ |
| 9 | trait CogsAwareUnitTestSuiteTrait { |
| 10 | /** |
| 11 | * Enable the Cost of Goods Sold feature. |
| 12 | */ |
| 13 | private function enable_cogs_feature() { |
| 14 | update_option( 'woocommerce_feature_cost_of_goods_sold_enabled', 'yes' ); |
| 15 | } |
| 16 | |
| 17 | /** |
| 18 | * Enable the Cost of Goods Sold feature. |
| 19 | */ |
| 20 | private function disable_cogs_feature() { |
| 21 | delete_option( 'woocommerce_feature_cost_of_goods_sold_enabled' ); |
| 22 | } |
| 23 | |
| 24 | /** |
| 25 | * Sets the expectation for a "doing it wrong" being thrown. |
| 26 | * |
| 27 | * @param string $method_name The method name inside the error message. |
| 28 | */ |
| 29 | private function expect_doing_it_wrong_cogs_disabled( string $method_name ) { |
| 30 | $this->register_legacy_proxy_function_mocks( |
| 31 | array( |
| 32 | 'wc_doing_it_wrong' => function ( $function_name, $message ) { |
| 33 | // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped |
| 34 | throw new \Exception( "Doing it wrong, function: '$function_name', message: '$message'" ); |
| 35 | }, |
| 36 | ) |
| 37 | ); |
| 38 | |
| 39 | $this->expectExceptionMessage( "Doing it wrong, function: '{$method_name}', message: 'The Cost of Goods sold feature is disabled, thus the method called will do nothing and will return dummy data.'" ); |
| 40 | } |
| 41 | } |
| 42 |