Skip to content

Commit 564ef23

Browse files
committed
Add tests
Simplify existing one Fix found issues Add deprecations
1 parent f01f2a2 commit 564ef23

File tree

95 files changed

+3854
-2458
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+3854
-2458
lines changed

CHANGELOG.md

+9-11
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,17 @@
22

33
All Notable changes to `PHP Telegram Bot Api` will be documented in this file
44

5-
## NEXT - YYYY-MM-DD
5+
## [Unreleased] - [YYYY-MM-DD]
66

77
### Added
8-
- Nothing
9-
10-
### Deprecated
11-
- Nothing
8+
- Add `\TelegramBot\Api\Types\Venue` mapping (`foursquare_type`, `google_place_id`, `google_place_type`)
129

1310
### Fixed
14-
- Nothing
11+
- Fix `\TelegramBot\Api\Collection\Collection::addItem` max count constraint (#333)
12+
- Fix `\TelegramBot\Api\Types\StickerSet` mapping
1513

16-
### Removed
17-
- Nothing
18-
19-
### Security
20-
- Nothing
14+
### Deprecated
15+
- Deprecate `\TelegramBot\Api\Botan` class
16+
- Deprecate `$trackerToken` parameter in `\TelegramBot\Api\BotApi::__construct`
17+
- Deprecate `$trackerToken` parameter in `\TelegramBot\Api\Events\EventCollection::__construct`
18+
- Deprecate `\TelegramBot\Api\Types\PollAnswer::getFrom` use `\TelegramBot\Api\Types\PollAnswer::getUser`

composer.json

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
},
3939
"scripts": {
4040
"test": "vendor/bin/simple-phpunit --colors=always",
41+
"coverage": "XDEBUG_MODE=coverage vendor/bin/simple-phpunit --coverage-html build/coverage",
4142
"cs-fix": "vendor/bin/php-cs-fixer fix --allow-risky=yes --diff --ansi",
4243
"cs-check": "vendor/bin/php-cs-fixer fix --allow-risky=yes --diff --ansi --dry-run"
4344
},

phpunit.xml.dist

+3
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,7 @@
1919
<directory suffix=".php">src/</directory>
2020
</whitelist>
2121
</filter>
22+
<php>
23+
<env name="SYMFONY_DEPRECATIONS_HELPER" value="999999" />
24+
</php>
2225
</phpunit>

src/BotApi.php

+1
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ public function __construct($token, $trackerToken = null)
191191
$this->token = $token;
192192

193193
if ($trackerToken) {
194+
@trigger_error(sprintf('Passing $trackerToken to %s is deprecated', self::class), \E_USER_DEPRECATED);
194195
$this->tracker = new Botan($trackerToken);
195196
}
196197
}

src/Botan.php

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
use TelegramBot\Api\Types\Message;
66

7+
/**
8+
* @deprecated
9+
*/
710
class Botan
811
{
912
/**

src/Client.php

+3
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ class Client
4444
*/
4545
public function __construct($token, $trackerToken = null)
4646
{
47+
if ($trackerToken) {
48+
@trigger_error(sprintf('Passing $trackerToken to %s is deprecated', self::class), \E_USER_DEPRECATED);
49+
}
4750
$this->api = new BotApi($token);
4851
$this->events = new EventCollection($trackerToken);
4952
}

src/Collection/Collection.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class Collection
2828
*/
2929
public function addItem(CollectionItemInterface $item, $key = null)
3030
{
31-
if ($this->maxCount > 0 && $this->count() + 1 >= $this->maxCount) {
31+
if ($this->maxCount > 0 && $this->count() + 1 > $this->maxCount) {
3232
throw new ReachedMaxSizeException("Maximum collection items count reached. Max size: {$this->maxCount}");
3333
}
3434

src/Events/EventCollection.php

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class EventCollection
3131
public function __construct($trackerToken = null)
3232
{
3333
if ($trackerToken) {
34+
@trigger_error(sprintf('Passing $trackerToken to %s is deprecated', self::class), \E_USER_DEPRECATED);
3435
$this->tracker = new Botan($trackerToken);
3536
}
3637
}

src/Types/Payments/ShippingAddress.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,14 @@ class ShippingAddress extends BaseType
6060
/**
6161
* Second line for the address
6262
*
63-
* @var integer
63+
* @var string
6464
*/
6565
protected $streetLine2;
6666

6767
/**
6868
* Address post code
6969
*
70-
* @var integer
70+
* @var string
7171
*/
7272
protected $postCode;
7373

@@ -145,7 +145,7 @@ public function setStreetLine1($streetLine1)
145145

146146
/**
147147
* @author MY
148-
* @return int
148+
* @return string
149149
*/
150150
public function getStreetLine2()
151151
{
@@ -154,7 +154,7 @@ public function getStreetLine2()
154154

155155
/**
156156
* @author MY
157-
* @param int $streetLine2
157+
* @param string $streetLine2
158158
*/
159159
public function setStreetLine2($streetLine2)
160160
{
@@ -163,7 +163,7 @@ public function setStreetLine2($streetLine2)
163163

164164
/**
165165
* @author MY
166-
* @return int
166+
* @return string
167167
*/
168168
public function getPostCode()
169169
{
@@ -172,7 +172,7 @@ public function getPostCode()
172172

173173
/**
174174
* @author MY
175-
* @param int $postCode
175+
* @param string $postCode
176176
*/
177177
public function setPostCode($postCode)
178178
{

src/Types/PollAnswer.php

+4-8
Original file line numberDiff line numberDiff line change
@@ -82,19 +82,15 @@ public function setUser(User $from)
8282
}
8383

8484
/**
85+
* @deprecated
86+
*
8587
* @return User
8688
*/
8789
public function getFrom()
8890
{
89-
return $this->getUser();
90-
}
91+
@trigger_error(sprintf('Access user with %s is deprecated, use "%s::getUser" method', __METHOD__, __CLASS__), \E_USER_DEPRECATED);
9192

92-
/**
93-
* @param User $from
94-
*/
95-
public function setFrom(User $from)
96-
{
97-
return $this->setUser($from);
93+
return $this->getUser();
9894
}
9995

10096
/**

src/Types/ReplyKeyboardMarkup.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class ReplyKeyboardMarkup extends BaseType
6565
*/
6666
protected $selective;
6767

68-
public function __construct($keyboard, $oneTimeKeyboard = null, $resizeKeyboard = null, $selective = null)
68+
public function __construct($keyboard = [], $oneTimeKeyboard = null, $resizeKeyboard = null, $selective = null)
6969
{
7070
$this->keyboard = $keyboard;
7171
$this->oneTimeKeyboard = $oneTimeKeyboard;

src/Types/ReplyKeyboardRemove.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ class ReplyKeyboardRemove extends BaseType
4848
*/
4949
protected $selective;
5050

51-
public function __construct($remove_keyboard = true, $selective = false)
51+
public function __construct($removeKeyboard = true, $selective = false)
5252
{
53-
$this->removeKeyboard = $remove_keyboard;
53+
$this->removeKeyboard = $removeKeyboard;
5454
$this->selective = $selective;
5555
}
5656

@@ -63,11 +63,11 @@ public function getRemoveKeyboard()
6363
}
6464

6565
/**
66-
* @param bool $remove_keyboard
66+
* @param bool $removeKeyboard
6767
*/
68-
public function setRemoveKeyboard($remove_keyboard)
68+
public function setRemoveKeyboard($removeKeyboard)
6969
{
70-
$this->removeKeyboard = $remove_keyboard;
70+
$this->removeKeyboard = $removeKeyboard;
7171
}
7272

7373
/**

src/Types/Sticker.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,15 @@ class Sticker extends BaseType implements TypeInterface
3636
*/
3737
protected static $map = [
3838
'file_id' => true,
39+
'file_unique_id' => true,
40+
'type' => true,
3941
'width' => true,
4042
'height' => true,
41-
'thumb' => PhotoSize::class,
42-
'file_size' => true,
43-
'type' => true,
44-
'file_unique_id' => true,
45-
'premium_animation' => true,
4643
'is_animated' => true,
4744
'is_video' => true,
45+
'thumb' => PhotoSize::class,
46+
'file_size' => true,
47+
'premium_animation' => File::class,
4848
'emoji' => true,
4949
'set_name' => true,
5050
'mask_position' => MaskPosition::class,

src/Types/StickerSet.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ class StickerSet extends BaseType implements TypeInterface
3232
'sticker_type' => true,
3333
'is_animated' => true,
3434
'is_video' => true,
35-
'stickers' => true,
36-
'thumb' => true,
35+
'stickers' => ArrayOfSticker::class,
36+
'thumb' => PhotoSize::class,
3737
];
3838

3939
/**

src/Types/Venue.php

+72
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ class Venue extends BaseType implements TypeInterface
3636
'title' => true,
3737
'address' => true,
3838
'foursquare_id' => true,
39+
'foursquare_type' => true,
40+
'google_place_id' => true,
41+
'google_place_type' => true,
3942
];
4043

4144
/**
@@ -66,6 +69,27 @@ class Venue extends BaseType implements TypeInterface
6669
*/
6770
protected $foursquareId;
6871

72+
/**
73+
* Optional. Foursquare type of the venue. (For example, “arts_entertainment/default”, “arts_entertainment/aquarium” or “food/icecream”.)
74+
*
75+
* @var string
76+
*/
77+
protected $foursquareType;
78+
79+
/**
80+
* Optional. Google Places identifier of the venue
81+
*
82+
* @var string
83+
*/
84+
protected $googlePlaceId;
85+
86+
/**
87+
* Optional. Google Places type of the venue.
88+
*
89+
* @var string
90+
*/
91+
protected $googlePlaceType;
92+
6993
/**
7094
* @return Location
7195
*/
@@ -129,4 +153,52 @@ public function setFoursquareId($foursquareId)
129153
{
130154
$this->foursquareId = $foursquareId;
131155
}
156+
157+
/**
158+
* @return string
159+
*/
160+
public function getFoursquareType()
161+
{
162+
return $this->foursquareType;
163+
}
164+
165+
/**
166+
* @param string $foursquareType
167+
*/
168+
public function setFoursquareType($foursquareType)
169+
{
170+
$this->foursquareType = $foursquareType;
171+
}
172+
173+
/**
174+
* @return string
175+
*/
176+
public function getGooglePlaceId()
177+
{
178+
return $this->googlePlaceId;
179+
}
180+
181+
/**
182+
* @param string $googlePlaceId
183+
*/
184+
public function setGooglePlaceId($googlePlaceId)
185+
{
186+
$this->googlePlaceId = $googlePlaceId;
187+
}
188+
189+
/**
190+
* @return string
191+
*/
192+
public function getGooglePlaceType()
193+
{
194+
return $this->googlePlaceType;
195+
}
196+
197+
/**
198+
* @param string $googlePlaceType
199+
*/
200+
public function setGooglePlaceType($googlePlaceType)
201+
{
202+
$this->googlePlaceType = $googlePlaceType;
203+
}
132204
}

0 commit comments

Comments
 (0)