Skip to content

Commit

Permalink
Merge branch 'master' of github.com:botman/studio-addons
Browse files Browse the repository at this point in the history
  • Loading branch information
mpociot committed Aug 28, 2017
2 parents b4f3631 + 6fea393 commit 19c664e
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/Console/Commands/BotManListDrivers.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use GuzzleHttp\Client;
use Illuminate\Console\Command;

class BotManListDriver extends Command
class BotManListDrivers extends Command
{
const DRIVER_REPOSITORY_URL = 'https://botman.io/studio/drivers.json';

Expand Down
79 changes: 74 additions & 5 deletions src/Testing/BotManTester.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class BotManTester

/**
* BotManTester constructor.
*
* @param BotMan $bot
* @param FakeDriver $driver
*/
Expand All @@ -48,7 +49,6 @@ protected function listen()
*/
protected function getReply()
{
$this->listen();
$messages = $this->getMessages();

return array_pop($messages);
Expand All @@ -71,6 +71,9 @@ public function receives($message)
{
$this->driver->messages = [new IncomingMessage($message, $this->username, $this->channel)];

$this->driver->resetBotMessages();
$this->listen();

return $this;
}

Expand All @@ -86,35 +89,72 @@ public function receivesInteractiveMessage($message)
}

/**
* @param $text
* @param $message
* @return $this
*/
public function assertReply($text)
public function assertReply($message)
{
PHPUnit::assertSame($this->getReply()->getText(), $text);
if ($this->getReply() instanceof OutgoingMessage) {
PHPUnit::assertSame($this->getReply()->getText(), $message);
} else {
PHPUnit::assertEquals($message, $this->getReply());
}

return $this;
}

/**
* Assert that there are specific multiple replies.
*
* @param array $expectedMessages
* @return $this
*/
public function assertReplies($expectedMessages)
{
$actualMessages = $this->getMessages();

foreach ($actualMessages as $key => $actualMessage) {
if ($actualMessage instanceof OutgoingMessage) {
PHPUnit::assertSame($expectedMessages[$key], $actualMessage->getText());
} else {
PHPUnit::assertEquals($expectedMessages[$key], $actualMessage);
}
}

return $this;
}

/**
* @param $text
* @return $this
*/
public function assertReplyIsNot($text)
{
PHPUnit::assertNotSame($this->getReply()->getText(), $text);

return $this;
}

/**
* @param array $haystack
* @return $this
*/
public function assertReplyIn(array $haystack)
{
PHPUnit::assertTrue(in_array($this->getReply()->getText(), $haystack));

return $this;
}

/**
* @param array $haystack
* @return $this
*/
public function assertReplyNotIn(array $haystack)
{
PHPUnit::assertFalse(in_array($this->getReply()->getText(), $haystack));

return $this;
}

/**
Expand All @@ -123,7 +163,6 @@ public function assertReplyNotIn(array $haystack)
*/
public function assertQuestion($text = null)
{
$this->listen();
$messages = $this->getMessages();

/** @var Question $question */
Expand All @@ -144,4 +183,34 @@ public function getMessages()
{
return $this->driver->getBotMessages();
}

/**
* @param string $template
* @return $this
*/
public function assertTemplate(string $template)
{
$messages = $this->getMessages();

/** @var Question $question */
$message = array_pop($messages);
PHPUnit::assertInstanceOf($template, $message);

return $this;
}

/**
* @param array $payload
* @return $this
*/
public function assertPayload(array $payload)
{
$messages = $this->getMessages();

/** @var Question $question */
$message = array_pop($messages);
PHPUnit::assertEquals($message->toArray(), $payload);

return $this;
}
}

0 comments on commit 19c664e

Please sign in to comment.