Use better PHPUnit assertions for TelegramLog tests.

parent 9a66af0d
...@@ -29,10 +29,10 @@ class TelegramLogTest extends TestCase ...@@ -29,10 +29,10 @@ class TelegramLogTest extends TestCase
* @var array Dummy logfile paths * @var array Dummy logfile paths
*/ */
private $logfiles = [ private $logfiles = [
'error' => '/tmp/errorlog.log', 'error' => '/tmp/php-telegram-bot-errorlog.log',
'debug' => '/tmp/debuglog.log', 'debug' => '/tmp/php-telegram-bot-debuglog.log',
'update' => '/tmp/updatelog.log', 'update' => '/tmp/php-telegram-bot-updatelog.log',
'external' => '/tmp/externallog.log', 'external' => '/tmp/php-telegram-bot-externallog.log',
]; ];
/** /**
...@@ -82,37 +82,37 @@ class TelegramLogTest extends TestCase ...@@ -82,37 +82,37 @@ class TelegramLogTest extends TestCase
public function testErrorStream() public function testErrorStream()
{ {
$file = $this->logfiles['error']; $file = $this->logfiles['error'];
$this->assertFalse(file_exists($file)); $this->assertFileNotExists($file);
TelegramLog::initErrorLog($file); TelegramLog::initErrorLog($file);
TelegramLog::error('my error'); TelegramLog::error('my error');
$this->assertTrue(file_exists($file)); $this->assertFileExists($file);
$this->assertContains('bot_log.ERROR: my error', file_get_contents($file)); $this->assertContains('bot_log.ERROR: my error', file_get_contents($file));
} }
public function testDebugStream() public function testDebugStream()
{ {
$file = $this->logfiles['debug']; $file = $this->logfiles['debug'];
$this->assertFalse(file_exists($file)); $this->assertFileNotExists($file);
TelegramLog::initDebugLog($file); TelegramLog::initDebugLog($file);
TelegramLog::debug('my debug'); TelegramLog::debug('my debug');
$this->assertTrue(file_exists($file)); $this->assertFileExists($file);
$this->assertContains('bot_log.DEBUG: my debug', file_get_contents($file)); $this->assertContains('bot_log.DEBUG: my debug', file_get_contents($file));
} }
public function testUpdateStream() public function testUpdateStream()
{ {
$file = $this->logfiles['update']; $file = $this->logfiles['update'];
$this->assertFalse(file_exists($file)); $this->assertFileNotExists($file);
TelegramLog::initUpdateLog($file); TelegramLog::initUpdateLog($file);
TelegramLog::update('my update'); TelegramLog::update('my update');
$this->assertTrue(file_exists($file)); $this->assertFileExists($file);
$this->assertContains('my update', file_get_contents($file)); $this->assertContains('my update', file_get_contents($file));
} }
public function testExternalStream() public function testExternalStream()
{ {
$file = $this->logfiles['external']; $file = $this->logfiles['external'];
$this->assertFalse(file_exists($file)); $this->assertFileNotExists($file);
$external_monolog = new Logger('bot_update_log'); $external_monolog = new Logger('bot_update_log');
$external_monolog->pushHandler(new StreamHandler($file, Logger::ERROR)); $external_monolog->pushHandler(new StreamHandler($file, Logger::ERROR));
...@@ -122,7 +122,7 @@ class TelegramLogTest extends TestCase ...@@ -122,7 +122,7 @@ class TelegramLogTest extends TestCase
TelegramLog::error('my error'); TelegramLog::error('my error');
TelegramLog::debug('my debug'); TelegramLog::debug('my debug');
$this->assertTrue(file_exists($file)); $this->assertFileExists($file);
$file_contents = file_get_contents($file); $file_contents = file_get_contents($file);
$this->assertContains('bot_update_log.ERROR: my error', $file_contents); $this->assertContains('bot_update_log.ERROR: my error', $file_contents);
$this->assertContains('bot_update_log.DEBUG: my debug', $file_contents); $this->assertContains('bot_update_log.DEBUG: my debug', $file_contents);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment