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