From 386a1825fc81dd1e0a9273d5eb107d9a312fd44d Mon Sep 17 00:00:00 2001 From: tienvx Date: Mon, 25 Jul 2022 23:13:12 +0700 Subject: [PATCH 1/4] Update commands in readme --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 378eb17a..c09a76f5 100644 --- a/README.md +++ b/README.md @@ -24,9 +24,9 @@ vendor/bin/phpunit ## Validate code with coding standards ```shell -phpcs --standard=PSR12 src tests +phpcs --standard=PSR12 src tests config php-cs-fixer fix --diff --dry-run -phpstan analyse src tests +phpstan analyse src tests config ``` ## Built With From 99fcef1f830bc9dd66b5f80b491f49a3d3260470 Mon Sep 17 00:00:00 2001 From: tienvx Date: Tue, 26 Jul 2022 19:12:59 +0700 Subject: [PATCH 2/4] Promote properties in constructors --- src/EventListener/EntitySubscriber.php | 5 +--- src/Generator/RandomGenerator.php | 17 +++---------- src/Message/RecordVideoMessage.php | 5 +--- src/Message/ReduceBugMessage.php | 5 +--- src/Message/ReduceStepsMessage.php | 17 +++++-------- src/Message/ReportBugMessage.php | 5 +--- src/Message/RunTaskMessage.php | 5 +--- .../RecordVideoMessageHandler.php | 5 +--- .../ReduceBugMessageHandler.php | 5 +--- .../ReduceStepsMessageHandler.php | 5 +--- .../ReportBugMessageHandler.php | 5 +--- src/MessageHandler/RunTaskMessageHandler.php | 5 +--- src/Model/Bug/Step.php | 13 ++++------ src/Model/Values.php | 4 +-- src/Plugin/PluginManager.php | 11 +++----- src/Reducer/DispatcherTemplate.php | 5 +--- src/Reducer/HandlerTemplate.php | 19 +++++--------- src/Service/Bug/BugHelper.php | 25 +++++-------------- src/Service/Petrinet/MarkingHelper.php | 5 +--- src/Service/Petrinet/PetrinetHelper.php | 13 +++------- .../Step/Builder/PetrinetDomainLogic.php | 13 +++------- .../Step/Builder/ShortestPathStepsBuilder.php | 13 +++------- .../Step/Runner/ExploreStepsRunner.php | 4 +-- src/Service/Step/Runner/StepRunner.php | 5 +--- src/Service/Step/Runner/StepsRunner.php | 11 +++----- src/Service/Task/TaskHelper.php | 17 +++---------- 26 files changed, 63 insertions(+), 179 deletions(-) diff --git a/src/EventListener/EntitySubscriber.php b/src/EventListener/EntitySubscriber.php index 0b6ea242..aba160f5 100644 --- a/src/EventListener/EntitySubscriber.php +++ b/src/EventListener/EntitySubscriber.php @@ -11,13 +11,10 @@ class EntitySubscriber implements EventSubscriber { - protected MessageBusInterface $messageBus; - protected string $reducer; - public function __construct(MessageBusInterface $messageBus) + public function __construct(protected MessageBusInterface $messageBus) { - $this->messageBus = $messageBus; } public function postPersist(LifecycleEventArgs $args): void diff --git a/src/Generator/RandomGenerator.php b/src/Generator/RandomGenerator.php index 94269c4f..49534fd9 100644 --- a/src/Generator/RandomGenerator.php +++ b/src/Generator/RandomGenerator.php @@ -20,21 +20,12 @@ class RandomGenerator extends AbstractGenerator public const MAX_TRANSITION_COVERAGE = 100; public const MAX_PLACE_COVERAGE = 100; - protected PetrinetHelperInterface $petrinetHelper; - protected MarkingHelperInterface $markingHelper; - protected ModelHelperInterface $modelHelper; - protected GuardedTransitionServiceInterface $transitionService; - public function __construct( - PetrinetHelperInterface $petrinetHelper, - MarkingHelperInterface $markingHelper, - ModelHelperInterface $modelHelper, - GuardedTransitionServiceInterface $transitionService + protected PetrinetHelperInterface $petrinetHelper, + protected MarkingHelperInterface $markingHelper, + protected ModelHelperInterface $modelHelper, + protected GuardedTransitionServiceInterface $transitionService ) { - $this->petrinetHelper = $petrinetHelper; - $this->markingHelper = $markingHelper; - $this->modelHelper = $modelHelper; - $this->transitionService = $transitionService; } public static function getName(): string diff --git a/src/Message/RecordVideoMessage.php b/src/Message/RecordVideoMessage.php index 9316b80f..11b10275 100644 --- a/src/Message/RecordVideoMessage.php +++ b/src/Message/RecordVideoMessage.php @@ -4,11 +4,8 @@ class RecordVideoMessage implements MessageInterface { - protected int $bugId; - - public function __construct(int $bugId) + public function __construct(protected int $bugId) { - $this->bugId = $bugId; } public function getBugId(): int diff --git a/src/Message/ReduceBugMessage.php b/src/Message/ReduceBugMessage.php index d802a850..a9253eb9 100644 --- a/src/Message/ReduceBugMessage.php +++ b/src/Message/ReduceBugMessage.php @@ -4,11 +4,8 @@ class ReduceBugMessage implements MessageInterface { - protected int $id; - - public function __construct(int $id) + public function __construct(protected int $id) { - $this->id = $id; } public function getId(): int diff --git a/src/Message/ReduceStepsMessage.php b/src/Message/ReduceStepsMessage.php index 110051b2..12f8e636 100644 --- a/src/Message/ReduceStepsMessage.php +++ b/src/Message/ReduceStepsMessage.php @@ -4,17 +4,12 @@ class ReduceStepsMessage implements MessageInterface { - protected int $bugId; - protected int $length; - protected int $from; - protected int $to; - - public function __construct(int $bugId, int $length, int $from, int $to) - { - $this->bugId = $bugId; - $this->length = $length; - $this->from = $from; - $this->to = $to; + public function __construct( + protected int $bugId, + protected int $length, + protected int $from, + protected int $to + ) { } public function getBugId(): int diff --git a/src/Message/ReportBugMessage.php b/src/Message/ReportBugMessage.php index 05795e8c..090e915f 100644 --- a/src/Message/ReportBugMessage.php +++ b/src/Message/ReportBugMessage.php @@ -4,11 +4,8 @@ class ReportBugMessage implements MessageInterface { - protected int $bugId; - - public function __construct(int $bugId) + public function __construct(protected int $bugId) { - $this->bugId = $bugId; } public function getBugId(): int diff --git a/src/Message/RunTaskMessage.php b/src/Message/RunTaskMessage.php index 2110d432..dd7878b5 100644 --- a/src/Message/RunTaskMessage.php +++ b/src/Message/RunTaskMessage.php @@ -4,11 +4,8 @@ class RunTaskMessage implements MessageInterface { - protected int $id; - - public function __construct(int $id) + public function __construct(protected int $id) { - $this->id = $id; } public function getId(): int diff --git a/src/MessageHandler/RecordVideoMessageHandler.php b/src/MessageHandler/RecordVideoMessageHandler.php index 36deb367..b360b651 100644 --- a/src/MessageHandler/RecordVideoMessageHandler.php +++ b/src/MessageHandler/RecordVideoMessageHandler.php @@ -8,11 +8,8 @@ class RecordVideoMessageHandler implements MessageHandlerInterface { - protected BugHelperInterface $bugHelper; - - public function __construct(BugHelperInterface $bugHelper) + public function __construct(protected BugHelperInterface $bugHelper) { - $this->bugHelper = $bugHelper; } public function __invoke(RecordVideoMessage $message): void diff --git a/src/MessageHandler/ReduceBugMessageHandler.php b/src/MessageHandler/ReduceBugMessageHandler.php index 937469d4..42010be1 100644 --- a/src/MessageHandler/ReduceBugMessageHandler.php +++ b/src/MessageHandler/ReduceBugMessageHandler.php @@ -8,11 +8,8 @@ class ReduceBugMessageHandler implements MessageHandlerInterface { - protected BugHelperInterface $bugHelper; - - public function __construct(BugHelperInterface $bugHelper) + public function __construct(protected BugHelperInterface $bugHelper) { - $this->bugHelper = $bugHelper; } public function __invoke(ReduceBugMessage $message): void diff --git a/src/MessageHandler/ReduceStepsMessageHandler.php b/src/MessageHandler/ReduceStepsMessageHandler.php index 61cfd587..a6ffd4d3 100644 --- a/src/MessageHandler/ReduceStepsMessageHandler.php +++ b/src/MessageHandler/ReduceStepsMessageHandler.php @@ -8,11 +8,8 @@ class ReduceStepsMessageHandler implements MessageHandlerInterface { - protected BugHelperInterface $bugHelper; - - public function __construct(BugHelperInterface $bugHelper) + public function __construct(protected BugHelperInterface $bugHelper) { - $this->bugHelper = $bugHelper; } public function __invoke(ReduceStepsMessage $message): void diff --git a/src/MessageHandler/ReportBugMessageHandler.php b/src/MessageHandler/ReportBugMessageHandler.php index 9bd67b9a..28047960 100644 --- a/src/MessageHandler/ReportBugMessageHandler.php +++ b/src/MessageHandler/ReportBugMessageHandler.php @@ -8,11 +8,8 @@ class ReportBugMessageHandler implements MessageHandlerInterface { - protected BugHelperInterface $bugHelper; - - public function __construct(BugHelperInterface $bugHelper) + public function __construct(protected BugHelperInterface $bugHelper) { - $this->bugHelper = $bugHelper; } public function __invoke(ReportBugMessage $message): void diff --git a/src/MessageHandler/RunTaskMessageHandler.php b/src/MessageHandler/RunTaskMessageHandler.php index f35b2102..59668e6e 100644 --- a/src/MessageHandler/RunTaskMessageHandler.php +++ b/src/MessageHandler/RunTaskMessageHandler.php @@ -8,11 +8,8 @@ class RunTaskMessageHandler implements MessageHandlerInterface { - protected TaskHelperInterface $taskHelper; - - public function __construct(TaskHelperInterface $taskHelper) + public function __construct(protected TaskHelperInterface $taskHelper) { - $this->taskHelper = $taskHelper; } public function __invoke(RunTaskMessage $message): void diff --git a/src/Model/Bug/Step.php b/src/Model/Bug/Step.php index 4322cb29..d966da01 100644 --- a/src/Model/Bug/Step.php +++ b/src/Model/Bug/Step.php @@ -8,10 +8,6 @@ class Step implements StepInterface, NodeIdentifierInterface { - protected ColorInterface $color; - protected array $places; - protected int $transition; - public function __serialize(): array { return [ @@ -28,11 +24,12 @@ public function __unserialize(array $data) $this->transition = $data['transition']; } - public function __construct(array $places, ColorInterface $color, int $transition) - { + public function __construct( + protected array $places, + protected ColorInterface $color, + protected int $transition + ) { $this->setPlaces($places); - $this->setColor($color); - $this->setTransition($transition); } public function __clone() diff --git a/src/Model/Values.php b/src/Model/Values.php index 0d689c59..59d5460e 100644 --- a/src/Model/Values.php +++ b/src/Model/Values.php @@ -4,9 +4,7 @@ class Values implements ValuesInterface { - protected array $values = []; - - public function __construct(array $values = []) + public function __construct(protected array $values = []) { $this->values = []; diff --git a/src/Plugin/PluginManager.php b/src/Plugin/PluginManager.php index b0a124a7..87ba558c 100644 --- a/src/Plugin/PluginManager.php +++ b/src/Plugin/PluginManager.php @@ -7,13 +7,10 @@ class PluginManager implements PluginManagerInterface { - protected ServiceLocator $locator; - protected array $plugins; - - public function __construct(ServiceLocator $locator, array $plugins) - { - $this->locator = $locator; - $this->plugins = $plugins; + public function __construct( + protected ServiceLocator $locator, + protected array $plugins + ) { } public function all(): array diff --git a/src/Reducer/DispatcherTemplate.php b/src/Reducer/DispatcherTemplate.php index 39e43460..593286b0 100644 --- a/src/Reducer/DispatcherTemplate.php +++ b/src/Reducer/DispatcherTemplate.php @@ -10,11 +10,8 @@ abstract class DispatcherTemplate implements DispatcherInterface { protected const MIN_STEPS = 3; - protected MessageBusInterface $messageBus; - - public function __construct(MessageBusInterface $messageBus) + public function __construct(protected MessageBusInterface $messageBus) { - $this->messageBus = $messageBus; } public function dispatch(BugInterface $bug): int diff --git a/src/Reducer/HandlerTemplate.php b/src/Reducer/HandlerTemplate.php index dc0a5df9..74a8aa16 100644 --- a/src/Reducer/HandlerTemplate.php +++ b/src/Reducer/HandlerTemplate.php @@ -8,26 +8,19 @@ use Tienvx\Bundle\MbtBundle\Message\ReduceBugMessage; use Tienvx\Bundle\MbtBundle\Model\BugInterface; use Tienvx\Bundle\MbtBundle\Repository\BugRepositoryInterface; +use Tienvx\Bundle\MbtBundle\Service\ConfigInterface; 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 BugStepsRunner $stepsRunner; - protected StepsBuilderInterface $stepsBuilder; - public function __construct( - BugRepositoryInterface $bugRepository, - MessageBusInterface $messageBus, - BugStepsRunner $stepsRunner, - StepsBuilderInterface $stepsBuilder + protected BugRepositoryInterface $bugRepository, + protected MessageBusInterface $messageBus, + protected BugStepsRunner $stepsRunner, + protected StepsBuilderInterface $stepsBuilder, + protected ConfigInterface $config ) { - $this->bugRepository = $bugRepository; - $this->messageBus = $messageBus; - $this->stepsRunner = $stepsRunner; - $this->stepsBuilder = $stepsBuilder; } public function handle(BugInterface $bug, int $from, int $to): void diff --git a/src/Service/Bug/BugHelper.php b/src/Service/Bug/BugHelper.php index cbb4f976..c5e8e470 100644 --- a/src/Service/Bug/BugHelper.php +++ b/src/Service/Bug/BugHelper.php @@ -17,27 +17,14 @@ class BugHelper implements BugHelperInterface { - protected ReducerManagerInterface $reducerManager; - protected BugRepositoryInterface $bugRepository; - protected MessageBusInterface $messageBus; - protected BugNotifierInterface $bugNotifier; - protected BugStepsRunner $stepsRunner; - protected ConfigInterface $config; - public function __construct( - ReducerManagerInterface $reducerManager, - BugRepositoryInterface $bugRepository, - MessageBusInterface $messageBus, - BugNotifierInterface $bugNotifier, - BugStepsRunner $stepsRunner, - ConfigInterface $config + protected ReducerManagerInterface $reducerManager, + protected BugRepositoryInterface $bugRepository, + protected MessageBusInterface $messageBus, + protected BugNotifierInterface $bugNotifier, + protected BugStepsRunner $stepsRunner, + protected ConfigInterface $config ) { - $this->reducerManager = $reducerManager; - $this->bugRepository = $bugRepository; - $this->messageBus = $messageBus; - $this->bugNotifier = $bugNotifier; - $this->stepsRunner = $stepsRunner; - $this->config = $config; } public function reduceBug(int $bugId): void diff --git a/src/Service/Petrinet/MarkingHelper.php b/src/Service/Petrinet/MarkingHelper.php index 2a5597c6..ba732867 100644 --- a/src/Service/Petrinet/MarkingHelper.php +++ b/src/Service/Petrinet/MarkingHelper.php @@ -13,11 +13,8 @@ class MarkingHelper implements MarkingHelperInterface { - protected ColorfulFactoryInterface $colorfulFactory; - - public function __construct(ColorfulFactoryInterface $colorfulFactory) + public function __construct(protected ColorfulFactoryInterface $colorfulFactory) { - $this->colorfulFactory = $colorfulFactory; } /** diff --git a/src/Service/Petrinet/PetrinetHelper.php b/src/Service/Petrinet/PetrinetHelper.php index 45907ec5..dc9ea438 100644 --- a/src/Service/Petrinet/PetrinetHelper.php +++ b/src/Service/Petrinet/PetrinetHelper.php @@ -18,18 +18,11 @@ class PetrinetHelper implements PetrinetHelperInterface { public const FAKE_START_PLACE_ID = -1; - protected ColorfulFactoryInterface $colorfulFactory; - protected ExpressionLanguage $expressionLanguage; - protected AssignmentsEvaluator $assignmentsEvaluator; - public function __construct( - ColorfulFactoryInterface $colorfulFactory, - ExpressionLanguage $expressionLanguage, - AssignmentsEvaluator $assignmentsEvaluator + protected ColorfulFactoryInterface $colorfulFactory, + protected ExpressionLanguage $expressionLanguage, + protected AssignmentsEvaluator $assignmentsEvaluator ) { - $this->colorfulFactory = $colorfulFactory; - $this->expressionLanguage = $expressionLanguage; - $this->assignmentsEvaluator = $assignmentsEvaluator; } public function build(RevisionInterface $revision): PetrinetInterface diff --git a/src/Service/Step/Builder/PetrinetDomainLogic.php b/src/Service/Step/Builder/PetrinetDomainLogic.php index 9a1de37a..6d3ec638 100644 --- a/src/Service/Step/Builder/PetrinetDomainLogic.php +++ b/src/Service/Step/Builder/PetrinetDomainLogic.php @@ -12,18 +12,11 @@ class PetrinetDomainLogic implements DomainLogicInterface { - protected GuardedTransitionServiceInterface $transitionService; - protected MarkingHelperInterface $markingHelper; - protected PetrinetInterface $petrinet; - public function __construct( - GuardedTransitionServiceInterface $transitionService, - MarkingHelperInterface $markingHelper, - PetrinetInterface $petrinet + protected GuardedTransitionServiceInterface $transitionService, + protected MarkingHelperInterface $markingHelper, + protected PetrinetInterface $petrinet ) { - $this->transitionService = $transitionService; - $this->markingHelper = $markingHelper; - $this->petrinet = $petrinet; } public function calculateEstimatedCost(mixed $fromNode, mixed $toNode): float|int diff --git a/src/Service/Step/Builder/ShortestPathStepsBuilder.php b/src/Service/Step/Builder/ShortestPathStepsBuilder.php index 5cdd29b8..d3d4419d 100644 --- a/src/Service/Step/Builder/ShortestPathStepsBuilder.php +++ b/src/Service/Step/Builder/ShortestPathStepsBuilder.php @@ -17,18 +17,11 @@ class ShortestPathStepsBuilder implements StepsBuilderInterface { - protected PetrinetHelperInterface $petrinetHelper; - protected GuardedTransitionServiceInterface $transitionService; - protected MarkingHelperInterface $markingHelper; - public function __construct( - PetrinetHelperInterface $petrinetHelper, - GuardedTransitionServiceInterface $transitionService, - MarkingHelperInterface $markingHelper + protected PetrinetHelperInterface $petrinetHelper, + protected GuardedTransitionServiceInterface $transitionService, + protected MarkingHelperInterface $markingHelper ) { - $this->petrinetHelper = $petrinetHelper; - $this->transitionService = $transitionService; - $this->markingHelper = $markingHelper; } /** diff --git a/src/Service/Step/Runner/ExploreStepsRunner.php b/src/Service/Step/Runner/ExploreStepsRunner.php index b4dfc22f..1845c362 100644 --- a/src/Service/Step/Runner/ExploreStepsRunner.php +++ b/src/Service/Step/Runner/ExploreStepsRunner.php @@ -15,15 +15,13 @@ class ExploreStepsRunner extends StepsRunner { protected array $steps; - protected ConfigInterface $config; public function __construct( SelenoidHelperInterface $selenoidHelper, StepRunnerInterface $stepRunner, - ConfigInterface $config + protected ConfigInterface $config ) { parent::__construct($selenoidHelper, $stepRunner); - $this->config = $config; } protected function start(DebugInterface $entity): RemoteWebDriver diff --git a/src/Service/Step/Runner/StepRunner.php b/src/Service/Step/Runner/StepRunner.php index 73c5c4c5..384ac1b2 100644 --- a/src/Service/Step/Runner/StepRunner.php +++ b/src/Service/Step/Runner/StepRunner.php @@ -13,11 +13,8 @@ class StepRunner implements StepRunnerInterface { - protected CommandManagerInterface $commandManager; - - public function __construct(CommandManagerInterface $commandManager) + public function __construct(protected CommandManagerInterface $commandManager) { - $this->commandManager = $commandManager; } public function run(StepInterface $step, RevisionInterface $revision, RemoteWebDriver $driver): void diff --git a/src/Service/Step/Runner/StepsRunner.php b/src/Service/Step/Runner/StepsRunner.php index c88d5d34..b539c677 100644 --- a/src/Service/Step/Runner/StepsRunner.php +++ b/src/Service/Step/Runner/StepsRunner.php @@ -13,13 +13,10 @@ abstract class StepsRunner implements StepsRunnerInterface { - protected SelenoidHelperInterface $selenoidHelper; - protected StepRunnerInterface $stepRunner; - - public function __construct(SelenoidHelperInterface $selenoidHelper, StepRunnerInterface $stepRunner) - { - $this->selenoidHelper = $selenoidHelper; - $this->stepRunner = $stepRunner; + public function __construct( + protected SelenoidHelperInterface $selenoidHelper, + protected StepRunnerInterface $stepRunner + ) { } /** diff --git a/src/Service/Task/TaskHelper.php b/src/Service/Task/TaskHelper.php index 55a65cf3..b449b278 100644 --- a/src/Service/Task/TaskHelper.php +++ b/src/Service/Task/TaskHelper.php @@ -13,21 +13,12 @@ class TaskHelper implements TaskHelperInterface { - protected GeneratorManagerInterface $generatorManager; - protected TaskRepositoryInterface $taskRepository; - protected ExploreStepsRunner $stepsRunner; - protected ConfigInterface $config; - public function __construct( - GeneratorManagerInterface $generatorManager, - TaskRepositoryInterface $taskRepository, - ExploreStepsRunner $stepsRunner, - ConfigInterface $config + protected GeneratorManagerInterface $generatorManager, + protected TaskRepositoryInterface $taskRepository, + protected ExploreStepsRunner $stepsRunner, + protected ConfigInterface $config ) { - $this->generatorManager = $generatorManager; - $this->taskRepository = $taskRepository; - $this->stepsRunner = $stepsRunner; - $this->config = $config; } public function run(int $taskId): void From 1c2b8e0359f2114b12170ba75ac9b13528ac3f34 Mon Sep 17 00:00:00 2001 From: tienvx Date: Tue, 26 Jul 2022 21:32:37 +0700 Subject: [PATCH 3/4] Create new bug while reducing. Allow config default bug title --- src/Message/CreateBugMessage.php | 28 +++++++ .../CreateBugMessageHandler.php | 45 +++++++++++ src/Reducer/HandlerTemplate.php | 7 ++ src/Repository/TaskRepository.php | 7 ++ src/Repository/TaskRepositoryInterface.php | 3 + src/Service/ConfigInterface.php | 4 + .../Step/Runner/ExploreStepsRunner.php | 14 +--- src/Service/Task/TaskHelper.php | 13 +++- .../CreateBugMessageHandlerTest.php | 77 +++++++++++++++++++ .../RunTaskMessageHandlerTest.php | 3 +- tests/Reducer/HandlerTestCase.php | 51 +++++++++--- tests/Reducer/Random/RandomHandlerTest.php | 4 +- tests/Reducer/Split/SplitHandlerTest.php | 4 +- tests/Repository/TaskRepositoryTest.php | 15 +++- .../Step/Runner/ExploreStepsRunnerTest.php | 16 +--- .../Step/Runner/StepsRunnerTestCase.php | 6 +- tests/Service/Task/TaskHelperTest.php | 50 ++++++++---- 17 files changed, 283 insertions(+), 64 deletions(-) create mode 100644 src/Message/CreateBugMessage.php create mode 100644 src/MessageHandler/CreateBugMessageHandler.php create mode 100644 tests/MessageHandler/CreateBugMessageHandlerTest.php diff --git a/src/Message/CreateBugMessage.php b/src/Message/CreateBugMessage.php new file mode 100644 index 00000000..4d6bf4e7 --- /dev/null +++ b/src/Message/CreateBugMessage.php @@ -0,0 +1,28 @@ +taskId; + } + + public function getSteps(): array + { + return $this->steps; + } + + public function getMessage(): string + { + return $this->message; + } +} diff --git a/src/MessageHandler/CreateBugMessageHandler.php b/src/MessageHandler/CreateBugMessageHandler.php new file mode 100644 index 00000000..bba7da52 --- /dev/null +++ b/src/MessageHandler/CreateBugMessageHandler.php @@ -0,0 +1,45 @@ +taskRepository->find($message->getTaskId()); + + if (!$task instanceof TaskInterface) { + throw new UnexpectedValueException(sprintf( + 'Can not create bug for task %d: task not found', + $message->getTaskId() + )); + } + + $this->taskRepository->addBug($task, $this->createBug($message->getSteps(), $message->getMessage())); + } + + public function createBug(array $steps, string $message): BugInterface + { + $bug = new Bug(); + $bug->setTitle($this->config->getDefaultBugTitle()); + $bug->setSteps($steps); + $bug->setMessage($message); + + return $bug; + } +} diff --git a/src/Reducer/HandlerTemplate.php b/src/Reducer/HandlerTemplate.php index 74a8aa16..4b228b81 100644 --- a/src/Reducer/HandlerTemplate.php +++ b/src/Reducer/HandlerTemplate.php @@ -5,6 +5,7 @@ use Symfony\Component\Messenger\MessageBusInterface; use Throwable; use Tienvx\Bundle\MbtBundle\Exception\StepsNotConnectedException; +use Tienvx\Bundle\MbtBundle\Message\CreateBugMessage; use Tienvx\Bundle\MbtBundle\Message\ReduceBugMessage; use Tienvx\Bundle\MbtBundle\Model\BugInterface; use Tienvx\Bundle\MbtBundle\Repository\BugRepositoryInterface; @@ -43,6 +44,12 @@ function (Throwable $throwable) use ($bug, $newSteps): void { if ($throwable->getMessage() === $bug->getMessage()) { $this->bugRepository->updateSteps($bug, $newSteps); $this->messageBus->dispatch(new ReduceBugMessage($bug->getId())); + } elseif ($this->config->shouldCreateNewBugWhileReducing()) { + $this->messageBus->dispatch(new CreateBugMessage( + $bug->getTask()->getId(), + $newSteps, + $throwable->getMessage() + )); } } ); diff --git a/src/Repository/TaskRepository.php b/src/Repository/TaskRepository.php index 3855c268..69ad2a83 100644 --- a/src/Repository/TaskRepository.php +++ b/src/Repository/TaskRepository.php @@ -5,6 +5,7 @@ use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; use Doctrine\Persistence\ManagerRegistry; use Tienvx\Bundle\MbtBundle\Entity\Task; +use Tienvx\Bundle\MbtBundle\Model\BugInterface; use Tienvx\Bundle\MbtBundle\Model\TaskInterface; class TaskRepository extends ServiceEntityRepository implements TaskRepositoryInterface @@ -27,4 +28,10 @@ public function stopRunning(TaskInterface $task): void $this->getEntityManager()->getConnection()->connect(); $this->getEntityManager()->flush(); } + + public function addBug(TaskInterface $task, BugInterface $bug): void + { + $task->addBug($bug); + $this->getEntityManager()->flush(); + } } diff --git a/src/Repository/TaskRepositoryInterface.php b/src/Repository/TaskRepositoryInterface.php index 5e33da05..fe51d651 100644 --- a/src/Repository/TaskRepositoryInterface.php +++ b/src/Repository/TaskRepositoryInterface.php @@ -3,6 +3,7 @@ namespace Tienvx\Bundle\MbtBundle\Repository; use Doctrine\Persistence\ObjectRepository; +use Tienvx\Bundle\MbtBundle\Model\BugInterface; use Tienvx\Bundle\MbtBundle\Model\TaskInterface; interface TaskRepositoryInterface extends ObjectRepository @@ -10,4 +11,6 @@ interface TaskRepositoryInterface extends ObjectRepository public function startRunning(TaskInterface $task): void; public function stopRunning(TaskInterface $task): void; + + public function addBug(TaskInterface $task, BugInterface $bug): void; } diff --git a/src/Service/ConfigInterface.php b/src/Service/ConfigInterface.php index cf67b524..69f6cda6 100644 --- a/src/Service/ConfigInterface.php +++ b/src/Service/ConfigInterface.php @@ -11,4 +11,8 @@ public function getReducer(): string; public function shouldReportBug(): bool; public function getMaxSteps(): int; + + public function shouldCreateNewBugWhileReducing(): bool; + + public function getDefaultBugTitle(): string; } diff --git a/src/Service/Step/Runner/ExploreStepsRunner.php b/src/Service/Step/Runner/ExploreStepsRunner.php index 1845c362..469c198d 100644 --- a/src/Service/Step/Runner/ExploreStepsRunner.php +++ b/src/Service/Step/Runner/ExploreStepsRunner.php @@ -4,9 +4,7 @@ use Facebook\WebDriver\Remote\RemoteWebDriver; use Throwable; -use Tienvx\Bundle\MbtBundle\Entity\Bug; use Tienvx\Bundle\MbtBundle\Model\Bug\StepInterface; -use Tienvx\Bundle\MbtBundle\Model\BugInterface; use Tienvx\Bundle\MbtBundle\Model\DebugInterface; use Tienvx\Bundle\MbtBundle\Model\Model\RevisionInterface; use Tienvx\Bundle\MbtBundle\Service\ConfigInterface; @@ -37,7 +35,7 @@ protected function catchException(callable $handleException, Throwable $throwabl // Last step cause the bug, we can't capture it. We capture it here. $this->steps[] = clone $step; } - $handleException($this->createBug($this->steps, $throwable->getMessage())); + $handleException($throwable, $this->steps); } protected function stop(?RemoteWebDriver $driver): void @@ -53,14 +51,4 @@ protected function runStep(StepInterface $step, RevisionInterface $revision, Rem return count($this->steps) < $this->config->getMaxSteps(); } - - protected function createBug(array $steps, string $message): BugInterface - { - $bug = new Bug(); - $bug->setTitle(''); - $bug->setSteps($steps); - $bug->setMessage($message); - - return $bug; - } } diff --git a/src/Service/Task/TaskHelper.php b/src/Service/Task/TaskHelper.php index b449b278..0af2a235 100644 --- a/src/Service/Task/TaskHelper.php +++ b/src/Service/Task/TaskHelper.php @@ -3,9 +3,11 @@ namespace Tienvx\Bundle\MbtBundle\Service\Task; use Symfony\Component\Messenger\Exception\RecoverableMessageHandlingException; +use Symfony\Component\Messenger\MessageBusInterface; +use Throwable; use Tienvx\Bundle\MbtBundle\Exception\UnexpectedValueException; use Tienvx\Bundle\MbtBundle\Generator\GeneratorManagerInterface; -use Tienvx\Bundle\MbtBundle\Model\BugInterface; +use Tienvx\Bundle\MbtBundle\Message\CreateBugMessage; use Tienvx\Bundle\MbtBundle\Model\TaskInterface; use Tienvx\Bundle\MbtBundle\Repository\TaskRepositoryInterface; use Tienvx\Bundle\MbtBundle\Service\ConfigInterface; @@ -16,6 +18,7 @@ class TaskHelper implements TaskHelperInterface public function __construct( protected GeneratorManagerInterface $generatorManager, protected TaskRepositoryInterface $taskRepository, + protected MessageBusInterface $messageBus, protected ExploreStepsRunner $stepsRunner, protected ConfigInterface $config ) { @@ -41,8 +44,12 @@ public function run(int $taskId): void $this->stepsRunner->run( $this->generatorManager->getGenerator($this->config->getGenerator())->generate($task), $task, - function (BugInterface $bug) use ($task) { - $task->addBug($bug); + function (Throwable $throwable, array $steps) use ($taskId) { + $this->messageBus->dispatch(new CreateBugMessage( + $taskId, + $steps, + $throwable->getMessage() + )); } ); } finally { diff --git a/tests/MessageHandler/CreateBugMessageHandlerTest.php b/tests/MessageHandler/CreateBugMessageHandlerTest.php new file mode 100644 index 00000000..df6ff9c9 --- /dev/null +++ b/tests/MessageHandler/CreateBugMessageHandlerTest.php @@ -0,0 +1,77 @@ +config = $this->createMock(ConfigInterface::class); + $this->taskRepository = $this->createMock(TaskRepositoryInterface::class); + $this->handler = new CreateBugMessageHandler($this->config, $this->taskRepository); + $this->message = new CreateBugMessage( + 123, + [$this->createMock(StepInterface::class), $this->createMock(StepInterface::class)], + 'Something wrong' + ); + $this->task = new Task(); + $this->task->setId(123); + } + + public function testInvokeNoTask(): void + { + $this->expectException(UnexpectedValueException::class); + $this->expectExceptionMessage('Can not create bug for task 123: task not found'); + $this->taskRepository->expects($this->once())->method('find')->with(123)->willReturn(null); + call_user_func($this->handler, $this->message); + } + + public function testInvoke(): void + { + $this->taskRepository + ->expects($this->once()) + ->method('find') + ->with(123) + ->willReturn($this->task); + $this->config + ->expects($this->once()) + ->method('getDefaultBugTitle') + ->willReturn('Bug title'); + $this->taskRepository + ->expects($this->once()) + ->method('addBug') + ->with($this->task, $this->callback(function ($bug) { + return $bug instanceof Bug && + 'Bug title' === $bug->getTitle() && + $bug->getSteps() === $this->message->getSteps() && + 'Something wrong' === $bug->getMessage(); + })); + call_user_func($this->handler, $this->message); + } +} diff --git a/tests/MessageHandler/RunTaskMessageHandlerTest.php b/tests/MessageHandler/RunTaskMessageHandlerTest.php index d1e05d3d..06bbe563 100644 --- a/tests/MessageHandler/RunTaskMessageHandlerTest.php +++ b/tests/MessageHandler/RunTaskMessageHandlerTest.php @@ -2,6 +2,7 @@ namespace Tienvx\Bundle\MbtBundle\Tests\MessageHandler; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Tienvx\Bundle\MbtBundle\Message\RunTaskMessage; use Tienvx\Bundle\MbtBundle\MessageHandler\RunTaskMessageHandler; @@ -13,7 +14,7 @@ */ class RunTaskMessageHandlerTest extends TestCase { - protected TaskHelperInterface $taskHelper; + protected TaskHelperInterface|MockObject $taskHelper; protected RunTaskMessageHandler $handler; protected RunTaskMessage $message; diff --git a/tests/Reducer/HandlerTestCase.php b/tests/Reducer/HandlerTestCase.php index e902042a..c73f7fe3 100644 --- a/tests/Reducer/HandlerTestCase.php +++ b/tests/Reducer/HandlerTestCase.php @@ -3,6 +3,7 @@ namespace Tienvx\Bundle\MbtBundle\Tests\Reducer; use Exception; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\Stub\Stub; use PHPUnit\Framework\TestCase; use Symfony\Component\Messenger\Envelope; @@ -11,23 +12,25 @@ use Tienvx\Bundle\MbtBundle\Entity\Bug; use Tienvx\Bundle\MbtBundle\Entity\Model\Revision; use Tienvx\Bundle\MbtBundle\Entity\Task; -use Tienvx\Bundle\MbtBundle\Exception\RuntimeException; use Tienvx\Bundle\MbtBundle\Exception\StepsNotConnectedException; +use Tienvx\Bundle\MbtBundle\Message\CreateBugMessage; use Tienvx\Bundle\MbtBundle\Message\ReduceBugMessage; use Tienvx\Bundle\MbtBundle\Model\Bug\StepInterface; use Tienvx\Bundle\MbtBundle\Model\BugInterface; use Tienvx\Bundle\MbtBundle\Reducer\HandlerInterface; use Tienvx\Bundle\MbtBundle\Repository\BugRepositoryInterface; +use Tienvx\Bundle\MbtBundle\Service\ConfigInterface; use Tienvx\Bundle\MbtBundle\Service\Step\Builder\StepsBuilderInterface; use Tienvx\Bundle\MbtBundle\Service\Step\Runner\BugStepsRunner; abstract class HandlerTestCase extends TestCase { protected HandlerInterface $handler; - protected BugRepositoryInterface $bugRepository; - protected MessageBusInterface $messageBus; - protected BugStepsRunner $stepsRunner; - protected StepsBuilderInterface $stepsBuilder; + protected BugRepositoryInterface|MockObject $bugRepository; + protected MessageBusInterface|MockObject $messageBus; + protected BugStepsRunner|MockObject $stepsRunner; + protected StepsBuilderInterface|MockObject $stepsBuilder; + protected ConfigInterface|MockObject $config; protected array $newSteps; protected Revision $revision; protected BugInterface $bug; @@ -38,6 +41,7 @@ protected function setUp(): void $this->messageBus = $this->createMock(MessageBusInterface::class); $this->stepsRunner = $this->createMock(BugStepsRunner::class); $this->stepsBuilder = $this->createMock(StepsBuilderInterface::class); + $this->config = $this->createMock(ConfigInterface::class); $this->newSteps = [ $this->createMock(StepInterface::class), $this->createMock(StepInterface::class), @@ -57,6 +61,7 @@ protected function setUp(): void $this->bug->setDebug(true); $this->revision = new Revision(); $task = new Task(); + $task->setId(123); $task->setModelRevision($this->revision); $this->bug->setTask($task); $this->stepsBuilder @@ -88,7 +93,7 @@ public function testHandleOldBug(): void /** * @dataProvider exceptionProvider */ - public function testHandle(?Throwable $exception, bool $updateSteps): void + public function testHandle(?Throwable $exception, bool $updateSteps, bool $createNewBug): void { $this->expectStepsBuilder($this->returnValue((fn () => yield from $this->newSteps)())); $this->stepsRunner->expects($this->once()) @@ -112,11 +117,34 @@ public function testHandle(?Throwable $exception, bool $updateSteps): void $this->messageBus ->expects($this->once()) ->method('dispatch') - ->with($this->isInstanceOf(ReduceBugMessage::class)) + ->with($this->callback(function ($message) { + return $message instanceof ReduceBugMessage && $message->getId() === $this->bug->getId(); + })) ->willReturn(new Envelope(new \stdClass())); } else { $this->bugRepository->expects($this->never())->method('updateSteps'); - $this->messageBus->expects($this->never())->method('dispatch'); + if ($exception) { + $this->config + ->expects($this->once()) + ->method('shouldCreateNewBugWhileReducing') + ->willReturn($createNewBug); + if ($createNewBug) { + $this->messageBus + ->expects($this->once()) + ->method('dispatch') + ->with($this->callback(function ($message) use ($exception) { + return $message instanceof CreateBugMessage && + $message->getMessage() === $exception->getMessage() && + $message->getSteps() === $this->newSteps && + 123 === $message->getTaskId(); + })) + ->willReturn(new Envelope(new \stdClass())); + } else { + $this->messageBus->expects($this->never())->method('dispatch'); + } + } else { + $this->messageBus->expects($this->never())->method('dispatch'); + } } $this->handler->handle($this->bug, 1, 2); $this->assertFalse($this->bug->isDebug()); @@ -125,9 +153,10 @@ public function testHandle(?Throwable $exception, bool $updateSteps): void public function exceptionProvider(): array { return [ - [null, false], - [new RuntimeException('Something else wrong'), false], - [new Exception('Something wrong'), true], + [null, false, false], + [new Exception('Something else wrong'), false, false], + [new Exception('Something else wrong'), false, true], + [new Exception('Something wrong'), true, false], ]; } diff --git a/tests/Reducer/Random/RandomHandlerTest.php b/tests/Reducer/Random/RandomHandlerTest.php index 3a1b866a..727ff67c 100644 --- a/tests/Reducer/Random/RandomHandlerTest.php +++ b/tests/Reducer/Random/RandomHandlerTest.php @@ -15,6 +15,7 @@ * @uses \Tienvx\Bundle\MbtBundle\Model\Task * @uses \Tienvx\Bundle\MbtBundle\Model\Bug\Step * @uses \Tienvx\Bundle\MbtBundle\Message\ReduceBugMessage + * @uses \Tienvx\Bundle\MbtBundle\Message\CreateBugMessage * @uses \Tienvx\Bundle\MbtBundle\Model\Progress * @uses \Tienvx\Bundle\MbtBundle\Model\Debug */ @@ -27,7 +28,8 @@ protected function setUp(): void $this->bugRepository, $this->messageBus, $this->stepsRunner, - $this->stepsBuilder + $this->stepsBuilder, + $this->config ); } } diff --git a/tests/Reducer/Split/SplitHandlerTest.php b/tests/Reducer/Split/SplitHandlerTest.php index 63515131..edbe06f7 100644 --- a/tests/Reducer/Split/SplitHandlerTest.php +++ b/tests/Reducer/Split/SplitHandlerTest.php @@ -15,6 +15,7 @@ * @uses \Tienvx\Bundle\MbtBundle\Model\Task * @uses \Tienvx\Bundle\MbtBundle\Model\Bug\Step * @uses \Tienvx\Bundle\MbtBundle\Message\ReduceBugMessage + * @uses \Tienvx\Bundle\MbtBundle\Message\CreateBugMessage * @uses \Tienvx\Bundle\MbtBundle\Model\Progress * @uses \Tienvx\Bundle\MbtBundle\Model\Debug */ @@ -27,7 +28,8 @@ protected function setUp(): void $this->bugRepository, $this->messageBus, $this->stepsRunner, - $this->stepsBuilder + $this->stepsBuilder, + $this->config ); } } diff --git a/tests/Repository/TaskRepositoryTest.php b/tests/Repository/TaskRepositoryTest.php index d436440e..82b8bcc2 100644 --- a/tests/Repository/TaskRepositoryTest.php +++ b/tests/Repository/TaskRepositoryTest.php @@ -6,7 +6,9 @@ use Doctrine\ORM\Decorator\EntityManagerDecorator; use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\Persistence\ManagerRegistry; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; +use Tienvx\Bundle\MbtBundle\Entity\Bug; use Tienvx\Bundle\MbtBundle\Entity\Task; use Tienvx\Bundle\MbtBundle\Model\TaskInterface; use Tienvx\Bundle\MbtBundle\Repository\TaskRepository; @@ -17,10 +19,12 @@ * * @uses \Tienvx\Bundle\MbtBundle\Entity\Task * @uses \Tienvx\Bundle\MbtBundle\Model\Task + * @uses \Tienvx\Bundle\MbtBundle\Entity\Bug + * @uses \Tienvx\Bundle\MbtBundle\Model\Bug */ class TaskRepositoryTest extends TestCase { - protected EntityManagerDecorator $manager; + protected EntityManagerDecorator|MockObject $manager; protected TaskInterface $task; protected TaskRepositoryInterface $taskRepository; @@ -60,4 +64,13 @@ public function testStopRunningTask(): void $this->taskRepository->stopRunning($this->task); $this->assertFalse($this->task->isRunning()); } + + public function testAddBug(): void + { + $bug = new Bug(); + $this->assertEmpty($this->task->getBugs()); + $this->manager->expects($this->once())->method('flush'); + $this->taskRepository->addBug($this->task, $bug); + $this->assertSame([$bug], $this->task->getBugs()->toArray()); + } } diff --git a/tests/Service/Step/Runner/ExploreStepsRunnerTest.php b/tests/Service/Step/Runner/ExploreStepsRunnerTest.php index a066d4a9..6275eeaf 100644 --- a/tests/Service/Step/Runner/ExploreStepsRunnerTest.php +++ b/tests/Service/Step/Runner/ExploreStepsRunnerTest.php @@ -3,8 +3,7 @@ namespace Tienvx\Bundle\MbtBundle\Tests\Service\Step\Runner; use Exception; -use Tienvx\Bundle\MbtBundle\Model\Bug\StepInterface; -use Tienvx\Bundle\MbtBundle\Model\BugInterface; +use PHPUnit\Framework\MockObject\MockObject; use Tienvx\Bundle\MbtBundle\Model\DebugInterface; use Tienvx\Bundle\MbtBundle\Service\ConfigInterface; use Tienvx\Bundle\MbtBundle\Service\Step\Runner\ExploreStepsRunner; @@ -23,7 +22,7 @@ */ class ExploreStepsRunnerTest extends StepsRunnerTestCase { - protected ConfigInterface $config; + protected ConfigInterface|MockObject $config; protected function setUp(): void { @@ -53,16 +52,7 @@ protected function assertHandlingException(Exception $exception, array $bugSteps $this->handleException ->expects($this->once()) ->method('__invoke') - ->with($this->callback(fn (object $bug) => $bug instanceof BugInterface && - '' === $bug->getTitle() && - $bug->getMessage() === $exception->getMessage() && - !array_udiff( - $bug->getSteps(), - $bugSteps, - fn (StepInterface $step1, StepInterface $step2) => $step1->getPlaces() === $step2->getPlaces() && - $step1->getTransition() === $step2->getTransition() && - $step1->getColor()->getValues() === $step2->getColor()->getValues() - ))); + ->with($exception, $bugSteps); } protected function assertRunSteps(array $steps = [], ?Exception $exception = null, int $maxSteps = 99): void diff --git a/tests/Service/Step/Runner/StepsRunnerTestCase.php b/tests/Service/Step/Runner/StepsRunnerTestCase.php index d062f074..d56fe260 100644 --- a/tests/Service/Step/Runner/StepsRunnerTestCase.php +++ b/tests/Service/Step/Runner/StepsRunnerTestCase.php @@ -23,10 +23,10 @@ abstract class StepsRunnerTestCase extends TestCase { protected array $steps; - protected StepRunnerInterface $stepRunner; + protected StepRunnerInterface|MockObject $stepRunner; protected StepsRunnerInterface $stepsRunner; - protected SelenoidHelperInterface $selenoidHelper; - protected RemoteWebDriver $driver; + protected SelenoidHelperInterface|MockObject $selenoidHelper; + protected RemoteWebDriver|MockObject $driver; protected Revision $revision; protected TaskInterface $task; protected BugInterface $bug; diff --git a/tests/Service/Task/TaskHelperTest.php b/tests/Service/Task/TaskHelperTest.php index beac0f02..4bd4821b 100644 --- a/tests/Service/Task/TaskHelperTest.php +++ b/tests/Service/Task/TaskHelperTest.php @@ -2,15 +2,18 @@ namespace Tienvx\Bundle\MbtBundle\Tests\Service\Task; +use Exception; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use SingleColorPetrinet\Model\Color; +use Symfony\Component\Messenger\Envelope; use Symfony\Component\Messenger\Exception\RecoverableMessageHandlingException; -use Tienvx\Bundle\MbtBundle\Entity\Bug; +use Symfony\Component\Messenger\MessageBusInterface; use Tienvx\Bundle\MbtBundle\Entity\Task; use Tienvx\Bundle\MbtBundle\Exception\UnexpectedValueException; use Tienvx\Bundle\MbtBundle\Generator\GeneratorInterface; use Tienvx\Bundle\MbtBundle\Generator\GeneratorManagerInterface; -use Tienvx\Bundle\MbtBundle\Model\BugInterface; +use Tienvx\Bundle\MbtBundle\Message\CreateBugMessage; use Tienvx\Bundle\MbtBundle\Model\TaskInterface; use Tienvx\Bundle\MbtBundle\Repository\TaskRepositoryInterface; use Tienvx\Bundle\MbtBundle\Service\ConfigInterface; @@ -29,15 +32,17 @@ * @uses \Tienvx\Bundle\MbtBundle\Model\Bug * @uses \Tienvx\Bundle\MbtBundle\Model\Bug\Step * @uses \Tienvx\Bundle\MbtBundle\Model\Debug + * @uses \Tienvx\Bundle\MbtBundle\Message\CreateBugMessage */ class TaskHelperTest extends TestCase { protected array $steps; - protected GeneratorManagerInterface $generatorManager; - protected TaskRepositoryInterface $taskRepository; - protected ExploreStepsRunner $stepsRunner; + protected GeneratorManagerInterface|MockObject $generatorManager; + protected TaskRepositoryInterface|MockObject $taskRepository; + protected MessageBusInterface|MockObject $messageBus; + protected ExploreStepsRunner|MockObject $stepsRunner; protected TaskHelperInterface $taskHelper; - protected ConfigInterface $config; + protected ConfigInterface|MockObject $config; protected TaskInterface $task; protected function setUp(): void @@ -50,11 +55,13 @@ protected function setUp(): void ]; $this->generatorManager = $this->createMock(GeneratorManagerInterface::class); $this->taskRepository = $this->createMock(TaskRepositoryInterface::class); + $this->messageBus = $this->createMock(MessageBusInterface::class); $this->stepsRunner = $this->createMock(ExploreStepsRunner::class); $this->config = $this->createMock(ConfigInterface::class); $this->taskHelper = new TaskHelper( $this->generatorManager, $this->taskRepository, + $this->messageBus, $this->stepsRunner, $this->config ); @@ -82,9 +89,9 @@ public function testRunTaskAlreadyRunning(): void } /** - * @dataProvider bugProvider + * @dataProvider exceptionProvider */ - public function testRun(?BugInterface $bug): void + public function testRun(?Exception $exception): void { $this->taskRepository->expects($this->once())->method('find')->with(123)->willReturn($this->task); $this->taskRepository->expects($this->once())->method('startRunning')->with($this->task); @@ -99,27 +106,36 @@ public function testRun(?BugInterface $bug): void ->with( $this->steps, $this->task, - $this->callback(function (callable $exceptionCallback) use ($bug) { - if ($bug) { - $exceptionCallback($bug); + $this->callback(function (callable $exceptionCallback) use ($exception) { + if ($exception) { + $exceptionCallback($exception, $this->steps); } return true; }) ); - $this->taskHelper->run(123); - if ($bug) { - $this->assertSame([$bug], $this->task->getBugs()->toArray()); + if ($exception) { + $this->messageBus + ->expects($this->once()) + ->method('dispatch') + ->with($this->callback(function ($message) use ($exception) { + return $message instanceof CreateBugMessage && + $message->getMessage() === $exception->getMessage() && + $message->getSteps() === $this->steps && + 123 === $message->getTaskId(); + })) + ->willReturn(new Envelope(new \stdClass())); } else { - $this->assertEmpty($this->task->getBugs()); + $this->messageBus->expects($this->never())->method('dispatch'); } + $this->taskHelper->run(123); } - public function bugProvider(): array + public function exceptionProvider(): array { return [ [null], - [new Bug()], + [new Exception('Something wrong')], ]; } } From a04a649e69362524cbb8b218ebd28a514b64c194 Mon Sep 17 00:00:00 2001 From: tienvx Date: Tue, 26 Jul 2022 22:06:22 +0700 Subject: [PATCH 4/4] Type hint mock object --- tests/Command/Assert/AssertCheckedCommandTest.php | 6 ++---- .../Command/Assert/AssertEditableCommandTest.php | 6 ++---- .../Assert/AssertElementNotPresentCommandTest.php | 4 +--- .../Assert/AssertElementPresentCommandTest.php | 4 +--- .../Assert/AssertNotCheckedCommandTest.php | 6 ++---- .../Assert/AssertNotEditableCommandTest.php | 6 ++---- .../Assert/AssertNotSelectedLabelCommandTest.php | 5 ++--- .../Assert/AssertNotSelectedValueCommandTest.php | 5 ++--- tests/Command/Assert/AssertNotTextCommandTest.php | 6 ++---- .../Assert/AssertSelectedLabelCommandTest.php | 5 ++--- .../Assert/AssertSelectedValueCommandTest.php | 5 ++--- tests/Command/Assert/AssertTextCommandTest.php | 6 ++---- tests/Command/Assert/AssertValueCommandTest.php | 6 ++---- tests/Command/Keyboard/SendKeysCommandTest.php | 8 +++----- tests/Command/Keyboard/TypeCommandTest.php | 10 ++++------ tests/Command/Mouse/AddSelectionCommandTest.php | 6 ++---- tests/Command/Mouse/CheckCommandTest.php | 8 +++----- tests/Command/Mouse/ClickAtCommandTest.php | 6 ++---- tests/Command/Mouse/ClickCommandTest.php | 6 ++---- tests/Command/Mouse/DoubleClickAtCommandTest.php | 6 ++---- tests/Command/Mouse/DoubleClickCommandTest.php | 6 ++---- .../Command/Mouse/RemoveSelectionCommandTest.php | 6 ++---- tests/Command/Mouse/UncheckCommandTest.php | 8 +++----- tests/Command/Store/StoreAttributeCommandTest.php | 6 ++---- .../Store/StoreElementCountCommandTest.php | 4 +--- tests/Command/Store/StoreTextCommandTest.php | 6 ++---- tests/Command/Store/StoreValueCommandTest.php | 6 ++---- .../Wait/WaitForElementEditableCommandTest.php | 6 ++---- .../Wait/WaitForElementNotEditableCommandTest.php | 6 ++---- .../Wait/WaitForElementNotPresentCommandTest.php | 3 +-- .../Wait/WaitForElementNotVisibleCommandTest.php | 6 ++---- .../Wait/WaitForElementPresentCommandTest.php | 4 +--- .../Wait/WaitForElementVisibleCommandTest.php | 6 ++---- tests/Command/Window/SelectFrameCommandTest.php | 6 ++---- tests/EventListener/EntitySubscriberTest.php | 15 +++++++++++---- .../RecordVideoMessageHandlerTest.php | 3 ++- .../ReduceBugMessageHandlerTest.php | 3 ++- .../ReduceStepsMessageHandlerTest.php | 3 ++- .../ReportBugMessageHandlerTest.php | 3 ++- tests/Reducer/DispatcherTestCase.php | 3 ++- tests/Reducer/Random/RandomReducerTest.php | 5 +++-- tests/Reducer/Split/SplitReducerTest.php | 5 +++-- tests/Repository/BugRepositoryTest.php | 3 ++- tests/Service/Bug/BugHelperTest.php | 13 +++++++------ .../Step/Builder/PetrinetDomainLogicTest.php | 7 ++++--- tests/Service/Step/Runner/StepRunnerTest.php | 5 +++-- 46 files changed, 111 insertions(+), 156 deletions(-) diff --git a/tests/Command/Assert/AssertCheckedCommandTest.php b/tests/Command/Assert/AssertCheckedCommandTest.php index 8b49e288..34a7c480 100644 --- a/tests/Command/Assert/AssertCheckedCommandTest.php +++ b/tests/Command/Assert/AssertCheckedCommandTest.php @@ -4,7 +4,6 @@ use Exception; use Facebook\WebDriver\WebDriverBy; -use Facebook\WebDriver\WebDriverElement; use Tienvx\Bundle\MbtBundle\Command\Assert\AssertCheckedCommand; use Tienvx\Bundle\MbtBundle\Tests\Command\CommandTestCase; @@ -34,8 +33,7 @@ public function testRun(bool $isSelected, ?Exception $exception): void if ($exception) { $this->expectExceptionObject($exception); } - $element = $this->createMock(WebDriverElement::class); - $element->expects($this->once())->method('isSelected')->willReturn($isSelected); + $this->element->expects($this->once())->method('isSelected')->willReturn($isSelected); $this->driver ->expects($this->once()) ->method('findElement') @@ -44,7 +42,7 @@ public function testRun(bool $isSelected, ?Exception $exception): void && 'css selector' === $selector->getMechanism() && '.term-and-condition' === $selector->getValue(); })) - ->willReturn($element); + ->willReturn($this->element); $this->command->run('css=.term-and-condition', null, $this->values, $this->driver); } diff --git a/tests/Command/Assert/AssertEditableCommandTest.php b/tests/Command/Assert/AssertEditableCommandTest.php index 0c10fd0e..badfd9b4 100644 --- a/tests/Command/Assert/AssertEditableCommandTest.php +++ b/tests/Command/Assert/AssertEditableCommandTest.php @@ -4,7 +4,6 @@ use Exception; use Facebook\WebDriver\WebDriverBy; -use Facebook\WebDriver\WebDriverElement; use Tienvx\Bundle\MbtBundle\Command\Assert\AssertEditableCommand; use Tienvx\Bundle\MbtBundle\Tests\Command\CommandTestCase; @@ -34,7 +33,6 @@ public function testRun(bool $enabled, bool $readonly, ?Exception $exception): v if ($exception) { $this->expectExceptionObject($exception); } - $element = $this->createMock(WebDriverElement::class); $this->driver ->expects($this->once()) ->method('findElement') @@ -43,13 +41,13 @@ public function testRun(bool $enabled, bool $readonly, ?Exception $exception): v && 'name' === $selector->getMechanism() && 'username' === $selector->getValue(); })) - ->willReturn($element); + ->willReturn($this->element); $this->driver ->expects($this->once()) ->method('executeScript') ->with( 'return { enabled: !arguments[0].disabled, readonly: arguments[0].readOnly };', - [$element] + [$this->element] ) ->willReturn((object) ['enabled' => $enabled, 'readonly' => $readonly]); $this->command->run('name=username', null, $this->values, $this->driver); diff --git a/tests/Command/Assert/AssertElementNotPresentCommandTest.php b/tests/Command/Assert/AssertElementNotPresentCommandTest.php index 46676684..6eab0095 100644 --- a/tests/Command/Assert/AssertElementNotPresentCommandTest.php +++ b/tests/Command/Assert/AssertElementNotPresentCommandTest.php @@ -4,7 +4,6 @@ use Exception; use Facebook\WebDriver\WebDriverBy; -use Facebook\WebDriver\WebDriverElement; use Tienvx\Bundle\MbtBundle\Command\Assert\AssertElementNotPresentCommand; use Tienvx\Bundle\MbtBundle\Tests\Command\CommandTestCase; @@ -34,7 +33,6 @@ public function testRun(int $count, ?Exception $exception): void if ($exception) { $this->expectExceptionObject($exception); } - $element = $this->createMock(WebDriverElement::class); $this->driver ->expects($this->once()) ->method('findElements') @@ -45,7 +43,7 @@ public function testRun(int $count, ?Exception $exception): void && '.cart' === $selector->getValue(); }) ) - ->willReturn(array_fill(0, $count, $element)); + ->willReturn(array_fill(0, $count, $this->element)); $this->command->run('css=.cart', null, $this->values, $this->driver); } diff --git a/tests/Command/Assert/AssertElementPresentCommandTest.php b/tests/Command/Assert/AssertElementPresentCommandTest.php index ba71f049..81fbb7e3 100644 --- a/tests/Command/Assert/AssertElementPresentCommandTest.php +++ b/tests/Command/Assert/AssertElementPresentCommandTest.php @@ -4,7 +4,6 @@ use Exception; use Facebook\WebDriver\WebDriverBy; -use Facebook\WebDriver\WebDriverElement; use Tienvx\Bundle\MbtBundle\Command\Assert\AssertElementPresentCommand; use Tienvx\Bundle\MbtBundle\Tests\Command\CommandTestCase; @@ -34,7 +33,6 @@ public function testRun(int $count, ?Exception $exception): void if ($exception) { $this->expectExceptionObject($exception); } - $element = $this->createMock(WebDriverElement::class); $this->driver ->expects($this->once()) ->method('findElements') @@ -45,7 +43,7 @@ public function testRun(int $count, ?Exception $exception): void && '.cart' === $selector->getValue(); }) ) - ->willReturn(array_fill(0, $count, $element)); + ->willReturn(array_fill(0, $count, $this->element)); $this->command->run('css=.cart', null, $this->values, $this->driver); } diff --git a/tests/Command/Assert/AssertNotCheckedCommandTest.php b/tests/Command/Assert/AssertNotCheckedCommandTest.php index db5eb899..60050431 100644 --- a/tests/Command/Assert/AssertNotCheckedCommandTest.php +++ b/tests/Command/Assert/AssertNotCheckedCommandTest.php @@ -4,7 +4,6 @@ use Exception; use Facebook\WebDriver\WebDriverBy; -use Facebook\WebDriver\WebDriverElement; use Tienvx\Bundle\MbtBundle\Command\Assert\AssertNotCheckedCommand; use Tienvx\Bundle\MbtBundle\Tests\Command\CommandTestCase; @@ -34,8 +33,7 @@ public function testRun(bool $isSelected, ?Exception $exception): void if ($exception) { $this->expectExceptionObject($exception); } - $element = $this->createMock(WebDriverElement::class); - $element->expects($this->once())->method('isSelected')->willReturn($isSelected); + $this->element->expects($this->once())->method('isSelected')->willReturn($isSelected); $this->driver ->expects($this->once()) ->method('findElement') @@ -44,7 +42,7 @@ public function testRun(bool $isSelected, ?Exception $exception): void && 'css selector' === $selector->getMechanism() && '.term-and-condition' === $selector->getValue(); })) - ->willReturn($element); + ->willReturn($this->element); $this->command->run('css=.term-and-condition', null, $this->values, $this->driver); } diff --git a/tests/Command/Assert/AssertNotEditableCommandTest.php b/tests/Command/Assert/AssertNotEditableCommandTest.php index f8fc5ce8..3e0b5572 100644 --- a/tests/Command/Assert/AssertNotEditableCommandTest.php +++ b/tests/Command/Assert/AssertNotEditableCommandTest.php @@ -4,7 +4,6 @@ use Exception; use Facebook\WebDriver\WebDriverBy; -use Facebook\WebDriver\WebDriverElement; use Tienvx\Bundle\MbtBundle\Command\Assert\AssertNotEditableCommand; use Tienvx\Bundle\MbtBundle\Tests\Command\CommandTestCase; @@ -34,7 +33,6 @@ public function testRun(bool $enabled, bool $readonly, ?Exception $exception): v if ($exception) { $this->expectExceptionObject($exception); } - $element = $this->createMock(WebDriverElement::class); $this->driver ->expects($this->once()) ->method('findElement') @@ -43,13 +41,13 @@ public function testRun(bool $enabled, bool $readonly, ?Exception $exception): v && 'name' === $selector->getMechanism() && 'username' === $selector->getValue(); })) - ->willReturn($element); + ->willReturn($this->element); $this->driver ->expects($this->once()) ->method('executeScript') ->with( 'return { enabled: !arguments[0].disabled, readonly: arguments[0].readOnly };', - [$element] + [$this->element] ) ->willReturn((object) ['enabled' => $enabled, 'readonly' => $readonly]); $this->command->run('name=username', null, $this->values, $this->driver); diff --git a/tests/Command/Assert/AssertNotSelectedLabelCommandTest.php b/tests/Command/Assert/AssertNotSelectedLabelCommandTest.php index ca0a50c8..07c1fbbb 100644 --- a/tests/Command/Assert/AssertNotSelectedLabelCommandTest.php +++ b/tests/Command/Assert/AssertNotSelectedLabelCommandTest.php @@ -35,7 +35,6 @@ public function testRun(string $actual, ?Exception $exception): void if ($exception) { $this->expectExceptionObject($exception); } - $element = $this->createMock(WebDriverElement::class); $this->driver ->expects($this->once()) ->method('findElement') @@ -44,13 +43,13 @@ public function testRun(string $actual, ?Exception $exception): void && 'partial link text' === $selector->getMechanism() && 'Language' === $selector->getValue(); })) - ->willReturn($element); + ->willReturn($this->element); $option = $this->createMock(WebDriverElement::class); $option->expects($this->once())->method('getText')->willReturn($actual); $select = $this->createMock(WebDriverSelect::class); $select->expects($this->once())->method('getFirstSelectedOption')->willReturn($option); $command = $this->createPartialMock(AssertNotSelectedLabelCommand::class, ['getSelect']); - $command->expects($this->once())->method('getSelect')->with($element)->willReturn($select); + $command->expects($this->once())->method('getSelect')->with($this->element)->willReturn($select); $command->run('partialLinkText=Language', 'United Kingdom', $this->values, $this->driver); } diff --git a/tests/Command/Assert/AssertNotSelectedValueCommandTest.php b/tests/Command/Assert/AssertNotSelectedValueCommandTest.php index 846ebf00..8e56755e 100644 --- a/tests/Command/Assert/AssertNotSelectedValueCommandTest.php +++ b/tests/Command/Assert/AssertNotSelectedValueCommandTest.php @@ -35,7 +35,6 @@ public function testRun(string $actual, ?Exception $exception): void if ($exception) { $this->expectExceptionObject($exception); } - $element = $this->createMock(WebDriverElement::class); $this->driver ->expects($this->once()) ->method('findElement') @@ -44,13 +43,13 @@ public function testRun(string $actual, ?Exception $exception): void && 'partial link text' === $selector->getMechanism() && 'Language' === $selector->getValue(); })) - ->willReturn($element); + ->willReturn($this->element); $option = $this->createMock(WebDriverElement::class); $option->expects($this->once())->method('getAttribute')->with('value')->willReturn($actual); $select = $this->createMock(WebDriverSelect::class); $select->expects($this->once())->method('getFirstSelectedOption')->willReturn($option); $command = $this->createPartialMock(AssertNotSelectedValueCommand::class, ['getSelect']); - $command->expects($this->once())->method('getSelect')->with($element)->willReturn($select); + $command->expects($this->once())->method('getSelect')->with($this->element)->willReturn($select); $command->run('partialLinkText=Language', 'en_GB', $this->values, $this->driver); } diff --git a/tests/Command/Assert/AssertNotTextCommandTest.php b/tests/Command/Assert/AssertNotTextCommandTest.php index 4f6df886..06d530da 100644 --- a/tests/Command/Assert/AssertNotTextCommandTest.php +++ b/tests/Command/Assert/AssertNotTextCommandTest.php @@ -4,7 +4,6 @@ use Exception; use Facebook\WebDriver\WebDriverBy; -use Facebook\WebDriver\WebDriverElement; use Tienvx\Bundle\MbtBundle\Command\Assert\AssertNotTextCommand; use Tienvx\Bundle\MbtBundle\Tests\Command\CommandTestCase; @@ -34,8 +33,7 @@ public function testRun(string $actual, ?Exception $exception): void if ($exception) { $this->expectExceptionObject($exception); } - $element = $this->createMock(WebDriverElement::class); - $element->expects($this->once())->method('getText')->willReturn($actual); + $this->element->expects($this->once())->method('getText')->willReturn($actual); $this->driver ->expects($this->once()) ->method('findElement') @@ -44,7 +42,7 @@ public function testRun(string $actual, ?Exception $exception): void && 'xpath' === $selector->getMechanism() && '//h4[@href="#"]' === $selector->getValue(); })) - ->willReturn($element); + ->willReturn($this->element); $this->command->run('xpath=//h4[@href="#"]', 'Welcome to our store', $this->values, $this->driver); } diff --git a/tests/Command/Assert/AssertSelectedLabelCommandTest.php b/tests/Command/Assert/AssertSelectedLabelCommandTest.php index 4bb9e888..dd046ca8 100644 --- a/tests/Command/Assert/AssertSelectedLabelCommandTest.php +++ b/tests/Command/Assert/AssertSelectedLabelCommandTest.php @@ -35,7 +35,6 @@ public function testRun(string $actual, ?Exception $exception): void if ($exception) { $this->expectExceptionObject($exception); } - $element = $this->createMock(WebDriverElement::class); $this->driver ->expects($this->once()) ->method('findElement') @@ -44,13 +43,13 @@ public function testRun(string $actual, ?Exception $exception): void && 'partial link text' === $selector->getMechanism() && 'Language' === $selector->getValue(); })) - ->willReturn($element); + ->willReturn($this->element); $option = $this->createMock(WebDriverElement::class); $option->expects($this->once())->method('getText')->willReturn($actual); $select = $this->createMock(WebDriverSelect::class); $select->expects($this->once())->method('getFirstSelectedOption')->willReturn($option); $command = $this->createPartialMock(AssertSelectedLabelCommand::class, ['getSelect']); - $command->expects($this->once())->method('getSelect')->with($element)->willReturn($select); + $command->expects($this->once())->method('getSelect')->with($this->element)->willReturn($select); $command->run('partialLinkText=Language', 'United Kingdom', $this->values, $this->driver); } diff --git a/tests/Command/Assert/AssertSelectedValueCommandTest.php b/tests/Command/Assert/AssertSelectedValueCommandTest.php index 835d19d6..7a697f46 100644 --- a/tests/Command/Assert/AssertSelectedValueCommandTest.php +++ b/tests/Command/Assert/AssertSelectedValueCommandTest.php @@ -35,7 +35,6 @@ public function testRun(string $actual, ?Exception $exception): void if ($exception) { $this->expectExceptionObject($exception); } - $element = $this->createMock(WebDriverElement::class); $this->driver ->expects($this->once()) ->method('findElement') @@ -44,13 +43,13 @@ public function testRun(string $actual, ?Exception $exception): void && 'partial link text' === $selector->getMechanism() && 'Language' === $selector->getValue(); })) - ->willReturn($element); + ->willReturn($this->element); $option = $this->createMock(WebDriverElement::class); $option->expects($this->once())->method('getAttribute')->with('value')->willReturn($actual); $select = $this->createMock(WebDriverSelect::class); $select->expects($this->once())->method('getFirstSelectedOption')->willReturn($option); $command = $this->createPartialMock(AssertSelectedValueCommand::class, ['getSelect']); - $command->expects($this->once())->method('getSelect')->with($element)->willReturn($select); + $command->expects($this->once())->method('getSelect')->with($this->element)->willReturn($select); $command->run('partialLinkText=Language', 'en_GB', $this->values, $this->driver); } diff --git a/tests/Command/Assert/AssertTextCommandTest.php b/tests/Command/Assert/AssertTextCommandTest.php index c878adbd..a07c32a0 100644 --- a/tests/Command/Assert/AssertTextCommandTest.php +++ b/tests/Command/Assert/AssertTextCommandTest.php @@ -4,7 +4,6 @@ use Exception; use Facebook\WebDriver\WebDriverBy; -use Facebook\WebDriver\WebDriverElement; use Tienvx\Bundle\MbtBundle\Command\Assert\AssertTextCommand; use Tienvx\Bundle\MbtBundle\Tests\Command\CommandTestCase; @@ -34,8 +33,7 @@ public function testRun(string $actual, ?Exception $exception): void if ($exception) { $this->expectExceptionObject($exception); } - $element = $this->createMock(WebDriverElement::class); - $element->expects($this->once())->method('getText')->willReturn($actual); + $this->element->expects($this->once())->method('getText')->willReturn($actual); $this->driver ->expects($this->once()) ->method('findElement') @@ -44,7 +42,7 @@ public function testRun(string $actual, ?Exception $exception): void && 'xpath' === $selector->getMechanism() && '//h4[@href="#"]' === $selector->getValue(); })) - ->willReturn($element); + ->willReturn($this->element); $this->command->run('xpath=//h4[@href="#"]', 'Welcome to our store', $this->values, $this->driver); } diff --git a/tests/Command/Assert/AssertValueCommandTest.php b/tests/Command/Assert/AssertValueCommandTest.php index 0d8e1760..d2290004 100644 --- a/tests/Command/Assert/AssertValueCommandTest.php +++ b/tests/Command/Assert/AssertValueCommandTest.php @@ -4,7 +4,6 @@ use Exception; use Facebook\WebDriver\WebDriverBy; -use Facebook\WebDriver\WebDriverElement; use Tienvx\Bundle\MbtBundle\Command\Assert\AssertValueCommand; use Tienvx\Bundle\MbtBundle\Tests\Command\CommandTestCase; @@ -34,8 +33,7 @@ public function testRun(string $actual, ?Exception $exception): void if ($exception) { $this->expectExceptionObject($exception); } - $element = $this->createMock(WebDriverElement::class); - $element + $this->element ->expects($this->once()) ->method('getAttribute') ->with('value') @@ -48,7 +46,7 @@ public function testRun(string $actual, ?Exception $exception): void && 'css selector' === $selector->getMechanism() && '.quality' === $selector->getValue(); })) - ->willReturn($element); + ->willReturn($this->element); $this->command->run('css=.quality', '14', $this->values, $this->driver); } diff --git a/tests/Command/Keyboard/SendKeysCommandTest.php b/tests/Command/Keyboard/SendKeysCommandTest.php index 2000a54e..6c6991fb 100644 --- a/tests/Command/Keyboard/SendKeysCommandTest.php +++ b/tests/Command/Keyboard/SendKeysCommandTest.php @@ -3,7 +3,6 @@ namespace Tienvx\Bundle\MbtBundle\Tests\Command\Keyboard; use Facebook\WebDriver\WebDriverBy; -use Facebook\WebDriver\WebDriverElement; use Tienvx\Bundle\MbtBundle\Command\Keyboard\SendKeysCommand; use Tienvx\Bundle\MbtBundle\Tests\Command\CommandTestCase; @@ -27,14 +26,13 @@ protected function createCommand(): SendKeysCommand public function testRun(): void { - $element = $this->createMock(WebDriverElement::class); - $element->expects($this->once())->method('click')->willReturnSelf(); - $element->expects($this->once())->method('sendKeys')->with('123'); + $this->element->expects($this->once())->method('click')->willReturnSelf(); + $this->element->expects($this->once())->method('sendKeys')->with('123'); $this->driver->expects($this->once())->method('findElement')->with($this->callback(function ($selector) { return $selector instanceof WebDriverBy && 'css selector' === $selector->getMechanism() && '.quantity' === $selector->getValue(); - }))->willReturn($element); + }))->willReturn($this->element); $this->command->run('css=.quantity', '123', $this->values, $this->driver); } diff --git a/tests/Command/Keyboard/TypeCommandTest.php b/tests/Command/Keyboard/TypeCommandTest.php index d0623c33..01fe80af 100644 --- a/tests/Command/Keyboard/TypeCommandTest.php +++ b/tests/Command/Keyboard/TypeCommandTest.php @@ -3,7 +3,6 @@ namespace Tienvx\Bundle\MbtBundle\Tests\Command\Keyboard; use Facebook\WebDriver\WebDriverBy; -use Facebook\WebDriver\WebDriverElement; use Tienvx\Bundle\MbtBundle\Command\Keyboard\TypeCommand; use Tienvx\Bundle\MbtBundle\Tests\Command\CommandTestCase; @@ -27,10 +26,9 @@ protected function createCommand(): TypeCommand public function testRun(): void { - $element = $this->createMock(WebDriverElement::class); - $element->expects($this->once())->method('click')->willReturnSelf(); - $element->expects($this->once())->method('clear')->willReturnSelf(); - $element->expects($this->once())->method('sendKeys')->with('20 years old'); + $this->element->expects($this->once())->method('click')->willReturnSelf(); + $this->element->expects($this->once())->method('clear')->willReturnSelf(); + $this->element->expects($this->once())->method('sendKeys')->with('20 years old'); $this->driver ->expects($this->once()) ->method('findElement') @@ -39,7 +37,7 @@ public function testRun(): void && 'name' === $selector->getMechanism() && 'age' === $selector->getValue(); })) - ->willReturn($element); + ->willReturn($this->element); $this->command->run('name=age', '20 years old', $this->values, $this->driver); } diff --git a/tests/Command/Mouse/AddSelectionCommandTest.php b/tests/Command/Mouse/AddSelectionCommandTest.php index 59a09b2c..a3bfdc70 100644 --- a/tests/Command/Mouse/AddSelectionCommandTest.php +++ b/tests/Command/Mouse/AddSelectionCommandTest.php @@ -3,7 +3,6 @@ namespace Tienvx\Bundle\MbtBundle\Tests\Command\Mouse; use Facebook\WebDriver\WebDriverBy; -use Facebook\WebDriver\WebDriverElement; use Facebook\WebDriver\WebDriverSelect; use Tienvx\Bundle\MbtBundle\Command\Mouse\AddSelectionCommand; use Tienvx\Bundle\MbtBundle\Tests\Command\CommandTestCase; @@ -32,7 +31,6 @@ protected function createCommand(): AddSelectionCommand */ public function testRun(string $value, string $method, string|int $with): void { - $element = $this->createMock(WebDriverElement::class); $this->driver ->expects($this->once()) ->method('findElement') @@ -41,11 +39,11 @@ public function testRun(string $value, string $method, string|int $with): void && 'partial link text' === $selector->getMechanism() && 'Language' === $selector->getValue(); })) - ->willReturn($element); + ->willReturn($this->element); $select = $this->createMock(WebDriverSelect::class); $select->expects($this->once())->method($method)->with($with); $command = $this->createPartialMock(AddSelectionCommand::class, ['getSelect']); - $command->expects($this->once())->method('getSelect')->with($element)->willReturn($select); + $command->expects($this->once())->method('getSelect')->with($this->element)->willReturn($select); $command->run('partialLinkText=Language', $value, $this->values, $this->driver); } diff --git a/tests/Command/Mouse/CheckCommandTest.php b/tests/Command/Mouse/CheckCommandTest.php index f752d3ff..b15f8f41 100644 --- a/tests/Command/Mouse/CheckCommandTest.php +++ b/tests/Command/Mouse/CheckCommandTest.php @@ -3,7 +3,6 @@ namespace Tienvx\Bundle\MbtBundle\Tests\Command\Mouse; use Facebook\WebDriver\WebDriverBy; -use Facebook\WebDriver\WebDriverElement; use Tienvx\Bundle\MbtBundle\Command\Mouse\CheckCommand; use Tienvx\Bundle\MbtBundle\Tests\Command\CommandTestCase; @@ -30,9 +29,8 @@ protected function createCommand(): CheckCommand */ public function testRun(bool $selected, bool $checked): void { - $element = $this->createMock(WebDriverElement::class); - $element->expects($this->once())->method('isSelected')->willReturn($selected); - $element->expects($this->exactly(+$checked))->method('click'); + $this->element->expects($this->once())->method('isSelected')->willReturn($selected); + $this->element->expects($this->exactly(+$checked))->method('click'); $this->driver ->expects($this->once()) ->method('findElement') @@ -41,7 +39,7 @@ public function testRun(bool $selected, bool $checked): void && 'id' === $selector->getMechanism() && 'language' === $selector->getValue(); })) - ->willReturn($element); + ->willReturn($this->element); $this->command->run('id=language', null, $this->values, $this->driver); } diff --git a/tests/Command/Mouse/ClickAtCommandTest.php b/tests/Command/Mouse/ClickAtCommandTest.php index 9f84acc5..3ed31924 100644 --- a/tests/Command/Mouse/ClickAtCommandTest.php +++ b/tests/Command/Mouse/ClickAtCommandTest.php @@ -4,7 +4,6 @@ use Facebook\WebDriver\Interactions\WebDriverActions; use Facebook\WebDriver\WebDriverBy; -use Facebook\WebDriver\WebDriverElement; use Tienvx\Bundle\MbtBundle\Command\Mouse\ClickAtCommand; use Tienvx\Bundle\MbtBundle\Tests\Command\CommandTestCase; @@ -29,14 +28,13 @@ protected function createCommand(): ClickAtCommand public function testRun(): void { - $element = $this->createMock(WebDriverElement::class); $this->driver->expects($this->once())->method('findElement')->with($this->callback(function ($selector) { return $selector instanceof WebDriverBy && 'id' === $selector->getMechanism() && 'cart' === $selector->getValue(); - }))->willReturn($element); + }))->willReturn($this->element); $action = $this->createMock(WebDriverActions::class); - $action->expects($this->once())->method('moveToElement')->with($element, 5, 10)->willReturnSelf(); + $action->expects($this->once())->method('moveToElement')->with($this->element, 5, 10)->willReturnSelf(); $action->expects($this->once())->method('click')->willReturnSelf(); $action->expects($this->once())->method('perform'); $this->driver->expects($this->once())->method('action')->willReturn($action); diff --git a/tests/Command/Mouse/ClickCommandTest.php b/tests/Command/Mouse/ClickCommandTest.php index 6e04a4ed..083e32ec 100644 --- a/tests/Command/Mouse/ClickCommandTest.php +++ b/tests/Command/Mouse/ClickCommandTest.php @@ -3,7 +3,6 @@ namespace Tienvx\Bundle\MbtBundle\Tests\Command\Mouse; use Facebook\WebDriver\WebDriverBy; -use Facebook\WebDriver\WebDriverElement; use Tienvx\Bundle\MbtBundle\Command\Mouse\ClickCommand; use Tienvx\Bundle\MbtBundle\Tests\Command\CommandTestCase; @@ -27,13 +26,12 @@ protected function createCommand(): ClickCommand public function testRun(): void { - $element = $this->createMock(WebDriverElement::class); - $element->expects($this->once())->method('click'); + $this->element->expects($this->once())->method('click'); $this->driver->expects($this->once())->method('findElement')->with($this->callback(function ($selector) { return $selector instanceof WebDriverBy && 'id' === $selector->getMechanism() && 'add-to-cart' === $selector->getValue(); - }))->willReturn($element); + }))->willReturn($this->element); $this->command->run('id=add-to-cart', null, $this->values, $this->driver); } diff --git a/tests/Command/Mouse/DoubleClickAtCommandTest.php b/tests/Command/Mouse/DoubleClickAtCommandTest.php index 2fb71515..c71396f4 100644 --- a/tests/Command/Mouse/DoubleClickAtCommandTest.php +++ b/tests/Command/Mouse/DoubleClickAtCommandTest.php @@ -4,7 +4,6 @@ use Facebook\WebDriver\Interactions\WebDriverActions; use Facebook\WebDriver\WebDriverBy; -use Facebook\WebDriver\WebDriverElement; use Tienvx\Bundle\MbtBundle\Command\Mouse\DoubleClickAtCommand; use Tienvx\Bundle\MbtBundle\Tests\Command\CommandTestCase; @@ -29,14 +28,13 @@ protected function createCommand(): DoubleClickAtCommand public function testRun(): void { - $element = $this->createMock(WebDriverElement::class); $this->driver->expects($this->once())->method('findElement')->with($this->callback(function ($selector) { return $selector instanceof WebDriverBy && 'id' === $selector->getMechanism() && 'cart' === $selector->getValue(); - }))->willReturn($element); + }))->willReturn($this->element); $action = $this->createMock(WebDriverActions::class); - $action->expects($this->once())->method('moveToElement')->with($element, 5, 10)->willReturnSelf(); + $action->expects($this->once())->method('moveToElement')->with($this->element, 5, 10)->willReturnSelf(); $action->expects($this->once())->method('doubleClick')->willReturnSelf(); $action->expects($this->once())->method('perform'); $this->driver->expects($this->once())->method('action')->willReturn($action); diff --git a/tests/Command/Mouse/DoubleClickCommandTest.php b/tests/Command/Mouse/DoubleClickCommandTest.php index 2d4c3fd0..60ac8621 100644 --- a/tests/Command/Mouse/DoubleClickCommandTest.php +++ b/tests/Command/Mouse/DoubleClickCommandTest.php @@ -4,7 +4,6 @@ use Facebook\WebDriver\Interactions\WebDriverActions; use Facebook\WebDriver\WebDriverBy; -use Facebook\WebDriver\WebDriverElement; use Tienvx\Bundle\MbtBundle\Command\Mouse\DoubleClickCommand; use Tienvx\Bundle\MbtBundle\Tests\Command\CommandTestCase; @@ -28,14 +27,13 @@ protected function createCommand(): DoubleClickCommand public function testRun(): void { - $element = $this->createMock(WebDriverElement::class); $this->driver->expects($this->once())->method('findElement')->with($this->callback(function ($selector) { return $selector instanceof WebDriverBy && 'id' === $selector->getMechanism() && 'cart' === $selector->getValue(); - }))->willReturn($element); + }))->willReturn($this->element); $action = $this->createMock(WebDriverActions::class); - $action->expects($this->once())->method('doubleClick')->with($element)->willReturnSelf(); + $action->expects($this->once())->method('doubleClick')->with($this->element)->willReturnSelf(); $action->expects($this->once())->method('perform'); $this->driver->expects($this->once())->method('action')->willReturn($action); $this->command->run('id=cart', null, $this->values, $this->driver); diff --git a/tests/Command/Mouse/RemoveSelectionCommandTest.php b/tests/Command/Mouse/RemoveSelectionCommandTest.php index ddd005d1..de14048d 100644 --- a/tests/Command/Mouse/RemoveSelectionCommandTest.php +++ b/tests/Command/Mouse/RemoveSelectionCommandTest.php @@ -3,7 +3,6 @@ namespace Tienvx\Bundle\MbtBundle\Tests\Command\Mouse; use Facebook\WebDriver\WebDriverBy; -use Facebook\WebDriver\WebDriverElement; use Facebook\WebDriver\WebDriverSelect; use Tienvx\Bundle\MbtBundle\Command\Mouse\RemoveSelectionCommand; use Tienvx\Bundle\MbtBundle\Tests\Command\CommandTestCase; @@ -32,7 +31,6 @@ protected function createCommand(): RemoveSelectionCommand */ public function testRun(string $value, string $method, string|int $with): void { - $element = $this->createMock(WebDriverElement::class); $this->driver ->expects($this->once()) ->method('findElement') @@ -41,11 +39,11 @@ public function testRun(string $value, string $method, string|int $with): void && 'partial link text' === $selector->getMechanism() && 'Language' === $selector->getValue(); })) - ->willReturn($element); + ->willReturn($this->element); $select = $this->createMock(WebDriverSelect::class); $select->expects($this->once())->method($method)->with($with); $command = $this->createPartialMock(RemoveSelectionCommand::class, ['getSelect']); - $command->expects($this->once())->method('getSelect')->with($element)->willReturn($select); + $command->expects($this->once())->method('getSelect')->with($this->element)->willReturn($select); $command->run('partialLinkText=Language', $value, $this->values, $this->driver); } diff --git a/tests/Command/Mouse/UncheckCommandTest.php b/tests/Command/Mouse/UncheckCommandTest.php index 759293d0..6c5fb551 100644 --- a/tests/Command/Mouse/UncheckCommandTest.php +++ b/tests/Command/Mouse/UncheckCommandTest.php @@ -3,7 +3,6 @@ namespace Tienvx\Bundle\MbtBundle\Tests\Command\Mouse; use Facebook\WebDriver\WebDriverBy; -use Facebook\WebDriver\WebDriverElement; use Tienvx\Bundle\MbtBundle\Command\Mouse\UncheckCommand; use Tienvx\Bundle\MbtBundle\Tests\Command\CommandTestCase; @@ -30,9 +29,8 @@ protected function createCommand(): UncheckCommand */ public function testRun(bool $selected, bool $unchecked): void { - $element = $this->createMock(WebDriverElement::class); - $element->expects($this->once())->method('isSelected')->willReturn($selected); - $element->expects($this->exactly(+$unchecked))->method('click'); + $this->element->expects($this->once())->method('isSelected')->willReturn($selected); + $this->element->expects($this->exactly(+$unchecked))->method('click'); $this->driver ->expects($this->once()) ->method('findElement') @@ -41,7 +39,7 @@ public function testRun(bool $selected, bool $unchecked): void && 'id' === $selector->getMechanism() && 'language' === $selector->getValue(); })) - ->willReturn($element); + ->willReturn($this->element); $this->command->run('id=language', null, $this->values, $this->driver); } diff --git a/tests/Command/Store/StoreAttributeCommandTest.php b/tests/Command/Store/StoreAttributeCommandTest.php index 5479d4c4..1dd788fa 100644 --- a/tests/Command/Store/StoreAttributeCommandTest.php +++ b/tests/Command/Store/StoreAttributeCommandTest.php @@ -3,7 +3,6 @@ namespace Tienvx\Bundle\MbtBundle\Tests\Command\Store; use Facebook\WebDriver\WebDriverBy; -use Facebook\WebDriver\WebDriverElement; use Tienvx\Bundle\MbtBundle\Command\Store\StoreAttributeCommand; use Tienvx\Bundle\MbtBundle\Tests\Command\CommandTestCase; @@ -31,8 +30,7 @@ public function testRun(): void ->expects($this->once()) ->method('setValue') ->with('readmoreLink', 'http://example.com'); - $element = $this->createMock(WebDriverElement::class); - $element + $this->element ->expects($this->once()) ->method('getAttribute') ->with('href') @@ -45,7 +43,7 @@ public function testRun(): void && 'css selector' === $selector->getMechanism() && '.readmore' === $selector->getValue(); })) - ->willReturn($element); + ->willReturn($this->element); $this->command->run('css=.readmore@href', 'readmoreLink', $this->values, $this->driver); } diff --git a/tests/Command/Store/StoreElementCountCommandTest.php b/tests/Command/Store/StoreElementCountCommandTest.php index fdafdef4..2ff98d34 100644 --- a/tests/Command/Store/StoreElementCountCommandTest.php +++ b/tests/Command/Store/StoreElementCountCommandTest.php @@ -3,7 +3,6 @@ namespace Tienvx\Bundle\MbtBundle\Tests\Command\Store; use Facebook\WebDriver\WebDriverBy; -use Facebook\WebDriver\WebDriverElement; use Tienvx\Bundle\MbtBundle\Command\Store\StoreElementCountCommand; use Tienvx\Bundle\MbtBundle\Tests\Command\CommandTestCase; @@ -28,12 +27,11 @@ protected function createCommand(): StoreElementCountCommand public function testRun(): void { $this->values->expects($this->once())->method('setValue')->with('itemCount', 2); - $element = $this->createMock(WebDriverElement::class); $this->driver->expects($this->once())->method('findElements')->with($this->callback(function ($selector) { return $selector instanceof WebDriverBy && 'css selector' === $selector->getMechanism() && '.item' === $selector->getValue(); - }))->willReturn([$element, $element]); + }))->willReturn([$this->element, $this->element]); $this->command->run('css=.item', 'itemCount', $this->values, $this->driver); } diff --git a/tests/Command/Store/StoreTextCommandTest.php b/tests/Command/Store/StoreTextCommandTest.php index d39f14d2..3e528114 100644 --- a/tests/Command/Store/StoreTextCommandTest.php +++ b/tests/Command/Store/StoreTextCommandTest.php @@ -3,7 +3,6 @@ namespace Tienvx\Bundle\MbtBundle\Tests\Command\Store; use Facebook\WebDriver\WebDriverBy; -use Facebook\WebDriver\WebDriverElement; use Tienvx\Bundle\MbtBundle\Command\Store\StoreTextCommand; use Tienvx\Bundle\MbtBundle\Tests\Command\CommandTestCase; @@ -31,8 +30,7 @@ public function testRun(): void ->expects($this->once()) ->method('setValue') ->with('headLine', 'Welcome to our site'); - $element = $this->createMock(WebDriverElement::class); - $element->expects($this->once())->method('getText')->willReturn('Welcome to our site'); + $this->element->expects($this->once())->method('getText')->willReturn('Welcome to our site'); $this->driver ->expects($this->once()) ->method('findElement') @@ -41,7 +39,7 @@ public function testRun(): void && 'css selector' === $selector->getMechanism() && '.head-line' === $selector->getValue(); })) - ->willReturn($element); + ->willReturn($this->element); $this->command->run('css=.head-line', 'headLine', $this->values, $this->driver); } diff --git a/tests/Command/Store/StoreValueCommandTest.php b/tests/Command/Store/StoreValueCommandTest.php index e47bb7f5..de882984 100644 --- a/tests/Command/Store/StoreValueCommandTest.php +++ b/tests/Command/Store/StoreValueCommandTest.php @@ -3,7 +3,6 @@ namespace Tienvx\Bundle\MbtBundle\Tests\Command\Store; use Facebook\WebDriver\WebDriverBy; -use Facebook\WebDriver\WebDriverElement; use Tienvx\Bundle\MbtBundle\Command\Store\StoreValueCommand; use Tienvx\Bundle\MbtBundle\Tests\Command\CommandTestCase; @@ -28,8 +27,7 @@ protected function createCommand(): StoreValueCommand public function testRun(): void { $this->values->expects($this->once())->method('setValue')->with('age', 23); - $element = $this->createMock(WebDriverElement::class); - $element->expects($this->once())->method('getAttribute')->with('value')->willReturn(23); + $this->element->expects($this->once())->method('getAttribute')->with('value')->willReturn(23); $this->driver ->expects($this->once()) ->method('findElement') @@ -38,7 +36,7 @@ public function testRun(): void && 'css selector' === $selector->getMechanism() && '.age' === $selector->getValue(); })) - ->willReturn($element); + ->willReturn($this->element); $this->command->run('css=.age', 'age', $this->values, $this->driver); } diff --git a/tests/Command/Wait/WaitForElementEditableCommandTest.php b/tests/Command/Wait/WaitForElementEditableCommandTest.php index 4da8613f..4ce01d45 100644 --- a/tests/Command/Wait/WaitForElementEditableCommandTest.php +++ b/tests/Command/Wait/WaitForElementEditableCommandTest.php @@ -4,7 +4,6 @@ use Closure; use Facebook\WebDriver\WebDriverBy; -use Facebook\WebDriver\WebDriverElement; use Facebook\WebDriver\WebDriverWait; use Tienvx\Bundle\MbtBundle\Command\Wait\WaitForElementEditableCommand; @@ -25,7 +24,6 @@ protected function createCommand(): WaitForElementEditableCommand */ public function testRun(bool $enabled, bool $readonly, bool $editable): void { - $element = $this->createMock(WebDriverElement::class); $this->driver ->expects($this->once()) ->method('findElement') @@ -34,7 +32,7 @@ public function testRun(bool $enabled, bool $readonly, bool $editable): void && 'id' === $selector->getMechanism() && 'name' === $selector->getValue(); })) - ->willReturn($element); + ->willReturn($this->element); $wait = $this->createMock(WebDriverWait::class); $wait ->expects($this->once()) @@ -48,7 +46,7 @@ public function testRun(bool $enabled, bool $readonly, bool $editable): void ->method('executeScript') ->with( 'return { enabled: !arguments[0].disabled, readonly: arguments[0].readOnly };', - [$element] + [$this->element] ) ->willReturn((object) ['enabled' => $enabled, 'readonly' => $readonly]); $this->command->run('id=name', 123, $this->values, $this->driver); diff --git a/tests/Command/Wait/WaitForElementNotEditableCommandTest.php b/tests/Command/Wait/WaitForElementNotEditableCommandTest.php index f7dc8e95..d4c70123 100644 --- a/tests/Command/Wait/WaitForElementNotEditableCommandTest.php +++ b/tests/Command/Wait/WaitForElementNotEditableCommandTest.php @@ -4,7 +4,6 @@ use Closure; use Facebook\WebDriver\WebDriverBy; -use Facebook\WebDriver\WebDriverElement; use Facebook\WebDriver\WebDriverWait; use Tienvx\Bundle\MbtBundle\Command\Wait\WaitForElementNotEditableCommand; @@ -25,7 +24,6 @@ protected function createCommand(): WaitForElementNotEditableCommand */ public function testRun(bool $enabled, bool $readonly, bool $editable): void { - $element = $this->createMock(WebDriverElement::class); $this->driver ->expects($this->once()) ->method('findElement') @@ -34,7 +32,7 @@ public function testRun(bool $enabled, bool $readonly, bool $editable): void && 'id' === $selector->getMechanism() && 'name' === $selector->getValue(); })) - ->willReturn($element); + ->willReturn($this->element); $wait = $this->createMock(WebDriverWait::class); $wait ->expects($this->once()) @@ -48,7 +46,7 @@ public function testRun(bool $enabled, bool $readonly, bool $editable): void ->method('executeScript') ->with( 'return { enabled: !arguments[0].disabled, readonly: arguments[0].readOnly };', - [$element] + [$this->element] ) ->willReturn((object) ['enabled' => $enabled, 'readonly' => $readonly]); $this->command->run('id=name', 123, $this->values, $this->driver); diff --git a/tests/Command/Wait/WaitForElementNotPresentCommandTest.php b/tests/Command/Wait/WaitForElementNotPresentCommandTest.php index 134c768c..8050fc26 100644 --- a/tests/Command/Wait/WaitForElementNotPresentCommandTest.php +++ b/tests/Command/Wait/WaitForElementNotPresentCommandTest.php @@ -4,7 +4,6 @@ use Facebook\WebDriver\Exception\StaleElementReferenceException; use Facebook\WebDriver\WebDriverBy; -use Facebook\WebDriver\WebDriverElement; use Facebook\WebDriver\WebDriverExpectedCondition; use Facebook\WebDriver\WebDriverWait; use Tienvx\Bundle\MbtBundle\Command\Wait\WaitForElementNotPresentCommand; @@ -26,7 +25,7 @@ protected function createCommand(): WaitForElementNotPresentCommand */ public function testRun(int $elementsCount, bool $stale): void { - $elements = array_fill(0, $elementsCount, $this->createMock(WebDriverElement::class)); + $elements = array_fill(0, $elementsCount, $this->element); $this->driver ->expects($this->once()) ->method('findElements') diff --git a/tests/Command/Wait/WaitForElementNotVisibleCommandTest.php b/tests/Command/Wait/WaitForElementNotVisibleCommandTest.php index e8acc21d..adcedef6 100644 --- a/tests/Command/Wait/WaitForElementNotVisibleCommandTest.php +++ b/tests/Command/Wait/WaitForElementNotVisibleCommandTest.php @@ -5,7 +5,6 @@ use Facebook\WebDriver\Exception\NoSuchElementException; use Facebook\WebDriver\Exception\StaleElementReferenceException; use Facebook\WebDriver\WebDriverBy; -use Facebook\WebDriver\WebDriverElement; use Facebook\WebDriver\WebDriverExpectedCondition; use Facebook\WebDriver\WebDriverWait; use Tienvx\Bundle\MbtBundle\Command\Wait\WaitForElementNotVisibleCommand; @@ -27,7 +26,6 @@ protected function createCommand(): WaitForElementNotVisibleCommand */ public function testRun(bool $displayed, bool $present, bool $stale): void { - $element = $this->createMock(WebDriverElement::class); $mock = $this->driver ->expects($this->once()) ->method('findElement') @@ -37,8 +35,8 @@ public function testRun(bool $displayed, bool $present, bool $stale): void && 'title' === $selector->getValue(); })); if ($present) { - $mock->willReturn($element); - $mock = $element + $mock->willReturn($this->element); + $mock = $this->element ->expects($this->once()) ->method('isDisplayed'); if ($stale) { diff --git a/tests/Command/Wait/WaitForElementPresentCommandTest.php b/tests/Command/Wait/WaitForElementPresentCommandTest.php index 189588eb..89d7ea62 100644 --- a/tests/Command/Wait/WaitForElementPresentCommandTest.php +++ b/tests/Command/Wait/WaitForElementPresentCommandTest.php @@ -4,7 +4,6 @@ use Facebook\WebDriver\Exception\NoSuchElementException; use Facebook\WebDriver\WebDriverBy; -use Facebook\WebDriver\WebDriverElement; use Facebook\WebDriver\WebDriverExpectedCondition; use Facebook\WebDriver\WebDriverWait; use Tienvx\Bundle\MbtBundle\Command\Wait\WaitForElementPresentCommand; @@ -26,7 +25,6 @@ protected function createCommand(): WaitForElementPresentCommand */ public function testRun(bool $present): void { - $element = $this->createMock(WebDriverElement::class); $mock = $this->driver ->expects($this->once()) ->method('findElement') @@ -36,7 +34,7 @@ public function testRun(bool $present): void && 'title' === $selector->getValue(); })); if ($present) { - $mock->willReturn($element); + $mock->willReturn($this->element); } else { $mock->willThrowException(new NoSuchElementException('Element missing')); } diff --git a/tests/Command/Wait/WaitForElementVisibleCommandTest.php b/tests/Command/Wait/WaitForElementVisibleCommandTest.php index c59176b6..90dde3e5 100644 --- a/tests/Command/Wait/WaitForElementVisibleCommandTest.php +++ b/tests/Command/Wait/WaitForElementVisibleCommandTest.php @@ -4,7 +4,6 @@ use Facebook\WebDriver\Exception\StaleElementReferenceException; use Facebook\WebDriver\WebDriverBy; -use Facebook\WebDriver\WebDriverElement; use Facebook\WebDriver\WebDriverExpectedCondition; use Facebook\WebDriver\WebDriverWait; use Tienvx\Bundle\MbtBundle\Command\Wait\WaitForElementVisibleCommand; @@ -26,7 +25,6 @@ protected function createCommand(): WaitForElementVisibleCommand */ public function testRun(bool $displayed, bool $stale): void { - $element = $this->createMock(WebDriverElement::class); $this->driver ->expects($this->once()) ->method('findElement') @@ -35,8 +33,8 @@ public function testRun(bool $displayed, bool $stale): void && 'id' === $selector->getMechanism() && 'title' === $selector->getValue(); })) - ->willReturn($element); - $mock = $element + ->willReturn($this->element); + $mock = $this->element ->expects($this->once()) ->method('isDisplayed'); if ($stale) { diff --git a/tests/Command/Window/SelectFrameCommandTest.php b/tests/Command/Window/SelectFrameCommandTest.php index ac4244e3..4f3a9fe5 100644 --- a/tests/Command/Window/SelectFrameCommandTest.php +++ b/tests/Command/Window/SelectFrameCommandTest.php @@ -4,7 +4,6 @@ use Facebook\WebDriver\Remote\RemoteTargetLocator; use Facebook\WebDriver\WebDriverBy; -use Facebook\WebDriver\WebDriverElement; use Facebook\WebDriver\WebDriverExpectedCondition; use Facebook\WebDriver\WebDriverWait; use Tienvx\Bundle\MbtBundle\Command\Window\SelectFrameCommand; @@ -34,7 +33,6 @@ protected function createCommand(): SelectFrameCommand public function testRun(string $target, string $method, ?array $params): void { if (is_null($params)) { - $element = $this->createMock(WebDriverElement::class); $this->driver ->expects($this->exactly(2)) ->method('findElement') @@ -43,8 +41,8 @@ public function testRun(string $target, string $method, ?array $params): void && 'link text' === $selector->getMechanism() && 'Read More' === $selector->getValue(); })) - ->willReturn($element); - $params = [$element]; + ->willReturn($this->element); + $params = [$this->element]; $wait = $this->createMock(WebDriverWait::class); $wait ->expects($this->once()) diff --git a/tests/EventListener/EntitySubscriberTest.php b/tests/EventListener/EntitySubscriberTest.php index 673fbabb..5e4031d8 100644 --- a/tests/EventListener/EntitySubscriberTest.php +++ b/tests/EventListener/EntitySubscriberTest.php @@ -5,6 +5,7 @@ use Doctrine\ORM\Event\LifecycleEventArgs; use Doctrine\ORM\Events; use Doctrine\Persistence\ObjectManager; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Symfony\Component\Messenger\Envelope; use Symfony\Component\Messenger\MessageBusInterface; @@ -21,9 +22,16 @@ */ class EntitySubscriberTest extends TestCase { + protected MessageBusInterface|MockObject $messageBus; + + protected function setUp(): void + { + $this->messageBus = $this->createMock(MessageBusInterface::class); + } + public function testGetSubscribedEvents(): void { - $subscriber = new EntitySubscriber($this->createMock(MessageBusInterface::class)); + $subscriber = new EntitySubscriber($this->messageBus); $this->assertSame([ Events::postPersist, ], $subscriber->getSubscribedEvents()); @@ -33,13 +41,12 @@ public function testPostPersistBug(): void { $bug = new Bug(); $bug->setId(23); - $messageBus = $this->createMock(MessageBusInterface::class); - $messageBus + $this->messageBus ->expects($this->once()) ->method('dispatch') ->with($this->callback(fn ($message) => $message instanceof ReduceBugMessage && 23 === $message->getId())) ->willReturn(new Envelope(new \stdClass())); - $subscriber = new EntitySubscriber($messageBus); + $subscriber = new EntitySubscriber($this->messageBus); $args = new LifecycleEventArgs($bug, $this->createMock(ObjectManager::class)); $subscriber->postPersist($args); } diff --git a/tests/MessageHandler/RecordVideoMessageHandlerTest.php b/tests/MessageHandler/RecordVideoMessageHandlerTest.php index ba1c8a78..84418553 100644 --- a/tests/MessageHandler/RecordVideoMessageHandlerTest.php +++ b/tests/MessageHandler/RecordVideoMessageHandlerTest.php @@ -2,6 +2,7 @@ namespace Tienvx\Bundle\MbtBundle\Tests\MessageHandler; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Tienvx\Bundle\MbtBundle\Message\RecordVideoMessage; use Tienvx\Bundle\MbtBundle\MessageHandler\RecordVideoMessageHandler; @@ -13,7 +14,7 @@ */ class RecordVideoMessageHandlerTest extends TestCase { - protected BugHelperInterface $bugHelper; + protected BugHelperInterface|MockObject $bugHelper; protected RecordVideoMessageHandler $handler; protected RecordVideoMessage $message; diff --git a/tests/MessageHandler/ReduceBugMessageHandlerTest.php b/tests/MessageHandler/ReduceBugMessageHandlerTest.php index 6d9fe3fa..8d5c6acf 100644 --- a/tests/MessageHandler/ReduceBugMessageHandlerTest.php +++ b/tests/MessageHandler/ReduceBugMessageHandlerTest.php @@ -2,6 +2,7 @@ namespace Tienvx\Bundle\MbtBundle\Tests\MessageHandler; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Tienvx\Bundle\MbtBundle\Message\ReduceBugMessage; use Tienvx\Bundle\MbtBundle\MessageHandler\ReduceBugMessageHandler; @@ -13,7 +14,7 @@ */ class ReduceBugMessageHandlerTest extends TestCase { - protected BugHelperInterface $bugHelper; + protected BugHelperInterface|MockObject $bugHelper; protected ReduceBugMessageHandler $handler; protected ReduceBugMessage $message; diff --git a/tests/MessageHandler/ReduceStepsMessageHandlerTest.php b/tests/MessageHandler/ReduceStepsMessageHandlerTest.php index 5eec79c6..3a45a087 100644 --- a/tests/MessageHandler/ReduceStepsMessageHandlerTest.php +++ b/tests/MessageHandler/ReduceStepsMessageHandlerTest.php @@ -2,6 +2,7 @@ namespace Tienvx\Bundle\MbtBundle\Tests\MessageHandler; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Tienvx\Bundle\MbtBundle\Message\ReduceStepsMessage; use Tienvx\Bundle\MbtBundle\MessageHandler\ReduceStepsMessageHandler; @@ -13,7 +14,7 @@ */ class ReduceStepsMessageHandlerTest extends TestCase { - protected BugHelperInterface $bugHelper; + protected BugHelperInterface|MockObject $bugHelper; protected ReduceStepsMessageHandler $handler; protected ReduceStepsMessage $message; diff --git a/tests/MessageHandler/ReportBugMessageHandlerTest.php b/tests/MessageHandler/ReportBugMessageHandlerTest.php index a1e89fb3..04facf6a 100644 --- a/tests/MessageHandler/ReportBugMessageHandlerTest.php +++ b/tests/MessageHandler/ReportBugMessageHandlerTest.php @@ -2,6 +2,7 @@ namespace Tienvx\Bundle\MbtBundle\Tests\MessageHandler; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Tienvx\Bundle\MbtBundle\Message\ReportBugMessage; use Tienvx\Bundle\MbtBundle\MessageHandler\ReportBugMessageHandler; @@ -13,7 +14,7 @@ */ class ReportBugMessageHandlerTest extends TestCase { - protected BugHelperInterface $bugHelper; + protected BugHelperInterface|MockObject $bugHelper; protected ReportBugMessageHandler $handler; protected ReportBugMessage $message; diff --git a/tests/Reducer/DispatcherTestCase.php b/tests/Reducer/DispatcherTestCase.php index 9629eefe..9be6f841 100644 --- a/tests/Reducer/DispatcherTestCase.php +++ b/tests/Reducer/DispatcherTestCase.php @@ -3,6 +3,7 @@ namespace Tienvx\Bundle\MbtBundle\Tests\Reducer; use PHPUnit\Framework\Constraint\Callback; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Symfony\Component\Messenger\Envelope; use Symfony\Component\Messenger\MessageBusInterface; @@ -15,7 +16,7 @@ abstract class DispatcherTestCase extends TestCase { protected DispatcherInterface $dispatcher; - protected MessageBusInterface $messageBus; + protected MessageBusInterface|MockObject $messageBus; protected BugInterface $bug; protected array $pairs = []; diff --git a/tests/Reducer/Random/RandomReducerTest.php b/tests/Reducer/Random/RandomReducerTest.php index 4d7066db..3b4b2004 100644 --- a/tests/Reducer/Random/RandomReducerTest.php +++ b/tests/Reducer/Random/RandomReducerTest.php @@ -2,6 +2,7 @@ namespace Tienvx\Bundle\MbtBundle\Tests\Reducer\Random; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Tienvx\Bundle\MbtBundle\Entity\Bug; use Tienvx\Bundle\MbtBundle\Reducer\Random\RandomDispatcher; @@ -18,8 +19,8 @@ */ class RandomReducerTest extends TestCase { - protected RandomDispatcher $dispatcher; - protected RandomHandler $handler; + protected RandomDispatcher|MockObject $dispatcher; + protected RandomHandler|MockObject $handler; protected RandomReducer $reducer; protected function setUp(): void diff --git a/tests/Reducer/Split/SplitReducerTest.php b/tests/Reducer/Split/SplitReducerTest.php index 63fb9e32..a5c92992 100644 --- a/tests/Reducer/Split/SplitReducerTest.php +++ b/tests/Reducer/Split/SplitReducerTest.php @@ -2,6 +2,7 @@ namespace Tienvx\Bundle\MbtBundle\Tests\Reducer\Split; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Tienvx\Bundle\MbtBundle\Entity\Bug; use Tienvx\Bundle\MbtBundle\Reducer\ReducerManager; @@ -18,8 +19,8 @@ */ class SplitReducerTest extends TestCase { - protected SplitDispatcher $dispatcher; - protected SplitHandler $handler; + protected SplitDispatcher|MockObject $dispatcher; + protected SplitHandler|MockObject $handler; protected SplitReducer $reducer; protected function setUp(): void diff --git a/tests/Repository/BugRepositoryTest.php b/tests/Repository/BugRepositoryTest.php index 9aca76e6..217e095e 100644 --- a/tests/Repository/BugRepositoryTest.php +++ b/tests/Repository/BugRepositoryTest.php @@ -7,6 +7,7 @@ use Doctrine\ORM\Decorator\EntityManagerDecorator; use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\Persistence\ManagerRegistry; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Tienvx\Bundle\MbtBundle\Entity\Bug; use Tienvx\Bundle\MbtBundle\Entity\Progress; @@ -25,7 +26,7 @@ */ class BugRepositoryTest extends TestCase { - protected EntityManagerDecorator $manager; + protected EntityManagerDecorator|MockObject $manager; protected BugInterface $bug; protected BugRepositoryInterface $bugRepository; protected Connection $connection; diff --git a/tests/Service/Bug/BugHelperTest.php b/tests/Service/Bug/BugHelperTest.php index 63596ba5..40af8967 100644 --- a/tests/Service/Bug/BugHelperTest.php +++ b/tests/Service/Bug/BugHelperTest.php @@ -3,6 +3,7 @@ namespace Tienvx\Bundle\MbtBundle\Tests\Service\Bug; use Exception; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Symfony\Component\Messenger\Envelope; use Symfony\Component\Messenger\Exception\RecoverableMessageHandlingException; @@ -43,12 +44,12 @@ */ class BugHelperTest extends TestCase { - protected ReducerManagerInterface $reducerManager; - protected BugRepositoryInterface $bugRepository; - protected MessageBusInterface $messageBus; - protected BugNotifierInterface $bugNotifier; - protected BugStepsRunner $stepsRunner; - protected ConfigInterface $config; + protected ReducerManagerInterface|MockObject $reducerManager; + protected BugRepositoryInterface|MockObject $bugRepository; + protected MessageBusInterface|MockObject $messageBus; + protected BugNotifierInterface|MockObject $bugNotifier; + protected BugStepsRunner|MockObject $stepsRunner; + protected ConfigInterface|MockObject $config; protected BugHelperInterface $helper; protected Revision $revision; protected BugInterface $bug; diff --git a/tests/Service/Step/Builder/PetrinetDomainLogicTest.php b/tests/Service/Step/Builder/PetrinetDomainLogicTest.php index 08593ab4..aa273cf5 100644 --- a/tests/Service/Step/Builder/PetrinetDomainLogicTest.php +++ b/tests/Service/Step/Builder/PetrinetDomainLogicTest.php @@ -3,6 +3,7 @@ namespace Tienvx\Bundle\MbtBundle\Tests\Service\Step\Builder; use Petrinet\Model\MarkingInterface; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use SingleColorPetrinet\Model\Color; use SingleColorPetrinet\Model\ColorfulMarking; @@ -23,9 +24,9 @@ */ class PetrinetDomainLogicTest extends TestCase { - protected GuardedTransitionServiceInterface $transitionService; - protected MarkingHelperInterface $markingHelper; - protected PetrinetInterface $petrinet; + protected GuardedTransitionServiceInterface|MockObject $transitionService; + protected MarkingHelperInterface|MockObject $markingHelper; + protected PetrinetInterface|MockObject $petrinet; protected PetrinetDomainLogic $petrinetDomainLogic; protected array $transitions; protected array $markings; diff --git a/tests/Service/Step/Runner/StepRunnerTest.php b/tests/Service/Step/Runner/StepRunnerTest.php index bb90febe..342fc16a 100644 --- a/tests/Service/Step/Runner/StepRunnerTest.php +++ b/tests/Service/Step/Runner/StepRunnerTest.php @@ -3,6 +3,7 @@ namespace Tienvx\Bundle\MbtBundle\Tests\Service\Step\Runner; use Facebook\WebDriver\Remote\RemoteWebDriver; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use SingleColorPetrinet\Model\ColorInterface; use Tienvx\Bundle\MbtBundle\Command\CommandManager; @@ -30,9 +31,9 @@ class StepRunnerTest extends TestCase { protected RevisionInterface $revision; protected array $commands = []; - protected CommandManager $commandManager; + protected CommandManager|MockObject $commandManager; protected RemoteWebDriver $driver; - protected ColorInterface $color; + protected ColorInterface|MockObject $color; protected array $valuesInstances = []; protected function setUp(): void