Skip to content

Commit

Permalink
More tests, specifically with chosen_inline_result
Browse files Browse the repository at this point in the history
  • Loading branch information
unreal4u committed Jan 26, 2016
1 parent 0b71f7f commit 501a020
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 49 deletions.
12 changes: 5 additions & 7 deletions src/InternalFunctionality/FormConstructor.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class FormConstructor
* @param TelegramMethods $method
* @return mixed
*/
private function constructFormData(TelegramMethods $method): array
public function constructFormData(TelegramMethods $method): array
{
$result = $this->checkSpecialConditions($method);

Expand Down Expand Up @@ -40,8 +40,10 @@ private function constructFormData(TelegramMethods $method): array
* @param TelegramMethods $method
* @return array
*/
private function checkSpecialConditions(TelegramMethods $method): array
public function checkSpecialConditions(TelegramMethods $method): array
{
$method->performSpecialConditions();

$return = [false];

foreach ($method as $key => $value) {
Expand All @@ -53,10 +55,6 @@ private function checkSpecialConditions(TelegramMethods $method): array
'id' => $key,
'stream' => $value->getStream(),
];
} elseif (in_array('unreal4u\\InternalFunctionality\\KeyboardMethods', class_parents($value))) {
// If we are about to send a KeyboardMethod, we must send a serialized object
$method->$key = json_encode($value);
$return = [true];
}
}
}
Expand All @@ -72,7 +70,7 @@ private function checkSpecialConditions(TelegramMethods $method): array
* @param resource $stream The actual file handler
* @return array Returns the actual formdata to be sent
*/
private function buildMultipartFormData(array $data, string $fileKeyName, $stream): array
public function buildMultipartFormData(array $data, string $fileKeyName, $stream): array
{
$formData = [
'multipart' => [],
Expand Down
68 changes: 68 additions & 0 deletions tests/InternalFunctionality/FormConstructorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php

namespace tests\InternalFunctionality;

use unreal4u\InternalFunctionality\FormConstructor;

class FormConstructorTest extends \PHPUnit_Framework_TestCase
{
/**
* @var FormConstructor
*/
private $formConstructor;

/**
* Prepares the environment before running a test.
*/
protected function setUp()
{
parent::setUp();
$this->formConstructor = new FormConstructor();
}

/**
* Cleans up the environment after running a test.
*/
protected function tearDown()
{
$this->formConstructor = null;
parent::tearDown();
}

public function providerBuildMultipartFormData()
{
$mapValues[] = [
[
'id' => 'lala',
'contents' => 'lolo',
],
'non-existant',
null,
[
'multipart' => [
0 => [
'name' => 'id',
'contents' => 'lala',
],
1 => [
'name' => 'contents',
'contents' => 'lolo',
]
]
],
];

$mapValues[] = [[], '', null, ['multipart' => [],]];

return $mapValues;
}

/**
* @dataProvider providerBuildMultipartFormData
*/
public function testBuildMultipartFormData(array $data, string $fileKeyName, $stream = null, array $expected = [])
{
$result = $this->formConstructor->buildMultipartFormData($data, $fileKeyName, $stream);
$this->assertEquals($expected, $result);
}
}
1 change: 0 additions & 1 deletion tests/Telegram/Methods/AnswerInlineQueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace tests\Telegram\Methods;

use tests\Mock\MockTgLog;
use tests\Mock\MockClientException;
use unreal4u\Telegram\Methods\AnswerInlineQuery;
use unreal4u\Telegram\Types\InlineQueryResultArticle;

Expand Down
7 changes: 1 addition & 6 deletions tests/Telegram/Types/Custom/InputFileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,9 @@

class InputFileTest extends \PHPUnit_Framework_TestCase
{
/**
* @var InputFile
*/
private $inputFile;

public function testInvalidFile()
{
$this->setExpectedException('unreal4u\\Exceptions\\FileNotReadable');
$this->inputFile = new InputFile('non-existant-file.txt');
new InputFile('non-existant-file.txt');
}
}
38 changes: 34 additions & 4 deletions tests/Telegram/Types/UpdateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@

class UpdateTest extends \PHPUnit_Framework_TestCase
{
public function testInlineQuery()
{
$updateObject = new Update([
private $dataProvider = [
'inlineQuery' => [
'update_id' => 123498765,
'inline_query' => [
'id' => 12345678901234567,
Expand All @@ -21,12 +20,43 @@ public function testInlineQuery()
'query' => 'let\'s ask something!',
'offset' => '',
],
]);
],
'inlineResult' => [
'update_id' => 123451234,
'chosen_inline_result' => [
'from' => [
'id' => 12341234,
'first_name' => 'Camilo',
'last_name' => 'Sperberg',
'username' => 'unreal4u',
],
'query' => 'what is love?',
'result_id' => '2368eee6cf37da22bc64034c87c3b0b8',
],
],
];

public function testInlineQuery()
{
$updateObject = new Update($this->dataProvider['inlineQuery']);

$this->assertInstanceOf('unreal4u\\Telegram\\Types\\Update', $updateObject);
$this->assertInstanceOf('unreal4u\\Telegram\\Types\\InlineQuery', $updateObject->inline_query);
$this->assertInstanceOf('unreal4u\\Telegram\\Types\\User', $updateObject->inline_query->from);
$this->assertNull($updateObject->message);
$this->assertNull($updateObject->chosen_inline_result);
}

public function testChosenInlineResult()
{
$updateObject = new Update($this->dataProvider['inlineResult']);

$this->assertInstanceOf('unreal4u\\Telegram\\Types\\Update', $updateObject);
$this->assertInstanceOf('unreal4u\\Telegram\\Types\\ChosenInlineResult', $updateObject->chosen_inline_result);
$this->assertInstanceOf('unreal4u\\Telegram\\Types\\User', $updateObject->chosen_inline_result->from);
$this->assertNull($updateObject->message);
$this->assertNull($updateObject->inline_query);
$this->assertNotEmpty($updateObject->chosen_inline_result->query);
$this->assertNotEmpty($updateObject->chosen_inline_result->result_id);
}
}
33 changes: 2 additions & 31 deletions tests/TgLogTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,42 +29,13 @@ protected function tearDown()
parent::tearDown();
}

public function providerBuildMultipartFormData()
{
$mapValues[] = [
[
'id' => 'lala',
'contents' => 'lolo',
],
'non-existant',
null,
[
'multipart' => [
0 => [
'name' => 'id',
'contents' => 'lala',
],
1 => [
'name' => 'contents',
'contents' => 'lolo',
]
]
],
];

return $mapValues;
}

/**
* @dataProvider providerBuildMultipartFormData
*/
public function testBuildMultipartFormData(array $data, string $fileKeyName, $stream = null, array $expected = [])
/*public function testBuildMultipartFormData(array $data, string $fileKeyName, $stream = null, array $expected = [])
{
$call = new \ReflectionMethod('unreal4u\\TgLog', 'buildMultipartFormData');
$call->setAccessible(true);
$result = $call->invokeArgs(new \unreal4u\TgLog('TEST-TEST'), [$data, $fileKeyName, $stream]);
$this->assertEquals($expected, $result);
}
}*/

public function testComposeApiMethodUrl()
{
Expand Down

0 comments on commit 501a020

Please sign in to comment.