From 1b66e4ee3a6369dd1484ca35ad24bb73954f7676 Mon Sep 17 00:00:00 2001 From: Akolzin Dmitry Date: Tue, 30 Mar 2021 15:20:02 +0300 Subject: [PATCH] add tests and phpdoc --- Tests/DataFixtures/TestMessage.php | 15 ++++++++ Tests/Messenger/CommandMessageTest.php | 38 +++++++++++++++++++ .../MessageHandler/InNewProcessRunnerTest.php | 5 +++ .../SimpleConsoleRunnerTest.php | 5 +++ Tests/Messenger/MessageHandlerTest.php | 26 +++++++++++++ 5 files changed, 89 insertions(+) create mode 100644 Tests/DataFixtures/TestMessage.php create mode 100644 Tests/Messenger/CommandMessageTest.php create mode 100644 Tests/Messenger/MessageHandlerTest.php diff --git a/Tests/DataFixtures/TestMessage.php b/Tests/DataFixtures/TestMessage.php new file mode 100644 index 0000000..b69877e --- /dev/null +++ b/Tests/DataFixtures/TestMessage.php @@ -0,0 +1,15 @@ +commandName = 'test'; + $this->arguments = ['argument' => 'argument']; + $this->options = ['option' => 'option']; + } +} diff --git a/Tests/Messenger/CommandMessageTest.php b/Tests/Messenger/CommandMessageTest.php new file mode 100644 index 0000000..fdd13b1 --- /dev/null +++ b/Tests/Messenger/CommandMessageTest.php @@ -0,0 +1,38 @@ +getCommandName()); + static::assertEquals(['argument' => 'argument'], $message->getArguments()); + static::assertEquals(['option' => 'option'], $message->getOptions()); + static::assertEquals(['--option' => 'option'], $message->getFormattedOptions()); + + $message->addOption('option2', 'option2'); + $message->addArgument('argument2', 'argument2'); + + static::assertEquals(['argument' => 'argument', 'argument2' => 'argument2'], $message->getArguments()); + static::assertEquals(['option' => 'option', 'option2' => 'option2'], $message->getOptions()); + static::assertEquals(['--option' => 'option', '--option2' => 'option2'], $message->getFormattedOptions()); + + $message->setOptions(['option' => 'option']); + $message->setArguments(['argument' => 'argument']); + + static::assertEquals(['argument' => 'argument'], $message->getArguments()); + static::assertEquals(['option' => 'option'], $message->getOptions()); + static::assertEquals(['--option' => 'option'], $message->getFormattedOptions()); + } +} diff --git a/Tests/Messenger/MessageHandler/InNewProcessRunnerTest.php b/Tests/Messenger/MessageHandler/InNewProcessRunnerTest.php index 38b8507..cada1a3 100644 --- a/Tests/Messenger/MessageHandler/InNewProcessRunnerTest.php +++ b/Tests/Messenger/MessageHandler/InNewProcessRunnerTest.php @@ -7,6 +7,11 @@ use RetailCrm\ServiceBundle\Messenger\MessageHandler\InNewProcessRunner; use RetailCrm\ServiceBundle\Tests\Fixtures\App\TestCommandMessage; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; +/** + * Class InNewProcessRunnerTest + * + * @package RetailCrm\ServiceBundle\Tests\Messenger\MessageHandler + */ class InNewProcessRunnerTest extends KernelTestCase { protected function setUp(): void diff --git a/Tests/Messenger/MessageHandler/SimpleConsoleRunnerTest.php b/Tests/Messenger/MessageHandler/SimpleConsoleRunnerTest.php index f279d52..d5256b7 100644 --- a/Tests/Messenger/MessageHandler/SimpleConsoleRunnerTest.php +++ b/Tests/Messenger/MessageHandler/SimpleConsoleRunnerTest.php @@ -7,6 +7,11 @@ use RetailCrm\ServiceBundle\Messenger\MessageHandler\SimpleConsoleRunner; use RetailCrm\ServiceBundle\Tests\Fixtures\App\TestCommandMessage; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; +/** + * Class SimpleConsoleRunnerTest + * + * @package RetailCrm\ServiceBundle\Tests\Messenger\MessageHandler + */ class SimpleConsoleRunnerTest extends KernelTestCase { protected function setUp(): void diff --git a/Tests/Messenger/MessageHandlerTest.php b/Tests/Messenger/MessageHandlerTest.php new file mode 100644 index 0000000..1f66d97 --- /dev/null +++ b/Tests/Messenger/MessageHandlerTest.php @@ -0,0 +1,26 @@ +createMock(JobRunner::class); + $runner->expects(static::once())->method('run'); + $message = $this->createMock(CommandMessage::class); + + $handler = new MessageHandler($runner); + $handler->__invoke($message); + } +}