diff --git a/src/Command/HandlePathReducerMessageCommand.php b/src/Command/HandlePathReducerMessageCommand.php index d36b3ef8..a78287f5 100644 --- a/src/Command/HandlePathReducerMessageCommand.php +++ b/src/Command/HandlePathReducerMessageCommand.php @@ -2,6 +2,7 @@ namespace Tienvx\Bundle\MbtBundle\Command; +use Exception; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -31,7 +32,7 @@ protected function configure() /** * @param InputInterface $input * @param OutputInterface $output - * @throws \Exception + * @throws Exception */ protected function execute(InputInterface $input, OutputInterface $output) { diff --git a/src/Command/ReduceStepsCommand.php b/src/Command/ReduceStepsCommand.php index 7ed924f3..2becb946 100644 --- a/src/Command/ReduceStepsCommand.php +++ b/src/Command/ReduceStepsCommand.php @@ -2,6 +2,7 @@ namespace Tienvx\Bundle\MbtBundle\Command; +use Exception; use Doctrine\ORM\EntityManagerInterface; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; @@ -34,7 +35,7 @@ protected function configure() /** * @param InputInterface $input * @param OutputInterface $output - * @throws \Exception + * @throws Exception */ protected function execute(InputInterface $input, OutputInterface $output) { diff --git a/src/Command/ReportBugCommand.php b/src/Command/ReportBugCommand.php index 3a7caa45..18223d40 100644 --- a/src/Command/ReportBugCommand.php +++ b/src/Command/ReportBugCommand.php @@ -2,6 +2,7 @@ namespace Tienvx\Bundle\MbtBundle\Command; +use Exception; use Doctrine\ORM\EntityManagerInterface; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; @@ -35,7 +36,7 @@ protected function configure() /** * @param InputInterface $input * @param OutputInterface $output - * @throws \Exception + * @throws Exception */ protected function execute(InputInterface $input, OutputInterface $output) { diff --git a/src/DependencyInjection/Compiler/GeneratorPass.php b/src/DependencyInjection/Compiler/GeneratorPass.php index 0eafd8c1..8b4199fe 100644 --- a/src/DependencyInjection/Compiler/GeneratorPass.php +++ b/src/DependencyInjection/Compiler/GeneratorPass.php @@ -2,6 +2,7 @@ namespace Tienvx\Bundle\MbtBundle\DependencyInjection\Compiler; +use Exception; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\Exception\RuntimeException; @@ -21,7 +22,7 @@ public function __construct(string $generatorService = 'mbt.generator_manager', /** * @param ContainerBuilder $container - * @throws \Exception + * @throws Exception */ public function process(ContainerBuilder $container) { diff --git a/src/DependencyInjection/Compiler/PathReducerPass.php b/src/DependencyInjection/Compiler/PathReducerPass.php index f0451fc8..b1a3755e 100644 --- a/src/DependencyInjection/Compiler/PathReducerPass.php +++ b/src/DependencyInjection/Compiler/PathReducerPass.php @@ -2,6 +2,7 @@ namespace Tienvx\Bundle\MbtBundle\DependencyInjection\Compiler; +use Exception; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\Exception\RuntimeException; @@ -21,7 +22,7 @@ public function __construct(string $pathReducerService = 'mbt.path_reducer_manag /** * @param ContainerBuilder $container - * @throws \Exception + * @throws Exception */ public function process(ContainerBuilder $container) { diff --git a/src/DependencyInjection/Compiler/ReporterPass.php b/src/DependencyInjection/Compiler/ReporterPass.php index 1e23c9dd..18ad89d9 100644 --- a/src/DependencyInjection/Compiler/ReporterPass.php +++ b/src/DependencyInjection/Compiler/ReporterPass.php @@ -2,6 +2,7 @@ namespace Tienvx\Bundle\MbtBundle\DependencyInjection\Compiler; +use Exception; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\Exception\RuntimeException; @@ -21,7 +22,7 @@ public function __construct(string $reporterService = 'mbt.reporter_manager', st /** * @param ContainerBuilder $container - * @throws \Exception + * @throws Exception */ public function process(ContainerBuilder $container) { diff --git a/src/DependencyInjection/Compiler/SecurityTokenPass.php b/src/DependencyInjection/Compiler/SecurityTokenPass.php index 23f5728e..bd9e1677 100644 --- a/src/DependencyInjection/Compiler/SecurityTokenPass.php +++ b/src/DependencyInjection/Compiler/SecurityTokenPass.php @@ -2,6 +2,7 @@ namespace Tienvx\Bundle\MbtBundle\DependencyInjection\Compiler; +use Exception; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\Reference; @@ -21,7 +22,7 @@ public function __construct(string $tokenStorageService = 'security.token_storag /** * @param ContainerBuilder $container - * @throws \Exception + * @throws Exception */ public function process(ContainerBuilder $container) { diff --git a/src/DependencyInjection/Compiler/TaggedServiceTrait.php b/src/DependencyInjection/Compiler/TaggedServiceTrait.php index 1497e3f3..45329a93 100644 --- a/src/DependencyInjection/Compiler/TaggedServiceTrait.php +++ b/src/DependencyInjection/Compiler/TaggedServiceTrait.php @@ -2,6 +2,7 @@ namespace Tienvx\Bundle\MbtBundle\DependencyInjection\Compiler; +use Exception; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Reference; use InvalidArgumentException; @@ -12,7 +13,7 @@ trait TaggedServiceTrait * @param string $tagName * @param ContainerBuilder $container * @return array - * @throws \Exception + * @throws Exception */ private function findTaggedServices(string $tagName, ContainerBuilder $container) { diff --git a/src/DependencyInjection/TienvxMbtExtension.php b/src/DependencyInjection/TienvxMbtExtension.php index 50309a32..d2d6dc82 100644 --- a/src/DependencyInjection/TienvxMbtExtension.php +++ b/src/DependencyInjection/TienvxMbtExtension.php @@ -2,6 +2,7 @@ namespace Tienvx\Bundle\MbtBundle\DependencyInjection; +use Exception; use GuzzleHttp\Client; use Psr\Log\LoggerInterface; use Symfony\Bridge\Monolog\Logger; @@ -36,7 +37,7 @@ class TienvxMbtExtension extends Extension { /** * {@inheritdoc} - * @throws \Exception + * @throws Exception */ public function load(array $configs, ContainerBuilder $container) { diff --git a/src/Entity/Bug.php b/src/Entity/Bug.php index 7ec6db34..afb04091 100644 --- a/src/Entity/Bug.php +++ b/src/Entity/Bug.php @@ -35,6 +35,7 @@ class Bug /** * @ORM\Column(type="text") * @Assert\NotBlank + * @MbtAssert\Path */ private $path; diff --git a/src/Generator/GeneratorManager.php b/src/Generator/GeneratorManager.php index bbb8d08d..28d3ac8f 100644 --- a/src/Generator/GeneratorManager.php +++ b/src/Generator/GeneratorManager.php @@ -2,6 +2,8 @@ namespace Tienvx\Bundle\MbtBundle\Generator; +use Exception; + class GeneratorManager { /** @@ -30,7 +32,7 @@ public function getGenerators(): array * @param $name * @return GeneratorInterface * - * @throws \Exception + * @throws Exception */ public function getGenerator($name): GeneratorInterface { @@ -38,7 +40,7 @@ public function getGenerator($name): GeneratorInterface return $this->generators[$name]; } - throw new \Exception(sprintf('Generator %s does not exist.', $name)); + throw new Exception(sprintf('Generator %s does not exist.', $name)); } /** diff --git a/src/Graph/Path.php b/src/Graph/Path.php index d19c020e..a79e4330 100644 --- a/src/Graph/Path.php +++ b/src/Graph/Path.php @@ -2,6 +2,7 @@ namespace Tienvx\Bundle\MbtBundle\Graph; +use Exception; use Iterator; use Serializable; @@ -27,8 +28,18 @@ class Path implements Serializable, Iterator */ protected $position; + /** + * Path constructor. + * @param array $transitions + * @param array $data + * @param array $places + * @throws Exception + */ public function __construct(array $transitions = [], array $data = [], array $places = []) { + if (count($transitions) !== count($data) || count($transitions) !== count($places)) { + throw new Exception('Invalid transitions, data or places for path'); + } $this->transitions = $transitions; $this->data = $data; $this->places = $places; @@ -42,16 +53,26 @@ public function add(?string $transition, ?array $data, array $places) $this->places[] = $places; } - public function countTransitions() + public function countTransitions(): int { return count(array_filter($this->transitions)); } - public function countPlaces() + public function countPlaces(): int { return count($this->places); } + public function countUniqueTransitions(): int + { + return count(array_unique(array_filter($this->transitions))); + } + + public function countUniquePlaces(): int + { + return count(array_unique(call_user_func_array('array_merge', $this->places))); + } + public function getTransitionAt(int $index): ?string { return $this->transitions[$index]; @@ -72,29 +93,24 @@ public function setDataAt(int $index, array $data) $this->data[$index] = $data; } - public function getAllTransitions(): array - { - return $this->transitions; - } - - public function getAllData(): array - { - return $this->data; - } - - public function getAllPlaces(): array - { - return $this->places; - } - public function serialize() { return serialize([$this->transitions, $this->data, $this->places]); } + /** + * @param string $serialized + * @throws Exception + */ public function unserialize($serialized) { - list($this->transitions, $this->data, $this->places) = unserialize($serialized); + list($transitions, $data, $places) = unserialize($serialized); + if (count($transitions) !== count($data) || count($transitions) !== count($places)) { + throw new Exception('Invalid transitions, data or places for path'); + } + $this->transitions = $transitions; + $this->data = $data; + $this->places = $places; } public function current() diff --git a/src/Helper/PathRunner.php b/src/Helper/PathRunner.php index a7d38f17..9ce6bdd3 100644 --- a/src/Helper/PathRunner.php +++ b/src/Helper/PathRunner.php @@ -2,6 +2,7 @@ namespace Tienvx\Bundle\MbtBundle\Helper; +use Exception; use Symfony\Component\Workflow\Workflow; use Tienvx\Bundle\MbtBundle\Graph\Path; use Tienvx\Bundle\MbtBundle\Subject\Subject; @@ -12,7 +13,7 @@ class PathRunner * @param Path $path * @param Workflow $workflow * @param Subject $subject - * @throws \Exception + * @throws Exception */ public static function run(Path $path, Workflow $workflow, Subject $subject) { diff --git a/src/MessageHandler/BugMessageHandler.php b/src/MessageHandler/BugMessageHandler.php index 9a144036..6efc0f51 100644 --- a/src/MessageHandler/BugMessageHandler.php +++ b/src/MessageHandler/BugMessageHandler.php @@ -2,6 +2,7 @@ namespace Tienvx\Bundle\MbtBundle\MessageHandler; +use Exception; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; use Symfony\Component\Messenger\Handler\MessageHandlerInterface; use Symfony\Component\Process\Process; @@ -18,7 +19,7 @@ public function __construct(ParameterBagInterface $params) /** * @param BugMessage $bugMessage - * @throws \Exception + * @throws Exception */ public function __invoke(BugMessage $bugMessage) { diff --git a/src/MessageHandler/QueuedLoopMessageHandler.php b/src/MessageHandler/QueuedLoopMessageHandler.php index a9886fa0..1ad192e2 100644 --- a/src/MessageHandler/QueuedLoopMessageHandler.php +++ b/src/MessageHandler/QueuedLoopMessageHandler.php @@ -2,6 +2,7 @@ namespace Tienvx\Bundle\MbtBundle\MessageHandler; +use Exception; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; use Symfony\Component\Messenger\Handler\MessageHandlerInterface; use Symfony\Component\Process\Process; @@ -19,7 +20,7 @@ public function __construct(ParameterBagInterface $params) /** * @param QueuedLoopMessage $queuedLoopMessage - * @throws \Exception + * @throws Exception */ public function __invoke(QueuedLoopMessage $queuedLoopMessage) { diff --git a/src/MessageHandler/TaskMessageHandler.php b/src/MessageHandler/TaskMessageHandler.php index 3bc71217..ca429d77 100644 --- a/src/MessageHandler/TaskMessageHandler.php +++ b/src/MessageHandler/TaskMessageHandler.php @@ -2,6 +2,7 @@ namespace Tienvx\Bundle\MbtBundle\MessageHandler; +use Exception; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; use Symfony\Component\Messenger\Handler\MessageHandlerInterface; use Symfony\Component\Process\Process; @@ -18,7 +19,7 @@ public function __construct(ParameterBagInterface $params) /** * @param TaskMessage $taskMessage - * @throws \Exception + * @throws Exception */ public function __invoke(TaskMessage $taskMessage) { diff --git a/src/PathReducer/AbstractPathReducer.php b/src/PathReducer/AbstractPathReducer.php index 0625def8..7e9e5c51 100644 --- a/src/PathReducer/AbstractPathReducer.php +++ b/src/PathReducer/AbstractPathReducer.php @@ -2,6 +2,7 @@ namespace Tienvx\Bundle\MbtBundle\PathReducer; +use Exception; use Doctrine\ORM\EntityManagerInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\Workflow\Registry; @@ -54,7 +55,7 @@ protected function finish(int $bugId) /** * @param Bug $bug * @param Path $path - * @throws \Exception + * @throws Exception */ protected function updatePath(Bug $bug, Path $path) { diff --git a/src/PathReducer/BinaryPathReducer.php b/src/PathReducer/BinaryPathReducer.php index f2c8ca9f..5caa10fd 100644 --- a/src/PathReducer/BinaryPathReducer.php +++ b/src/PathReducer/BinaryPathReducer.php @@ -14,7 +14,7 @@ class BinaryPathReducer extends AbstractPathReducer { /** * @param Bug $bug - * @throws \Exception + * @throws Exception */ public function reduce(Bug $bug) { diff --git a/src/PathReducer/GreedyPathReducer.php b/src/PathReducer/GreedyPathReducer.php index 59f2d7eb..c5fd516e 100644 --- a/src/PathReducer/GreedyPathReducer.php +++ b/src/PathReducer/GreedyPathReducer.php @@ -14,7 +14,7 @@ class GreedyPathReducer extends AbstractPathReducer { /** * @param Bug $bug - * @throws \Exception + * @throws Exception */ public function reduce(Bug $bug) { diff --git a/src/PathReducer/LoopPathReducer.php b/src/PathReducer/LoopPathReducer.php index 83e7ee6c..c120ffa3 100644 --- a/src/PathReducer/LoopPathReducer.php +++ b/src/PathReducer/LoopPathReducer.php @@ -2,6 +2,7 @@ namespace Tienvx\Bundle\MbtBundle\PathReducer; +use Exception; use Throwable; use Tienvx\Bundle\MbtBundle\Entity\Bug; use Tienvx\Bundle\MbtBundle\Helper\PathBuilder; @@ -11,7 +12,7 @@ class LoopPathReducer extends AbstractPathReducer { /** * @param Bug $bug - * @throws \Exception + * @throws Exception */ public function reduce(Bug $bug) { diff --git a/src/PathReducer/PathReducerManager.php b/src/PathReducer/PathReducerManager.php index 9c2a9e06..5c990e38 100644 --- a/src/PathReducer/PathReducerManager.php +++ b/src/PathReducer/PathReducerManager.php @@ -2,6 +2,8 @@ namespace Tienvx\Bundle\MbtBundle\PathReducer; +use Exception; + class PathReducerManager { /** @@ -30,7 +32,7 @@ public function getPathReducers(): array * @param $name * @return PathReducerInterface * - * @throws \Exception + * @throws Exception */ public function getPathReducer($name): PathReducerInterface { @@ -38,7 +40,7 @@ public function getPathReducer($name): PathReducerInterface return $this->pathReducers[$name]; } - throw new \Exception(sprintf('Path reducer %s does not exist.', $name)); + throw new Exception(sprintf('Path reducer %s does not exist.', $name)); } /** diff --git a/src/PathReducer/QueuedLoopPathReducer.php b/src/PathReducer/QueuedLoopPathReducer.php index 5202ff24..f91ab484 100644 --- a/src/PathReducer/QueuedLoopPathReducer.php +++ b/src/PathReducer/QueuedLoopPathReducer.php @@ -37,7 +37,7 @@ public function __construct( /** * @param Bug $bug - * @throws \Exception + * @throws Exception */ public function reduce(Bug $bug) { @@ -54,7 +54,7 @@ public function reduce(Bug $bug) /** * @param string $message - * @throws \Exception + * @throws Exception */ public function handle(string $message) { @@ -95,7 +95,7 @@ public function handle(string $message) /** * @param QueuedLoopMessage $queuedLoopMessage - * @throws \Exception + * @throws Exception */ public function postHandle(QueuedLoopMessage $queuedLoopMessage) { @@ -135,7 +135,7 @@ public function postHandle(QueuedLoopMessage $queuedLoopMessage) /** * @param int $queuedLoopId - * @throws \Exception + * @throws Exception */ public function dispatch(int $queuedLoopId) { diff --git a/src/PathReducer/RandomPathReducer.php b/src/PathReducer/RandomPathReducer.php index 66dad167..6fdef478 100644 --- a/src/PathReducer/RandomPathReducer.php +++ b/src/PathReducer/RandomPathReducer.php @@ -15,7 +15,7 @@ class RandomPathReducer extends AbstractPathReducer { /** * @param Bug $bug - * @throws \Exception + * @throws Exception */ public function reduce(Bug $bug) { diff --git a/src/Reporter/AbstractReporter.php b/src/Reporter/AbstractReporter.php index 2980c438..414225ce 100644 --- a/src/Reporter/AbstractReporter.php +++ b/src/Reporter/AbstractReporter.php @@ -2,6 +2,7 @@ namespace Tienvx\Bundle\MbtBundle\Reporter; +use Exception; use GuzzleHttp\Client; use Tienvx\Bundle\MbtBundle\Entity\Bug; use Tienvx\Bundle\MbtBundle\Helper\PathBuilder; @@ -30,15 +31,15 @@ public function setTwig(Twig $twig) } /** - * @throws \Exception + * @throws Exception */ protected function check() { if (!$this->client) { - throw new \Exception('Need to install guzzlehttp/guzzle package to send hipchat message'); + throw new Exception('Need to install guzzlehttp/guzzle package to send hipchat message'); } if (!$this->twig) { - throw new \Exception('Need to install symfony/twig-bundle package to send hipchat message'); + throw new Exception('Need to install symfony/twig-bundle package to send hipchat message'); } } @@ -48,7 +49,7 @@ protected function check() * @throws \Twig_Error_Loader * @throws \Twig_Error_Runtime * @throws \Twig_Error_Syntax - * @throws \Exception + * @throws Exception */ protected function render(Bug $bug) { diff --git a/src/Reporter/EmailReporter.php b/src/Reporter/EmailReporter.php index 67e3abbf..fb907621 100644 --- a/src/Reporter/EmailReporter.php +++ b/src/Reporter/EmailReporter.php @@ -2,6 +2,7 @@ namespace Tienvx\Bundle\MbtBundle\Reporter; +use Exception; use Swift_Mailer; use Tienvx\Bundle\MbtBundle\Entity\Bug; @@ -45,15 +46,15 @@ public function setMailer(Swift_Mailer $mailer) * @throws \Twig_Error_Loader * @throws \Twig_Error_Runtime * @throws \Twig_Error_Syntax - * @throws \Exception + * @throws Exception */ public function report(Bug $bug) { if (!$this->mailer) { - throw new \Exception('Need to install symfony/swiftmailer-bundle package to send email'); + throw new Exception('Need to install symfony/swiftmailer-bundle package to send email'); } if (!$this->twig) { - throw new \Exception('Need to install symfony/twig-bundle package to send email'); + throw new Exception('Need to install symfony/twig-bundle package to send email'); } $body = $this->render($bug); diff --git a/src/Reporter/GithubReporter.php b/src/Reporter/GithubReporter.php index 0d702682..aacc1280 100644 --- a/src/Reporter/GithubReporter.php +++ b/src/Reporter/GithubReporter.php @@ -2,6 +2,7 @@ namespace Tienvx\Bundle\MbtBundle\Reporter; +use Exception; use Tienvx\Bundle\MbtBundle\Entity\Bug; class GithubReporter extends AbstractReporter @@ -54,7 +55,7 @@ public function setToken(string $token) * @throws \Twig_Error_Loader * @throws \Twig_Error_Runtime * @throws \Twig_Error_Syntax - * @throws \Exception + * @throws Exception */ public function report(Bug $bug) { diff --git a/src/Reporter/GitlabReporter.php b/src/Reporter/GitlabReporter.php index e13d272c..734f9dce 100644 --- a/src/Reporter/GitlabReporter.php +++ b/src/Reporter/GitlabReporter.php @@ -2,6 +2,7 @@ namespace Tienvx\Bundle\MbtBundle\Reporter; +use Exception; use Tienvx\Bundle\MbtBundle\Entity\Bug; class GitlabReporter extends AbstractReporter @@ -44,7 +45,7 @@ public function setToken(string $token) * @throws \Twig_Error_Loader * @throws \Twig_Error_Runtime * @throws \Twig_Error_Syntax - * @throws \Exception + * @throws Exception */ public function report(Bug $bug) { diff --git a/src/Reporter/HipchatReporter.php b/src/Reporter/HipchatReporter.php index 685a7b92..e8f6006f 100644 --- a/src/Reporter/HipchatReporter.php +++ b/src/Reporter/HipchatReporter.php @@ -2,6 +2,7 @@ namespace Tienvx\Bundle\MbtBundle\Reporter; +use Exception; use Tienvx\Bundle\MbtBundle\Entity\Bug; class HipchatReporter extends AbstractReporter @@ -74,7 +75,7 @@ public function setFormat(string $format) * @throws \Twig_Error_Loader * @throws \Twig_Error_Runtime * @throws \Twig_Error_Syntax - * @throws \Exception + * @throws Exception */ public function report(Bug $bug) { diff --git a/src/Reporter/JiraReporter.php b/src/Reporter/JiraReporter.php index ec108552..1f7daac9 100644 --- a/src/Reporter/JiraReporter.php +++ b/src/Reporter/JiraReporter.php @@ -2,6 +2,7 @@ namespace Tienvx\Bundle\MbtBundle\Reporter; +use Exception; use Tienvx\Bundle\MbtBundle\Entity\Bug; class JiraReporter extends AbstractReporter @@ -64,7 +65,7 @@ public function setPassword(string $password) * @throws \Twig_Error_Loader * @throws \Twig_Error_Runtime * @throws \Twig_Error_Syntax - * @throws \Exception + * @throws Exception */ public function report(Bug $bug) { diff --git a/src/Reporter/LoggerReporter.php b/src/Reporter/LoggerReporter.php index fed8c285..303b5e35 100644 --- a/src/Reporter/LoggerReporter.php +++ b/src/Reporter/LoggerReporter.php @@ -2,6 +2,7 @@ namespace Tienvx\Bundle\MbtBundle\Reporter; +use Exception; use Psr\Log\LoggerInterface; use Tienvx\Bundle\MbtBundle\Entity\Bug; @@ -25,15 +26,15 @@ public function setLogger(LoggerInterface $logger) * @throws \Twig_Error_Loader * @throws \Twig_Error_Runtime * @throws \Twig_Error_Syntax - * @throws \Exception + * @throws Exception */ public function report(Bug $bug) { if (!$this->logger) { - throw new \Exception('Need to install symfony/monolog-bundle package to log bug'); + throw new Exception('Need to install symfony/monolog-bundle package to log bug'); } if (!$this->twig) { - throw new \Exception('Need to install symfony/twig-bundle package to log bug'); + throw new Exception('Need to install symfony/twig-bundle package to log bug'); } $this->logger->error($this->render($bug)); diff --git a/src/Reporter/ReporterManager.php b/src/Reporter/ReporterManager.php index 9c746915..0bfd421a 100644 --- a/src/Reporter/ReporterManager.php +++ b/src/Reporter/ReporterManager.php @@ -2,6 +2,8 @@ namespace Tienvx\Bundle\MbtBundle\Reporter; +use Exception; + class ReporterManager { /** @@ -30,7 +32,7 @@ public function getReporters(): array * @param $name * @return ReporterInterface * - * @throws \Exception + * @throws Exception */ public function getReporter($name): ReporterInterface { @@ -38,7 +40,7 @@ public function getReporter($name): ReporterInterface return $this->reporters[$name]; } - throw new \Exception(sprintf('Reporter %s does not exist.', $name)); + throw new Exception(sprintf('Reporter %s does not exist.', $name)); } /** diff --git a/src/Reporter/SlackReporter.php b/src/Reporter/SlackReporter.php index bc26d1c9..460aec87 100644 --- a/src/Reporter/SlackReporter.php +++ b/src/Reporter/SlackReporter.php @@ -2,6 +2,7 @@ namespace Tienvx\Bundle\MbtBundle\Reporter; +use Exception; use Tienvx\Bundle\MbtBundle\Entity\Bug; class SlackReporter extends AbstractReporter @@ -44,7 +45,7 @@ public function setToken(string $token) * @throws \Twig_Error_Loader * @throws \Twig_Error_Runtime * @throws \Twig_Error_Syntax - * @throws \Exception + * @throws Exception */ public function report(Bug $bug) { diff --git a/src/Subject/SubjectManager.php b/src/Subject/SubjectManager.php index 51463d13..7a64cf05 100644 --- a/src/Subject/SubjectManager.php +++ b/src/Subject/SubjectManager.php @@ -2,6 +2,8 @@ namespace Tienvx\Bundle\MbtBundle\Subject; +use Exception; + class SubjectManager { /** @@ -36,19 +38,19 @@ public function hasSubjectForModel(string $model) /** * @param string $model * @return Subject - * @throws \Exception + * @throws Exception */ public function createSubjectForModel(string $model): Subject { if (!isset($this->subjects[$model])) { - throw new \Exception(sprintf('Subject for model %s is not specified.', $model)); + throw new Exception(sprintf('Subject for model %s is not specified.', $model)); } elseif (!class_exists($this->subjects[$model])) { - throw new \Exception(sprintf('Subject class for model %s does not exist.', $model)); + throw new Exception(sprintf('Subject class for model %s does not exist.', $model)); } $subject = new $this->subjects[$model]; if (!$subject instanceof Subject) { - throw new \Exception(sprintf('Subject for model %s is not instance of %s.', $model, Subject::class)); + throw new Exception(sprintf('Subject for model %s is not instance of %s.', $model, Subject::class)); } return $subject; } diff --git a/src/Validator/Constraints/ModelValidator.php b/src/Validator/Constraints/ModelValidator.php index ed1082a3..66a0de66 100644 --- a/src/Validator/Constraints/ModelValidator.php +++ b/src/Validator/Constraints/ModelValidator.php @@ -2,6 +2,7 @@ namespace Tienvx\Bundle\MbtBundle\Validator\Constraints; +use Exception; use Symfony\Component\Validator\Constraint; use Symfony\Component\Validator\ConstraintValidator; use Symfony\Component\Validator\Exception\UnexpectedTypeException; @@ -34,7 +35,7 @@ public function __construct( /** * @param mixed $value * @param Constraint $constraint - * @throws \Exception + * @throws Exception */ public function validate($value, Constraint $constraint) { diff --git a/src/Validator/Constraints/Path.php b/src/Validator/Constraints/Path.php new file mode 100644 index 00000000..11c170a9 --- /dev/null +++ b/src/Validator/Constraints/Path.php @@ -0,0 +1,13 @@ +context->buildViolation($constraint->message) + ->setParameter('{{ string }}', $value) + ->addViolation(); + } + } + } +} diff --git a/tests/Api/BugTest.php b/tests/Api/BugTest.php index 556207ad..ffb765f4 100644 --- a/tests/Api/BugTest.php +++ b/tests/Api/BugTest.php @@ -15,7 +15,7 @@ public function testGetBugs() "id": 1, "title": "Bug 1", "status": "unverified", - "path": "step1 step2 step3", + "path": "C:34:\"Tienvx\\\\Bundle\\\\MbtBundle\\\\Graph\\\\Path\":165:{a:3:{i:0;a:3:{i:0;N;i:1;s:11:\"transition1\";i:2;s:11:\"transition2\";}i:1;a:3:{i:0;N;i:1;a:0:{}i:2;a:0:{}}i:2;a:3:{i:0;s:6:\"place1\";i:1;s:6:\"place2\";i:2;s:6:\"place3\";}}}", "length": 3, "task": "/mbt/tasks/1", "bugMessage": "Something happen on shopping_cart model" @@ -24,7 +24,7 @@ public function testGetBugs() "id": 2, "title": "Bug 2", "status": "valid", - "path": "step1 step2 step3 step4 step5", + "path": "C:34:\"Tienvx\\\\Bundle\\\\MbtBundle\\\\Graph\\\\Path\":265:{a:3:{i:0;a:5:{i:0;N;i:1;s:11:\"transition1\";i:2;s:11:\"transition2\";i:3;s:11:\"transition3\";i:4;s:11:\"transition4\";}i:1;a:5:{i:0;N;i:1;a:0:{}i:2;a:0:{}i:3;a:0:{}i:4;a:0:{}}i:2;a:5:{i:0;s:6:\"place1\";i:1;s:6:\"place2\";i:2;s:6:\"place3\";i:3;s:6:\"place4\";i:4;s:6:\"place5\";}}}", "length": 5, "task": "/mbt/tasks/1", "bugMessage": "We found a bug on shopping_cart model" @@ -33,7 +33,7 @@ public function testGetBugs() "id": 3, "title": "Bug 3", "status": "valid", - "path": "step1 step2", + "path": "C:34:\"Tienvx\\\\Bundle\\\\MbtBundle\\\\Graph\\\\Path\":115:{a:3:{i:0;a:2:{i:0;N;i:1;s:11:\"transition1\";}i:1;a:2:{i:0;N;i:1;a:0:{}}i:2;a:2:{i:0;s:6:\"place1\";i:1;s:6:\"place2\";}}}", "length": 2, "task": "/mbt/tasks/2", "bugMessage": "Weird bug when we test shoping_cart model" @@ -47,8 +47,8 @@ public function testCreateBug() { "task": "/mbt/tasks/2", "bugMessage": "This bug never happen on task 2", - "path": "step1 step2 step3.1 step3.2", - "length": 4, + "path": "C:34:\"Tienvx\\\\Bundle\\\\MbtBundle\\\\Graph\\\\Path\":196:{a:3:{i:0;a:3:{i:0;N;i:1;s:11:\"transition1\";i:2;s:11:\"transition2\";}i:1;a:3:{i:0;N;i:1;a:0:{}i:2;a:0:{}}i:2;a:3:{i:0;s:6:\"place1\";i:1;s:6:\"place2\";i:2;a:2:{i:0;s:8:\"place3.1\";i:1;s:8:\"place3.2\";}}}}", + "length": 3, "title": "Bug 3", "status": "unverified" }'); @@ -60,8 +60,8 @@ public function testCreateBug() "id": 4, "task": "/mbt/tasks/2", "bugMessage": "This bug never happen on task 2", - "path": "step1 step2 step3.1 step3.2", - "length": 4, + "path": "C:34:\"Tienvx\\\\Bundle\\\\MbtBundle\\\\Graph\\\\Path\":196:{a:3:{i:0;a:3:{i:0;N;i:1;s:11:\"transition1\";i:2;s:11:\"transition2\";}i:1;a:3:{i:0;N;i:1;a:0:{}i:2;a:0:{}}i:2;a:3:{i:0;s:6:\"place1\";i:1;s:6:\"place2\";i:2;a:2:{i:0;s:8:\"place3.1\";i:1;s:8:\"place3.2\";}}}}", + "length": 3, "title": "Bug 3", "status": "unverified" }', $response->getContent()); @@ -75,7 +75,7 @@ public function testCreateInvalidBug() "title": "Bug 5", "status": "invalid-bug", "bugMessage": "This bug is invalid", - "path": "How to reproduce this bug?", + "path": "The way to reproduce this bug", "length": 5 }'); @@ -83,12 +83,16 @@ public function testCreateInvalidBug() $this->assertEquals('application/problem+json; charset=utf-8', $response->headers->get('Content-Type')); $this->assertArraySubset(json_decode(' { - "title": "An error occurred", - "detail": "status: The value you selected is not a valid choice.", - "violations": [ + "title":"An error occurred", + "detail":"status: The value you selected is not a valid choice.\npath: \u0022The way to reproduce this bug\u0022 is not a valid path.", + "violations":[ { - "propertyPath": "status", - "message": "The value you selected is not a valid choice." + "propertyPath":"status", + "message":"The value you selected is not a valid choice." + }, + { + "propertyPath":"path", + "message":"\u0022The way to reproduce this bug\u0022 is not a valid path." } ] }', true), json_decode($response->getContent(), true)); diff --git a/tests/Command/GeneratePathCommandTest.php b/tests/Command/GeneratePathCommandTest.php index eae4953b..3bcec8cd 100644 --- a/tests/Command/GeneratePathCommandTest.php +++ b/tests/Command/GeneratePathCommandTest.php @@ -53,20 +53,19 @@ public function testExecute($model, $generator, $transitionCoverage, $placeCover $this->assertInstanceOf(Path::class, $path); if ($path instanceof Path) { - $placeInPathCount = count(array_unique(call_user_func_array('array_merge', $path->getAllPlaces()))); - $transitionInPathCount = count(array_unique(array_filter($path->getAllTransitions()))); - $allPlaces = $path->getAllPlaces(); - if ($generator === 'all-transitions' && array_diff(end($allPlaces), ['home'])) { + $uniquePlaces = $path->countUniquePlaces(); + $uniqueTransitions = $path->countUniqueTransitions(); + if ($generator === 'all-transitions' && array_diff($path->getPlacesAt($path->countPlaces() - 1), ['home'])) { // Sometime, we can't get the path through all transitions, so ignore it. - } elseif ($generator === 'all-places' && $transitionInPathCount === 1) { + } elseif ($generator === 'all-places' && $uniqueTransitions === 1) { // Sometime, we can't get the path through all places, so ignore it. } elseif ($generator === 'random' && $path->countTransitions() === 300) { // Sometime we reach the path length limit, so ignore it. - $this->assertGreaterThanOrEqual(1, $transitionInPathCount); - $this->assertGreaterThanOrEqual(1, $placeInPathCount); + $this->assertGreaterThanOrEqual(1, $uniqueTransitions); + $this->assertGreaterThanOrEqual(1, $uniquePlaces); } else { - $this->assertGreaterThanOrEqual($transitionCount, $transitionInPathCount); - $this->assertGreaterThanOrEqual($placeCount, $placeInPathCount); + $this->assertGreaterThanOrEqual($transitionCount, $uniqueTransitions); + $this->assertGreaterThanOrEqual($placeCount, $uniquePlaces); } } } diff --git a/tests/Message/MessageTestCase.php b/tests/Message/MessageTestCase.php index 99cf3696..19dab735 100644 --- a/tests/Message/MessageTestCase.php +++ b/tests/Message/MessageTestCase.php @@ -82,7 +82,7 @@ protected function hasMessages() protected function clearLog() { - exec("rm {$this->logDir}/test.log"); + exec("rm -f {$this->logDir}/test.log"); } protected function hasLog() diff --git a/tests/app/src/DataFixtures/BugFixtures.php b/tests/app/src/DataFixtures/BugFixtures.php index ddb507ce..06abdc2f 100644 --- a/tests/app/src/DataFixtures/BugFixtures.php +++ b/tests/app/src/DataFixtures/BugFixtures.php @@ -21,7 +21,7 @@ public function load(ObjectManager $manager) $bug1->setTitle('Bug 1'); $bug1->setStatus('unverified'); $bug1->setBugMessage('Something happen on shopping_cart model'); - $bug1->setPath('step1 step2 step3'); + $bug1->setPath('C:34:"Tienvx\Bundle\MbtBundle\Graph\Path":165:{a:3:{i:0;a:3:{i:0;N;i:1;s:11:"transition1";i:2;s:11:"transition2";}i:1;a:3:{i:0;N;i:1;a:0:{}i:2;a:0:{}}i:2;a:3:{i:0;s:6:"place1";i:1;s:6:"place2";i:2;s:6:"place3";}}}'); $bug1->setLength(3); $bug1->setTask($task1); $manager->persist($bug1); @@ -30,7 +30,7 @@ public function load(ObjectManager $manager) $bug2->setTitle('Bug 2'); $bug2->setStatus('valid'); $bug2->setBugMessage('We found a bug on shopping_cart model'); - $bug2->setPath('step1 step2 step3 step4 step5'); + $bug2->setPath('C:34:"Tienvx\Bundle\MbtBundle\Graph\Path":265:{a:3:{i:0;a:5:{i:0;N;i:1;s:11:"transition1";i:2;s:11:"transition2";i:3;s:11:"transition3";i:4;s:11:"transition4";}i:1;a:5:{i:0;N;i:1;a:0:{}i:2;a:0:{}i:3;a:0:{}i:4;a:0:{}}i:2;a:5:{i:0;s:6:"place1";i:1;s:6:"place2";i:2;s:6:"place3";i:3;s:6:"place4";i:4;s:6:"place5";}}}'); $bug2->setLength(5); $bug2->setTask($task1); $manager->persist($bug2); @@ -39,7 +39,7 @@ public function load(ObjectManager $manager) $bug3->setTitle('Bug 3'); $bug3->setStatus('valid'); $bug3->setBugMessage('Weird bug when we test shoping_cart model'); - $bug3->setPath('step1 step2'); + $bug3->setPath('C:34:"Tienvx\Bundle\MbtBundle\Graph\Path":115:{a:3:{i:0;a:2:{i:0;N;i:1;s:11:"transition1";}i:1;a:2:{i:0;N;i:1;a:0:{}}i:2;a:2:{i:0;s:6:"place1";i:1;s:6:"place2";}}}'); $bug3->setLength(2); $bug3->setTask($task2); $manager->persist($bug3);