public function run() { ApiMessage::create(['sent_id' => '1', 'receiver_id' => '2', 'message' => 'message test 1', 'status' => '1']); ApiMessage::create(['sent_id' => '1', 'receiver_id' => '2', 'message' => 'message test 2', 'status' => '1']); ApiMessage::create(['sent_id' => '2', 'receiver_id' => '1', 'message' => 'message test 3', 'status' => '1']); ApiMessage::create(['sent_id' => '2', 'receiver_id' => '1', 'message' => 'message test 4', 'status' => '1']); ApiMessage::create(['sent_id' => '2', 'receiver_id' => '1', 'message' => 'message test 5', 'status' => '1']); ApiMessage::create(['sent_id' => '1', 'receiver_id' => '3', 'message' => 'message test 6', 'status' => '1']); }
/** * Add warnings and errors from a Status object to the result * @param string $moduleName * @param Status $status * @param string[] $types 'warning' and/or 'error' */ public function addMessagesFromStatus($moduleName, Status $status, $types = ['warning', 'error']) { if ($status->isGood() || !$status->errors) { return; } $types = (array) $types; foreach ($status->errors as $error) { if (!in_array($error['type'], $types, true)) { continue; } if ($error['type'] === 'error') { $tag = 'error'; } else { // Assume any unknown type is a warning $tag = 'warning'; } if (is_array($error) && isset($error['message'])) { // Normal case if ($error['message'] instanceof Message) { $msg = ApiMessage::create($error['message'], null, []); } else { $args = isset($error['params']) ? $error['params'] : []; array_unshift($args, $error['message']); $error += ['params' => []]; $msg = ApiMessage::create($args, null, []); } } elseif (is_array($error)) { // Weird case handled by Message::getErrorMessage $msg = ApiMessage::create($error, null, []); } else { // Another weird case handled by Message::getErrorMessage $msg = ApiMessage::create($error, null, []); } $msg->inLanguage($this->lang)->title($this->getDummyTitle())->useDatabase($this->useDB); $this->addWarningOrError($tag, $moduleName, $msg); } }
/** * @covers ApiMessage::create */ public function testApiMessageCreate() { $this->assertInstanceOf('ApiMessage', ApiMessage::create(new Message('mainpage'))); $this->assertInstanceOf('ApiRawMessage', ApiMessage::create(new RawMessage('mainpage'))); $this->assertInstanceOf('ApiMessage', ApiMessage::create('mainpage')); $msg = new ApiMessage('mainpage'); $this->assertSame($msg, ApiMessage::create($msg)); $msg = new ApiRawMessage('mainpage'); $this->assertSame($msg, ApiMessage::create($msg)); }
public static function createNewMessage($input, $id, $table = null) { if ($table) { $inputMsg = ['sent_id' => $input['user_id'], 'receiver_id' => $id, 'message' => $input['message'], 'status' => INACTIVE]; } else { $inputMsg = ['sent_id' => $input['user_id'], 'receiver_id' => $id, 'message' => $input['message'], 'status' => INACTIVE]; } $messageId = ApiMessage::create($inputMsg)->id; return $messageId; }