Skip to content

Commit

Permalink
Clean up the post interface
Browse files Browse the repository at this point in the history
  • Loading branch information
dwightwatson committed Dec 18, 2023
1 parent 5e7c657 commit c6fa663
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 53 deletions.
57 changes: 6 additions & 51 deletions src/FacebookPosterPost.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,15 @@

class FacebookPosterPost
{
/**
* The post message.
*
* @var string
*/
protected $message;

/**
* The post link.
*
* @var string
*/
protected $link;

/**
* Additional post parameters.
*
* @var array
*/
protected array $params = [];

/**
* Create a new post instance.
*
* @param string $message
* @return void
*/
public function __construct($message)
{
$this->message = $message;
public function __construct(
public ?string $message = null,
public ?string $link = null,
public array $params = []
) {
//
}

/**
Expand All @@ -46,14 +25,6 @@ public function withMessage(?string $message)
return $this;
}

/**
* Get the post message.
*/
public function getMessage(): ?string
{
return $this->message;
}

/**
* Set ths post link.
*/
Expand All @@ -64,14 +35,6 @@ public function withLink(?string $link)
return $this;
}

/**
* Get the post link.
*/
public function getLink(): ?string
{
return $this->link;
}

/**
* Set the post params.
*/
Expand All @@ -82,14 +45,6 @@ public function withParams(array $params)
return $this;
}

/**
* Get the post params.
*/
public function getParams(): array
{
return $this->params;
}

/**
* Get the filtered body.
*/
Expand Down
35 changes: 33 additions & 2 deletions tests/FacebookPosterPostTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,41 @@

class FacebookPosterPostTest extends TestCase
{
public function test_it_can_be_instantiated()
{
$post = new FacebookPosterPost('message');

$this->assertInstanceOf(FacebookPosterPost::class, $post);

$result = $post->getBody();

$this->assertEquals([
'message' => 'message',
], $result);
}

public function test_it_can_be_instantiated_with_arguments()
{
$post = new FacebookPosterPost(
message: 'message',
link: 'https://laravel.com',
params: ['foo' => 'bar'],
);

$result = $post->getBody();

$this->assertEquals([
'message' => 'message',
'link' => 'https://laravel.com',
'foo' => 'bar',
], $result);
}

/** @test */
public function it_returns_body()
public function test_it_can_be_instantiated_with_setters()
{
$post = (new FacebookPosterPost('message'))
$post = (new FacebookPosterPost)
->withMessage('message')
->withLink('https://laravel.com')
->withParams([
'foo' => 'bar',
Expand Down

0 comments on commit c6fa663

Please sign in to comment.