You've already forked wc-composable-product
76 lines
2.1 KiB
PHP
76 lines
2.1 KiB
PHP
|
|
<?php
|
||
|
|
/**
|
||
|
|
* Base Test Case
|
||
|
|
*
|
||
|
|
* @package Magdev\WcComposableProduct\Tests
|
||
|
|
*/
|
||
|
|
|
||
|
|
namespace Magdev\WcComposableProduct\Tests;
|
||
|
|
|
||
|
|
use PHPUnit\Framework\TestCase as PHPUnitTestCase;
|
||
|
|
use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;
|
||
|
|
use Brain\Monkey;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Base test case with Brain Monkey and Mockery integration.
|
||
|
|
*
|
||
|
|
* All test classes should extend this instead of PHPUnit\Framework\TestCase.
|
||
|
|
*/
|
||
|
|
abstract class TestCase extends PHPUnitTestCase
|
||
|
|
{
|
||
|
|
use MockeryPHPUnitIntegration;
|
||
|
|
|
||
|
|
protected function setUp(): void
|
||
|
|
{
|
||
|
|
parent::setUp();
|
||
|
|
Monkey\setUp();
|
||
|
|
|
||
|
|
// Stub common WordPress translation functions (__(), _e(), esc_html__(), etc.)
|
||
|
|
Monkey\Functions\stubTranslationFunctions();
|
||
|
|
|
||
|
|
// Stub common WordPress escaping functions (esc_html(), esc_attr(), etc.)
|
||
|
|
Monkey\Functions\stubEscapeFunctions();
|
||
|
|
}
|
||
|
|
|
||
|
|
protected function tearDown(): void
|
||
|
|
{
|
||
|
|
Monkey\tearDown();
|
||
|
|
parent::tearDown();
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Create a Mockery mock of WC_Product with sensible defaults.
|
||
|
|
*
|
||
|
|
* @param array $overrides Method return value overrides
|
||
|
|
* @return \Mockery\MockInterface
|
||
|
|
*/
|
||
|
|
protected function createProductMock(array $overrides = []): \Mockery\MockInterface
|
||
|
|
{
|
||
|
|
$defaults = [
|
||
|
|
'get_id' => 100,
|
||
|
|
'get_name' => 'Test Product',
|
||
|
|
'get_type' => 'simple',
|
||
|
|
'get_price' => '10.00',
|
||
|
|
'get_regular_price' => '10.00',
|
||
|
|
'get_price_html' => '<span>$10.00</span>',
|
||
|
|
'get_permalink' => 'https://example.com/product/test',
|
||
|
|
'get_image_id' => 1,
|
||
|
|
'get_stock_quantity' => null,
|
||
|
|
'get_stock_status' => 'instock',
|
||
|
|
'is_purchasable' => true,
|
||
|
|
'is_in_stock' => true,
|
||
|
|
'managing_stock' => false,
|
||
|
|
'backorders_allowed' => false,
|
||
|
|
];
|
||
|
|
|
||
|
|
$config = array_merge($defaults, $overrides);
|
||
|
|
$mock = \Mockery::mock('WC_Product');
|
||
|
|
|
||
|
|
foreach ($config as $method => $return) {
|
||
|
|
$mock->shouldReceive($method)->andReturn($return)->byDefault();
|
||
|
|
}
|
||
|
|
|
||
|
|
return $mock;
|
||
|
|
}
|
||
|
|
}
|