<?php
function config($key){return $GLOBALS['database_type'];}
function getImgFullPath($path='',$exist=false){return $path?'media:'.$path:'';}
class NutritionProductRows {
 public $rows=[];public $one;
 public function inquiryCount(...$args){return count($this->rows);}
 public function inquiryNutrition(...$args){return $this->rows;}
 public function inquiryColumn(...$args){return ['测试分类'];}
 public function read(...$args){return $this->one;}
}
require $argv[1];require $argv[2];
$p=(new ReflectionClass(\app\p\logic\Nutrition::class))->newInstanceWithoutConstructor();$m=(new ReflectionClass(\app\m\logic\Nutrition::class))->newInstanceWithoutConstructor();$model=new NutritionProductRows();
foreach([$p,$m] as $logic){foreach(['model','modelNutritionCategory'] as $key){$prop=new ReflectionProperty($logic,$key);$prop->setAccessible(true);$prop->setValue($logic,$model);}}
$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,'other_time'=>$value,'employ'=>1,'nutrition_category_uuid'=>'fixture-category','specifications'=>'规格','img_path'=>'image','source_img_path'=>'source','app_img'=>'app'];$model->rows=[$row];$model->one=$row;$expected=$row;$expected['create_time']=$want;
  $pcList=$expected;foreach(['img_path','source_img_path','app_img'] as $key)$pcList[$key]='media:'.$expected[$key];$check($p->lists(['is_del'=>1],1,10,[],['*'])['data'],['total'=>1,'rows'=>[$pcList],'nutrition_sum'=>1],$type.':p lists '.$index);
  $mobileList=$expected;foreach(['img_path','source_img_path'] as $key)$mobileList[$key]='media:'.$expected[$key];$check($m->lists(['is_del'=>1],1,10,[],['*'])['data'],['total'=>1,'rows'=>[$mobileList],'nutrition_sum'=>1],$type.':m lists '.$index);
  $pcInfo=$expected;$pcInfo['nutrition_category_name']='测试分类';foreach(['img_path','app_img'] as $key)$pcInfo[$key]='media:'.$expected[$key];$check($p->info('fixture')['data'],$pcInfo,$type.':p info '.$index);
  $mobileInfo=$expected;foreach(['img_path','source_img_path','app_img'] as $key)$mobileInfo[$key]='media:'.$expected[$key];$check($m->info('fixture')['data'],$mobileInfo,$type.':m info '.$index);
 }
 $model->rows=[];$check($p->lists([],1,10,[],['*'])['data'],['total'=>0,'rows'=>[],'nutrition_sum'=>0],$type.':p empty');$check($m->lists([],1,10,[],['*'])['data'],['rows'=>[],'nutrition_sum'=>0],$type.':m empty');
}
echo json_encode(['passed'=>$failed===[],'assertions'=>$n,'failures'=>$failed]),"\n";exit($failed===[]?0:2);
