Skip to content

Commit

Permalink
Merge pull request #40 from tienvx/remove-reproduce-path-entity
Browse files Browse the repository at this point in the history
Remove ReproducePath entity
  • Loading branch information
tienvx committed Jun 21, 2018
2 parents b1234f1 + 5084742 commit 38e6acf
Show file tree
Hide file tree
Showing 33 changed files with 453 additions and 725 deletions.
23 changes: 15 additions & 8 deletions src/Command/ExecuteTaskCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Throwable;
use Tienvx\Bundle\MbtBundle\Entity\ReproducePath;
use Tienvx\Bundle\MbtBundle\Entity\Bug;
use Tienvx\Bundle\MbtBundle\Entity\Task;
use Tienvx\Bundle\MbtBundle\Service\GeneratorManager;
use Tienvx\Bundle\MbtBundle\Service\ModelRegistry;
Expand All @@ -20,6 +20,7 @@ class ExecuteTaskCommand extends Command
private $generatorManager;
private $entityManager;
private $stopConditionManager;
private $defaultBugTitle;

public function __construct(
ModelRegistry $modelRegistry,
Expand All @@ -44,6 +45,11 @@ protected function configure()
->addArgument('task-id', InputArgument::REQUIRED, 'The task id to execute.');
}

public function setDefaultBugTitle(string $defaultBugTitle)
{
$this->defaultBugTitle = $defaultBugTitle;
}

/**
* @param InputInterface $input
* @param OutputInterface $output
Expand Down Expand Up @@ -74,13 +80,14 @@ protected function execute(InputInterface $input, OutputInterface $output)
}
} catch (Throwable $throwable) {
$path = $generator->getPath();
$reproducePath = new ReproducePath();
$reproducePath->setSteps($path);
$reproducePath->setLength($path->countEdges());
$reproducePath->setBugMessage($throwable->getMessage());
$reproducePath->setTask($task);

$this->entityManager->persist($reproducePath);
$bug = new Bug();
$bug->setTitle($this->defaultBugTitle);
$bug->setSteps($path);
$bug->setLength($path->countEdges());
$bug->setBugMessage($throwable->getMessage());
$bug->setTask($task);
$bug->setStatus('unverified');
$this->entityManager->persist($bug);
$this->entityManager->flush();
} finally {
$subject->tearDown();
Expand Down
2 changes: 0 additions & 2 deletions src/Command/HandlePathReducerMessageCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@

namespace Tienvx\Bundle\MbtBundle\Command;

use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Tienvx\Bundle\MbtBundle\Entity\ReproducePath;
use Tienvx\Bundle\MbtBundle\Service\PathReducerManager;

class HandlePathReducerMessageCommand extends Command
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Tienvx\Bundle\MbtBundle\Entity\ReproducePath;
use Tienvx\Bundle\MbtBundle\Entity\Bug;
use Tienvx\Bundle\MbtBundle\Service\PathReducerManager;

class ReduceReproducePathCommand extends Command
class ReduceStepsCommand extends Command
{
private $pathReducerManager;
private $entityManager;
Expand All @@ -26,10 +26,10 @@ public function __construct(PathReducerManager $pathReducerManager, EntityManage
protected function configure()
{
$this
->setName('mbt:reduce-reproduce-path')
->setDescription('Reduce a reproduce path.')
->setHelp("Make reproduce path's steps shorter.")
->addArgument('reproduce-path-id', InputArgument::REQUIRED, 'The reproduce path id to reduce.');
->setName('mbt:reduce-steps')
->setDescription('Reduce a reproduce steps.')
->setHelp("Make bug's reproduce steps shorter.")
->addArgument('bug-id', InputArgument::REQUIRED, 'The bug id to reduce the steps.');
}

/**
Expand All @@ -39,16 +39,16 @@ protected function configure()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$reproducePathId = $input->getArgument('reproduce-path-id');
/** @var ReproducePath $reproducePath */
$reproducePath = $this->entityManager->getRepository(ReproducePath::class)->find($reproducePathId);
$bugId = $input->getArgument('bug-id');
/** @var Bug $bug */
$bug = $this->entityManager->getRepository(Bug::class)->find($bugId);

if (!$reproducePath) {
$output->writeln(sprintf('No reproduce path found for id %d', $reproducePathId));
if (!$bug) {
$output->writeln(sprintf('No bug found for id %d', $bugId));
return;
}

$pathReducer = $this->pathReducerManager->getPathReducer($reproducePath->getTask()->getReducer());
$pathReducer->reduce($reproducePath);
$pathReducer = $this->pathReducerManager->getPathReducer($bug->getTask()->getReducer());
$pathReducer->reduce($bug);
}
}
2 changes: 1 addition & 1 deletion src/Command/ReportBugCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
return;
}

$reporter = $this->reporterManager->getReporter($bug->getReproducePath()->getTask()->getReporter());
$reporter = $this->reporterManager->getReporter($bug->getTask()->getReporter());
$reporter->report($bug);
}
}
6 changes: 3 additions & 3 deletions src/DependencyInjection/TienvxMbtExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Swift_Mailer;
use Tienvx\Bundle\MbtBundle\EventListener\ReducerSubscriber;
use Tienvx\Bundle\MbtBundle\Command\ExecuteTaskCommand;
use Tienvx\Bundle\MbtBundle\Generator\GeneratorInterface;
use Tienvx\Bundle\MbtBundle\PathReducer\PathReducerInterface;
use Tienvx\Bundle\MbtBundle\Reporter\EmailReporter;
Expand Down Expand Up @@ -47,8 +47,8 @@ public function load(array $configs, ContainerBuilder $container)
$emailReporterDefinition->addMethodCall('setTwig', [new Reference(Twig::class)]);
}

$reducerSubscriberDefinition = $container->getDefinition(ReducerSubscriber::class);
$reducerSubscriberDefinition->addMethodCall('setDefaultBugTitle', [$config['default_bug_title']]);
$executeTaskCommandDefinition = $container->getDefinition(ExecuteTaskCommand::class);
$executeTaskCommandDefinition->addMethodCall('setDefaultBugTitle', [$config['default_bug_title']]);

$coverageStopConditionDefinition = $container->getDefinition(CoverageStopCondition::class);
$coverageStopConditionDefinition->addMethodCall('setMaxPathLength', [$config['max_path_length']]);
Expand Down
80 changes: 64 additions & 16 deletions src/Entity/Bug.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@ class Bug
*/
private $id;

/**
* @ORM\OneToOne(targetEntity="ReproducePath")
* @ORM\JoinColumn(name="reproduce_path_id", referencedColumnName="id")
*/
private $reproducePath;

/**
* @ORM\Column(type="text")
* @Assert\NotBlank
Expand All @@ -38,19 +32,33 @@ class Bug
*/
private $status;

public function getId()
{
return $this->id;
}
/**
* @ORM\Column(type="text")
* @Assert\NotBlank
*/
private $steps;

public function getReproducePath(): ReproducePath
{
return $this->reproducePath;
}
/**
* @ORM\Column(type="integer")
* @Assert\NotBlank
*/
private $length;

/**
* @ORM\ManyToOne(targetEntity="Task")
* @ORM\JoinColumn(name="task_id", referencedColumnName="id")
*/
private $task;

public function setReproducePath(ReproducePath $reproducePath)
/**
* @ORM\Column(type="text")
* @Assert\NotBlank
*/
private $bugMessage;

public function getId()
{
$this->reproducePath = $reproducePath;
return $this->id;
}

public function getTitle(): string
Expand All @@ -72,4 +80,44 @@ public function setStatus(string $status)
{
$this->status = $status;
}

public function getSteps(): string
{
return $this->steps;
}

public function setSteps(string $steps)
{
$this->steps = $steps;
}

public function getLength(): int
{
return $this->length;
}

public function setLength(int $length)
{
$this->length = $length;
}

public function getTask(): Task
{
return $this->task;
}

public function setTask(Task $task)
{
$this->task = $task;
}

public function getBugMessage(): string
{
return $this->bugMessage;
}

public function setBugMessage(string $bugMessage)
{
$this->bugMessage = $bugMessage;
}
}
16 changes: 8 additions & 8 deletions src/Entity/QueuedReproducePath.php → src/Entity/QueuedLoop.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/**
* @ORM\Entity
*/
class QueuedReproducePath
class QueuedLoop
{
/**
* @ORM\Column(type="integer")
Expand All @@ -25,10 +25,10 @@ class QueuedReproducePath
private $messageHashes;

/**
* @ORM\OneToOne(targetEntity="ReproducePath")
* @ORM\JoinColumn(name="reproduce_path_id", referencedColumnName="id")
* @ORM\OneToOne(targetEntity="Bug")
* @ORM\JoinColumn(name="bug_id", referencedColumnName="id")
*/
private $reproducePath;
private $bug;

/**
* @ORM\Column(type="integer")
Expand All @@ -51,14 +51,14 @@ public function setMessageHashes(array $messageHashes)
$this->messageHashes = $messageHashes;
}

public function getReproducePath(): ReproducePath
public function getBug(): Bug
{
return $this->reproducePath;
return $this->bug;
}

public function setReproducePath(ReproducePath $reproducePath)
public function setBug(Bug $bug)
{
$this->reproducePath = $reproducePath;
$this->bug = $bug;
}

public function getIndicator(): int
Expand Down
90 changes: 0 additions & 90 deletions src/Entity/ReproducePath.php

This file was deleted.

Loading

0 comments on commit 38e6acf

Please sign in to comment.