Skip to content
Open
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
17 changes: 14 additions & 3 deletions src/Plugins/BangMessage/Inbound/BangMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,22 @@ class BangMessage extends Message
*/
public function bangCommand()
{
return head(explode(' ', $this->text()));
list($bangCommand, $bangText) = explode(' ', $this->text(), 2);

return ltrim($bangCommand, '!');
}

public function text()
/**
* The bang text
* e.g. the message "!somersault mouse acrobat"
* would return "mouse acrobat" as the bang text
*
* @return string
*/
public function bangText()
{
return ltrim(parent::text(), '!');
list($bangCommand, $bangText) = explode(' ', $this->text(), 2);

return $bangText;
}
}
2 changes: 1 addition & 1 deletion src/Plugins/BangMessage/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Plugin
*/
public function createBangMessage(Message $message)
{
if ($message->text()[0] === '!') {
if (preg_match('/^![^\s]/', $message->text())) {
return BangMessage::from($message);
}

Expand Down
10 changes: 5 additions & 5 deletions tests/Plugins/BangMessage/Inbound/BangMessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,26 @@

namespace Spires\Tests\Plugins\BangMessage\Inbound;

use Spires\Plugins\BangMessage\Inbound\BangMessage;
use Spires\Tests\Resources\SpiresTestCase;
use Spires\Plugins\BangMessage\Inbound\BangMessage;

class BangMessageTest extends SpiresTestCase
{
/**
* @test
*/
function it_returns_the_text_minus_the_bang()
function it_provides_the_bang_command()
{
$bangMessage = BangMessage::from($this->newRawMessage("!foo hello world"));
assertThat($bangMessage->text(), is("foo hello world"));
assertThat($bangMessage->bangCommand(), is("foo"));
}

/**
* @test
*/
function it_provides_the_bang_command()
function it_provides_the_bang_params()
{
$bangMessage = BangMessage::from($this->newRawMessage("!foo hello world"));
assertThat($bangMessage->bangCommand(), is("foo"));
assertThat($bangMessage->bangText(), is("hello world"));
}
}
59 changes: 59 additions & 0 deletions tests/Plugins/BangMessage/PluginTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

namespace Spires\Tests\Plugins\BangMessage;

use Spires\Plugins\BangMessage\Inbound\BangMessage;
use Spires\Plugins\BangMessage\Plugin;
use Spires\Plugins\Message\Inbound\Message;
use Spires\Tests\Resources\SpiresTestCase;

class PluginTest extends SpiresTestCase
{
/**
* @test
*/
public function recognize_just_a_bang_command()
{
$plugin = new Plugin();
$message = Message::from($this->newRawMessage("!foo"));
$bang = $plugin->createBangMessage($message);

assertThat($bang, is(anInstanceOf(BangMessage::class)));
}

/**
* @test
*/
public function recognize_bang_command_with_additional_text()
{
$plugin = new Plugin();
$message = Message::from($this->newRawMessage("!foo hello world"));
$bang = $plugin->createBangMessage($message);

assertThat($bang, is(anInstanceOf(BangMessage::class)));
}

/**
* @test
*/
public function do_not_recognize_if_just_a_bang()
{
$plugin = new Plugin();
$message = Message::from($this->newRawMessage("!"));
$bang = $plugin->createBangMessage($message);

assertThat($bang, is(nullValue()));
}

/**
* @test
*/
public function do_not_recognize_if_space_after_bang()
{
$plugin = new Plugin();
$message = Message::from($this->newRawMessage("! foo"));
$bang = $plugin->createBangMessage($message);

assertThat($bang, is(nullValue()));
}
}
29 changes: 29 additions & 0 deletions tests/helpersTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace Spires;

class helpersTest extends \PHPUnit_Framework_TestCase
{
/**
* @test
*/
public function head_returns_first_element_of_an_array()
{
$array = ['a', 'b', 'c', 'd'];
$first = head($array);

assertThat($first, is('a'));
}

/**
* @test
*/
public function tail_returns_array_without_first_element()
{
$array = ['a', 'b', 'c', 'd'];
$tail = tail($array);

assertThat($tail, is(['b', 'c', 'd']));
}

}