public function testSetFields() { $a = new Attachment(['fallback' => 'Fallback', 'text' => 'Text']); $a->addField(['title' => 'Title 1', 'value' => 'Value 1', 'short' => true])->addField(['title' => 'Title 2', 'value' => 'Value 2', 'short' => true]); $this->assertSame(2, count($a->getFields())); $a->setFields([]); $this->assertSame(0, count($a->getFields())); }
/** * Add an attachment to the message. * * @param mixed $attachment * @return $this */ public function attach($attachment) { if ($attachment instanceof Attachment) { $this->attachments[] = $attachment; return $this; } elseif (is_array($attachment)) { $attachmentObject = new Attachment($attachment); if (!isset($attachment['mrkdwn_in'])) { $attachmentObject->setMarkdownFields($this->getMarkdownInAttachments()); } $this->attachments[] = $attachmentObject; return $this; } throw new InvalidArgumentException('Attachment must be an instance of Maknz\\Slack\\Attachment or a keyed array'); }