12
12
namespace Longman \TelegramBot \Tests \Unit ;
13
13
14
14
use DMS \PHPUnitExtensions \ArraySubset \ArraySubsetAsserts ;
15
+ use Exception ;
16
+ use Longman \TelegramBot \Commands \UserCommands \StartCommand ;
15
17
use Longman \TelegramBot \Entities \Update ;
16
18
use Longman \TelegramBot \Exception \TelegramException ;
17
19
use Longman \TelegramBot \Telegram ;
@@ -133,6 +135,33 @@ public function testAddCustomCommandsPaths(): void
133
135
self ::assertCount (4 , $ tg ->getCommandsPaths ());
134
136
}
135
137
138
+ public function testAddCustomCommandsClass (): void
139
+ {
140
+ $ tg = $ this ->telegram ;
141
+ $ class = StartCommand::class;
142
+
143
+ self ::assertCount (3 , $ tg ->getCommandsClasses ());
144
+
145
+ try {
146
+ $ tg ->addCommandsClass ('test ' , 'not\exist\Class ' , 'user ' );
147
+ }
148
+ catch (\Exception $ ex ){}
149
+ self ::assertCount (0 , $ tg ->getCommandsClasses ()['User ' ]);
150
+
151
+ try {
152
+ $ tg ->addCommandsClass ('' , $ class , 'user ' );
153
+ }
154
+ catch (\Exception $ ex ){}
155
+ self ::assertCount (0 , $ tg ->getCommandsClasses ()['User ' ]);
156
+
157
+ $ tg ->addCommandsClass ('test ' , $ class , 'user ' );
158
+ self ::assertCount (1 , $ tg ->getCommandsClasses ()['User ' ]);
159
+
160
+ $ tg ->addCommandsClass ('testadmin ' , $ class , 'admin ' );
161
+ self ::assertCount (1 , $ tg ->getCommandsClasses ()['Admin ' ]);
162
+
163
+ }
164
+
136
165
public function testSettingDownloadUploadPaths (): void
137
166
{
138
167
self ::assertEmpty ($ this ->telegram ->getDownloadPath ());
@@ -152,6 +181,23 @@ public function testGetCommandsList(): void
152
181
self ::assertNotCount (0 , $ commands );
153
182
}
154
183
184
+ public function testGetCommandClass (): void
185
+ {
186
+ $ className = StartCommand::class;
187
+ $ commands = $ this ->telegram ->getCommandsClasses ();
188
+ self ::assertIsArray ($ commands );
189
+ self ::assertCount (3 , $ commands );
190
+
191
+ $ class = $ this ->telegram ->getCommandClassName ('user ' , 'notexist ' );
192
+ self ::assertNull ($ class );
193
+
194
+ $ this ->telegram ->addCommandsClass ('test ' , $ className , 'user ' );
195
+ $ class = $ this ->telegram ->getCommandClassName ('user ' , 'test ' );
196
+ self ::assertNotNull ($ class );
197
+ self ::assertSame ($ className , $ class );
198
+
199
+ }
200
+
155
201
public function testUpdateFilter (): void
156
202
{
157
203
$ rawUpdate = '{
0 commit comments