Improve wp acorn compability

This commit is contained in:
Jan-Niclas Loosen
2026-06-29 19:54:12 +02:00
parent 7f3fd36186
commit 102abe7927
28 changed files with 4090 additions and 1980 deletions
+50
View File
@@ -0,0 +1,50 @@
<?php
declare(strict_types=1);
namespace AcornPlugin\Tests\Acorn;
use AcornPlugin\Acorn\BootCoordinator;
use AcornPlugin\Tests\TestCase;
use Brain\Monkey\Functions;
final class BootCoordinatorTest extends TestCase
{
// -----------------------------------------------------------------------
// shouldBoot()
// -----------------------------------------------------------------------
public function test_should_boot_returns_true_when_action_has_not_fired(): void
{
Functions\when('did_action')->justReturn(0);
$result = (new BootCoordinator())->shouldBoot();
$this->assertTrue($result);
}
public function test_should_boot_returns_false_when_action_already_fired(): void
{
Functions\expect('did_action')
->once()
->with(BootCoordinator::BOOTED_ACTION)
->andReturn(1);
$result = (new BootCoordinator())->shouldBoot();
$this->assertFalse($result);
}
// -----------------------------------------------------------------------
// markBooted()
// -----------------------------------------------------------------------
public function test_mark_booted_fires_the_booted_action_once(): void
{
Functions\expect('do_action')
->once()
->with(BootCoordinator::BOOTED_ACTION);
(new BootCoordinator())->markBooted();
}
}
+28
View File
@@ -0,0 +1,28 @@
<?php
declare(strict_types=1);
namespace AcornPlugin\Tests;
use Brain\Monkey;
use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;
use PHPUnit\Framework\TestCase as PhpUnitTestCase;
abstract class TestCase extends PhpUnitTestCase
{
// Bridges Brain\Monkey's Mockery-backed expectations into PHPUnit's
// assertion count, so expectation-only tests aren't reported as "risky".
use MockeryPHPUnitIntegration;
protected function setUp(): void
{
parent::setUp();
Monkey\setUp();
}
protected function tearDown(): void
{
Monkey\tearDown();
parent::tearDown();
}
}
+15
View File
@@ -0,0 +1,15 @@
<?php
declare(strict_types=1);
/*
* WordPress isn't loaded in unit tests. Define ABSPATH as insurance so any code
* that transitively pulls in a file guarded by `defined('ABSPATH') || exit;`
* fails loudly instead of vanishing mid-load. BootCoordinator itself needs no WP
* constants — Brain\Monkey mocks did_action()/do_action() per test.
*/
if (! defined('ABSPATH')) {
define('ABSPATH', __DIR__ . '/');
}
require_once __DIR__ . '/../vendor/autoload.php';