<?php
namespace oss {class OSSServer {public static function getInstance(){return new self();}public function getConfig(){return ['fileUrlPrefix'=>'media-prefix/'];}}}
namespace {
function config($key){return $GLOBALS['database_type'];}
function getImgFullPath($path='',$exist=false){return $path?'media:'.$path:'';}
class TemplateStationRows {public $rows=[];public $one;public function inquiryCount(...$args){return count($this->rows);}public function inquiry(...$args){return $this->rows;}public function inquiryTemplate(...$args){return $this->rows;}public function inquiryAllInfo(...$args){return [];}public function inquiryInfo(...$args){return [];}public function inquiryColumn(...$args){return [];}public function read(...$args){return $this->one;}}
require $argv[1];require $argv[2];$template=(new \ReflectionClass(\app\p\logic\NutritionTemplate::class))->newInstanceWithoutConstructor();$station=(new \ReflectionClass(\app\p\logic\NutritionStation::class))->newInstanceWithoutConstructor();$model=new TemplateStationRows();$ext=new TemplateStationRows();
foreach([$template,$station] as $logic){$property=new \ReflectionProperty($logic,'model');$property->setAccessible(true);$property->setValue($logic,$model);}
$property=new \ReflectionProperty($template,'modelExt');$property->setAccessible(true);$property->setValue($template,$ext);$station->modelExt=$ext;$property=new \ReflectionProperty($station,'modelAnnex');$property->setAccessible(true);$property->setValue($station,$ext);
$n=0;$failed=[];$check=static function($actual,$want,$label)use(&$n,&$failed){$n++;if($actual!==$want)$failed[]=$label;};
$samples=[['2001-02-03 04:05:06.000000','2001-02-03 04:05:06'],['2024-02-29 23:59:59.0','2024-02-29 23:59:59'],['2001-02-03 04:05:06.123456','2001-02-03 04:05:06.123456'],['2001-02-29 04:05:06.000000','2001-02-29 04:05:06.000000'],['2001-02-03 24:05:06.000000','2001-02-03 24:05:06.000000'],['2001-02-03 04:60:06.000000','2001-02-03 04:60:06.000000'],['2001-02-03 04:05:60.000000','2001-02-03 04:05:60.000000'],['0999-02-03 04:05:06.000000','0999-02-03 04:05:06.000000'],['2001-02-03 04:05:06.0000000','2001-02-03 04:05:06.0000000'],['0000-00-00 00:00:00.000000','0000-00-00 00:00:00.000000'],['2001-02-03 04:05:06','2001-02-03 04:05:06'],['',''],[null,null],[0,0],[0.0,0.0],[false,false]];
foreach(['mysql','app\\cores\\database\\Dm'] as $type){$GLOBALS['database_type']=$type;foreach($samples as $index=>$sample){[$value,$want]=$sample;if($type==='mysql')$want=$value;$row=['id'=>1,'uuid'=>'fixture','name'=>'模板/站点','create_time'=>$value,'date'=>$value,'other_time'=>$value,'img_path'=>'image','version'=>1];$model->rows=[$row];$model->one=$row;
 $expected=$row;$expected['create_time']=$want;$check($template->lists([],1,10,[],['*'])['data'],['total'=>1,'rows'=>[$expected]],$type.':template lists '.$index);$expected['template_ext']=[];$check($template->info('fixture')['data'],$expected,$type.':template info '.$index);
 $expected=$row;$expected['date']=$want;$expected['img_path']='media:image';$check($station->lists([],1,3,[],['*'])['data'],['total'=>1,'rows'=>[$expected]],$type.':station lists '.$index);$expected['nutrition_ext']=[];$expected['file_path']=[];$expected['fileUrlPrefix']='media-prefix/';$check($station->info('fixture')['data'],$expected,$type.':station info '.$index);
 }
 $model->rows=[];$check($template->lists([],1,10,[],['*'])['data'],['total'=>0,'rows'=>[]],$type.':empty template');$check($station->lists([],1,3,[],['*'])['data'],['total'=>0,'rows'=>[]],$type.':empty station');$model->one=false;$check($template->info('missing')['code'],1,$type.':missing template');$check($station->info('missing')['code'],1,$type.':missing station');
}
echo json_encode(['passed'=>$failed===[],'assertions'=>$n,'failures'=>$failed]),"\n";exit($failed===[]?0:2);
}
