fc21fd1f06
Also: add acf_add_options_page to acf-stubs.php; add translation-function
stubs to acf-stubs.php; fix TestCase::tearDown to call Patchwork::restoreAll()
in a finally block so that when('function_exists') routes are always cleaned up
even when Mockery::close() throws InvalidCountException.
48 lines
1.5 KiB
PHP
48 lines
1.5 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace WPMultiCity\Tests;
|
|
|
|
use Brain\Monkey;
|
|
use PHPUnit\Framework\TestCase as BaseTestCase;
|
|
use WPMultiCity\Helpers;
|
|
use WPMultiCity\ShortcodeDmr;
|
|
|
|
abstract class TestCase extends BaseTestCase
|
|
{
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
Monkey\setUp();
|
|
// Load ACF stubs through Patchwork's stream wrapper (AFTER setUp activates it)
|
|
// so the functions can be redefined across test classes in the same process.
|
|
require_once __DIR__ . '/acf-stubs.php';
|
|
Monkey\Functions\stubTranslationFunctions();
|
|
Monkey\Functions\when('shortcode_atts')->alias(function (array $defaults, array $atts): array {
|
|
return array_merge($defaults, array_intersect_key($atts, $defaults));
|
|
});
|
|
Helpers::reset_cache();
|
|
ShortcodeDmr::reset_cache();
|
|
}
|
|
|
|
protected function tearDown(): void
|
|
{
|
|
unset(
|
|
$_SERVER['REQUEST_URI'],
|
|
$GLOBALS['wp_query'],
|
|
$GLOBALS['wp_the_query'],
|
|
$GLOBALS['post']
|
|
);
|
|
try {
|
|
Monkey\tearDown();
|
|
} finally {
|
|
// Patchwork routes MUST be disconnected even when Monkey\tearDown() throws
|
|
// (e.g. Mockery count validation failure). If they are not, any
|
|
// when('function_exists')->alias() from the failed test stays active and
|
|
// causes "Cannot redeclare function __()..." in the next test's setUp().
|
|
\Patchwork\restoreAll();
|
|
}
|
|
parent::tearDown();
|
|
}
|
|
}
|