CKTIS / PHP
Test e asserzioni
Confrontare un risultato osservabile con un’attesa esplicita includendo i limiti.
Versione: PHP 8.4; repository runtime, production runtime not attested
Sintassi
if ($actual !== $expected) { throw new RuntimeException(); }Confrontare un risultato osservabile con un’attesa esplicita includendo i limiti. Il confronto stretto rileva tipi diversi come 0 e «0». assert() può essere disattivato da zend.assertions, quindi un test sempre attivo può lanciare in caso di differenza. Provare successo e fallimento.
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
Esempi
<?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();}
Risultato
pass mismatch