1212namespace Longman \TelegramBot \Tests \Unit ;
1313
1414use DMS \PHPUnitExtensions \ArraySubset \ArraySubsetAsserts ;
15+ use Exception ;
16+ use Longman \TelegramBot \Commands \UserCommands \StartCommand ;
1517use Longman \TelegramBot \Entities \Update ;
1618use Longman \TelegramBot \Exception \TelegramException ;
1719use Longman \TelegramBot \Telegram ;
@@ -133,6 +135,33 @@ public function testAddCustomCommandsPaths(): void
133135 self ::assertCount (4 , $ tg ->getCommandsPaths ());
134136 }
135137
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+
136165 public function testSettingDownloadUploadPaths (): void
137166 {
138167 self ::assertEmpty ($ this ->telegram ->getDownloadPath ());
@@ -152,6 +181,23 @@ public function testGetCommandsList(): void
152181 self ::assertNotCount (0 , $ commands );
153182 }
154183
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+
155201 public function testUpdateFilter (): void
156202 {
157203 $ rawUpdate = '{
0 commit comments