Skip to content
This repository was archived by the owner on Sep 2, 2025. It is now read-only.

Commit 501a020

Browse files
committed
More tests, specifically with chosen_inline_result
1 parent 0b71f7f commit 501a020

File tree

6 files changed

+110
-49
lines changed

6 files changed

+110
-49
lines changed

src/InternalFunctionality/FormConstructor.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class FormConstructor
1010
* @param TelegramMethods $method
1111
* @return mixed
1212
*/
13-
private function constructFormData(TelegramMethods $method): array
13+
public function constructFormData(TelegramMethods $method): array
1414
{
1515
$result = $this->checkSpecialConditions($method);
1616

@@ -40,8 +40,10 @@ private function constructFormData(TelegramMethods $method): array
4040
* @param TelegramMethods $method
4141
* @return array
4242
*/
43-
private function checkSpecialConditions(TelegramMethods $method): array
43+
public function checkSpecialConditions(TelegramMethods $method): array
4444
{
45+
$method->performSpecialConditions();
46+
4547
$return = [false];
4648

4749
foreach ($method as $key => $value) {
@@ -53,10 +55,6 @@ private function checkSpecialConditions(TelegramMethods $method): array
5355
'id' => $key,
5456
'stream' => $value->getStream(),
5557
];
56-
} elseif (in_array('unreal4u\\InternalFunctionality\\KeyboardMethods', class_parents($value))) {
57-
// If we are about to send a KeyboardMethod, we must send a serialized object
58-
$method->$key = json_encode($value);
59-
$return = [true];
6058
}
6159
}
6260
}
@@ -72,7 +70,7 @@ private function checkSpecialConditions(TelegramMethods $method): array
7270
* @param resource $stream The actual file handler
7371
* @return array Returns the actual formdata to be sent
7472
*/
75-
private function buildMultipartFormData(array $data, string $fileKeyName, $stream): array
73+
public function buildMultipartFormData(array $data, string $fileKeyName, $stream): array
7674
{
7775
$formData = [
7876
'multipart' => [],
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?php
2+
3+
namespace tests\InternalFunctionality;
4+
5+
use unreal4u\InternalFunctionality\FormConstructor;
6+
7+
class FormConstructorTest extends \PHPUnit_Framework_TestCase
8+
{
9+
/**
10+
* @var FormConstructor
11+
*/
12+
private $formConstructor;
13+
14+
/**
15+
* Prepares the environment before running a test.
16+
*/
17+
protected function setUp()
18+
{
19+
parent::setUp();
20+
$this->formConstructor = new FormConstructor();
21+
}
22+
23+
/**
24+
* Cleans up the environment after running a test.
25+
*/
26+
protected function tearDown()
27+
{
28+
$this->formConstructor = null;
29+
parent::tearDown();
30+
}
31+
32+
public function providerBuildMultipartFormData()
33+
{
34+
$mapValues[] = [
35+
[
36+
'id' => 'lala',
37+
'contents' => 'lolo',
38+
],
39+
'non-existant',
40+
null,
41+
[
42+
'multipart' => [
43+
0 => [
44+
'name' => 'id',
45+
'contents' => 'lala',
46+
],
47+
1 => [
48+
'name' => 'contents',
49+
'contents' => 'lolo',
50+
]
51+
]
52+
],
53+
];
54+
55+
$mapValues[] = [[], '', null, ['multipart' => [],]];
56+
57+
return $mapValues;
58+
}
59+
60+
/**
61+
* @dataProvider providerBuildMultipartFormData
62+
*/
63+
public function testBuildMultipartFormData(array $data, string $fileKeyName, $stream = null, array $expected = [])
64+
{
65+
$result = $this->formConstructor->buildMultipartFormData($data, $fileKeyName, $stream);
66+
$this->assertEquals($expected, $result);
67+
}
68+
}

tests/Telegram/Methods/AnswerInlineQueryTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace tests\Telegram\Methods;
44

55
use tests\Mock\MockTgLog;
6-
use tests\Mock\MockClientException;
76
use unreal4u\Telegram\Methods\AnswerInlineQuery;
87
use unreal4u\Telegram\Types\InlineQueryResultArticle;
98

tests/Telegram/Types/Custom/InputFileTest.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,9 @@
66

77
class InputFileTest extends \PHPUnit_Framework_TestCase
88
{
9-
/**
10-
* @var InputFile
11-
*/
12-
private $inputFile;
13-
149
public function testInvalidFile()
1510
{
1611
$this->setExpectedException('unreal4u\\Exceptions\\FileNotReadable');
17-
$this->inputFile = new InputFile('non-existant-file.txt');
12+
new InputFile('non-existant-file.txt');
1813
}
1914
}

tests/Telegram/Types/UpdateTest.php

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@
66

77
class UpdateTest extends \PHPUnit_Framework_TestCase
88
{
9-
public function testInlineQuery()
10-
{
11-
$updateObject = new Update([
9+
private $dataProvider = [
10+
'inlineQuery' => [
1211
'update_id' => 123498765,
1312
'inline_query' => [
1413
'id' => 12345678901234567,
@@ -21,12 +20,43 @@ public function testInlineQuery()
2120
'query' => 'let\'s ask something!',
2221
'offset' => '',
2322
],
24-
]);
23+
],
24+
'inlineResult' => [
25+
'update_id' => 123451234,
26+
'chosen_inline_result' => [
27+
'from' => [
28+
'id' => 12341234,
29+
'first_name' => 'Camilo',
30+
'last_name' => 'Sperberg',
31+
'username' => 'unreal4u',
32+
],
33+
'query' => 'what is love?',
34+
'result_id' => '2368eee6cf37da22bc64034c87c3b0b8',
35+
],
36+
],
37+
];
38+
39+
public function testInlineQuery()
40+
{
41+
$updateObject = new Update($this->dataProvider['inlineQuery']);
2542

2643
$this->assertInstanceOf('unreal4u\\Telegram\\Types\\Update', $updateObject);
2744
$this->assertInstanceOf('unreal4u\\Telegram\\Types\\InlineQuery', $updateObject->inline_query);
2845
$this->assertInstanceOf('unreal4u\\Telegram\\Types\\User', $updateObject->inline_query->from);
2946
$this->assertNull($updateObject->message);
3047
$this->assertNull($updateObject->chosen_inline_result);
3148
}
49+
50+
public function testChosenInlineResult()
51+
{
52+
$updateObject = new Update($this->dataProvider['inlineResult']);
53+
54+
$this->assertInstanceOf('unreal4u\\Telegram\\Types\\Update', $updateObject);
55+
$this->assertInstanceOf('unreal4u\\Telegram\\Types\\ChosenInlineResult', $updateObject->chosen_inline_result);
56+
$this->assertInstanceOf('unreal4u\\Telegram\\Types\\User', $updateObject->chosen_inline_result->from);
57+
$this->assertNull($updateObject->message);
58+
$this->assertNull($updateObject->inline_query);
59+
$this->assertNotEmpty($updateObject->chosen_inline_result->query);
60+
$this->assertNotEmpty($updateObject->chosen_inline_result->result_id);
61+
}
3262
}

tests/TgLogTest.php

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -29,42 +29,13 @@ protected function tearDown()
2929
parent::tearDown();
3030
}
3131

32-
public function providerBuildMultipartFormData()
33-
{
34-
$mapValues[] = [
35-
[
36-
'id' => 'lala',
37-
'contents' => 'lolo',
38-
],
39-
'non-existant',
40-
null,
41-
[
42-
'multipart' => [
43-
0 => [
44-
'name' => 'id',
45-
'contents' => 'lala',
46-
],
47-
1 => [
48-
'name' => 'contents',
49-
'contents' => 'lolo',
50-
]
51-
]
52-
],
53-
];
54-
55-
return $mapValues;
56-
}
57-
58-
/**
59-
* @dataProvider providerBuildMultipartFormData
60-
*/
61-
public function testBuildMultipartFormData(array $data, string $fileKeyName, $stream = null, array $expected = [])
32+
/*public function testBuildMultipartFormData(array $data, string $fileKeyName, $stream = null, array $expected = [])
6233
{
6334
$call = new \ReflectionMethod('unreal4u\\TgLog', 'buildMultipartFormData');
6435
$call->setAccessible(true);
6536
$result = $call->invokeArgs(new \unreal4u\TgLog('TEST-TEST'), [$data, $fileKeyName, $stream]);
6637
$this->assertEquals($expected, $result);
67-
}
38+
}*/
6839

6940
public function testComposeApiMethodUrl()
7041
{

0 commit comments

Comments
 (0)