2,'SKU_PROPERTY_ID'=>99];} } class CIBlockElement { public $LAST_ERROR='fixture failure'; static $count=0; function Add($fields){self::$count++;$GLOBALS['calls'][]=['element',$fields];if(($GLOBALS['scenario']==='product'&&self::$count===1)||($GLOBALS['scenario']==='offer'&&self::$count===2))return false;return self::$count===1?101:202;} } class CCatalogProduct { static function Add($fields){$GLOBALS['calls'][]=['catalog',$fields];return $GLOBALS['scenario']!=='catalog';} } class CPrice { static function SetBasePrice($id,$price,$currency){$GLOBALS['calls'][]=['price',$id,$price,$currency];return $GLOBALS['scenario']!=='price';} } function must($condition,$message){if(!$condition)throw new \RuntimeException($message);} foreach(['module','relation','product','offer','catalog','price','success'] as $scenario){ $GLOBALS['scenario']=$scenario;$GLOBALS['calls']=[];CIBlockElement::$count=0;$error=null; try{include __DIR__.'/offer-example.php';}catch(\RuntimeException $e){$error=$e->getMessage();} must(($error===null)===($scenario==='success'),'wrong success/failure for '.$scenario); if($scenario==='success'){ must($offerId===202&&$productId===101,'IDs not preserved'); must($GLOBALS['calls'][1][1]['PROPERTY_VALUES'][99]===101,'offer must reference product'); must($GLOBALS['calls'][2][1]['ID']===202,'catalog parameters must use offerId'); must($GLOBALS['calls'][3][1]===202,'price must use offerId'); } $length=['module'=>0,'relation'=>0,'product'=>1,'offer'=>2,'catalog'=>3,'price'=>4,'success'=>4][$scenario];must(count($GLOBALS['calls'])===$length,'operation continued after failure: '.$scenario); echo $scenario.': passed'.PHP_EOL; } echo 'Contract fixture only: no real Bitrix/database integration was executed.'.PHP_EOL; }