* 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 * style: auto-fix PHPCS violations via phpcbf * fix(ci): resolve latent PHPCS + JS lint failures Latent debt surfaced by the reusable PHPCS job (previously continue-on-error). PHPCS fixes (all pre-existing, not introduced by this PR): - Add @package PeptideReconstitutionCalculator to file docblocks in all 12 PHP files (previously missing; phpcbf cannot insert missing docblock tags). - Replace two short-ternary ?: operators in class-prc-preset-provider.php with full ternary (Universal.Operators.DisallowShortTernary.Found; lines 136+152). JS lint fix: - Add package.json + package-lock.json (no deps; lint script = node --check) so the reusable lint-js job's npm ci / cache: npm steps succeed. The calculator ships vanilla JS with no build toolchain — package.json is the minimal stub the reusable workflow requires for has_js: true. Agent-Session: claude/adopt-ci-20260616 * style: auto-fix PHPCS violations via phpcbf * fix(phpcs): suppress intentional warnings with phpcs:ignore annotations uninstall.php: direct wpdb->query() intentional in uninstall (no caching available); add phpcs:ignore DirectDatabaseQuery.DirectQuery and NoCaching. class-prc-rest-controller.php get_presets(): request param required by WP REST API callback contract; add phpcs:ignore UnusedFunctionParameter. Agent-Session: claude/adopt-ci-20260616 --------- Co-authored-by: peptiderepo <bot@peptiderepo.com> Co-authored-by: peptiderepo <peptiderepo@users.noreply.github.com>
88 lines
2.6 KiB
PHP
88 lines
2.6 KiB
PHP
<?php
|
|
/**
|
|
* Main orchestrator for the Reconstitution Calculator plugin.
|
|
*
|
|
* What: Boots all subsystems — shortcode, REST API, admin settings.
|
|
* Who calls it: plugins_loaded hook in bootstrap.
|
|
* Dependencies: PRC_Shortcode, PRC_Rest_Controller, PRC_Preset_Provider.
|
|
*
|
|
* @see class-prc-shortcode.php — Frontend calculator widget.
|
|
* @see class-prc-rest-controller.php — REST endpoints for presets.
|
|
* @see class-prc-preset-provider.php — PR Core integration + fallback defaults.
|
|
* @package PeptideReconstitutionCalculator
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
/**
|
|
* Central boot class — wires hooks for the entire plugin.
|
|
*/
|
|
class PRC_Calculator {
|
|
|
|
/**
|
|
* Boot the plugin — called on plugins_loaded.
|
|
*
|
|
* Registers the shortcode, REST routes, and admin notice
|
|
* if PR Core is not active.
|
|
*
|
|
* @return void
|
|
*/
|
|
public static function boot(): void {
|
|
// Frontend shortcode — always available.
|
|
$shortcode = new PRC_Shortcode();
|
|
add_action( 'init', array( $shortcode, 'register' ) );
|
|
|
|
// REST API — serves presets to the JS calculator.
|
|
add_action( 'rest_api_init', array( new PRC_Rest_Controller(), 'register_routes' ) );
|
|
|
|
// Cache invalidation — keep presets in sync with PR Core dosing data.
|
|
PRC_Cache_Listener::register();
|
|
|
|
// Admin notice when PR Core is absent.
|
|
if ( is_admin() && ! self::is_pr_core_active() ) {
|
|
add_action( 'admin_notices', array( __CLASS__, 'render_pr_core_notice' ) );
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Check whether Peptide Repo Core is active.
|
|
*
|
|
* Looks for the PR_CORE_VERSION constant which is defined
|
|
* in peptide-repo-core.php's bootstrap.
|
|
*
|
|
* @return bool True if PR Core is loaded.
|
|
*/
|
|
public static function is_pr_core_active(): bool {
|
|
return defined( 'PR_CORE_VERSION' );
|
|
}
|
|
|
|
/**
|
|
* Render an admin notice suggesting PR Core installation.
|
|
*
|
|
* Not a blocker — the calculator works standalone with built-in
|
|
* defaults. PR Core just unlocks peptide-specific presets.
|
|
*
|
|
* @return void Side effect: outputs HTML notice.
|
|
*/
|
|
public static function render_pr_core_notice(): void {
|
|
$screen = get_current_screen();
|
|
if ( null === $screen ) {
|
|
return;
|
|
}
|
|
|
|
// Only show on plugins page and the calculator's own pages.
|
|
$show_on = array( 'plugins', 'settings_page_prc-settings' );
|
|
if ( ! in_array( $screen->id, $show_on, true ) ) {
|
|
return;
|
|
}
|
|
|
|
printf(
|
|
'<div class="notice notice-info is-dismissible"><p>%s</p></div>',
|
|
esc_html__(
|
|
'Peptide Reconstitution Calculator: Install Peptide Repo Core to unlock peptide-specific presets with real dosing data. The calculator works without it using built-in defaults.',
|
|
'peptide-reconstitution-calculator'
|
|
)
|
|
);
|
|
}
|
|
}
|