Skip to content

Commit

Permalink
Add DateTimeImmutable tests
Browse files Browse the repository at this point in the history
  • Loading branch information
antonkomarev committed Feb 23, 2020
1 parent 27da688 commit 58ac0d6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/RocketChatAttachment.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,10 @@ public function text(string $text): self
public function timestamp($timestamp): self
{
if (! ($timestamp instanceof DateTime) && ! is_string($timestamp)) {
throw new InvalidArgumentException('Timestamp must be string or DateTime, '.gettype($timestamp).' given.');
throw new InvalidArgumentException(sprintf(
'Timestamp must be string or DateTime, %s given.',
get_class($timestamp)
));
}

if ($timestamp instanceof DateTime) {
Expand Down
14 changes: 13 additions & 1 deletion tests/RocketChatAttachmentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace NotificationChannels\RocketChat\Test;

use DateTime;
use DateTimeImmutable;
use NotificationChannels\RocketChat\RocketChatAttachment;
use PHPUnit\Framework\TestCase;

Expand Down Expand Up @@ -63,13 +65,23 @@ public function it_can_set_the_timestamp(): void
/** @test */
public function it_can_set_the_timestamp_as_datetime(): void
{
$date = \DateTime::createFromFormat('Y-m-d H:i:s.u', '2020-02-19 19:00:00.000');
$date = DateTime::createFromFormat('Y-m-d H:i:s.u', '2020-02-19 19:00:00.000');
$attachment = new RocketChatAttachment();
$attachment->timestamp($date);

$this->assertEquals(['ts' => '2020-02-19T19:00:00.000Z'], $attachment->toArray());
}

/** @test */
public function it_can_set_the_timestamp_as_immutable_datetime(): void
{
$date = DateTimeImmutable::createFromFormat('Y-m-d H:i:s.u', '2020-02-19 19:00:00.000');
$attachment = new RocketChatAttachment();
$attachment->timestamp($date);

$this->assertSame(['ts' => '2020-02-19T19:00:00.000Z'], $attachment->toArray());
}

/** @test */
public function it_can_set_the_thumb_url(): void
{
Expand Down

0 comments on commit 58ac0d6

Please sign in to comment.