-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Intergation tests, dependencies reduce.
- Loading branch information
Showing
23 changed files
with
686 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
/.gitattributes export-ignore | ||
/.gitignore export-ignore | ||
/.github export-ignore | ||
/tests export-ignore | ||
/phpunit.xml export-ignore | ||
/psalm.xml export-ignore | ||
/.php-cs-fixer.dist.php export-ignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,3 +29,6 @@ jobs: | |
|
||
- name: Psalm | ||
run: vendor/bin/psalm --no-cache | ||
|
||
- name: Tests | ||
run: vendor/bin/phpunit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,19 +11,31 @@ | |
"email": "[email protected]" | ||
} | ||
], | ||
"autoload": { | ||
"psr-4": { | ||
"Luzrain\\TelegramBotBundle\\": "src/" | ||
} | ||
}, | ||
"require": { | ||
"php" : "^8.2", | ||
"php": "^8.2", | ||
"luzrain/telegram-bot-api": "^2.1.1", | ||
"symfony/config": "^6.3", | ||
"symfony/console": "^6.3", | ||
"symfony/framework-bundle": "^6.3", | ||
"luzrain/telegram-bot-api": "^2.1.1" | ||
"symfony/dependency-injection": "^6.3", | ||
"symfony/http-kernel": "^6.3" | ||
}, | ||
"require-dev": { | ||
"friendsofphp/php-cs-fixer": "^3.20", | ||
"phpunit/phpunit": "^10.2", | ||
"symfony/framework-bundle": "^6.3", | ||
"vimeo/psalm": "^5.13" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Luzrain\\TelegramBotBundle\\": "src/" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"Luzrain\\TelegramBotBundle\\Test\\": "tests" | ||
} | ||
}, | ||
"config": { | ||
"sort-packages": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.2/phpunit.xsd" | ||
bootstrap="vendor/autoload.php" | ||
backupGlobals="false" | ||
colors="true" | ||
cacheDirectory="var" | ||
> | ||
<testsuites> | ||
<testsuite name="Test Suite"> | ||
<directory>tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
<coverage/> | ||
<php> | ||
<server name="APP_ENV" value="test" force="true"/> | ||
<server name="KERNEL_CLASS" value="Luzrain\TelegramBotBundle\Test\TestKernel" force="true"/> | ||
</php> | ||
<source> | ||
<include> | ||
<directory suffix=".php">src</directory> | ||
</include> | ||
</source> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Luzrain\TelegramBotBundle\Test; | ||
|
||
use Luzrain\TelegramBotApi\BotApi; | ||
use Luzrain\TelegramBotApi\ClientApi; | ||
use Luzrain\TelegramBotBundle\Attribute\OnCommand; | ||
use Luzrain\TelegramBotBundle\TelegramBot\Command\ButtonDeleteCommand; | ||
use Luzrain\TelegramBotBundle\TelegramBot\Command\ButtonSetCommandsCommand; | ||
use Luzrain\TelegramBotBundle\TelegramBot\Command\DeleteWebhookCommand; | ||
use Luzrain\TelegramBotBundle\TelegramBot\Command\PolllingStartCommand; | ||
use Luzrain\TelegramBotBundle\TelegramBot\Command\SetWebhookCommand; | ||
use Luzrain\TelegramBotBundle\TelegramBot\Command\WebhookInfoCommand; | ||
use Luzrain\TelegramBotBundle\TelegramBot\CommandMetadataProvider; | ||
use Luzrain\TelegramBotBundle\TelegramBot\Controller\WebHookController; | ||
use Luzrain\TelegramBotBundle\TelegramBot\LongPollingService; | ||
use Luzrain\TelegramBotBundle\TelegramBot\UpdateHandler; | ||
use Psr\Http\Client\ClientInterface; | ||
use Psr\Http\Message\RequestFactoryInterface; | ||
use Psr\Http\Message\StreamFactoryInterface; | ||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; | ||
use Symfony\Component\DependencyInjection\ContainerInterface; | ||
|
||
final class CommandMetadataProviderTest extends KernelTestCase | ||
{ | ||
public function testCommandsMetadata(): void | ||
{ | ||
$commandMetadataProvider = self::getContainer()->get('telegram_bot.command_metadata_provider'); | ||
$list = $commandMetadataProvider->gelMetadataList(); | ||
|
||
$this->assertCount(4, $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); | ||
} | ||
|
||
private function assertObjectInArray(object $obj, array $arra): void | ||
{ | ||
$this->assertContains(json_encode($obj), array_map(fn ($a) => json_encode($a), $arra)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Luzrain\TelegramBotBundle\Test\Controller; | ||
|
||
use Luzrain\TelegramBotApi\Event; | ||
use Luzrain\TelegramBotBundle\Attribute\OnEvent; | ||
use Luzrain\TelegramBotBundle\TelegramBot\TelegramCommand; | ||
use Luzrain\TelegramBotBundle\Test\Helper\ControllerTestHelper; | ||
|
||
final class AnyUpdateController extends TelegramCommand | ||
{ | ||
#[OnEvent(event: Event\Update::class, priority: 10)] | ||
public function __invoke(): void | ||
{ | ||
ControllerTestHelper::$isUpdate = true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Luzrain\TelegramBotBundle\Test\Controller; | ||
|
||
use Luzrain\TelegramBotApi\Method; | ||
use Luzrain\TelegramBotBundle\Attribute\OnCallback; | ||
use Luzrain\TelegramBotBundle\TelegramBot\TelegramCommand; | ||
use Luzrain\TelegramBotBundle\Test\Helper\ControllerTestHelper; | ||
|
||
final class CallbackCommandController extends TelegramCommand | ||
{ | ||
#[OnCallback('test_callback_1')] | ||
public function callback1(): Method | ||
{ | ||
ControllerTestHelper::$isCallback1 = true; | ||
return $this->reply('Callback1 answer'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Luzrain\TelegramBotBundle\Test\Controller; | ||
|
||
use Luzrain\TelegramBotApi\Event; | ||
use Luzrain\TelegramBotApi\Method; | ||
use Luzrain\TelegramBotApi\Type; | ||
use Luzrain\TelegramBotBundle\Attribute\OnEvent; | ||
use Luzrain\TelegramBotBundle\TelegramBot\TelegramCommand; | ||
use Luzrain\TelegramBotBundle\Test\Helper\ControllerTestHelper; | ||
|
||
final class MessageController extends TelegramCommand | ||
{ | ||
#[OnEvent(event: Event\Message::class)] | ||
public function __invoke(Type\Message $message): Method | ||
{ | ||
ControllerTestHelper::$isMessage = true; | ||
return $this->reply('You wrote: ' . $message->text); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Luzrain\TelegramBotBundle\Test\Controller; | ||
|
||
use Luzrain\TelegramBotApi\Method; | ||
use Luzrain\TelegramBotBundle\Attribute\OnCommand; | ||
use Luzrain\TelegramBotBundle\TelegramBot\TelegramCommand; | ||
use Luzrain\TelegramBotBundle\Test\Helper\ControllerTestHelper; | ||
|
||
final class StartCommandController extends TelegramCommand | ||
{ | ||
#[OnCommand('/start')] | ||
public function __invoke(): Method | ||
{ | ||
ControllerTestHelper::$isStartCommand = true; | ||
return $this->reply('Start answer'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Luzrain\TelegramBotBundle\Test\Controller; | ||
|
||
use Luzrain\TelegramBotApi\Method; | ||
use Luzrain\TelegramBotBundle\Attribute\OnCommand; | ||
use Luzrain\TelegramBotBundle\TelegramBot\TelegramCommand; | ||
use Luzrain\TelegramBotBundle\Test\Helper\ControllerTestHelper; | ||
|
||
final class TestCommandController extends TelegramCommand | ||
{ | ||
#[OnCommand(command: '/test1', description: 'test1 command description', publish: true)] | ||
public function test1(): Method | ||
{ | ||
ControllerTestHelper::$isTest1CommandCommand = true; | ||
return $this->reply('Test1 answer'); | ||
} | ||
|
||
#[OnCommand(command: '/test2', description: 'test2 command description', publish: true)] | ||
public function test2(): Method | ||
{ | ||
ControllerTestHelper::$isTest2CommandCommand = true; | ||
return $this->reply('Test2 answer'); | ||
} | ||
|
||
#[OnCommand(command: '/test3', description: 'test3 command description', publish: false)] | ||
public function test3(): Method | ||
{ | ||
ControllerTestHelper::$isTest3CommandCommand = true; | ||
return $this->reply('Test3 answer'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Luzrain\TelegramBotBundle\Test\Helper; | ||
|
||
final class ControllerTestHelper | ||
{ | ||
public static bool $isStartCommand = false; | ||
public static bool $isTest1CommandCommand = false; | ||
public static bool $isTest2CommandCommand = false; | ||
public static bool $isTest3CommandCommand = false; | ||
public static bool $isMessage = false; | ||
public static bool $isCallback1 = false; | ||
public static bool $isUpdate = false; | ||
|
||
public function __construct() | ||
{ | ||
self::$isStartCommand = false; | ||
self::$isTest1CommandCommand = false; | ||
self::$isTest2CommandCommand = false; | ||
self::$isTest3CommandCommand = false; | ||
self::$isMessage = false; | ||
self::$isCallback1 = false; | ||
self::$isUpdate = false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Luzrain\TelegramBotBundle\Test; | ||
|
||
use Luzrain\TelegramBotApi\BotApi; | ||
use Luzrain\TelegramBotApi\ClientApi; | ||
use Luzrain\TelegramBotBundle\TelegramBot\Command\ButtonDeleteCommand; | ||
use Luzrain\TelegramBotBundle\TelegramBot\Command\ButtonSetCommandsCommand; | ||
use Luzrain\TelegramBotBundle\TelegramBot\Command\DeleteWebhookCommand; | ||
use Luzrain\TelegramBotBundle\TelegramBot\Command\PolllingStartCommand; | ||
use Luzrain\TelegramBotBundle\TelegramBot\Command\SetWebhookCommand; | ||
use Luzrain\TelegramBotBundle\TelegramBot\Command\WebhookInfoCommand; | ||
use Luzrain\TelegramBotBundle\TelegramBot\CommandMetadataProvider; | ||
use Luzrain\TelegramBotBundle\TelegramBot\Controller\WebHookController; | ||
use Luzrain\TelegramBotBundle\TelegramBot\LongPollingService; | ||
use Luzrain\TelegramBotBundle\TelegramBot\UpdateHandler; | ||
use Psr\Http\Client\ClientInterface; | ||
use Psr\Http\Message\RequestFactoryInterface; | ||
use Psr\Http\Message\StreamFactoryInterface; | ||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; | ||
use Symfony\Component\DependencyInjection\ContainerInterface; | ||
|
||
final class ServicesAutowiringTest extends KernelTestCase | ||
{ | ||
private static ContainerInterface $container; | ||
|
||
public function setUp(): void | ||
{ | ||
self::$container = self::getContainer(); | ||
self::$container->set('httpClient', $this->createMock(ClientInterface::class)); | ||
self::$container->set('requestFactory', $this->createMock(RequestFactoryInterface::class)); | ||
self::$container->set('streamFactory', $this->createMock(StreamFactoryInterface::class)); | ||
} | ||
|
||
public function testServiceAutowiring(): void | ||
{ | ||
$this->assertInstanceOf(BotApi::class, self::$container->get(BotApi::class)); | ||
$this->assertInstanceOf(ClientApi::class, self::$container->get('telegram_bot.client_api')); | ||
$this->assertInstanceOf(WebHookController::class, self::$container->get('telegram_bot.webhook_controller')); | ||
$this->assertInstanceOf(LongPollingService::class, self::$container->get('telegram_bot.long_polling_service')); | ||
$this->assertInstanceOf(SetWebhookCommand::class, self::$container->get('telegram_bot.set_webhook_command')); | ||
$this->assertInstanceOf(WebhookInfoCommand::class, self::$container->get('telegram_bot.get_webhook_command')); | ||
$this->assertInstanceOf(DeleteWebhookCommand::class, self::$container->get('telegram_bot.delete_webhook_command')); | ||
$this->assertInstanceOf(PolllingStartCommand::class, self::$container->get('telegram_bot.polling_command')); | ||
$this->assertInstanceOf(ButtonSetCommandsCommand::class, self::$container->get('telegram_bot.menu_button_set_commands')); | ||
$this->assertInstanceOf(ButtonDeleteCommand::class, self::$container->get('telegram_bot.menu_button_delete')); | ||
$this->assertInstanceOf(UpdateHandler::class, self::$container->get('telegram_bot.update_handler')); | ||
$this->assertInstanceOf(CommandMetadataProvider::class, self::$container->get('telegram_bot.command_metadata_provider')); | ||
} | ||
} |
Oops, something went wrong.