Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
TelegramBot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kulya
TelegramBot
Commits
b1a89598
Commit
b1a89598
authored
Nov 24, 2016
by
MBoretto
Browse files
Options
Browse Files
Download
Plain Diff
resolve merge conflics
parents
38a86584
32ebf1af
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
437 additions
and
0 deletions
+437
-0
FileTest.php
tests/unit/Entities/FileTest.php
+144
-0
LocationTest.php
tests/unit/Entities/LocationTest.php
+118
-0
WebhookInfoTest.php
tests/unit/Entities/WebhookInfoTest.php
+175
-0
No files found.
tests/unit/Entities/FileTest.php
0 → 100644
View file @
b1a89598
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace
Longman\TelegramBot\Tests\Unit
;
use
Longman\TelegramBot\Entities\File
;
/**
* @package TelegramTest
* @author Baev Nikolay <gametester3d@gmail.com>
* @copyright Avtandil Kikabidze <akalongman@gmail.com>
* @license http://opensource.org/licenses/mit-license.php The MIT License (MIT)
* @link http://www.github.com/akalongman/php-telegram-bot
*/
class
FileTest
extends
TestCase
{
/**
* lat, long data
*
* @var array
*
*/
public
$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'
];
}
/**
*
* 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
);
$id
=
$file
->
getFileId
();
$this
->
assertInternalType
(
'int'
,
$id
);
$this
->
assertEquals
(
$this
->
data
[
'file_id'
],
$id
);
}
/**
*
* Testing getFileSize
*
*/
public
function
testGetFileSize
()
{
$file
=
new
File
(
$this
->
data
);
$size
=
$file
->
getFileSize
();
$this
->
assertInternalType
(
'int'
,
$size
);
$this
->
assertEquals
(
$this
->
data
[
'file_size'
],
$size
);
}
/**
*
* Testing getFilePath
*
*/
public
function
testGetFilePath
()
{
$file
=
new
File
(
$this
->
data
);
$path
=
$file
->
getFilePath
();
$this
->
assertEquals
(
$this
->
data
[
'file_path'
],
$path
);
}
/**
*
* Testing without file id
*
* @expectedException Longman\TelegramBot\Exception\TelegramException
*
*/
public
function
testCreateInstanceWithoutFileId
()
{
unset
(
$this
->
data
[
'file_id'
]);
new
File
(
$this
->
data
);
}
/**
*
* Testing getFileSize without data
*
*/
public
function
testGetFileSizeWithoutData
()
{
unset
(
$this
->
data
[
'file_size'
]);
$file
=
new
File
(
$this
->
data
);
$id
=
$file
->
getFileSize
();
$this
->
assertNull
(
$id
);
}
/**
*
* Testing getFilePath without data
*
*/
public
function
testGetFilePathWithoutData
()
{
unset
(
$this
->
data
[
'file_path'
]);
$file
=
new
File
(
$this
->
data
);
$path
=
$file
->
getFilePath
();
$this
->
assertNull
(
$path
);
}
}
tests/unit/Entities/LocationTest.php
0 → 100644
View file @
b1a89598
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace
Longman\TelegramBot\Tests\Unit
;
use
Longman\TelegramBot\Entities\Location
;
/**
* @package TelegramTest
* @author Baev Nikolay <gametester3d@gmail.com>
* @copyright Avtandil Kikabidze <akalongman@gmail.com>
* @license http://opensource.org/licenses/mit-license.php The MIT License (MIT)
* @link http://www.github.com/akalongman/php-telegram-bot
*/
class
LocationTest
extends
TestCase
{
/**
* 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
)
];
}
/**
*
* 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
);
$long
=
$location
->
getLongitude
();
$this
->
assertInternalType
(
'float'
,
$long
);
$this
->
assertEquals
(
$this
->
coordinates
[
'longitude'
],
$long
);
}
/**
*
* Testing getLatitude
*
*/
public
function
testGetLatitude
()
{
$location
=
new
Location
(
$this
->
coordinates
);
$lat
=
$location
->
getLatitude
();
$this
->
assertInternalType
(
'float'
,
$lat
);
$this
->
assertEquals
(
$this
->
coordinates
[
'latitude'
],
$lat
);
}
/**
*
* Testing without longitude
*
* @expectedException Longman\TelegramBot\Exception\TelegramException
*
*/
public
function
testCreateInstanceWithoutLongitude
()
{
unset
(
$this
->
coordinates
[
'longitude'
]);
new
Location
(
$this
->
coordinates
);
}
/**
*
* Testing without latitude
*
* @expectedException Longman\TelegramBot\Exception\TelegramException
*
*/
public
function
testCreateInstanceWithoutLatitude
()
{
unset
(
$this
->
coordinates
[
'latitude'
]);
new
Location
(
$this
->
coordinates
);
}
}
tests/unit/Entities/WebhookInfoTest.php
0 → 100644
View file @
b1a89598
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace
Longman\TelegramBot\Tests\Unit
;
use
Longman\TelegramBot\Entities\WebhookInfo
;
/**
* @package TelegramTest
* @author Baev Nikolay <gametester3d@gmail.com>
* @copyright Avtandil Kikabidze <akalongman@gmail.com>
* @license http://opensource.org/licenses/mit-license.php The MIT License (MIT)
* @link http://www.github.com/akalongman/php-telegram-bot
*/
class
WebhookInfoTest
extends
TestCase
{
/**
* webhook data
*
* @var array
*
*/
public
$data
;
/**
*
* Set Up
*
*/
public
function
setUp
()
{
$this
->
data
=
[
'url'
=>
'http://phpunit'
,
'has_custom_certificate'
=>
(
bool
)
mt_rand
(
0
,
1
),
'pending_update_count'
=>
(
int
)
mt_rand
(
1
,
9
),
'last_error_date'
=>
time
(),
'last_error_message'
=>
'Same_error_message'
];
}
/**
*
* TearDown
*
*/
public
function
tearDown
()
{
//pass
}
/**
*
* Testing base stage with data object creating
*
*/
public
function
testBaseStageWebhookInfo
()
{
$webhook
=
new
WebhookInfo
(
$this
->
data
);
$this
->
assertInstanceOf
(
'Longman\TelegramBot\Entities\WebhookInfo'
,
$webhook
);
}
/**
*
* Testing getUrl
*
*/
public
function
testGetUrl
()
{
$webhook
=
new
WebhookInfo
(
$this
->
data
);
$url
=
$webhook
->
getUrl
();
$this
->
assertEquals
(
$this
->
data
[
'url'
],
$url
);
}
/**
*
* Testing getHasCustomCertificate
*
*/
public
function
testGetHasCustomCertificate
()
{
$webhook
=
new
WebhookInfo
(
$this
->
data
);
$custom_certificate
=
$webhook
->
getHasCustomCertificate
();
$this
->
assertInternalType
(
'bool'
,
$custom_certificate
);
$this
->
assertEquals
(
$this
->
data
[
'has_custom_certificate'
],
$custom_certificate
);
}
/**
*
* Testing getPendingUpdateCount
*
*/
public
function
testGetPendingUpdateCount
()
{
$webhook
=
new
WebhookInfo
(
$this
->
data
);
$update_count
=
$webhook
->
getPendingUpdateCount
();
$this
->
assertInternalType
(
'int'
,
$update_count
);
$this
->
assertEquals
(
$this
->
data
[
'pending_update_count'
],
$update_count
);
}
/**
*
* Testing getLastErrorDate
*
*/
public
function
testGetLastErrorDate
()
{
$webhook
=
new
WebhookInfo
(
$this
->
data
);
$error_date
=
$webhook
->
getLastErrorDate
();
$this
->
assertInternalType
(
'int'
,
$error_date
);
#$this->assertRegExp('/([0-9]{10,})/', $error_date);
$this
->
assertEquals
(
$this
->
data
[
'last_error_date'
],
$error_date
);
}
/**
*
* Testing getLastErrorMessage
*
*/
public
function
testGetLastErrorMessage
()
{
$webhook
=
new
WebhookInfo
(
$this
->
data
);
$error_msg
=
$webhook
->
getLastErrorMessage
();
$this
->
assertInternalType
(
'string'
,
$error_msg
,
$error_msg
);
$this
->
assertEquals
(
$this
->
data
[
'last_error_message'
],
$error_msg
);
}
/**
*
* Testing get data without params
*
*/
public
function
testGetDataWithoutParams
()
{
unset
(
$this
->
data
[
'url'
]);
$webhook
=
new
WebhookInfo
(
$this
->
data
);
$result
=
$webhook
->
getUrl
();
$this
->
assertNull
(
$result
);
unset
(
$webhook
,
$result
);
unset
(
$this
->
data
[
'has_custom_certificate'
]);
$webhook
=
new
WebhookInfo
(
$this
->
data
);
$result
=
$webhook
->
getHasCustomCertificate
();
$this
->
assertNull
(
$result
);
unset
(
$webhook
,
$result
);
unset
(
$this
->
data
[
'pending_update_count'
]);
$webhook
=
new
WebhookInfo
(
$this
->
data
);
$result
=
$webhook
->
getPendingUpdateCount
();
$this
->
assertNull
(
$result
);
unset
(
$webhook
,
$result
);
unset
(
$this
->
data
[
'last_error_date'
]);
$webhook
=
new
WebhookInfo
(
$this
->
data
);
$result
=
$webhook
->
getLastErrorDate
();
$this
->
assertNull
(
$result
);
unset
(
$webhook
,
$result
);
unset
(
$this
->
data
[
'last_error_message'
]);
$webhook
=
new
WebhookInfo
(
$this
->
data
);
$result
=
$webhook
->
getLastErrorMessage
();
$this
->
assertNull
(
$result
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment