Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent updating steps after recording #612

Merged
merged 1 commit into from
Apr 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/Repository/BugRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,28 @@ public function increaseTotal(BugInterface $bug, int $total): void

public function startRecording(BugInterface $bug): void
{
$this->getEntityManager()->refresh($bug);
$bug->getVideo()->setRecording(true);
$this->getEntityManager()->flush();
}

public function stopRecording(BugInterface $bug): void
{
// Recording bug may take long time. Reconnect to flush changes.
$this->getEntityManager()->getConnection()->connect();
// Refresh so we don't update other fields while recording.
$this->getEntityManager()->refresh($bug);
$bug->getVideo()->setRecording(false);
$this->getEntityManager()->flush();
}

public function updateVideoErrorMessage(BugInterface $bug, ?string $errorMessage): void
{
// Recording bug may take long time. Reconnect to flush changes.
$this->getEntityManager()->getConnection()->connect();
// Refresh so we don't update other fields while recording.
$this->getEntityManager()->refresh($bug);
$bug->getVideo()->setErrorMessage($errorMessage);
$this->getEntityManager()->flush();
}
}
2 changes: 2 additions & 0 deletions src/Repository/BugRepositoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ public function increaseTotal(BugInterface $bug, int $total): void;
public function startRecording(BugInterface $bug): void;

public function stopRecording(BugInterface $bug): void;

public function updateVideoErrorMessage(BugInterface $bug, ?string $errorMessage): void;
}
3 changes: 2 additions & 1 deletion src/Service/Bug/BugHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ public function recordVideo(int $bugId): void
$this->bugRepository->startRecording($bug);
$bug->setDebug(true);
$this->stepsRunner->run($bug->getSteps(), $bug, function (Throwable $throwable) use ($bug) {
$bug->getVideo()->setErrorMessage(
$this->bugRepository->updateVideoErrorMessage(
$bug,
$throwable->getMessage() !== $bug->getMessage() ? $throwable->getMessage() : null
);
});
Expand Down
20 changes: 17 additions & 3 deletions tests/Repository/BugRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class BugRepositoryTest extends TestCase
protected EntityManagerDecorator $manager;
protected BugInterface $bug;
protected BugRepositoryInterface $bugRepository;
protected Connection $connection;

protected function setUp(): void
{
Expand All @@ -54,6 +55,7 @@ protected function setUp(): void
$this->createMock(StepInterface::class),
$this->createMock(StepInterface::class),
]);
$this->connection = $this->createMock(Connection::class);
}

public function testUpdateSteps(): void
Expand Down Expand Up @@ -156,19 +158,31 @@ public function testIncreaseTotal(): void
public function testStartRecordingBug(): void
{
$this->bug->getVideo()->setRecording(false);
$this->manager->expects($this->once())->method('refresh')->with($this->bug);
$this->manager->expects($this->once())->method('flush');
$this->bugRepository->startRecording($this->bug);
$this->assertTrue($this->bug->getVideo()->isRecording());
}

public function testStopRecordingBug(): void
{
$connection = $this->createMock(Connection::class);
$connection->expects($this->once())->method('connect');
$this->connection->expects($this->once())->method('connect');
$this->bug->getVideo()->setRecording(true);
$this->manager->expects($this->once())->method('refresh')->with($this->bug);
$this->manager->expects($this->once())->method('flush');
$this->manager->expects($this->once())->method('getConnection')->willReturn($connection);
$this->manager->expects($this->once())->method('getConnection')->willReturn($this->connection);
$this->bugRepository->stopRecording($this->bug);
$this->assertFalse($this->bug->getVideo()->isRecording());
}

public function testUpdateVideoErrorMessage(): void
{
$this->connection->expects($this->once())->method('connect');
$this->bug->getVideo()->setErrorMessage(null);
$this->manager->expects($this->once())->method('refresh')->with($this->bug);
$this->manager->expects($this->once())->method('flush');
$this->manager->expects($this->once())->method('getConnection')->willReturn($this->connection);
$this->bugRepository->updateVideoErrorMessage($this->bug, 'New error');
$this->assertSame('New error', $this->bug->getVideo()->getErrorMessage());
}
}
16 changes: 11 additions & 5 deletions tests/Service/Bug/BugHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,13 +256,19 @@ public function testRecordVideo(?Throwable $exception): void
$this->bugRepository->expects($this->once())->method('find')->with(123)->willReturn($this->bug);
$this->bugRepository->expects($this->once())->method('startRecording')->with($this->bug);
$this->bugRepository->expects($this->once())->method('stopRecording')->with($this->bug);
$this->helper->recordVideo(123);
$this->assertTrue($this->bug->isDebug());
if ($exception && $exception->getMessage() !== $this->bug->getMessage()) {
$this->assertSame($exception->getMessage(), $this->bug->getVideo()->getErrorMessage());
if ($exception) {
$this->bugRepository
->expects($this->once())
->method('updateVideoErrorMessage')
->with(
$this->bug,
$exception->getMessage() !== $this->bug->getMessage() ? $exception->getMessage() : null
);
} else {
$this->assertNull($this->bug->getVideo()->getErrorMessage());
$this->bugRepository->expects($this->never())->method('updateVideoErrorMessage');
}
$this->helper->recordVideo(123);
$this->assertTrue($this->bug->isDebug());
}

public function exceptionProvider(): array
Expand Down