Clean up tests and check coding standards for tests folder too.

parent 03abf2f4
......@@ -4,6 +4,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
## [Unreleased]
### Added
- Travis CI webhook for Support Bot.
- Ensure coding standards for `tests` folder with `phpcs`.
### Changed
- All links point to new organisation repo.
- Drop PHP 5.5, add PHP 7.1 support.
......
......@@ -41,7 +41,7 @@
},
"scripts": {
"check-code": [
"./vendor/bin/phpcs --standard=phpcs.xml -snp --encoding=utf-8 src/ --report-width=150"
"./vendor/bin/phpcs --standard=phpcs.xml -snp --encoding=utf-8 src/ tests/ --report-width=150"
],
"test": [
"./vendor/bin/phpunit"
......
......@@ -21,16 +21,15 @@ date_default_timezone_set('UTC');
$autoloader = __DIR__ . '/../vendor/autoload.php';
/*
* Check that --dev composer installation was done
* Check that composer installation was done.
*/
if (!file_exists($autoloader)) {
throw new Exception(
'Please run "php composer.phar install --dev" in root directory '
. 'to setup unit test dependencies before running the tests'
'Please run "composer install" in root directory to setup unit test dependencies before running the tests'
);
}
//Include the Composer autoloader
// Include the Composer autoloader.
require_once $autoloader;
/*
......
......@@ -10,9 +10,9 @@
namespace Longman\TelegramBot\Tests\Unit\Commands;
use Longman\TelegramBot\Telegram;
use Longman\TelegramBot\Tests\Unit\TestCase;
use Longman\TelegramBot\Tests\Unit\TestHelpers;
use Longman\TelegramBot\Telegram;
/**
* @package TelegramTest
......
......@@ -10,8 +10,8 @@
namespace Longman\TelegramBot\Tests\Unit\Commands;
use Longman\TelegramBot\Tests\Unit\TestCase;
use Longman\TelegramBot\Telegram;
use Longman\TelegramBot\Tests\Unit\TestCase;
/**
* @package TelegramTest
......
......@@ -27,9 +27,6 @@ class ConversationTest extends TestCase
*/
private $telegram;
/**
* setUp
*/
protected function setUp()
{
$credentials = [
......@@ -43,7 +40,7 @@ class ConversationTest extends TestCase
$this->telegram->enableMySql($credentials);
//Make sure we start with an empty DB for each test.
TestHelpers::emptyDB($credentials);
TestHelpers::emptyDb($credentials);
}
public function testConversationThatDoesntExistPropertiesSetCorrectly()
......
......@@ -26,9 +26,6 @@ class AudioTest extends TestCase
*/
private $record;
/**
* Set Up
*/
public function setUp()
{
$this->record = TestHelpers::getFakeRecordedAudio();
......
......@@ -21,55 +21,26 @@ use Longman\TelegramBot\Entities\File;
*/
class FileTest extends TestCase
{
/**
* lat, long data
*
* @var array
*
*/
public $data;
private $data;
/**
*
* Set Up
*
*/
public function setUp()
{
$this->data = [
'file_id' => (int)mt_rand(1, 99),
'file_size' => (int)mt_rand(100, 99999),
'file_path' => 'home' . DIRECTORY_SEPARATOR . 'phpunit'
'file_id' => (int) mt_rand(1, 99),
'file_size' => (int) mt_rand(100, 99999),
'file_path' => 'home' . DIRECTORY_SEPARATOR . 'phpunit',
];
}
/**
*
* TearDown
*
*/
public function tearDown()
{
//pass
}
/**
*
* Testing base stage with data object creating
*
*/
public function testBaseStageLocation()
{
$file = new File($this->data);
$this->assertInstanceOf('Longman\TelegramBot\Entities\File', $file);
}
/**
*
* Testing getFileId
*
*/
public function testGetFileId()
{
$file = new File($this->data);
......@@ -78,11 +49,6 @@ class FileTest extends TestCase
$this->assertEquals($this->data['file_id'], $id);
}
/**
*
* Testing getFileSize
*
*/
public function testGetFileSize()
{
$file = new File($this->data);
......@@ -91,11 +57,6 @@ class FileTest extends TestCase
$this->assertEquals($this->data['file_size'], $size);
}
/**
*
* Testing getFilePath
*
*/
public function testGetFilePath()
{
$file = new File($this->data);
......@@ -103,11 +64,6 @@ class FileTest extends TestCase
$this->assertEquals($this->data['file_path'], $path);
}
/**
*
* Testing getFileSize without data
*
*/
public function testGetFileSizeWithoutData()
{
unset($this->data['file_size']);
......@@ -116,11 +72,6 @@ class FileTest extends TestCase
$this->assertNull($id);
}
/**
*
* Testing getFilePath without data
*
*/
public function testGetFilePathWithoutData()
{
unset($this->data['file_path']);
......
......@@ -115,9 +115,9 @@ class KeyboardTest extends TestCase
public function testKeyboardWithDataArray()
{
$resize_keyboard = (bool)mt_rand(0, 1);
$one_time_keyboard = (bool)mt_rand(0, 1);
$selective = (bool)mt_rand(0, 1);
$resize_keyboard = (bool) mt_rand(0, 1);
$one_time_keyboard = (bool) mt_rand(0, 1);
$selective = (bool) mt_rand(0, 1);
$keyboard_obj = new Keyboard([
'resize_keyboard' => $resize_keyboard,
......
......@@ -21,54 +21,22 @@ use Longman\TelegramBot\Entities\Location;
*/
class LocationTest extends TestCase
{
private $coordinates;
/**
* lat, long data
*
* @var array
*
*/
public $coordinates;
/**
*
* Set Up
*
*/
public function setUp()
{
$this->coordinates = [
'longitude' => (float)mt_rand(10, 69),
'latitude' => (float)mt_rand(10, 48)
'longitude' => (float) mt_rand(10, 69),
'latitude' => (float) mt_rand(10, 48),
];
}
/**
*
* TearDown
*
*/
public function tearDown()
{
//pass
}
/**
*
* Testing base stage with data object creating
*
*/
public function testBaseStageLocation()
{
$location = new Location($this->coordinates);
$this->assertInstanceOf('Longman\TelegramBot\Entities\Location', $location);
}
/**
*
* Testing getLongitude
*
*/
public function testGetLongitude()
{
$location = new Location($this->coordinates);
......@@ -77,11 +45,6 @@ class LocationTest extends TestCase
$this->assertEquals($this->coordinates['longitude'], $long);
}
/**
*
* Testing getLatitude
*
*/
public function testGetLatitude()
{
$location = new Location($this->coordinates);
......
......@@ -23,10 +23,23 @@ class ReplyToMessageTest extends TestCase
{
public function testChatType()
{
$json = '
{"update_id":137809335,
"message":{"message_id":4479,"from":{"id":123,"first_name":"John","username":"MJohn"},"chat":{"id":-123,"title":"MyChat","type":"group"},"date":1449092987,"reply_to_message":{"message_id":11,"from":{"id":121,"first_name":"Myname","username":"mybot"},"chat":{"id":-123,"title":"MyChat","type":"group"},"date":1449092984,"text":"type some text"},"text":"some text"}}
';
$json = '{
"update_id":137809335,
"message":{
"message_id":4479,
"from":{"id":123,"first_name":"John","username":"MJohn"},
"chat":{"id":-123,"title":"MyChat","type":"group"},
"date":1449092987,
"reply_to_message":{
"message_id":11,
"from":{"id":121,"first_name":"Myname","username":"mybot"},
"chat":{"id":-123,"title":"MyChat","type":"group"},
"date":1449092984,
"text":"type some text"
},
"text":"some text"
}
}';
$update = new Update(json_decode($json, true), 'mybot');
$reply_to_message = $update->getMessage()->getReplyToMessage();
......
......@@ -60,8 +60,8 @@ class ServerResponseTest extends TestCase
self::assertEquals('Mjohn', $server_result->getChat()->getUsername());
self::assertEquals('1441378360', $server_result->getDate());
self::assertEquals('hello', $server_result->getText());
//... they are not finished...
//... they are not finished...
}
public function sendMessageFail()
......
......@@ -23,10 +23,24 @@ class UpdateTest extends TestCase
{
public function testUpdateCast()
{
$json = '
{"update_id":137809336,
"message":{"message_id":4479,"from":{"id":123,"first_name":"John","username":"MJohn"},"chat":{"id":-123,"title":"MyChat","type":"group"},"date":1449092987,"reply_to_message":{"message_id":11,"from":{"id":121,"first_name":"Myname","username":"mybot"},"chat":{"id":-123,"title":"MyChat","type":"group"},"date":1449092984,"text":"type some text"},"text":"some text"}}
';
$json = '{
"update_id":137809336,
"message":{
"message_id":4479,
"from":{"id":123,"first_name":"John","username":"MJohn"},
"chat":{"id":-123,"title":"MyChat","type":"group"},
"date":1449092987,
"reply_to_message":{
"message_id":11,
"from":{"id":121,"first_name":"Myname","username":"mybot"},
"chat":{"id":-123,"title":"MyChat","type":"group"},
"date":1449092984,
"text":"type some text"
},
"text":"some text"
}
}';
$struct = json_decode($json, true);
$update = new Update($struct, 'mybot');
......
......@@ -33,18 +33,12 @@ class TelegramLogTest extends TestCase
'external' => '/tmp/php-telegram-bot-externallog.log',
];
/**
* setUp
*/
protected function setUp()
{
// Make sure no monolog instance is set before each test.
TestHelpers::setStaticProperty('Longman\TelegramBot\TelegramLog', 'monolog', null);
}
/**
* tearDown
*/
protected function tearDown()
{
// Make sure no logfiles exist.
......
......@@ -35,9 +35,6 @@ class TelegramTest extends TestCase
'/tmp/php-telegram-bot-custom-commands-3',
];
/**
* setUp
*/
protected function setUp()
{
$this->telegram = new Telegram(self::$dummy_api_key, 'testbot');
......@@ -48,9 +45,6 @@ class TelegramTest extends TestCase
}
}
/**
* tearDown
*/
protected function tearDown()
{
// Clean up the custom commands paths.
......
......@@ -97,7 +97,7 @@ class TestHelpers
'id' => mt_rand(),
],
'date' => time(),
]
],
];
return new Update($data, 'testbot');
}
......@@ -162,11 +162,11 @@ class TestHelpers
$mime_type = ['audio/ogg', 'audio/mpeg', 'audio/vnd.wave', 'audio/x-ms-wma', 'audio/basic'];
$data = [
'file_id' => mt_rand(1, 999),
'duration' => (string)mt_rand(1, 99) . ':' . mt_rand(1, 60),
'duration' => (string) mt_rand(1, 99) . ':' . mt_rand(1, 60),
'performer' => 'phpunit',
'title' => 'track from phpunit',
'mime_type' => $mime_type[array_rand($mime_type, 1)],
'file_size' => mt_rand(1, 99999)
'file_size' => mt_rand(1, 99999),
];
return $data;
......@@ -225,7 +225,7 @@ class TestHelpers
*
* @param array $credentials
*/
public static function emptyDB(array $credentials)
public static function emptyDb(array $credentials)
{
$dsn = 'mysql:host=' . $credentials['host'] . ';dbname=' . $credentials['database'];
$options = [\PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'];
......
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