chore: initial import for test contour
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Service;
|
||||
|
||||
use App\Service\Crypt\AESCryptService;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class AESCryptServiceTest extends TestCase
|
||||
{
|
||||
private AESCryptService $service;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$secret = $_ENV['AES_SECRET_KEY'];
|
||||
$cipher = $_ENV['AES_CIPHER_METHOD'];
|
||||
|
||||
$this->service = new AESCryptService($secret, $cipher);
|
||||
}
|
||||
|
||||
public function testEncryptDecrypt(): void
|
||||
{
|
||||
$plaintext = 'Hello, world!';
|
||||
$encrypted = $this->service->encrypt($plaintext);
|
||||
$decrypted = $this->service->decrypt($encrypted);
|
||||
|
||||
$this->assertNotEquals($plaintext, $encrypted);
|
||||
$this->assertEquals($plaintext, $decrypted);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Service;
|
||||
|
||||
use App\Service\Dbal\BitrixService;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Doctrine\DBAL\Connection;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
class BitrixServiceTest extends TestCase
|
||||
{
|
||||
private BitrixService $service;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$databaseUrl = $_ENV['DATABASE_BITRIX_URL'];
|
||||
|
||||
$this->service = new BitrixService($databaseUrl);
|
||||
}
|
||||
|
||||
public function testConnect(): void
|
||||
{
|
||||
|
||||
$connection = $this->service->getConnection();
|
||||
|
||||
// $this->assertEquals($plaintext, $decrypted);
|
||||
|
||||
// Проверяем, что подключение установлено
|
||||
$this->assertInstanceOf(Connection::class, $connection);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Service;
|
||||
|
||||
use App\Dto\CalltouchCreateRequestDto;
|
||||
use App\Service\Client\CalltouchClientService;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class CalltouchClientServiceTest extends TestCase
|
||||
{
|
||||
private CalltouchClientService $service;
|
||||
private CalltouchCreateRequestDto $dto;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->dto = new CalltouchCreateRequestDto();
|
||||
|
||||
$this->dto->regionId = 91;
|
||||
$this->dto->requestNumber = 'test_' . time();
|
||||
$this->dto->subject = 'Тестовая заявка';
|
||||
$this->dto->requestUrl = 'CalltouchClientServiceTest';
|
||||
$this->dto->sessionId = null;
|
||||
$this->dto->phoneNumber = '79996243200';
|
||||
$this->dto->email = 'yahve1989@yandex.ru';
|
||||
$this->dto->fio = 'Тест Public API';
|
||||
$this->dto->addTags = ['public_api'];
|
||||
$this->dto->requestDate = date('Y-m-d');
|
||||
$this->dto->customSources = [
|
||||
'source' => '',
|
||||
'medium' => '',
|
||||
'campaign' => '',
|
||||
'term' => ''
|
||||
];
|
||||
|
||||
$ctUrl = $_ENV['CT_URL'];
|
||||
$apiClient = $_ENV['API_CLIENT'];
|
||||
$params = $_ENV['CT_PARAMS'];
|
||||
|
||||
$this->service = new CalltouchClientService($apiClient, $ctUrl , $params);
|
||||
}
|
||||
|
||||
public function testSend(): void
|
||||
{
|
||||
# -- 17 числа узнать документы
|
||||
$response = $this->service->requestCreate($this->dto);
|
||||
|
||||
var_dump($response, $this->dto);
|
||||
die();
|
||||
|
||||
// $plaintext = 'Hello, world!';
|
||||
// $encrypted = $this->service->encrypt($plaintext);
|
||||
// $decrypted = $this->service->decrypt($encrypted);
|
||||
|
||||
// $this->assertNotEquals($plaintext, $encrypted);
|
||||
// $this->assertEquals($plaintext, $decrypted);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Service;
|
||||
|
||||
use App\Service\Image\ImageService;
|
||||
use App\Service\Image\Interfaces\ImageServiceInterface;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
|
||||
class ImageServiceTest extends TestCase
|
||||
{
|
||||
private ImageServiceInterface $imageService;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->imageService = new ImageService();
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider imageDataProvider
|
||||
*/
|
||||
public function testGetPicture(string $filePath, int $width, int $height, string $expectedType): void
|
||||
{
|
||||
// Создаем тестовый файл изображения
|
||||
$testImagePath = __DIR__ . '/test_image.jpg';
|
||||
$this->createTestImage($testImagePath);
|
||||
|
||||
$response = $this->imageService->getPicture($testImagePath, $width, $height);
|
||||
|
||||
$this->assertInstanceOf(Response::class, $response);
|
||||
$this->assertEquals($expectedType, $response->headers->get('Content-Type'));
|
||||
$this->assertNotEmpty($response->getContent());
|
||||
|
||||
// Удаляем тестовый файл
|
||||
unlink($testImagePath);
|
||||
}
|
||||
|
||||
public function imageDataProvider(): array
|
||||
{
|
||||
return [
|
||||
['test_image.jpg', 200, 200, 'image/jpeg'],
|
||||
['test_image.png', 100, 100, 'image/png'],
|
||||
['test_image.gif', 150, 150, 'image/gif'],
|
||||
];
|
||||
}
|
||||
|
||||
public function testInvalidFile(): void
|
||||
{
|
||||
$response = $this->imageService->getPicture('non_existent_file.jpg');
|
||||
$this->assertInstanceOf(Response::class, $response);
|
||||
$this->assertEmpty($response->getContent());
|
||||
}
|
||||
|
||||
public function testDefaultSize(): void
|
||||
{
|
||||
$testImagePath = __DIR__ . '/test_image.jpg';
|
||||
$this->createTestImage($testImagePath);
|
||||
|
||||
$response = $this->imageService->getPicture($testImagePath);
|
||||
$this->assertInstanceOf(Response::class, $response);
|
||||
$this->assertEquals('image/jpeg', $response->headers->get('Content-Type'));
|
||||
$this->assertNotEmpty($response->getContent());
|
||||
|
||||
unlink($testImagePath);
|
||||
}
|
||||
|
||||
private function createTestImage(string $path): void
|
||||
{
|
||||
$image = imagecreatetruecolor(800, 600);
|
||||
$color = imagecolorallocate($image, 255, 0, 0);
|
||||
imagefilledrectangle($image, 0, 0, 800, 600, $color);
|
||||
imagejpeg($image, $path);
|
||||
imagedestroy($image);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Service;
|
||||
|
||||
use App\Service\Client\Interfaces\InfoclinicaClientServiceInterface;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Prophecy\Prophecy\ObjectProphecy;
|
||||
use Prophecy\Prophet;
|
||||
|
||||
|
||||
class InfoclinicaClientServiceTest extends TestCase
|
||||
{
|
||||
private $clientServiceMock;
|
||||
private $prophet;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->prophet = new Prophet();
|
||||
$this->clientServiceMock = $this->prophet->prophesize(InfoclinicaClientServiceInterface::class);
|
||||
}
|
||||
|
||||
private function expectedResult()
|
||||
{
|
||||
return [
|
||||
'schedule' => [
|
||||
'990000082' => [
|
||||
'20250520' => [
|
||||
'schedident' => 30240229,
|
||||
'rnum' => '2.06',
|
||||
'dcode' => 30001414,
|
||||
'filial' => 3,
|
||||
'intervals' => [
|
||||
[
|
||||
'time' => '14:30-15:00',
|
||||
'isFree' => false
|
||||
],
|
||||
[
|
||||
'time' => '15:00-15:30',
|
||||
'isFree' => false
|
||||
],
|
||||
[
|
||||
'time' => '15:30-16:00',
|
||||
'isFree' => false
|
||||
]
|
||||
],
|
||||
'depnum' => 990000082,
|
||||
'isFree' => false
|
||||
],
|
||||
]
|
||||
],
|
||||
'nearestDate' => []
|
||||
];
|
||||
}
|
||||
|
||||
public function testGetSchedule(): void
|
||||
{
|
||||
// Подготовка данных
|
||||
$queryString = '?st=20250516&en=20250530&dcode=30001414&onlineMode=0&filial=3';
|
||||
|
||||
// Настройка мок-объекта
|
||||
$this->clientServiceMock
|
||||
->getSchedule($queryString)
|
||||
->willReturn($this->expectedResult());
|
||||
|
||||
$service = $this->clientServiceMock->reveal();
|
||||
|
||||
$result = $service->getSchedule($queryString);
|
||||
|
||||
$this->assertEquals($this->expectedResult(), $result);
|
||||
}
|
||||
|
||||
public function testGetScheduleWithEmptyQuery(): void
|
||||
{
|
||||
$queryString = '';
|
||||
$expectedExceptionMessage = 'Query string cannot be empty';
|
||||
|
||||
$this->clientServiceMock
|
||||
->getSchedule($queryString)
|
||||
->willThrow(new \InvalidArgumentException($expectedExceptionMessage));
|
||||
|
||||
$service = $this->clientServiceMock->reveal();
|
||||
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
$this->expectExceptionMessage($expectedExceptionMessage);
|
||||
|
||||
$service->getSchedule($queryString);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Service;
|
||||
|
||||
use App\Service\MessageSender\MessageSenderService;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Console\Messenger\RunCommandMessage;
|
||||
use Symfony\Component\Messenger\Envelope;
|
||||
use Symfony\Component\Messenger\MessageBusInterface;
|
||||
|
||||
class MessageSenderServiceTest extends TestCase
|
||||
{
|
||||
public function testSendCommandDispatchesMessage(): void
|
||||
{
|
||||
// 1. Создаем mock для MessageBusInterface
|
||||
$messageBus = $this->createMock(MessageBusInterface::class);
|
||||
|
||||
// 2. Ожидаем, что dispatch() будет вызван с правильным сообщением
|
||||
$expectedMessage = new RunCommandMessage('debug:container');
|
||||
$messageBus->expects($this->once())
|
||||
->method('dispatch')
|
||||
->with($expectedMessage)
|
||||
->willReturn(new Envelope($expectedMessage));
|
||||
|
||||
// 3. Тестируемый сервис
|
||||
$service = new MessageSenderService($messageBus);
|
||||
$service->sendCommand('debug:container');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
// tests/Integration/Messenger/SchedulerTransportTest.php
|
||||
|
||||
namespace Tests\Service;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
use Symfony\Component\Console\Messenger\RunCommandMessage;
|
||||
use Symfony\Component\Messenger\MessageBusInterface;
|
||||
use Symfony\Component\Messenger\Transport\TransportInterface;
|
||||
|
||||
class SchedulerTransportTest extends KernelTestCase
|
||||
{
|
||||
public function testMessageIsSentToSchedulerTransport(): void
|
||||
{
|
||||
self::bootKernel();
|
||||
|
||||
// 1. Получаем MessageBusInterface (правильный способ)
|
||||
/** @var MessageBusInterface $messageBus */
|
||||
$messageBus = self::getContainer()->get(MessageBusInterface::class);
|
||||
|
||||
// 2. Получаем транспорт scheduler_default
|
||||
/** @var TransportInterface $transport */
|
||||
$transport = self::getContainer()->get('messenger.transport.scheduler_default');
|
||||
|
||||
// 3. Очищаем очередь перед тестом (если транспорт поддерживает)
|
||||
if (method_exists($transport, 'reset')) {
|
||||
$transport->reset();
|
||||
}
|
||||
|
||||
// 4. Отправляем сообщение
|
||||
$messageBus->dispatch(new RunCommandMessage('debug:container'));
|
||||
|
||||
// 5. Проверяем очередь
|
||||
$envelopes = $transport->get();
|
||||
$this->assertCount(1, $envelopes);
|
||||
|
||||
$receivedMessage = $envelopes[0]->getMessage();
|
||||
$this->assertInstanceOf(RunCommandMessage::class, $receivedMessage);
|
||||
$this->assertEquals('debug:container', $receivedMessage->getCommand());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Service;
|
||||
|
||||
use App\Service\Client\Sms4bClientService;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class Sms4bClientServiceTest extends TestCase
|
||||
{
|
||||
private Sms4bClientService $smsClient;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$userAgent = $_ENV['API_CLIENT'];
|
||||
$baseUrl = $_ENV['SMS4B_URL'];
|
||||
$token = $_ENV['SMS4B_TOKEN'];
|
||||
$sender = $_ENV['SMS4B_SENDER'];
|
||||
|
||||
$this->smsClient = new Sms4bClientService($userAgent, $baseUrl, $token, $sender);
|
||||
}
|
||||
|
||||
public function testBalance()
|
||||
{
|
||||
$result = $this->smsClient->balance();
|
||||
|
||||
$this->assertIsArray($result);
|
||||
}
|
||||
|
||||
public function testSenders()
|
||||
{
|
||||
$result = $this->smsClient->senders();
|
||||
|
||||
$this->assertIsArray($result);
|
||||
}
|
||||
|
||||
public function testSendSms()
|
||||
{
|
||||
$to = '79996243200';
|
||||
$msg = 'Тест sms4b интерфейса';
|
||||
|
||||
$result = $this->smsClient->send($to, $msg);
|
||||
|
||||
$this->assertIsArray($result);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Service;
|
||||
|
||||
use App\Service\Client\SmsruClientService;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class SmsruClientServiceTest extends TestCase
|
||||
{
|
||||
private SmsruClientService $smsClient;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$userAgent = $_ENV['API_CLIENT'];
|
||||
$baseUrl = $_ENV['SMSRU_URL'];
|
||||
$token = $_ENV['SMSRU_TOKEN'];
|
||||
$sender = $_ENV['SMSRU_SENDER'];
|
||||
|
||||
$this->smsClient = new SmsruClientService($userAgent, $baseUrl, $token, $sender);
|
||||
}
|
||||
|
||||
public function testBalance()
|
||||
{
|
||||
$result = $this->smsClient->balance();
|
||||
|
||||
$this->assertIsArray($result);
|
||||
}
|
||||
|
||||
public function testSenders()
|
||||
{
|
||||
$result = $this->smsClient->senders();
|
||||
|
||||
$this->assertIsArray($result);
|
||||
}
|
||||
|
||||
public function testSendSms()
|
||||
{
|
||||
$to = '79996243200';
|
||||
$msg = 'Тест smsru интерфейса.';
|
||||
|
||||
$result = $this->smsClient->send($to, $msg);
|
||||
|
||||
$this->assertIsArray($result);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user