Skip to content

Commit

Permalink
Issue with Events and secondary drivers that extends TelegramDriver m…
Browse files Browse the repository at this point in the history
…ain class (#12)

* Secondary Telegram drivers doesn't have any Event so should all be ignored at all

* Style fix

* Added some tests (not very necessary)
  • Loading branch information
Emulator000 authored and mpociot committed Sep 3, 2017
1 parent d0333ca commit c12d2f2
Show file tree
Hide file tree
Showing 10 changed files with 175 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/TelegramAudioDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ public function matchesRequest()
return ! is_null($this->event->get('from')) && (! is_null($this->event->get('audio')) || ! is_null($this->event->get('voice')));
}

/**
* @return bool
*/
public function hasMatchingEvent()
{
return false;
}

/**
* Retrieve the chat message.
*
Expand Down
8 changes: 8 additions & 0 deletions src/TelegramFileDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ public function matchesRequest()
return ! is_null($this->event->get('from')) && (! is_null($this->event->get('document')));
}

/**
* @return bool
*/
public function hasMatchingEvent()
{
return false;
}

/**
* Retrieve the chat message.
*
Expand Down
8 changes: 8 additions & 0 deletions src/TelegramLocationDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ public function matchesRequest()
return ! is_null($this->event->get('from')) && ! is_null($this->event->get('location'));
}

/**
* @return bool
*/
public function hasMatchingEvent()
{
return false;
}

/**
* Retrieve the chat message.
*
Expand Down
8 changes: 8 additions & 0 deletions src/TelegramPhotoDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ public function matchesRequest()
return ! is_null($this->event->get('from')) && ! is_null($this->event->get('photo'));
}

/**
* @return bool
*/
public function hasMatchingEvent()
{
return false;
}

/**
* Retrieve the chat message.
*
Expand Down
8 changes: 8 additions & 0 deletions src/TelegramVideoDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ public function matchesRequest()
return ! is_null($this->event->get('from')) && ! is_null($this->event->get('video'));
}

/**
* @return bool
*/
public function hasMatchingEvent()
{
return false;
}

/**
* Retrieve the chat message.
*
Expand Down
27 changes: 27 additions & 0 deletions tests/TelegramAudioDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,4 +240,31 @@ public function it_throws_exception_in_get_attachment_url()
$this->assertSame(TelegramAttachmentException::class, get_class($t));
}
}

/** @test */
public function it_havent_to_match_any_event()
{
$driver = $this->getDriver([
'update_id' => '1234567890',
'message' => [
'message_id' => '123',
'from' => [
'id' => 'from_id',
],
'chat' => [
'id' => 'chat_id',
],
'date' => '1480369277',
'text' => 'Hi Julia',
'new_chat_member' => [
'id' => '456',
'first_name' => 'Marcel',
'last_name' => 'Pociot',
'username' => 'mpociot',
],
],
]);
$this->assertFalse($driver->matchesRequest());
$this->assertFalse($driver->hasMatchingEvent());
}
}
27 changes: 27 additions & 0 deletions tests/TelegramFileDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,31 @@ public function it_throws_exception_in_get_attachment_url()
$this->assertSame(TelegramAttachmentException::class, get_class($t));
}
}

/** @test */
public function it_havent_to_match_any_event()
{
$driver = $this->getDriver([
'update_id' => '1234567890',
'message' => [
'message_id' => '123',
'from' => [
'id' => 'from_id',
],
'chat' => [
'id' => 'chat_id',
],
'date' => '1480369277',
'text' => 'Hi Julia',
'new_chat_member' => [
'id' => '456',
'first_name' => 'Marcel',
'last_name' => 'Pociot',
'username' => 'mpociot',
],
],
]);
$this->assertFalse($driver->matchesRequest());
$this->assertFalse($driver->hasMatchingEvent());
}
}
27 changes: 27 additions & 0 deletions tests/TelegramLocationDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,31 @@ public function it_returns_the_location()
'longitude' => -122.123854248,
], $location->getPayload());
}

/** @test */
public function it_havent_to_match_any_event()
{
$driver = $this->getDriver([
'update_id' => '1234567890',
'message' => [
'message_id' => '123',
'from' => [
'id' => 'from_id',
],
'chat' => [
'id' => 'chat_id',
],
'date' => '1480369277',
'text' => 'Hi Julia',
'new_chat_member' => [
'id' => '456',
'first_name' => 'Marcel',
'last_name' => 'Pociot',
'username' => 'mpociot',
],
],
]);
$this->assertFalse($driver->matchesRequest());
$this->assertFalse($driver->hasMatchingEvent());
}
}
27 changes: 27 additions & 0 deletions tests/TelegramPhotoDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,4 +177,31 @@ public function it_throws_exception_in_get_attachment_url()
$this->assertSame(TelegramAttachmentException::class, get_class($t));
}
}

/** @test */
public function it_havent_to_match_any_event()
{
$driver = $this->getDriver([
'update_id' => '1234567890',
'message' => [
'message_id' => '123',
'from' => [
'id' => 'from_id',
],
'chat' => [
'id' => 'chat_id',
],
'date' => '1480369277',
'text' => 'Hi Julia',
'new_chat_member' => [
'id' => '456',
'first_name' => 'Marcel',
'last_name' => 'Pociot',
'username' => 'mpociot',
],
],
]);
$this->assertFalse($driver->matchesRequest());
$this->assertFalse($driver->hasMatchingEvent());
}
}
27 changes: 27 additions & 0 deletions tests/TelegramVideoDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,4 +188,31 @@ public function it_throws_exception_in_get_attachment_url()
$this->assertSame(TelegramAttachmentException::class, get_class($t));
}
}

/** @test */
public function it_havent_to_match_any_event()
{
$driver = $this->getDriver([
'update_id' => '1234567890',
'message' => [
'message_id' => '123',
'from' => [
'id' => 'from_id',
],
'chat' => [
'id' => 'chat_id',
],
'date' => '1480369277',
'text' => 'Hi Julia',
'new_chat_member' => [
'id' => '456',
'first_name' => 'Marcel',
'last_name' => 'Pociot',
'username' => 'mpociot',
],
],
]);
$this->assertFalse($driver->matchesRequest());
$this->assertFalse($driver->hasMatchingEvent());
}
}

0 comments on commit c12d2f2

Please sign in to comment.