Adopt reusable CI standard + PHPUnit suite (#8)
* 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>
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
* @see class-prc-default-presets.php — Hardcoded fallback presets.
|
||||
* @see PR_Core_Peptide_Repository (PR Core) — Peptide list source.
|
||||
* @see PR_Core_Dosing_Repository (PR Core) — Dosing data source.
|
||||
* @package PeptideReconstitutionCalculator
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
@@ -89,19 +90,19 @@ class PRC_Preset_Provider {
|
||||
// could fail to autoload (e.g. fatal error in PR Core bootstrap).
|
||||
// Fall back to empty array so the caller merges in defaults gracefully.
|
||||
if ( ! class_exists( 'PR_Core_Peptide_Repository' ) || ! class_exists( 'PR_Core_Dosing_Repository' ) ) {
|
||||
return [];
|
||||
return array();
|
||||
}
|
||||
|
||||
$peptide_repo = new PR_Core_Peptide_Repository();
|
||||
$dosing_repo = new PR_Core_Dosing_Repository();
|
||||
|
||||
$peptides = $peptide_repo->find_all( [ 'posts_per_page' => 100 ] );
|
||||
$presets = [];
|
||||
$peptides = $peptide_repo->find_all( array( 'posts_per_page' => 100 ) );
|
||||
$presets = array();
|
||||
|
||||
foreach ( $peptides as $peptide ) {
|
||||
$rows = $dosing_repo->find_by_peptide(
|
||||
$peptide->id,
|
||||
[ 'route' => 'subcutaneous' ]
|
||||
array( 'route' => 'subcutaneous' )
|
||||
);
|
||||
|
||||
if ( empty( $rows ) ) {
|
||||
@@ -133,7 +134,7 @@ class PRC_Preset_Provider {
|
||||
// Extract dose range across all rows.
|
||||
$dose_mins = array_filter( array_map( fn( $r ) => $r->dose_min, $rows ) );
|
||||
$dose_maxs = array_filter( array_map( fn( $r ) => $r->dose_max, $rows ) );
|
||||
$dose_unit = $rows[0]->dose_unit ?: 'mcg';
|
||||
$dose_unit = ! empty( $rows[0]->dose_unit ) ? $rows[0]->dose_unit : 'mcg';
|
||||
|
||||
// Derive typical vial sizes from dose range.
|
||||
// Why: Most peptides are sold in standard vial sizes (2mg, 5mg, 10mg, 15mg, 30mg).
|
||||
@@ -141,26 +142,26 @@ class PRC_Preset_Provider {
|
||||
|
||||
$display_name = '';
|
||||
if ( method_exists( $peptide, 'to_array' ) ) {
|
||||
$arr = $peptide->to_array();
|
||||
$arr = $peptide->to_array();
|
||||
$display_name = $arr['display_name'] ?? $peptide->title ?? '';
|
||||
} else {
|
||||
$display_name = $peptide->title ?? '';
|
||||
}
|
||||
|
||||
return [
|
||||
'slug' => $peptide->slug,
|
||||
'name' => $display_name ?: $peptide->title,
|
||||
'vial_sizes_mg' => $vial_sizes,
|
||||
'default_vial_mg' => $vial_sizes[0] ?? 5,
|
||||
'recommended_water_ml' => $this->recommend_water_ml( $vial_sizes[0] ?? 5 ),
|
||||
'dose_range_min' => ! empty( $dose_mins ) ? min( $dose_mins ) : null,
|
||||
'dose_range_max' => ! empty( $dose_maxs ) ? max( $dose_maxs ) : null,
|
||||
'dose_unit' => $dose_unit,
|
||||
'typical_frequency' => $this->most_common_frequency( $rows ),
|
||||
'evidence_strength' => $peptide->evidence_strength ?? 'preclinical',
|
||||
'dosing_row_count' => count( $rows ),
|
||||
'source' => 'pr_core',
|
||||
];
|
||||
return array(
|
||||
'slug' => $peptide->slug,
|
||||
'name' => ! empty( $display_name ) ? $display_name : $peptide->title,
|
||||
'vial_sizes_mg' => $vial_sizes,
|
||||
'default_vial_mg' => $vial_sizes[0] ?? 5,
|
||||
'recommended_water_ml' => $this->recommend_water_ml( $vial_sizes[0] ?? 5 ),
|
||||
'dose_range_min' => ! empty( $dose_mins ) ? min( $dose_mins ) : null,
|
||||
'dose_range_max' => ! empty( $dose_maxs ) ? max( $dose_maxs ) : null,
|
||||
'dose_unit' => $dose_unit,
|
||||
'typical_frequency' => $this->most_common_frequency( $rows ),
|
||||
'evidence_strength' => $peptide->evidence_strength ?? 'preclinical',
|
||||
'dosing_row_count' => count( $rows ),
|
||||
'source' => 'pr_core',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -176,10 +177,10 @@ class PRC_Preset_Provider {
|
||||
* @return float[] Standard vial sizes in mg.
|
||||
*/
|
||||
private function infer_vial_sizes( array $dose_mins, array $dose_maxs, string $dose_unit ): array {
|
||||
$standard_sizes = [ 2, 5, 10, 15, 30 ];
|
||||
$standard_sizes = array( 2, 5, 10, 15, 30 );
|
||||
|
||||
if ( empty( $dose_mins ) && empty( $dose_maxs ) ) {
|
||||
return [ 5, 10 ];
|
||||
return array( 5, 10 );
|
||||
}
|
||||
|
||||
// Convert everything to mg for comparison.
|
||||
@@ -187,12 +188,12 @@ class PRC_Preset_Provider {
|
||||
$all_doses = array_merge( $dose_mins, $dose_maxs );
|
||||
|
||||
foreach ( $all_doses as $dose ) {
|
||||
$mg = ( 'mcg' === $dose_unit ) ? $dose / 1000 : $dose;
|
||||
$mg = ( 'mcg' === $dose_unit ) ? $dose / 1000 : $dose;
|
||||
$max_dose_mg = max( $max_dose_mg, $mg );
|
||||
}
|
||||
|
||||
// Pick vials that hold at least 10 doses at the max dose level.
|
||||
$viable = [];
|
||||
$viable = array();
|
||||
foreach ( $standard_sizes as $size ) {
|
||||
if ( $max_dose_mg > 0 && ( $size / $max_dose_mg ) >= 5 ) {
|
||||
$viable[] = $size;
|
||||
@@ -200,7 +201,7 @@ class PRC_Preset_Provider {
|
||||
}
|
||||
|
||||
// Fallback: return two middle sizes if heuristic found nothing.
|
||||
return ! empty( $viable ) ? array_slice( $viable, 0, 3 ) : [ 5, 10 ];
|
||||
return ! empty( $viable ) ? array_slice( $viable, 0, 3 ) : array( 5, 10 );
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user