public function testGetByClass() { $repository = new CheckRepository(); $repository->registerCheck($this->createMock(CheckInterface::class)); $check = $this->createMock(CheckInterface::class); $repository->registerCheck($check); $this->assertSame($check, $repository->getByClass(get_class($check))); }
/** * @param string $requiredCheck * @throws InvalidArgumentException */ public function requireListenableCheck($requiredCheck) { if (!$this->checkRepository->has($requiredCheck)) { throw new InvalidArgumentException(sprintf('Check: "%s" does not exist', $requiredCheck)); } $check = $this->checkRepository->getByClass($requiredCheck); if (!$check instanceof ListenableCheckInterface) { throw new InvalidArgumentException(sprintf('Check: "%s" is not a listenable check', $requiredCheck)); } $check->attach($this->eventDispatcher); }
/** * Queue a specific check to be run when the exercise is verified. When the exercise is verified * the check specified as the first argument will also be executed. Throws an `InvalidArgumentException` * if the check does not exist in the `CheckRepository`. * * @param string $requiredCheck The name of the required check. * @throws InvalidArgumentException If the check does not exist. */ public function requireCheck($requiredCheck) { if (!$this->checkRepository->has($requiredCheck)) { throw new InvalidArgumentException(sprintf('Check: "%s" does not exist', $requiredCheck)); } $check = $this->checkRepository->getByClass($requiredCheck); if ($check instanceof SimpleCheckInterface) { switch ($check->getPosition()) { case SimpleCheckInterface::CHECK_BEFORE: $this->checksToRunBefore[] = $check; break; case SimpleCheckInterface::CHECK_AFTER: $this->checksToRunAfter[] = $check; break; default: throw InvalidArgumentException::notValidParameter('position', [SimpleCheckInterface::CHECK_BEFORE, SimpleCheckInterface::CHECK_AFTER], $check->getPosition()); } return; } if (!$check instanceof ListenableCheckInterface) { throw new InvalidArgumentException(sprintf('Check: "%s" is not a listenable check', $requiredCheck)); } $check->attach($this->eventDispatcher); }