У меня есть куча обработчиков. Каждый из них, в конечном счете, содержит код для сохранения данных и выпуска событий. Что следует проверить? На данный момент это модульные тесты, может быть, это должно быть интеграционным? Я должен что -нибудь издеваться или нет? Почему? Должен ли он быть протестирован вообще?public function __invoke(AddCategory $command): int
{
// some code
$this->categories->save($category);
$this->events->publishAll($category->releaseEvents());
return $category->id()->value;
}
public function __invoke(RenameCategory $command): void
{
// some code
$this->categories->save($category);
$this->events->publishAll($category->releaseEvents());
}
На данный момент мои тесты выглядят так:
Добавление тестов
protected function setUp(): void
{
$this->categories = new TestCategoryRepository();
$this->events = new TestEventDispatcher();
$this->handler = new AddCategoryHandler($this->categories, $this->events);
}
public function testHandler(): void
{
// preparing code
($this->handler)($command);
$this->assertTrue($currentEventsCountMoreThanInitialEventsCount);
$this->assertTrue($currentRepositoryCountMoreThanInitialRepositoryCount);
$this->assertIsInt($categoryId);
$this->assertNotNull($category);
}
проверить некоторые изменения:
protected function setUp(): void
{
$this->categories = $this->createMock(CategoryRepository::class);
$this->events = new TestEventDispatcher();
$this->handler = new RenameCategoryHandler($this->categories, $this->events);
}
public function testHandler(): void
{
// preparing code
$this->categories->expects($this->once())
->method('getById')
->with($categoryId)
->willReturn($category);
$this->categories->expects($this->once())->method('save');
($this->handler)($command);
$this->assertTrue($currentEventsCountMoreThanInitialEventsCount);
}
Подробнее здесь: https://stackoverflow.com/questions/793 ... er-in-cqrs
Как тестировать и что нужно тестировать для CommandHandler в CQRS? ⇐ Php
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Могу ли я вызвать QueryHandler/CommandHandler в другом CommandHandler в CQRS?
Anonymous » » в форуме C# - 0 Ответы
- 12 Просмотры
-
Последнее сообщение Anonymous
-