/** * @dataProvider validDataProvider */ public function testValidData(array $perfomanceEvents) { $newPerformanceEvent = new PerformanceEvent(); $newPerformanceEvent->setDateTime(new \DateTime()); $validator = new TwoPerformanceEventsPerDayValidator($this->getPerformanceEventRepositoryMock($perfomanceEvents), $this->translator); $validator->initialize($this->context); $this->context->expects($this->exactly(0))->method('addViolationAt')->with('dateTime', $this->translator->trans($this->constraint->max_performances_per_day, ['%count%' => TwoPerformanceEventsPerDayValidator::MAX_PERFORMANCE_EVENTS_PER_ONE_DAY])); $validator->validate($newPerformanceEvent, $this->constraint); }
/** * @param PerformanceEvent $performanceEvent * @return bool */ protected function isMoreThanMax(PerformanceEvent $performanceEvent) { $from = clone $performanceEvent->getDateTime(); $from->setTime(00, 00, 00); $to = clone $performanceEvent->getDateTime(); $to->setTime(23, 59, 59); $countPerformanceEventsPerDate = count($this->repository->findByDateRangeAndSlug($from, $to)); if ($performanceEvent->getId()) { return $countPerformanceEventsPerDate >= self::MAX_PERFORMANCE_EVENTS_PER_ONE_DAY + 1; } else { return $countPerformanceEventsPerDate >= self::MAX_PERFORMANCE_EVENTS_PER_ONE_DAY; } }