<?php
require __DIR__.'/application/p/logic/MealOrder.php';
class DashboardTenantTest extends \PHPUnit\Framework\TestCase {
 public function testTenantScope() {
  \think\Config::set(['type'=>'sqlite','database'=>':memory:','prefix'=>'ydy_','resultset_type'=>'array'],'database');
  \think\Db::clear();
  \think\Db::execute('CREATE TABLE ydy_meal_order (id INTEGER PRIMARY KEY,store_id INTEGER,restaurant_id INTEGER,order_status INTEGER,refund_status INTEGER,is_delete INTEGER,bind_time TEXT,pay_price REAL,refund_amount REAL)');
  $status=\app\common\enum\order\OrderStatus::COMPLETED;
  foreach ([[1,10001,10],[2,99999,900]] as $row) {
   \think\Db::name('meal_order')->insert(['id'=>$row[0],'store_id'=>$row[1],'restaurant_id'=>$row[2],'order_status'=>$status,'refund_status'=>0,'is_delete'=>0,'bind_time'=>'2026-10-16 12:00:00','pay_price'=>100,'refund_amount'=>0]);
  }
  $logic=(new ReflectionClass(\app\p\logic\MealOrder::class))->newInstanceWithoutConstructor();
  $method=new ReflectionMethod($logic,'buildMobileDashboardPaidOrderQuery'); $method->setAccessible(true);
  $rows=$method->invoke($logic,'2026-10-16','2026-10-16',[])->select();
  echo 'Current store=',getStoreId(),'; dashboard store IDs=',json_encode(array_column($rows,'store_id')),PHP_EOL;
  $this->assertCount(1,$rows,'Dashboard should only query the current tenant');
 }
}
