Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions src/Models/CompanyPost.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace TruckersMP\APIClient\Models;

use Carbon\Carbon;

class CompanyPost
{
/**
Expand Down Expand Up @@ -53,6 +55,20 @@ class CompanyPost
*/
protected $pinned;

/**
* The date at which the post was last updated at.
*
* @var Carbon
*/
protected $updatedAt;

/**
* The date at which the post was published.
*
* @var Carbon
*/
protected $publishedAt;

/**
* Create a new Post instance.
*
Expand All @@ -72,6 +88,8 @@ public function __construct(array $post)
$this->authorId = $post['author_id'];
$this->author = $post['author'];
$this->pinned = $post['pinned'];
$this->updatedAt = new Carbon($post['updated_at'], 'UTC');
$this->publishedAt = new Carbon($post['published_at'], 'UTC');
}

/**
Expand Down Expand Up @@ -143,4 +161,24 @@ public function isPinned(): bool
{
return $this->pinned;
}

/**
* Get the date which the post was last updated at.
*
* @return Carbon
*/
public function getUpdatedAt(): Carbon
{
return $this->updatedAt;
}

/**
* Get the date which the post was published.
*
* @return Carbon
*/
public function getPublishedAt(): Carbon
{
return $this->publishedAt;
}
}
17 changes: 17 additions & 0 deletions tests/Unit/CompanyPostTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Tests\Unit;

use Carbon\Carbon;
use Tests\TestCase;
use TruckersMP\APIClient\Collections\Company\PostCollection;
use TruckersMP\APIClient\Models\CompanyPost;
Expand Down Expand Up @@ -95,4 +96,20 @@ public function it_is_pinned()

$this->assertIsBool($post->isPinned());
}

/** @test */
public function it_has_an_updated_at()
{
$post = $this->companyPost(self::TEST_COMPANY, self::TEST_POST);

$this->assertInstanceOf(Carbon::class, $post->getUpdatedAt());
}

/** @test */
public function it_has_a_published_at()
{
$post = $this->companyPost(self::TEST_COMPANY, self::TEST_POST);

$this->assertInstanceOf(Carbon::class, $post->getPublishedAt());
}
}