Skip to content

Commit

Permalink
Merge 418709e into 3c6c3a5
Browse files Browse the repository at this point in the history
  • Loading branch information
tienvx committed Apr 16, 2022
2 parents 3c6c3a5 + 418709e commit 869fd92
Show file tree
Hide file tree
Showing 43 changed files with 688 additions and 679 deletions.
14 changes: 13 additions & 1 deletion src/Model/Bug.php
Expand Up @@ -7,8 +7,10 @@
use Tienvx\Bundle\MbtBundle\Model\Bug\Video;
use Tienvx\Bundle\MbtBundle\Model\Bug\VideoInterface;

class Bug implements BugInterface
class Bug extends Debug implements BugInterface
{
protected const BUG = 'bug';

protected ?int $id = null;
protected string $title;
protected array $steps = [];
Expand Down Expand Up @@ -114,6 +116,16 @@ public function setVideo(VideoInterface $video): void
$this->video = $video;
}

public function getLogName(): string
{
return sprintf('%s-%d.log', static::BUG, $this->getId());
}

public function getVideoName(): string
{
return sprintf('%s-%d.mp4', static::BUG, $this->getId());
}

public function setCreatedAt(DateTimeInterface $createdAt): void
{
$this->createdAt = $createdAt;
Expand Down
4 changes: 1 addition & 3 deletions src/Model/BugInterface.php
Expand Up @@ -6,7 +6,7 @@
use Tienvx\Bundle\MbtBundle\Model\Bug\StepInterface;
use Tienvx\Bundle\MbtBundle\Model\Bug\VideoInterface;

interface BugInterface
interface BugInterface extends DebugInterface
{
public function setId(int $id);

Expand All @@ -25,8 +25,6 @@ public function setSteps(array $steps): void;

public function addStep(StepInterface $step): void;

public function getTask(): TaskInterface;

public function setTask(TaskInterface $task): void;

public function getMessage(): string;
Expand Down
18 changes: 18 additions & 0 deletions src/Model/Debug.php
@@ -0,0 +1,18 @@
<?php

namespace Tienvx\Bundle\MbtBundle\Model;

abstract class Debug implements DebugInterface
{
protected bool $debug = false;

public function isDebug(): bool
{
return $this->debug;
}

public function setDebug(bool $debug): void
{
$this->debug = $debug;
}
}
16 changes: 16 additions & 0 deletions src/Model/DebugInterface.php
@@ -0,0 +1,16 @@
<?php

namespace Tienvx\Bundle\MbtBundle\Model;

interface DebugInterface
{
public function isDebug(): bool;

public function setDebug(bool $debug): void;

public function getLogName(): string;

public function getVideoName(): string;

public function getTask(): TaskInterface;
}
18 changes: 12 additions & 6 deletions src/Model/Task.php
Expand Up @@ -8,16 +8,17 @@
use Tienvx\Bundle\MbtBundle\Model\Model\RevisionInterface;
use Tienvx\Bundle\MbtBundle\Model\Task\BrowserInterface;

class Task implements TaskInterface
class Task extends Debug implements TaskInterface
{
protected const TASK = 'task';

protected ?int $id = null;
protected string $title = '';
protected RevisionInterface $modelRevision;
protected ?int $author = null;
protected bool $running = false;
protected BrowserInterface $browser;
protected Collection $bugs;
protected bool $debug = false;
protected DateTimeInterface $updatedAt;
protected DateTimeInterface $createdAt;

Expand Down Expand Up @@ -102,14 +103,19 @@ public function addBug(BugInterface $bug): void
}
}

public function isDebug(): bool
public function getLogName(): string
{
return sprintf('%s-%d.log', static::TASK, $this->getId());
}

public function getVideoName(): string
{
return $this->debug;
return sprintf('%s-%d.mp4', static::TASK, $this->getId());
}

public function setDebug(bool $debug): void
public function getTask(): TaskInterface
{
$this->debug = $debug;
return $this;
}

public function setCreatedAt(DateTimeInterface $createdAt): void
Expand Down
6 changes: 1 addition & 5 deletions src/Model/TaskInterface.php
Expand Up @@ -7,7 +7,7 @@
use Tienvx\Bundle\MbtBundle\Model\Model\RevisionInterface;
use Tienvx\Bundle\MbtBundle\Model\Task\BrowserInterface;

interface TaskInterface
interface TaskInterface extends DebugInterface
{
public function setId(int $id);

Expand Down Expand Up @@ -37,10 +37,6 @@ public function getBugs(): Collection;

public function addBug(BugInterface $bug): void;

public function isDebug(): bool;

public function setDebug(bool $debug): void;

public function setCreatedAt(DateTimeInterface $createdAt): void;

public function getCreatedAt(): DateTimeInterface;
Expand Down
11 changes: 6 additions & 5 deletions src/Reducer/HandlerTemplate.php
Expand Up @@ -7,20 +7,20 @@
use Tienvx\Bundle\MbtBundle\Message\ReduceBugMessage;
use Tienvx\Bundle\MbtBundle\Model\BugInterface;
use Tienvx\Bundle\MbtBundle\Repository\BugRepositoryInterface;
use Tienvx\Bundle\MbtBundle\Service\StepsBuilderInterface;
use Tienvx\Bundle\MbtBundle\Service\StepsRunnerInterface;
use Tienvx\Bundle\MbtBundle\Service\Step\Builder\StepsBuilderInterface;
use Tienvx\Bundle\MbtBundle\Service\Step\Runner\BugStepsRunner;

abstract class HandlerTemplate implements HandlerInterface
{
protected BugRepositoryInterface $bugRepository;
protected MessageBusInterface $messageBus;
protected StepsRunnerInterface $stepsRunner;
protected BugStepsRunner $stepsRunner;
protected StepsBuilderInterface $stepsBuilder;

public function __construct(
BugRepositoryInterface $bugRepository,
MessageBusInterface $messageBus,
StepsRunnerInterface $stepsRunner,
BugStepsRunner $stepsRunner,
StepsBuilderInterface $stepsBuilder
) {
$this->bugRepository = $bugRepository;
Expand All @@ -36,7 +36,8 @@ public function handle(BugInterface $bug, int $from, int $to): void
return;
}

$this->stepsRunner->run($newSteps, $bug, false, function (Throwable $throwable) use ($bug, $newSteps): void {
$bug->setDebug(false);
$this->stepsRunner->run($newSteps, $bug, function (Throwable $throwable) use ($bug, $newSteps): void {
if ($throwable->getMessage() === $bug->getMessage()) {
$this->bugRepository->updateSteps($bug, $newSteps);
$this->messageBus->dispatch(new ReduceBugMessage($bug->getId()));
Expand Down
6 changes: 0 additions & 6 deletions src/Repository/BugRepository.php
Expand Up @@ -65,10 +65,4 @@ public function stopRecording(BugInterface $bug): void
$this->getEntityManager()->getConnection()->connect();
$this->getEntityManager()->flush();
}

public function updateVideoErrorMessage(BugInterface $bug, string $videoErrorMessage): void
{
$bug->getVideo()->setErrorMessage($videoErrorMessage);
$this->getEntityManager()->flush();
}
}
2 changes: 0 additions & 2 deletions src/Repository/BugRepositoryInterface.php
Expand Up @@ -16,6 +16,4 @@ 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 $videoErrorMessage): void;
}
16 changes: 8 additions & 8 deletions src/Resources/config/services.php
Expand Up @@ -62,12 +62,13 @@
use Tienvx\Bundle\MbtBundle\Service\Petrinet\PetrinetHelperInterface;
use Tienvx\Bundle\MbtBundle\Service\SelenoidHelper;
use Tienvx\Bundle\MbtBundle\Service\SelenoidHelperInterface;
use Tienvx\Bundle\MbtBundle\Service\ShortestPathStepsBuilder;
use Tienvx\Bundle\MbtBundle\Service\StepRunner;
use Tienvx\Bundle\MbtBundle\Service\StepRunnerInterface;
use Tienvx\Bundle\MbtBundle\Service\StepsBuilderInterface;
use Tienvx\Bundle\MbtBundle\Service\StepsRunner;
use Tienvx\Bundle\MbtBundle\Service\StepsRunnerInterface;
use Tienvx\Bundle\MbtBundle\Service\Step\Builder\ShortestPathStepsBuilder;
use Tienvx\Bundle\MbtBundle\Service\Step\Builder\StepsBuilderInterface;
use Tienvx\Bundle\MbtBundle\Service\Step\Runner\StepRunner;
use Tienvx\Bundle\MbtBundle\Service\Step\Runner\StepRunnerInterface;
use Tienvx\Bundle\MbtBundle\Service\Step\Runner\StepsRunner;
use Tienvx\Bundle\MbtBundle\Service\Step\Runner\StepsRunnerInterface;
use Tienvx\Bundle\MbtBundle\Service\Step\Runner\TaskStepsRunner;
use Tienvx\Bundle\MbtBundle\Service\Task\TaskHelper;
use Tienvx\Bundle\MbtBundle\Service\Task\TaskHelperInterface;
use Tienvx\Bundle\MbtBundle\Validator\TagsValidator;
Expand Down Expand Up @@ -239,8 +240,7 @@
->args([
service(GeneratorManagerInterface::class),
service(TaskRepositoryInterface::class),
service(StepsRunnerInterface::class),
service(BugHelperInterface::class),
service(TaskStepsRunner::class),
service(ConfigInterface::class),
])
->alias(TaskHelperInterface::class, TaskHelper::class)
Expand Down
22 changes: 6 additions & 16 deletions src/Service/Bug/BugHelper.php
Expand Up @@ -5,7 +5,6 @@
use Symfony\Component\Messenger\Exception\RecoverableMessageHandlingException;
use Symfony\Component\Messenger\MessageBusInterface;
use Throwable;
use Tienvx\Bundle\MbtBundle\Entity\Bug;
use Tienvx\Bundle\MbtBundle\Exception\ExceptionInterface;
use Tienvx\Bundle\MbtBundle\Exception\UnexpectedValueException;
use Tienvx\Bundle\MbtBundle\Message\RecordVideoMessage;
Expand All @@ -14,23 +13,23 @@
use Tienvx\Bundle\MbtBundle\Reducer\ReducerManagerInterface;
use Tienvx\Bundle\MbtBundle\Repository\BugRepositoryInterface;
use Tienvx\Bundle\MbtBundle\Service\ConfigInterface;
use Tienvx\Bundle\MbtBundle\Service\StepsRunnerInterface;
use Tienvx\Bundle\MbtBundle\Service\Step\Runner\BugStepsRunner;

class BugHelper implements BugHelperInterface
{
protected ReducerManagerInterface $reducerManager;
protected BugRepositoryInterface $bugRepository;
protected MessageBusInterface $messageBus;
protected BugNotifierInterface $bugNotifier;
protected StepsRunnerInterface $stepsRunner;
protected BugStepsRunner $stepsRunner;
protected ConfigInterface $config;

public function __construct(
ReducerManagerInterface $reducerManager,
BugRepositoryInterface $bugRepository,
MessageBusInterface $messageBus,
BugNotifierInterface $bugNotifier,
StepsRunnerInterface $stepsRunner,
BugStepsRunner $stepsRunner,
ConfigInterface $config
) {
$this->reducerManager = $reducerManager;
Expand Down Expand Up @@ -95,22 +94,13 @@ public function recordVideo(int $bugId): void
}

$this->bugRepository->startRecording($bug);
$this->stepsRunner->run($bug->getSteps(), $bug, true, function (Throwable $throwable) use ($bug): void {
$this->bugRepository->updateVideoErrorMessage($bug, $throwable->getMessage());
$bug->setDebug(true);
$this->stepsRunner->run($bug->getSteps(), $bug, function (Throwable $throwable) use ($bug) {
$bug->getVideo()->setErrorMessage($throwable->getMessage());
});
$this->bugRepository->stopRecording($bug);
}

public function createBug(array $steps, string $message): BugInterface
{
$bug = new Bug();
$bug->setTitle('');
$bug->setSteps($steps);
$bug->setMessage($message);

return $bug;
}

protected function getBug(int $bugId, string $action): BugInterface
{
$bug = $this->bugRepository->find($bugId);
Expand Down
4 changes: 0 additions & 4 deletions src/Service/Bug/BugHelperInterface.php
Expand Up @@ -2,8 +2,6 @@

namespace Tienvx\Bundle\MbtBundle\Service\Bug;

use Tienvx\Bundle\MbtBundle\Model\BugInterface;

interface BugHelperInterface
{
public function reduceBug(int $bugId): void;
Expand All @@ -13,6 +11,4 @@ public function reduceSteps(int $bugId, int $length, int $from, int $to): void;
public function reportBug(int $bugId): void;

public function recordVideo(int $bugId): void;

public function createBug(array $steps, string $message): BugInterface;
}
2 changes: 1 addition & 1 deletion src/Service/ExpressionLanguage.php
Expand Up @@ -8,6 +8,6 @@ class ExpressionLanguage extends BaseExpressionLanguage
{
protected function registerFunctions()
{
// Don't register const function
// Don't register constant function
}
}

0 comments on commit 869fd92

Please sign in to comment.