Skip to content

Commit

Permalink
Set correct value for channel in constructor
Browse files Browse the repository at this point in the history
Fixes maknz#3. This was a typo where username from the config was being used for the channel provided through the constructor. This affected users wanting to use the default channel in the config rather than using an explicit to() at runtime.
  • Loading branch information
maknz committed Sep 26, 2014
1 parent f559d6f commit cb4acd2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Maknz/Slack/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,16 @@ class Client {
/**
* Instantiate a new client
*
* @param array $config
* @param \GuzzleHttp\Client $guzzle
* @param string $endpoint The Slack webhook
* @param array $attributes
* @param \GuzzleHttp\Client $guzzle
* @return void
*/
public function __construct($endpoint, array $attributes = [], Guzzle $guzzle = null)
{
$this->setEndpoint($endpoint);

if (isset($attributes['channel'])) $this->setChannel($attributes['username']);
if (isset($attributes['channel'])) $this->setChannel($attributes['channel']);

if (isset($attributes['username'])) $this->setUsername($attributes['username']);

Expand Down
19 changes: 19 additions & 0 deletions tests/ClientUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,25 @@ public function testSetIconToUrl()
$this->assertEquals('http://www.fake.com/someimage.png', $client->getIcon());
}

public function testInstantiationSetsCorrectValues()
{
$data = [
'channel' => '#test',
'username' => 'Test Username',
'icon' => ':heart_eyes:'
];

$client = new Client($this->getEndpoint(), $data);

$this->assertEquals('#test', $client->getChannel());

$this->assertEquals('Test Username', $client->getUsername());

$this->assertEquals(':heart_eyes:', $client->getIcon());

$this->assertEquals(Client::ICON_TYPE_EMOJI, $client->getIconType());
}

private function getClient()
{
return new Client($this->getEndpoint());
Expand Down

0 comments on commit cb4acd2

Please sign in to comment.