Commit 2d32beca authored by Armando Lüscher's avatar Armando Lüscher

Fix a few base test classes.

parent f6cf49fe
<?php <?php
/* /**
* This file is part of the TelegramBot package. * This file is part of the TelegramBot package.
* *
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com> * (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
...@@ -7,7 +7,9 @@ ...@@ -7,7 +7,9 @@
* For the full copyright and license information, please view the LICENSE * For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
namespace Tests; namespace Tests;
/* /*
* Set error reporting to the max level. * Set error reporting to the max level.
*/ */
...@@ -18,24 +20,22 @@ error_reporting(-1); ...@@ -18,24 +20,22 @@ error_reporting(-1);
*/ */
date_default_timezone_set('UTC'); date_default_timezone_set('UTC');
$autoloader = __DIR__ . '/../vendor/autoload.php';
$root = realpath(dirname(dirname(__FILE__))); /*
/**
* Check that --dev composer installation was done * Check that --dev composer installation was done
*/ */
if (!file_exists($root . '/vendor/autoload.php')) { if (!file_exists($autoloader)) {
throw new \Exception( throw new \Exception(
'Please run "php composer.phar install --dev" in root directory ' 'Please run "php composer.phar install --dev" in root directory '
. 'to setup unit test dependencies before running the tests' . 'to setup unit test dependencies before running the tests'
); );
} }
// Include the Composer autoloader //Include the Composer autoloader
$loader = require __DIR__ . '/../vendor/autoload.php'; require_once $autoloader;
/* /*
* Unset global variables that are no longer needed. * Unset global variables that are no longer needed.
*/ */
unset($root, $loader); unset($autoloader);
<?php <?php
/* /**
* This file is part of the TelegramBot package. * This file is part of the TelegramBot package.
* *
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com> * (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
...@@ -7,9 +7,10 @@ ...@@ -7,9 +7,10 @@
* For the full copyright and license information, please view the LICENSE * For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
namespace Tests\Unit; namespace Tests\Unit;
use \Longman\TelegramBot\Telegram; use Longman\TelegramBot\Telegram;
/** /**
* @package TelegramTest * @package TelegramTest
...@@ -25,7 +26,6 @@ class TelegramTest extends TestCase ...@@ -25,7 +26,6 @@ class TelegramTest extends TestCase
*/ */
private $telegram; private $telegram;
/** /**
* setUp * setUp
*/ */
...@@ -34,51 +34,56 @@ class TelegramTest extends TestCase ...@@ -34,51 +34,56 @@ class TelegramTest extends TestCase
$this->telegram = new Telegram('testapikey', 'testbotname'); $this->telegram = new Telegram('testapikey', 'testbotname');
} }
/** /**
* @test * @test
* @expectedException \Longman\TelegramBot\Exception\TelegramException * @expectedException \Longman\TelegramBot\Exception\TelegramException
*/ */
public function newInstanceWithoutParams() { public function newInstanceWithoutApiKeyParam()
$telegram = new Telegram('testapikey', null); {
$telegram = new Telegram(null, 'test'); new Telegram(null, 'testbotname');
} }
/** /**
* @test * @test
* @expectedException \Longman\TelegramBot\Exception\TelegramException
*/ */
public function getCommandsList() { public function newInstanceWithoutBotNameParam()
$commands = $this->telegram->getCommandsList(); {
$this->assertInternalType('array', $commands); new Telegram('testapikey', null);
$this->assertNotCount(0, $commands);
} }
/** /**
* @test * @test
*/ */
public function getCommandsClass() { public function getApiKey()
$command = $this->telegram->getCommandClass('help'); {
$this->assertInstanceOf('Longman\TelegramBot\Commands\HelpCommand', $command); $this->assertEquals('testapikey', $this->telegram->getApiKey());
} }
/** /**
* @test * @test
*/ */
public function getApiKey() { public function getBotName()
$this->assertEquals('testapikey', $this->telegram->getApiKey()); {
$this->assertEquals('testbotname', $this->telegram->getBotName());
} }
/** /**
* @test * @test
*/ */
public function getBotName() { public function getCommandsList()
$this->assertEquals('testbotname', $this->telegram->getBotName()); {
$commands = $this->telegram->getCommandsList();
$this->assertInternalType('array', $commands);
$this->assertNotCount(0, $commands);
} }
/**
* @test
*/
public function getHelpCommandObject()
{
$command = $this->telegram->getCommandObject('help');
$this->assertInstanceOf('Longman\TelegramBot\Commands\UserCommands\HelpCommand', $command);
}
} }
...@@ -12,5 +12,4 @@ class TestCase extends \PHPUnit_Framework_TestCase ...@@ -12,5 +12,4 @@ class TestCase extends \PHPUnit_Framework_TestCase
); );
} }
} }
} }
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