Skip to content

Commit

Permalink
Merge pull request #92 from botman/fixes-test
Browse files Browse the repository at this point in the history
Fixes tests and run on PHP 7.0 - 7.4
  • Loading branch information
crynobone authored Sep 10, 2020
2 parents 6c2f1df + f7acfe3 commit 9159a6d
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 64 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
.DS_Store
composer.lock
.php_cs.cache
/vendor/
/vendor/

/.discovery/*
7 changes: 5 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ language: php
php:
- 7.0
- 7.1
- 7.2
- 7.3
- 7.4

before_script:
- travis_retry composer self-update --preview
- travis_retry composer install --prefer-dist --no-interaction
- travis_retry composer install --prefer-dist --no-interaction --ignore-platform-req=composer-plugin-api

script:
- vendor/bin/phpunit --coverage-clover=coverage.xml
Expand All @@ -16,4 +19,4 @@ before_install:
- echo "extension = redis.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini

after_success:
- codecov
- codecov
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
],
"require": {
"php": ">=7.0",
"botman/botman": "~2.0"
"botman/botman": "^2.0"
},
"require-dev": {
"botman/studio-addons": "~1.0",
"illuminate/contracts": "~5.5.0",
"phpunit/phpunit": "~5.0",
"mockery/mockery": "dev-master",
"botman/studio-addons": "^1.0",
"illuminate/contracts": "^5.5",
"phpunit/phpunit": "^5.0",
"mockery/mockery": "^1.1",
"ext-curl": "*"
},
"autoload": {
Expand Down
3 changes: 2 additions & 1 deletion src/Console/Commands/TelegramRegisterCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ public function handle()
$output = json_decode(file_get_contents($url));

if ($output->ok == true && $output->result == true) {
$this->info($remove
$this->info(
$remove
? 'Your bot Telegram\'s webhook has been removed!'
: 'Your bot is now set up with Telegram\'s webhook!'
);
Expand Down
8 changes: 6 additions & 2 deletions src/TelegramAudioDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,12 @@ public function getMessages()
*/
public function loadMessages()
{
$message = new IncomingMessage(Audio::PATTERN, $this->event->get('from')['id'], $this->event->get('chat')['id'],
$this->event);
$message = new IncomingMessage(
Audio::PATTERN,
$this->event->get('from')['id'],
$this->event->get('chat')['id'],
$this->event
);
$message->setAudio($this->getAudio());

$this->messages = [$message];
Expand Down
8 changes: 5 additions & 3 deletions src/TelegramDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,13 @@ public function loadMessages()
new IncomingMessage('', $this->queryParameters->get('id'), $this->queryParameters->get('id'), $this->queryParameters),
];
} else {
$event = $this->event->all();

$messages = [
new IncomingMessage(
$this->event->get('text'),
$this->event->get('from')['id'],
$this->event->get('chat')['id'],
isset($event['from']['id']) ? $event['from']['id'] : null,
isset($event['chat']['id']) ? $event['chat']['id'] : null,
$this->event
),
];
Expand Down Expand Up @@ -334,7 +336,7 @@ public function buildServicePayload($message, $matchingMessage, $additionalParam
$parameters = array_merge_recursive([
'chat_id' => $recipient,
], $additionalParameters + $defaultAdditionalParameters);

/*
* If we send a Question with buttons, ignore
* the text and append the question.
Expand Down
8 changes: 6 additions & 2 deletions src/TelegramFileDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,12 @@ public function getMessages()
*/
public function loadMessages()
{
$message = new IncomingMessage(File::PATTERN, $this->event->get('from')['id'], $this->event->get('chat')['id'],
$this->event);
$message = new IncomingMessage(
File::PATTERN,
$this->event->get('from')['id'],
$this->event->get('chat')['id'],
$this->event
);
$message->setFiles($this->getFiles());

$this->messages = [$message];
Expand Down
15 changes: 11 additions & 4 deletions src/TelegramLocationDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,17 @@ public function getMessages()
*/
public function loadMessages()
{
$message = new IncomingMessage(Location::PATTERN, $this->event->get('from')['id'], $this->event->get('chat')['id'],
$this->event);
$message->setLocation(new Location($this->event->get('location')['latitude'],
$this->event->get('location')['longitude'], $this->event->get('location')));
$message = new IncomingMessage(
Location::PATTERN,
$this->event->get('from')['id'],
$this->event->get('chat')['id'],
$this->event
);
$message->setLocation(new Location(
$this->event->get('location')['latitude'],
$this->event->get('location')['longitude'],
$this->event->get('location')
));

$this->messages = [$message];
}
Expand Down
8 changes: 6 additions & 2 deletions src/TelegramPhotoDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,12 @@ public function getMessages()
*/
public function loadMessages()
{
$message = new IncomingMessage(Image::PATTERN, $this->event->get('from')['id'], $this->event->get('chat')['id'],
$this->event);
$message = new IncomingMessage(
Image::PATTERN,
$this->event->get('from')['id'],
$this->event->get('chat')['id'],
$this->event
);
$message->setImages($this->getImages());

$this->messages = [$message];
Expand Down
8 changes: 6 additions & 2 deletions src/TelegramVideoDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,12 @@ public function getMessages()
*/
public function loadMessages()
{
$message = new IncomingMessage(Video::PATTERN, $this->event->get('from')['id'], $this->event->get('chat')['id'],
$this->event);
$message = new IncomingMessage(
Video::PATTERN,
$this->event->get('from')['id'],
$this->event->get('chat')['id'],
$this->event
);
$message->setVideos($this->getVideos());

$this->messages = [$message];
Expand Down
41 changes: 1 addition & 40 deletions tests/TelegramDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1461,45 +1461,6 @@ public function it_can_reply_message_objects_with_location()
$driver->sendPayload($driver->buildServicePayload(\BotMan\BotMan\Messages\Outgoing\OutgoingMessage::create('Test', new Location('123', '321')), $message));
}

/** @test */
public function it_can_reply_message_objects_with_contact()
{
$responseData = [
'update_id' => '1234567890',
'message' => [
'message_id' => '123',
'from' => [
'id' => 'from_id',
],
'chat' => [
'id' => '12345',
],
'date' => '1480369277',
'text' => 'Telegram Text',
],
];

$html = m::mock(Curl::class);
$html->shouldReceive('post')
->once()
->with('https://api.telegram.org/botTELEGRAM-BOT-TOKEN/sendContact', [], [
'chat_id' => '12345',
'phone_number' => '0775269856',
'first_name' => 'Daniele',
'first_name' => 'Rapisarda',
'user_id' => '123',
'caption' => 'Test',
]);

$request = m::mock(\Symfony\Component\HttpFoundation\Request::class.'[getContent]');
$request->shouldReceive('getContent')->andReturn(json_encode($responseData));

$driver = new TelegramDriver($request, $this->telegramConfig, $html);

$message = $driver->getMessages()[0];
$driver->sendPayload($driver->buildServicePayload(\BotMan\BotMan\Messages\Outgoing\OutgoingMessage::create('Test', new Contact('0775269856', 'Daniele', 'Rapisarda', '123')), $message));
}

/** @test */
public function it_can_reply_message_objects_with_contact()
{
Expand Down Expand Up @@ -1527,7 +1488,7 @@ public function it_can_reply_message_objects_with_contact()
'first_name' => 'Daniele',
'last_name' => 'Rapisarda',
'user_id' => '123',
'caption' => 'Test'
'caption' => 'Test',
]);

$request = m::mock(\Symfony\Component\HttpFoundation\Request::class.'[getContent]');
Expand Down

0 comments on commit 9159a6d

Please sign in to comment.