Skip to content
This repository has been archived by the owner on Feb 20, 2022. It is now read-only.

Commit

Permalink
Add setClient
Browse files Browse the repository at this point in the history
  • Loading branch information
ElfSundae committed Sep 4, 2017
1 parent 78b398a commit fb5d01c
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/Message.php
Expand Up @@ -69,9 +69,7 @@ class Message implements JsonSerializable
*/
public function __construct(Client $client = null)
{
if ($this->client = $client) {
$this->configureDefaults($client->getMessageDefaults(), true);
}
$this->setClient($client);
}

/**
Expand All @@ -84,6 +82,23 @@ public function getClient()
return $this->client;
}

/**
* Set the BearyChat Client instance.
*
* @param \ElfSundae\BearyChat\Client $client
* @return $this
*/
public function setClient($client)
{
if ($client instanceof Client && $this->client != $client) {
$this->configureDefaults($client->getMessageDefaults(), true);
}

$this->client = $client;

return $this;
}

/**
* Get the text.
*
Expand Down
26 changes: 26 additions & 0 deletions tests/MessageTest.php
Expand Up @@ -521,6 +521,32 @@ public function testAddImage()
], $message->toArray());
}

public function testSetClient()
{
$message = new Message;
$client = m::mock(Client::class)
->shouldReceive('getMessageDefaults')
->once()
->andReturn(['user' => 'elf'])
->mock();
$message->setClient($client);
$this->assertSame($client, $message->getClient());
$this->assertSame('elf', $message->getUser());

$message->setClient(null);
$this->assertNull($message->getClient());

$client = m::mock(Client::class)
->shouldReceive('getMessageDefaults')
->once()
->andReturn(['user' => 'sundae', 'markdown' => false])
->mock();
$message->setClient($client);
$this->assertSame($client, $message->getClient());
$this->assertSame('elf', $message->getUser());
$this->assertSame(false, $message->getMarkdown());
}

protected function getClient($defaults = ['user' => 'elf', 'notification' => 'noti', 'attachment_color' => '#f00'])
{
return m::mock(Client::class)
Expand Down

0 comments on commit fb5d01c

Please sign in to comment.