Skip to content

Commit

Permalink
Tests fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
luzrain committed Feb 28, 2024
1 parent 423c52c commit 9c8c16a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
10 changes: 4 additions & 6 deletions src/TelegramBot/CommandMetadataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ public function __construct(
public function gelMetadataList(): \Generator
{
foreach ($this->controllersMap as ['controller' => $controller]) {
if (isset($this->controllerClassMap[$controller])) {
return;
}
$this->controllerClassMap[$controller] = true;
foreach ($this->instantiateAttributes($controller) as $attrubute) {
yield $attrubute;
}
Expand All @@ -36,12 +40,6 @@ public function gelMetadataList(): \Generator
private function instantiateAttributes(string $controller): \Generator
{
[$class, $method] = \explode('::', $controller, 2);

if (isset($this->controllerClassMap[$class])) {
return;
}

$this->controllerClassMap[$class] = true;
$reflClass = new \ReflectionClass($class);
$reflMethod = $reflClass->getMethod($method);
$attributes = $reflMethod->getAttributes(OnCommand::class);
Expand Down
3 changes: 2 additions & 1 deletion tests/CommandMetadataProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ public function testCommandsMetadata(): void
$commandMetadataProvider = self::getContainer()->get('telegram_bot.command_metadata_provider');
$list = \iterator_to_array($commandMetadataProvider->gelMetadataList());

$this->assertCount(4, $list);
$this->assertCount(5, $list);
$this->assertObjectInArray(new OnCommand('/start', '', false, 0), $list);
$this->assertObjectInArray(new OnCommand('/test1', 'test1 command description', true, 0), $list);
$this->assertObjectInArray(new OnCommand('/test2', 'test2 command description', true, 0), $list);
$this->assertObjectInArray(new OnCommand('/test3', 'test3 command description', false, 0), $list);
$this->assertObjectInArray(new OnCommand('/test4', 'test4 command description', false, 0), $list);
}

private function assertObjectInArray(object $obj, array $array): void
Expand Down
1 change: 1 addition & 0 deletions tests/Controller/TestCommandController.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public function test2(): Method
}

#[OnCommand(command: '/test3', description: 'test3 command description', publish: false)]
#[OnCommand(command: '/test4', description: 'test4 command description', publish: false)]
public function test3(): Method
{
ControllerTestHelper::$isTest3CommandCommand = true;
Expand Down

0 comments on commit 9c8c16a

Please sign in to comment.