CKTIS / PHP
Testing and assertions
Compare an observable result against an explicit expectation and include boundary cases.
Version: PHP 8.4; repository runtime, production runtime not attested
Syntax
if ($actual !== $expected) { throw new RuntimeException(); }Compare an observable result against an explicit expectation and include boundary cases. Strict comparison detects type changes such as 0 versus "0". PHP assert() can be disabled through zend.assertions, so an always-enforced test can throw on mismatch instead. Exercise both the passing and failing paths of the check.
function check($actual,$expected){if($actual!==$expected)throw new RuntimeException("mismatch");}
check(0,0);echo "pass ";try{check("0",0);}catch(RuntimeException $e){echo $e->getMessage();}
pass mismatch
Examples
<?php
function check($actual,$expected){if($actual!==$expected)throw new RuntimeException("mismatch");}
check(0,0);echo "pass ";try{check("0",0);}catch(RuntimeException $e){echo $e->getMessage();}
Result
pass mismatch