setCallingFrom(new \DateTime('09:00')); $script->setCallingTo(new \DateTime('18:00')); $this->validate($script, null); } public function testAnEmptyWindowIsValid(): void { $this->validate(new CallScript(), null); } public function testPartialHoursAreRefused(): void { $script = new CallScript(); $script->setCallingFrom(new \DateTime('09:00')); $this->validate($script, 'mt3s.call_script.calling_window.partial_hours'); } public function testTheEndMustBeAfterTheStart(): void { $script = new CallScript(); $script->setCallingFrom(new \DateTime('18:00')); $script->setCallingTo(new \DateTime('09:00')); $this->validate($script, 'mt3s.call_script.calling_window.to_before_from'); } public function testAFixedModeNeedsATimezone(): void { $script = new CallScript(); $script->setCallingTimezoneMode(CallScriptTimezoneMode::Fixed); $this->validate($script, 'mt3s.call_script.calling_window.timezone_required'); } public function testAFixedModeWithATimezoneIsValid(): void { $script = new CallScript(); $script->setCallingTimezoneMode(CallScriptTimezoneMode::Fixed); $script->setCallingTimezone('Europe/Paris'); $this->validate($script, null); } private function validate(CallScript $script, ?string $expectedMessage): void { $violation = $this->createMock(ConstraintViolationBuilderInterface::class); $violation->method('atPath')->willReturnSelf(); $context = $this->createMock(ExecutionContextInterface::class); if (null === $expectedMessage) { $context->expects(self::never())->method('buildViolation'); } else { $context->expects(self::once()) ->method('buildViolation') ->with($expectedMessage) ->willReturn($violation); $violation->expects(self::once())->method('addViolation'); } $validator = new ValidCallingWindowValidator(); $validator->initialize($context); $validator->validate($script, new ValidCallingWindow()); } }