Skip to content

Commit 106b029

Browse files
committed
Clean up tests and check coding standards for tests folder too.
1 parent 03abf2f commit 106b029

16 files changed

+89
-166
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
44
## [Unreleased]
55
### Added
66
- Travis CI webhook for Support Bot.
7+
- Ensure coding standards for `tests` folder with `phpcs`.
78
### Changed
89
- All links point to new organisation repo.
910
- Drop PHP 5.5, add PHP 7.1 support.

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
},
4242
"scripts": {
4343
"check-code": [
44-
"./vendor/bin/phpcs --standard=phpcs.xml -snp --encoding=utf-8 src/ --report-width=150"
44+
"./vendor/bin/phpcs --standard=phpcs.xml -snp --encoding=utf-8 src/ tests/ --report-width=150"
4545
],
4646
"test": [
4747
"./vendor/bin/phpunit"

tests/bootstrap.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,15 @@
2121
$autoloader = __DIR__ . '/../vendor/autoload.php';
2222

2323
/*
24-
* Check that --dev composer installation was done
24+
* Check that composer installation was done.
2525
*/
2626
if (!file_exists($autoloader)) {
2727
throw new Exception(
28-
'Please run "php composer.phar install --dev" in root directory '
29-
. 'to setup unit test dependencies before running the tests'
28+
'Please run "composer install" in root directory to setup unit test dependencies before running the tests'
3029
);
3130
}
3231

33-
//Include the Composer autoloader
32+
// Include the Composer autoloader.
3433
require_once $autoloader;
3534

3635
/*

tests/unit/Commands/CommandTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010

1111
namespace Longman\TelegramBot\Tests\Unit\Commands;
1212

13+
use Longman\TelegramBot\Telegram;
1314
use Longman\TelegramBot\Tests\Unit\TestCase;
1415
use Longman\TelegramBot\Tests\Unit\TestHelpers;
15-
use Longman\TelegramBot\Telegram;
1616

1717
/**
1818
* @package TelegramTest
@@ -51,15 +51,15 @@ class CommandTest extends TestCase
5151
public function setUp()
5252
{
5353
//Default command object
54-
$this->telegram = new Telegram(self::$dummy_api_key, 'testbot');
54+
$this->telegram = new Telegram(self::$dummy_api_key, 'testbot');
5555
$this->command_stub = $this->getMockForAbstractClass($this->command_namespace, [$this->telegram]);
5656

5757
//Create separate command object that contain a command config
5858
$this->telegram_with_config = new Telegram(self::$dummy_api_key, 'testbot');
5959
$this->telegram_with_config->setCommandConfig('command_name', ['config_key' => 'config_value']);
6060
$this->command_stub_with_config = $this->getMockBuilder($this->command_namespace)
61-
->disableOriginalConstructor()
62-
->getMockForAbstractClass();
61+
->disableOriginalConstructor()
62+
->getMockForAbstractClass();
6363
//Set a name for the object property so that the constructor can set the config correctly
6464
TestHelpers::setObjectProperty($this->command_stub_with_config, 'name', 'command_name');
6565
$this->command_stub_with_config->__construct($this->telegram_with_config);
@@ -69,7 +69,7 @@ public function setUp()
6969
public function testCommandConstructorNeedsTelegramObject()
7070
{
7171
$exception_count = 0;
72-
$params_to_test = [
72+
$params_to_test = [
7373
[],
7474
[null],
7575
[12345],
@@ -160,7 +160,7 @@ public function testCommandSetUpdateAndMessage()
160160
$this->assertEquals(null, $stub->getUpdate());
161161
$this->assertEquals(null, $stub->getMessage());
162162

163-
$update = TestHelpers::getFakeUpdateObject();
163+
$update = TestHelpers::getFakeUpdateObject();
164164
$message = $update->getMessage();
165165
$stub->setUpdate($update);
166166
$this->assertAttributeEquals($update, 'update', $stub);

tests/unit/Commands/CommandTestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010

1111
namespace Longman\TelegramBot\Tests\Unit\Commands;
1212

13-
use Longman\TelegramBot\Tests\Unit\TestCase;
1413
use Longman\TelegramBot\Telegram;
14+
use Longman\TelegramBot\Tests\Unit\TestCase;
1515

1616
/**
1717
* @package TelegramTest

tests/unit/ConversationTest.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@ class ConversationTest extends TestCase
2727
*/
2828
private $telegram;
2929

30-
/**
31-
* setUp
32-
*/
3330
protected function setUp()
3431
{
3532
$credentials = [
@@ -43,7 +40,7 @@ protected function setUp()
4340
$this->telegram->enableMySql($credentials);
4441

4542
//Make sure we start with an empty DB for each test.
46-
TestHelpers::emptyDB($credentials);
43+
TestHelpers::emptyDb($credentials);
4744
}
4845

4946
public function testConversationThatDoesntExistPropertiesSetCorrectly()

tests/unit/Entities/AudioTest.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ class AudioTest extends TestCase
2626
*/
2727
private $record;
2828

29-
/**
30-
* Set Up
31-
*/
3229
public function setUp()
3330
{
3431
$this->record = TestHelpers::getFakeRecordedAudio();

tests/unit/Entities/FileTest.php

Lines changed: 10 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -21,68 +21,34 @@
2121
*/
2222
class FileTest extends TestCase
2323
{
24-
25-
/**
26-
* lat, long data
27-
*
28-
* @var array
29-
*
30-
*/
31-
public $data;
24+
/**
25+
* @var array
26+
*/
27+
private $data;
3228

33-
/**
34-
*
35-
* Set Up
36-
*
37-
*/
3829
public function setUp()
3930
{
4031
$this->data = [
41-
'file_id' => (int)mt_rand(1, 99),
42-
'file_size' => (int)mt_rand(100, 99999),
43-
'file_path' => 'home' . DIRECTORY_SEPARATOR . 'phpunit'
32+
'file_id' => (int) mt_rand(1, 99),
33+
'file_size' => (int) mt_rand(100, 99999),
34+
'file_path' => 'home' . DIRECTORY_SEPARATOR . 'phpunit',
4435
];
4536
}
4637

47-
/**
48-
*
49-
* TearDown
50-
*
51-
*/
52-
public function tearDown()
53-
{
54-
//pass
55-
}
56-
57-
/**
58-
*
59-
* Testing base stage with data object creating
60-
*
61-
*/
6238
public function testBaseStageLocation()
6339
{
6440
$file = new File($this->data);
6541
$this->assertInstanceOf('Longman\TelegramBot\Entities\File', $file);
6642
}
6743

68-
/**
69-
*
70-
* Testing getFileId
71-
*
72-
*/
7344
public function testGetFileId()
7445
{
7546
$file = new File($this->data);
76-
$id = $file->getFileId();
47+
$id = $file->getFileId();
7748
$this->assertInternalType('int', $id);
7849
$this->assertEquals($this->data['file_id'], $id);
7950
}
80-
81-
/**
82-
*
83-
* Testing getFileSize
84-
*
85-
*/
51+
8652
public function testGetFileSize()
8753
{
8854
$file = new File($this->data);
@@ -91,36 +57,21 @@ public function testGetFileSize()
9157
$this->assertEquals($this->data['file_size'], $size);
9258
}
9359

94-
/**
95-
*
96-
* Testing getFilePath
97-
*
98-
*/
9960
public function testGetFilePath()
10061
{
10162
$file = new File($this->data);
10263
$path = $file->getFilePath();
10364
$this->assertEquals($this->data['file_path'], $path);
10465
}
10566

106-
/**
107-
*
108-
* Testing getFileSize without data
109-
*
110-
*/
11167
public function testGetFileSizeWithoutData()
11268
{
11369
unset($this->data['file_size']);
11470
$file = new File($this->data);
115-
$id = $file->getFileSize();
71+
$id = $file->getFileSize();
11672
$this->assertNull($id);
11773
}
11874

119-
/**
120-
*
121-
* Testing getFilePath without data
122-
*
123-
*/
12475
public function testGetFilePathWithoutData()
12576
{
12677
unset($this->data['file_path']);

tests/unit/Entities/KeyboardTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,9 @@ public function testKeyboardWithButtonObjects()
115115

116116
public function testKeyboardWithDataArray()
117117
{
118-
$resize_keyboard = (bool)mt_rand(0, 1);
119-
$one_time_keyboard = (bool)mt_rand(0, 1);
120-
$selective = (bool)mt_rand(0, 1);
118+
$resize_keyboard = (bool) mt_rand(0, 1);
119+
$one_time_keyboard = (bool) mt_rand(0, 1);
120+
$selective = (bool) mt_rand(0, 1);
121121

122122
$keyboard_obj = new Keyboard([
123123
'resize_keyboard' => $resize_keyboard,

tests/unit/Entities/LocationTest.php

Lines changed: 6 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -21,71 +21,34 @@
2121
*/
2222
class LocationTest extends TestCase
2323
{
24-
25-
/**
26-
* lat, long data
27-
*
28-
* @var array
29-
*
30-
*/
31-
public $coordinates;
24+
private $coordinates;
3225

33-
/**
34-
*
35-
* Set Up
36-
*
37-
*/
3826
public function setUp()
3927
{
4028
$this->coordinates = [
41-
'longitude' => (float)mt_rand(10, 69),
42-
'latitude' => (float)mt_rand(10, 48)
29+
'longitude' => (float) mt_rand(10, 69),
30+
'latitude' => (float) mt_rand(10, 48),
4331
];
4432
}
4533

46-
/**
47-
*
48-
* TearDown
49-
*
50-
*/
51-
public function tearDown()
52-
{
53-
//pass
54-
}
55-
56-
/**
57-
*
58-
* Testing base stage with data object creating
59-
*
60-
*/
6134
public function testBaseStageLocation()
6235
{
6336
$location = new Location($this->coordinates);
6437
$this->assertInstanceOf('Longman\TelegramBot\Entities\Location', $location);
6538
}
6639

67-
/**
68-
*
69-
* Testing getLongitude
70-
*
71-
*/
7240
public function testGetLongitude()
7341
{
7442
$location = new Location($this->coordinates);
75-
$long = $location->getLongitude();
43+
$long = $location->getLongitude();
7644
$this->assertInternalType('float', $long);
7745
$this->assertEquals($this->coordinates['longitude'], $long);
7846
}
79-
80-
/**
81-
*
82-
* Testing getLatitude
83-
*
84-
*/
47+
8548
public function testGetLatitude()
8649
{
8750
$location = new Location($this->coordinates);
88-
$lat = $location->getLatitude();
51+
$lat = $location->getLatitude();
8952
$this->assertInternalType('float', $lat);
9053
$this->assertEquals($this->coordinates['latitude'], $lat);
9154
}

0 commit comments

Comments
 (0)