['127.0.0.1']]); $missingLabelLog = OperationLog::query()->create($this->operationLogData([ 'ip_address' => '192.168.1.10', 'user_label' => null, ])); $emptyLabelLog = OperationLog::query()->create($this->operationLogData([ 'ip_address' => '192.168.1.10', 'user_label' => '', ])); $existingLabelLog = OperationLog::query()->create($this->operationLogData([ 'ip_address' => '192.168.1.10', 'user_label' => 'lisi', ])); $otherIpLog = OperationLog::query()->create($this->operationLogData([ 'ip_address' => '192.168.1.11', 'user_label' => null, ])); $response = $this->postJson('/api/admin/ip-user-mappings', [ 'ip_address' => '192.168.1.10', 'user_name' => 'zhangsan', 'remark' => 'dev', ]); $response->assertOk() ->assertJsonPath('success', true) ->assertJsonPath('data.synced_operation_logs_count', 2); $this->assertSame('zhangsan', $missingLabelLog->refresh()->user_label); $this->assertSame('zhangsan', $emptyLabelLog->refresh()->user_label); $this->assertSame('lisi', $existingLabelLog->refresh()->user_label); $this->assertNull($otherIpLog->refresh()->user_label); } /** * @param array $overrides * @return array */ private function operationLogData(array $overrides = []): array { return array_merge([ 'ip_address' => '127.0.0.1', 'user_label' => null, 'method' => 'POST', 'path' => '/api/test', 'route_name' => null, 'status_code' => 200, 'duration_ms' => 12, 'request_payload' => [], 'user_agent' => 'PHPUnit', ], $overrides); } }