Skip to content

Commit

Permalink
Add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
iranianpep committed Jun 5, 2017
1 parent 2b63cae commit 15af32c
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 18 deletions.
2 changes: 2 additions & 0 deletions src/Botonomous/Sender.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ private function getResponseByListenerType()
return 'slashCommand';
case 'event':
return 'slack';
default:
return 'slashCommand';
}
}

Expand Down
1 change: 1 addition & 0 deletions src/Botonomous/Slackbot.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ private function handleUrlVerification()
}

echo $request['challenge'];
return;
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/Botonomous/utility/ClassUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ private function findBooleanPrefix($text)

return $booleanPrefix;
}

return;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Botonomous/utility/LoggerUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ public function logEmergency($message, array $context = [])
*
* @return bool
*/
private function log($level, $message, $context = [])
public function log($level, $message, $context = [])
{
if ($this->canLog() !== true) {
return false;
Expand All @@ -295,7 +295,7 @@ private function log($level, $message, $context = [])
$logger = $this->getLogger();

if (!in_array($level, self::$levels)) {
throw new \Exception("'{$level}' is invalid log level");
throw new \Exception("'{$level}' is an invalid log level");
}

$logger->$level($message, $context);
Expand Down
89 changes: 73 additions & 16 deletions tests/Botonomous/utility/LoggerUtilityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class LoggerUtilityTest extends TestCase
{
const TEST_LOG_FILE = 'bot-test.log';
const TEST_MESSAGE = 'test message';
const TEST_RAW_MESSAGE = 'this is a raw log';
const TEST_INFO_LOG = 'this is an info log';

/**
* Test logChatDisabled.
Expand All @@ -23,11 +23,9 @@ public function testLogChatDisabled()
{
$this->setTimezone();

$config = new Config();
$config->set(['logger', 'enabled'], false);
$this->setLogFile();

$utility = new LoggerUtility($config);
$utility = new LoggerUtility($this->getConfig(false));

$this->assertFalse($utility->logChat(__METHOD__, self::TEST_MESSAGE));
}
Expand All @@ -39,11 +37,9 @@ public function testLogChatEnabled()
{
$this->setTimezone();

$config = new Config();
$config->set(['logger', 'enabled'], true);
$this->setLogFile();

$utility = new LoggerUtility($config);
$utility = new LoggerUtility($this->getConfig());

$this->assertTrue($utility->logChat(__METHOD__, self::TEST_MESSAGE));
}
Expand All @@ -55,13 +51,11 @@ public function testLogRawLogging()
{
$this->setTimezone();

$config = new Config();
$config->set(['logger', 'enabled'], true);
$this->setLogFile();

$utility = new LoggerUtility($config);
$utility = new LoggerUtility($this->getConfig());

$this->assertTrue($utility->logInfo(self::TEST_RAW_MESSAGE));
$this->assertTrue($utility->logInfo(self::TEST_INFO_LOG));
}

/**
Expand All @@ -71,12 +65,9 @@ public function testLogRawNotLogging()
{
$this->setTimezone();

$config = new Config();
$config->set(['logger', 'enabled'], false);

$utility = new LoggerUtility($config);
$utility = new LoggerUtility($this->getConfig(false));

$this->assertFalse($utility->logInfo(self::TEST_RAW_MESSAGE));
$this->assertFalse($utility->logInfo(self::TEST_INFO_LOG));
}

public function setLogFile($name = null)
Expand All @@ -89,6 +80,72 @@ public function setLogFile($name = null)
$config->set(['logger', 'monolog', 'handlers', 'file', 'fileName'], $name);
}

public function testLogNotice()
{
$this->setLogFile();
$utility = new LoggerUtility($this->getConfig());

$this->assertTrue($utility->logNotice('This is a notice log'));
}

public function testLogWarning()
{
$this->setLogFile();
$utility = new LoggerUtility($this->getConfig());

$this->assertTrue($utility->logWarning('This is a warning log'));
}

public function testLogError()
{
$this->setLogFile();
$utility = new LoggerUtility($this->getConfig());

$this->assertTrue($utility->logError('This is an error log'));
}

public function testLogCritical()
{
$this->setLogFile();
$utility = new LoggerUtility($this->getConfig());

$this->assertTrue($utility->logCritical('This is a critical log'));
}

public function testLogAlert()
{
$this->setLogFile();
$utility = new LoggerUtility($this->getConfig());

$this->assertTrue($utility->logAlert('This is an alert log'));
}

public function testLogEmergency()
{
$this->setLogFile();
$utility = new LoggerUtility($this->getConfig());

$this->assertTrue($utility->logEmergency('This is an emergency log'));
}

public function testLogInvalidLevel()
{
$utility = new LoggerUtility($this->getConfig());

$this->expectException('\Exception');
$this->expectExceptionMessage("'invalidLevel' is an invalid log level");

$utility->log('invalidLevel', 'dummyMessage');
}

private function getConfig($loggerEnabled = true)
{
$config = new Config();
$config->set(['logger', 'enabled'], $loggerEnabled === true ? true : false);

return $config;
}

private function setTimezone()
{
$config = new Config();
Expand Down

0 comments on commit 15af32c

Please sign in to comment.