fix(tests): rewrite unit tests to plain-PHP bootstrap pattern; extract compute_status() from scanner

This commit is contained in:
peptiderepo
2026-04-27 05:23:39 +00:00
parent a90bb7ca4c
commit 6d96768892
3 changed files with 271 additions and 224 deletions

View File

@@ -45,20 +45,8 @@ class PR_Core_Verification_Scanner {
continue;
}
// Compute days since verification.
$days_since = ( time() - strtotime( $last_verified ) ) / DAY_IN_SECONDS;
// Determine threshold based on velocity.
$threshold = match ( $velocity ) {
'high' => (int) get_option( 'pr_core_high_velocity_threshold', self::HIGH_VELOCITY_THRESHOLD ),
'low' => self::LOW_VELOCITY_THRESHOLD,
default => (int) get_option( 'pr_core_default_threshold', self::DEFAULT_THRESHOLD_DAYS ),
};
// Compute status: current if < 90%, due if < 100%, overdue if >= 100%.
$status = $days_since < ( $threshold * 0.9 )
? 'current'
: ( $days_since < $threshold ? 'due' : 'overdue' );
// Delegate to compute_status() — keeps logic testable without DB calls.
$status = self::compute_status( $last_verified, $velocity );
update_post_meta( $dto->id, '_pr_verification_status', $status );
@@ -78,6 +66,33 @@ class PR_Core_Verification_Scanner {
}
}
/**
* Compute verification status for a single peptide.
*
* Extracted for direct unit-testability without database or WP-cron dependencies.
*
* @param string $last_verified YYYY-MM-DD date of last source verification. Empty = overdue.
* @param string $velocity Velocity tier: high | medium | low.
* @return string Status: current | due | overdue.
*/
public static function compute_status( string $last_verified, string $velocity ): string {
if ( empty( $last_verified ) ) {
return 'overdue';
}
$days_since = ( time() - strtotime( $last_verified ) ) / DAY_IN_SECONDS;
$threshold = match ( $velocity ) {
'high' => (int) get_option( 'pr_core_high_velocity_threshold', self::HIGH_VELOCITY_THRESHOLD ),
'low' => self::LOW_VELOCITY_THRESHOLD,
default => (int) get_option( 'pr_core_default_threshold', self::DEFAULT_THRESHOLD_DAYS ),
};
return $days_since < ( $threshold * 0.9 )
? 'current'
: ( $days_since < $threshold ? 'due' : 'overdue' );
}
/**
* Log scan summary to WP option, keeping last N entries.
*