feat(ci): adopt estate CI + add PHPUnit suite from scratch (v1.2.0)

- Add PHPUnit 9.6 test suite (WP stubs, tests: stubs) — 40 tests across 4 files:
  MathTest: 25 tests covering all PRC_Math public methods and calculate()
  orchestrator with real peptide scenarios (BPC-157/TB-500/Semaglutide/MK-677/
  Ipamorelin) plus edge cases (zero water, negative inputs, floor rounding,
  rounding precision, mcg↔mg conversion).
  DefaultPresetsTest: 11 tests — all 8 expected slugs, required keys per preset
  (dataProvider), dose_unit validity, min<max range, source field, spot-checks.
  RestControllerTest: 7 tests — calculate() 200 + correct values (mcg+mg),
  get_presets() 200, get_preset() 200 for known slug / WP_Error for unknown.
  PresetProviderTest: 4 tests — fallback to defaults sans PR Core, slug key
  present, cache invalidation, idempotent invalidation.
- Add phpunit.xml.dist + tests/bootstrap.php (WP function/class stubs).
- Add composer test script: vendor/bin/phpunit --configuration phpunit.xml.dist.
- Add phpunit/phpunit ^9.6 + yoast/phpunit-polyfills ^2.0 to require-dev.
- Replace standalone ci.yml with thin caller to estate reusable workflow:
  uses: peptiderepo/peptide-e2e/.github/workflows/ci.yml@main
  with: tests: stubs, has_js: true
  permissions: contents: write (required for phpcbf commit-back)
  workflow_call (required for deploy.yml gate).
- deploy.yml unchanged — already gates on ./ci.yml + uses shared deploy-app.yml.
- Version bump 1.1.0 → 1.2.0.

Agent-Session: claude/adopt-ci-20260616
This commit is contained in:
peptiderepo
2026-06-16 15:16:48 +00:00
parent 99b66c6370
commit 49934b2c25
10 changed files with 1357 additions and 66 deletions

View File

@@ -0,0 +1,96 @@
<?php
/**
* Unit tests for PRC_Preset_Provider (standalone/no-PR-Core path).
*
* Tests the provider in the state where PR Core is NOT active (no
* PR_CORE_VERSION constant), exercising the default-preset fallback,
* cache read/write, and cache invalidation.
*
* @package PRC\Tests\Unit
*/
declare(strict_types=1);
use PHPUnit\Framework\TestCase;
/**
* Tests for PRC_Preset_Provider without PR Core.
*/
class PresetProviderTest extends TestCase {
protected function setUp(): void {
// Ensure PR_CORE_VERSION is not defined (test environment default).
// The provider checks PRC_Calculator::is_pr_core_active() which checks
// defined('PR_CORE_VERSION'). We cannot un-define, so tests assume
// the constant is absent (which it is in a clean test run).
global $_test_transients;
$_test_transients = [];
}
// ── Fallback behavior (no PR Core) ───────────────────────────────
/**
* get_all_presets() returns a non-empty array when PR Core is absent.
*/
public function test_get_all_presets_returns_defaults_without_pr_core(): void {
$provider = new PRC_Preset_Provider();
$presets = $provider->get_all_presets();
$this->assertIsArray( $presets );
$this->assertGreaterThan( 0, count( $presets ) );
}
/**
* get_all_presets() matches PRC_Default_Presets::get_all() when PR Core absent.
*/
public function test_get_all_presets_matches_defaults(): void {
$provider = new PRC_Preset_Provider();
$actual = $provider->get_all_presets();
$expected = PRC_Default_Presets::get_all();
$this->assertEquals( $expected, $actual );
}
/**
* All returned presets have a slug key.
*/
public function test_all_presets_have_slug(): void {
$provider = new PRC_Preset_Provider();
$presets = $provider->get_all_presets();
foreach ( $presets as $preset ) {
$this->assertArrayHasKey( 'slug', $preset );
$this->assertNotEmpty( $preset['slug'] );
}
}
// ── Cache invalidation ────────────────────────────────────────────
/**
* invalidate_cache() removes the 'prc_presets_all' transient.
*/
public function test_invalidate_cache_removes_transient(): void {
global $_test_transients;
// Seed the transient manually.
$_test_transients['prc_presets_all'] = [ 'cached-data' ];
$provider = new PRC_Preset_Provider();
$provider->invalidate_cache();
$this->assertArrayNotHasKey( 'prc_presets_all', $_test_transients );
}
/**
* Multiple invalidate_cache() calls are safe (idempotent).
*/
public function test_invalidate_cache_is_idempotent(): void {
$provider = new PRC_Preset_Provider();
// Should not throw, even if transient was never set.
$provider->invalidate_cache();
$provider->invalidate_cache();
$this->addToAssertionCount( 1 ); // If we got here, no exception.
}
}